//查询图片所属分类 static public Packet GetClass(HttpContext context, int nCommand, ref string strError) { try { UInt32 nProjectID = CommandTool.ReqUint(context, "ProjectID"); UInt32 nPartID = CommandTool.ReqUint(context, "PartID"); UInt32 nImageID = CommandTool.ReqUint(context, "ImageID"); byte bIsFD = 0; PacketTable table = new PacketTable(); table.AddField("ProjectID", PacketTable.FieldType.TypeUint); table.AddField("PartID", PacketTable.FieldType.TypeUint); table.AddField("ImageID", PacketTable.FieldType.TypeUint); table.AddField("IsFD", PacketTable.FieldType.TypeByte); table.MakeTable(1); table.SetValue(0, 0, nProjectID); table.SetValue(0, 1, nPartID); table.SetValue(0, 2, nImageID); table.SetValue(0, 3, (byte)bIsFD); PacketTable[] arrTable = new PacketTable[1]; arrTable[0] = table; ServerConnection conn = new ServerConnection(); Packet recvPacket = conn.ExecuteCommand(nCommand, arrTable, 2); return(recvPacket); } catch (Exception ex) { strError = "CmdQuery-GetClass 错误:" + ex.Message; return(null); } }
public bool Process(AsyncSocketUserToken oUserToken, byte[] bytes, int offset, int count) { if (count < sizeof(int)) { return(false); // 判断包长度是否小于一个命令的长度 } int oPacketID = BitConverter.ToInt32(bytes, offset); // 获取命令ID IPacket oPacket = null; if (PacketTable.TryGetValue(oPacketID, out oPacket)) { IPacketCreate oIPacket = oPacket as IPacketCreate; IPacket oNewPacket = oIPacket.New() as IPacket; try { DynamicBuffer buffer = new DynamicBuffer(bytes, offset + sizeof(int), bytes.Length - offset - sizeof(int)); oNewPacket.Deserialization(buffer); oNewPacket.PacketID = oPacketID; oNewPacket.Owner = oUserToken; Packets.Enqueue(oNewPacket); return(true); } catch (Exception e) { Console.WriteLine(e); return(false); } } else { return(true); } }
private void AssemblyPacket() { List <Type> typeList = new List <Type>(); Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies(); for (int i = 0; i < assemblies.Length; i++) { typeList.AddRange(assemblies[i].GetTypes()); } Type[] types = typeList.ToArray(); for (int i = 0; i < types.Length; i++) { Type type = types[i]; object[] objs = type.GetCustomAttributes(typeof(ProtocolAttribute), false); if (objs.Length > 0) { // 如果包含包属性,则创建对象 object obj = Activator.CreateInstance(type); ProtocolAttribute oAttr = objs[0] as ProtocolAttribute; if (oAttr.Type == ProcessType.Receive) { IPacket oPacket = obj as IPacket; PacketTable.Add(oAttr.ID, oPacket); } else if (oAttr.Type == ProcessType.Process) { IProtocolProcess oProtocol = obj as IProtocolProcess; ProtocolTable.Add(oAttr.ID, oProtocol); } } } }
static public List <DM_ModelSortClass> StatSortClass(ServerConnection conn, UInt32 nProjectID, UInt32 nPartID, int nTopN, Period period, ref string strError) { if (conn == null) { conn = new ServerConnection(); } List <DM_ModelSortClass> arrSortClass = new List <DM_ModelSortClass>(); PacketTable sendTable = new PacketTable(); sendTable.AddField("LastNum", PacketTable.FieldType.TypeInt); sendTable.AddField("FromDate", PacketTable.FieldType.TypeDateTime); sendTable.AddField("ToDate", PacketTable.FieldType.TypeDateTime); sendTable.AddField("ProjectID", PacketTable.FieldType.TypeUint); sendTable.AddField("PartID", PacketTable.FieldType.TypeUint); sendTable.AddField("ClassID", PacketTable.FieldType.TypeUint); sendTable.AddField("IsFD", PacketTable.FieldType.TypeByte); sendTable.AddField("DataStatus", PacketTable.FieldType.TypeByte); sendTable.AddField("TopN", PacketTable.FieldType.TypeInt); sendTable.AddField("PeriodUnit", PacketTable.FieldType.TypeInt); sendTable.MakeTable(1); sendTable.SetValue(0, 0, period.LastNum); sendTable.SetValue(0, 1, period.DateFrom); sendTable.SetValue(0, 2, period.DateTo); sendTable.SetValue(0, 3, nProjectID); sendTable.SetValue(0, 4, nPartID); sendTable.SetValue(0, 5, (uint)0); sendTable.SetValue(0, 6, (byte)0); sendTable.SetValue(0, 7, (byte)1); sendTable.SetValue(0, 8, period.LastNum); sendTable.SetValue(0, 9, (int)1); PacketTable[] arrSendTable = new PacketTable[1]; arrSendTable[0] = sendTable; Packet recvPacket = conn.ExecuteCommand(204, arrSendTable); PacketTable[] arrRecvTable = conn.ReadTable(recvPacket); if (arrRecvTable == null) { strError = conn.ErrorMessage; return(null); } PacketTable recvTable = arrRecvTable[4]; int nIndexClassName = recvTable.GetFieldIndex("ClassName"); int nIndexPassrate = recvTable.GetFieldIndex("Passrate"); for (int i = 0; i < recvTable.Rows && i < nTopN; i++) { DM_ModelSortClass passrate = new DM_ModelSortClass(); passrate.ClassName = (string)recvTable.GetValue(i, nIndexClassName); passrate.Passrate = (float)recvTable.GetValue(i, nIndexPassrate); arrSortClass.Add(passrate); } return(arrSortClass); }
//查询文报告PDF文件 static public Packet GetReportPDF(HttpContext context, int nCommand, ref string strError) { try { string strFileUrl = CommandTool.ReqString(context, "PDFName"); PacketTable table = new PacketTable(); table.AddField("PDFName", PacketTable.FieldType.TypeString); table.MakeTable(1); table.SetValue(0, 0, strFileUrl); PacketTable[] arrTable = new PacketTable[1]; arrTable[0] = table; //连接服务器 ServerConnection conn = new ServerConnection(); Packet recvPacket = conn.ExecuteCommand(nCommand, arrTable); return(recvPacket); } catch (Exception ex) { strError = "CmdQuery-GetClass 错误:" + ex.Message; return(null); } }
private static Packet writeMeasureFile(DM_ModelProject modelProject, DM_ModelPart modelPart, DM_WorkPlace modelWorkPalce, DM_ModelWorkshop modelWorkShop, DataTable dtPoint, DataTable dtInfo, string strProgressName, ref string strError) { DateTime dtNow = DateTime.Now; MeasureFile file = new MeasureFile(); string strFileName = FileFun.CreateFileName(dtNow, "MeasureFile.txt"); string strFilePath = HttpContext.Current.Server.MapPath("~") + "\\MeasureFile\\" + strFileName; MeasureFileHead head = new MeasureFileHead(); head.MeasureDate = dtNow.Year + "-" + dtNow.Month + "-" + dtNow.Day; head.MeasureTime = dtNow.Hour + ":" + dtNow.Minute + ":" + dtNow.Second; head.ProjectName = modelProject.ProjectName; head.ProjectNo = modelProject.ProjectNo; head.PartName = modelPart.PartName; head.PartNo = modelPart.PartNO; head.SerNumber = ""; head.ComPonent = ""; head.Progress = strProgressName; head.WorkPlace = modelWorkPalce.WorkPlaceName; head.WorkShop = modelWorkShop.WorkshopName; file.FileHead = head; for (int i = 0; i < dtPoint.Rows.Count; i++) { string strPointName = dtPoint.Rows[i]["PointName"].ToString(); string strPointID = dtPoint.Rows[i]["PointID"].ToString(); float fMeas = dtPoint.Rows[i]["Value"].ToString() == "" ? MeasureFileBase.GlobalData.NULL_NUM : Convert.ToSingle(dtPoint.Rows[i]["Value"]); DataRow[] nomRows = dtInfo.Select("PointID = " + strPointID); float fNom = nomRows[0]["Nominal"].ToString() == "" ? MeasureFileBase.GlobalData.NULL_NUM : Convert.ToSingle(nomRows[0]["Nominal"]); float fUpTol = nomRows[0]["UpTol"].ToString() == "" ? MeasureFileBase.GlobalData.NULL_NUM : Convert.ToSingle(nomRows[0]["UpTol"]); float fLowTol = nomRows[0]["LowTol"].ToString() == "" ? MeasureFileBase.GlobalData.NULL_NUM : Convert.ToSingle(nomRows[0]["LowTol"]); MeasurePoint point = new MeasurePoint(strPointName, fMeas, fNom, fUpTol, fLowTol); file.AddPoint(point); } if (file.Save(strFilePath)) { byte[] byFileData = null; using (FileStream fs = new FileStream(strFilePath, FileMode.Open, FileAccess.Read)) { byFileData = new byte[(int)fs.Length]; fs.Read(byFileData, 0, (int)fs.Length); } PacketTable table = new PacketTable(); table.AddField("FileName", PacketTable.FieldType.TypeString); table.AddField("File", PacketTable.FieldType.TypeImage); table.MakeTable(1); table.SetValue(0, 0, strFileName); table.SetValue(0, 1, byFileData); PacketTable[] TableArray = new PacketTable[1]; TableArray[0] = table; ServerConnection conn = new ServerConnection(); Packet recvPacket = conn.ExecuteCommand(10001, TableArray); return(recvPacket); } else { strError = "生成文件或者上传文件出错!"; return(null); } }
/// <summary> /// Checks all types in executing assmebly and registers packets. /// </summary> public static void RegisterPackets() { // Load tables LoadTables("Data\\PacketTables.xml"); // Load packets Type[] types = Assembly.GetExecutingAssembly().GetTypes(); foreach (Type type in types) { UltimaPacketAttribute[] attrs = (UltimaPacketAttribute[])type.GetCustomAttributes(typeof(UltimaPacketAttribute), false); if (attrs.Length == 1) { UltimaPacketAttribute ultimaPacket = attrs[0]; if (ultimaPacket.Ids == null || ultimaPacket.Ids.Length == 0) { throw new SpyException("Packet {0} must have at least one ID", type); } PacketTable.RegisterPacket(type, ultimaPacket, 0); } else if (attrs.Length > 1) { throw new SpyException("Class {0} has too many UltimaPacket attributes", type); } } DefaultDefinition = new UltimaPacketDefinition(typeof(UltimaPacket), null); }
static private DM_WorkPlace getWorkInfo(UInt32 nProjectID, UInt32 nPartID, UInt32 nWorkProgressID) { PacketTable[] TableArray = new PacketTable[1]; PacketTable table = new PacketTable(); table.AddField("ProjectID", PacketTable.FieldType.TypeUint); table.AddField("PartID", PacketTable.FieldType.TypeUint); table.AddField("WorkProgressID", PacketTable.FieldType.TypeUint); table.MakeTable(1); table.SetValue(0, 0, nProjectID); table.SetValue(0, 1, nPartID); table.SetValue(0, 2, nWorkProgressID); TableArray[0] = table; ServerConnection connect = new ServerConnection(); Packet packet = connect.ExecuteCommand(26, TableArray, 2); DataTable dt = outWorkInfo(packet); DM_WorkPlace workPlace = new DM_WorkPlace(); workPlace.ParentID = (UInt32)dt.Rows[0]["ParentID"]; workPlace.Type = (int)dt.Rows[0]["Type"]; workPlace.WorkPlaceID = (UInt32)dt.Rows[0]["WorkPlaceID"]; workPlace.WorkPlaceName = dt.Rows[0]["WorkPlaceName"].ToString(); workPlace.WorkPlaceNO = dt.Rows[0]["WorkPlaceNO"].ToString(); workPlace.WorkshopID = (UInt32)dt.Rows[0]["WorkshopID"]; return(workPlace); }
static private DM_ModelPart getPartInfo(UInt32 nProjectID, UInt32 nPartID) { PacketTable[] TableArray = new PacketTable[1]; PacketTable table = new PacketTable(); table.AddField("ProjectID", PacketTable.FieldType.TypeUint); table.AddField("PartID", PacketTable.FieldType.TypeUint); table.AddField("PartName", PacketTable.FieldType.TypeString); table.MakeTable(1); table.SetValue(0, 0, nProjectID); table.SetValue(0, 1, nPartID); table.SetValue(0, 2, ""); TableArray[0] = table; ServerConnection connect = new ServerConnection(); Packet packet = connect.ExecuteCommand(14, TableArray); DataTable dt = outWorkInfo(packet); DM_ModelPart part = new DM_ModelPart(); part.PartOrder = (int)dt.Rows[0]["PartOrder"]; part.PartID = (UInt32)dt.Rows[0]["PartID"]; part.PartName = dt.Rows[0]["PartName"].ToString(); part.PartNO = dt.Rows[0]["PartNO"].ToString(); part.ParentID = (UInt32)dt.Rows[0]["ParentID"]; return(part); }
static public List <DM_Factory> GetFactoryArray(ServerConnection conn, ref string strError) { if (conn == null) { conn = new ServerConnection(); } //查询工厂信息 PacketTable[] arrSendTable = new PacketTable[0]; Packet recvPacket = conn.ExecuteCommand(4, arrSendTable); PacketTable[] arrRecvTable = conn.ReadTable(recvPacket); if (arrRecvTable == null) { strError = conn.ErrorMessage; return(null); } List <DM_Factory> arrFactory = new List <DM_Factory>(); PacketTable recvTable = arrRecvTable[0]; int nIndexFactoryName = recvTable.GetFieldIndex("FactoryName"); int nIndexDatabaseID = recvTable.GetFieldIndex("DatabaseID"); int nIndexServerID = recvTable.GetFieldIndex("ServerID"); for (int nRow = 0; nRow < recvTable.Rows; nRow++) { DM_Factory factory = new DM_Factory(); factory.ServerID = (int)recvTable.GetValue(nRow, nIndexServerID); factory.DatabaseID = (int)recvTable.GetValue(nRow, nIndexDatabaseID); factory.FactoryName = (string)recvTable.GetValue(nRow, nIndexFactoryName); arrFactory.Add(factory); } return(arrFactory); }
static public List <DM_ModelProject> GetProjectArray(ServerConnection conn, ref string strError) { if (conn == null) { conn = new ServerConnection(); } PacketTable[] arrSendTable = new PacketTable[0]; Packet recvPacket = conn.ExecuteCommand(1, arrSendTable); PacketTable[] arrRecvTable = conn.ReadTable(recvPacket); if (arrRecvTable == null) { strError = conn.ErrorMessage; return(null); } PacketTable recvTable = arrRecvTable[0]; int nIndexProjectID = recvTable.GetFieldIndex("ProjectID"); int nIndexProjectName = recvTable.GetFieldIndex("ProjectName"); List <DM_ModelProject> arrProject = new List <DM_ModelProject>(); for (int i = 0; i < recvTable.Rows; i++) { DM_ModelProject project = new DM_ModelProject(); project.ProjectID = (uint)recvTable.GetValue(i, nIndexProjectID); project.ProjectName = (string)recvTable.GetValue(i, nIndexProjectName); arrProject.Add(project); } return(arrProject); }
public async Task <bool> RunScan(CancellationTokenSource token, PacketDevice pd) { return(await Task.Run(async() => { using (var communicator = pd.Open(65536, PacketDeviceOpenAttributes.Promiscuous, 1000)) { using (var filter = communicator.CreateFilter("ip and udp")) { communicator.SetFilter(filter); } var packetTable = new PacketTable(); do { Packet packet; var result = communicator.ReceivePacket(out packet); switch (result) { case PacketCommunicatorReceiveResult.Ok: if (packet.IpV4 == null) { continue; } var ip = packet.Ethernet.IpV4; var udp = ip.Udp; var packetItem = new PacketLogItem { Destination = ip.Destination.ToString(), DestinationPort = udp.DestinationPort, Size = packet.Length, Source = ip.Source.ToString(), SourcePort = udp.SourcePort, TimeStamp = DateTime.Now }; OnNewPacketEntry(packetItem); await packetTable.WritePacketAsync(packetItem); break; } if (token.IsCancellationRequested) { return true; } } while (true); return true; } }, token.Token)); }
// в потоке клиента нельзя вызывать, только из потока событий unity static private int create_table(PacketHeader packet) { maxid++; PacketCreate create = UnityEngine.JsonUtility.FromJson <PacketCreate>(packet.json_data); delete(create.idname); PacketTable data = UnityEngine.JsonUtility.FromJson <PacketTable>(packet.json_data); tables[maxid] = table.Create(data.model, data.x, data.y, data.z, data.ex, data.ey, data.ez, data.scale, data.kinematic); idnames[create.idname] = maxid; return(maxid); }
/// <summary> /// 解析包中的表格信息 /// </summary> /// <param name="packet"></param> /// <returns>发生错误时,返回null,错误信息由ErrorMessage提供</returns> public PacketTable[] ReadTable(Packet packet) { if (packet == null) { ErrorMessage = "服务器错误"; return(null); } byte nResult = 0; if (!packet.Read(ref nResult)) { ErrorMessage = "无法读取执行的结果"; return(null); } string strMessage = ""; if (!packet.Read(ref strMessage)) { ErrorMessage = "无法读取执行结果提示信息!"; return(null); } if (nResult == 0) { return(null); } int nTableCount = 0; if (!packet.Read(ref nTableCount)) { ErrorMessage = "无法读取参数表的数量"; return(null); } PacketTable[] recvTables = new PacketTable[nTableCount]; for (int i = 0; i < nTableCount; i++) { PacketTable table = new PacketTable(); if (!packet.Read(ref table)) { ErrorMessage = "无法表格信息"; return(null); } recvTables[i] = table; } return(recvTables); }
//查询项目 static public Packet GetProjectArray(HttpContext context, int nCommand, ref string strError) { try { PacketTable[] arrTable = new PacketTable[0]; //连接服务器 ServerConnection conn = new ServerConnection(); Packet recvPacket = conn.ExecuteCommand(nCommand, arrTable); return(recvPacket); } catch (Exception ex) { strError = "CmdQuery-GetProjectArray:错误" + ex.Message; return(null); } }
//查询零件 static public List <DM_ModelPart> GetPartArray(ServerConnection conn, UInt32 nProjectID, ref string strError) { if (conn == null) { conn = new ServerConnection(); } PacketTable sendTable = new PacketTable(); sendTable.AddField("ProjectID", PacketTable.FieldType.TypeUint); sendTable.MakeTable(1); sendTable.SetValue(0, 0, nProjectID); PacketTable[] arrSendTable = new PacketTable[1]; arrSendTable[0] = sendTable; Packet recvPacket = conn.ExecuteCommand(2, arrSendTable); PacketTable[] arrRecvTable = conn.ReadTable(recvPacket); if (arrRecvTable == null) { strError = conn.ErrorMessage; return(null); } PacketTable recvTable = arrRecvTable[0]; int nIndexPartID = recvTable.GetFieldIndex("PartID"); int nIndexParentID = recvTable.GetFieldIndex("ParentID"); int nIndexPartName = recvTable.GetFieldIndex("PartName"); List <DM_ModelPart> arrPart = new List <DM_ModelPart>(); for (int i = 0; i < recvTable.Rows; i++) { DM_ModelPart part = new DM_ModelPart(); part.PartID = (uint)recvTable.GetValue(i, nIndexPartID); part.ParentID = (uint)recvTable.GetValue(i, nIndexParentID); part.PartName = (string)recvTable.GetValue(i, nIndexPartName); arrPart.Add(part); } return(arrPart); }
//统计报警 static public List <Packet> StatFileAlarm(HttpContext context, int nCommand, ref string strError) { try { List <Packet> arrPacket = new List <Packet>(); UInt32 nProjectID = CommandTool.ReqUint(context, "ProjectID"); int nLastNum = 30; string strPartID = CommandTool.ReqString(context, "PartID");; UInt32 nNominalID = 0; UInt32 nProgressID = 0; string strRuleIDs = ""; string[] nPartID = strPartID.Split(','); foreach (var PartID in nPartID) { PacketTable table = new PacketTable(); table.AddField("ProjectID", PacketTable.FieldType.TypeUint); table.AddField("LastNum", PacketTable.FieldType.TypeInt); table.AddField("PartID", PacketTable.FieldType.TypeUint); table.AddField("NominalID", PacketTable.FieldType.TypeUint); table.AddField("ProgressID", PacketTable.FieldType.TypeUint); table.AddField("RuleIDs", PacketTable.FieldType.TypeString); table.MakeTable(1); table.SetValue(0, 0, nProjectID); table.SetValue(0, 1, nLastNum); table.SetValue(0, 2, UInt32.Parse(PartID)); table.SetValue(0, 3, nNominalID); table.SetValue(0, 4, nProgressID); table.SetValue(0, 5, strRuleIDs); PacketTable[] arrTable = new PacketTable[1]; arrTable[0] = table; //连接服务器 ServerConnection conn = new ServerConnection(); Packet recvPacket = conn.ExecuteCommand(nCommand, arrTable); arrPacket.Add(recvPacket); } return(arrPacket); } catch (Exception ex) { strError = "CmdQuery_GetPartArray:错误" + ex.Message; return(null); } }
static public Packet GetQueryUser(HttpContext context, int nCommand, ref string strError) { string strUserName = CommandTool.ReqString(context, "UserName"); string strPassword = CommandTool.ReqString(context, "Password"); ServerConnection conn = new ServerConnection(1);//连接主服务器 PacketTable table = new PacketTable(); table.AddField("UserNO", PacketTable.FieldType.TypeString); table.AddField("Password", PacketTable.FieldType.TypeString); table.MakeTable(1); table.SetValue(0, 0, strUserName); table.SetValue(0, 1, strPassword); PacketTable[] arrTable = new PacketTable[1]; arrTable[0] = table; Packet recvPacket = conn.ExecuteCommand(nCommand, arrTable); return(recvPacket); }
static void Main(string[] args) { //Initializes the server on port 35565. MaxPlayers=4 NetworkManager.Init(35565, 4); //Initialize Content CommandTable.Init(); PacketTable.Init(); PacketManager.Lock(); //Locks the PacketManager. //Start Game Logic GameStarter.Start(Game.Start, Game.Stop, Game.Update); //Start listening for clients NetworkManager.StartListener(); _isRunning = true; StartCommandLoop(); }
//查询所属分类的下点的名义值、上下公差 static public Packet GetNominal(HttpContext context, int nCommand, ref string strError, string strClassID) { try { if (strClassID == "") { return(null); } UInt32 nClassID = Convert.ToUInt32(strClassID); UInt32 nProjectID = CommandTool.ReqUint(context, "ProjectID"); UInt32 nPartID = CommandTool.ReqUint(context, "PartID"); UInt32 nPointID = 0; byte bIsFD = 0; PacketTable table = new PacketTable(); table.AddField("ProjectID", PacketTable.FieldType.TypeUint); table.AddField("PartID", PacketTable.FieldType.TypeUint); table.AddField("ClassID", PacketTable.FieldType.TypeUint); table.AddField("PointID", PacketTable.FieldType.TypeUint); table.AddField("IsFD", PacketTable.FieldType.TypeByte); table.MakeTable(1); table.SetValue(0, 0, nProjectID); table.SetValue(0, 1, nPartID); table.SetValue(0, 2, nClassID); table.SetValue(0, 3, nPointID); table.SetValue(0, 4, (byte)bIsFD); PacketTable[] arrTable = new PacketTable[1]; arrTable[0] = table; ServerConnection conn = new ServerConnection(); Packet recvPacket = conn.ExecuteCommand(nCommand, arrTable); return(recvPacket); } catch (Exception ex) { strError = "CmdQuery-GetNominal:错误 " + ex.Message; return(null); } }
/// <summary> /// Constructs packet based on packet IDs. /// </summary> /// <param name="data">Data client sent or received.</param> /// <param name="fromClient">Determines whehter the client sent or received data.</param> /// <param name="time">Date and time packet was received.</param> /// <returns>Ultima packet.</returns> public static UltimaPacket ConstructPacket(byte[] data, bool fromClient, DateTime time) { byte id = 0; string ids = null; UltimaPacketDefinition definition = PacketTable.GetPacket(data, fromClient, ref id, ref ids); UltimaPacket packet = null; if (definition == null) { definition = DefaultDefinition; packet = new UltimaPacket(); } else { packet = definition.Constructor(); } packet.Definition = definition; packet.Data = data; packet.FromClient = fromClient; packet.DateTime = time; packet.ID = id; packet.Ids = ids; if (definition.Attribute != null) { packet.Name = definition.Attribute.Name; } else { packet.Name = "Unknown Packet"; } using (MemoryStream stream = new MemoryStream(data)) { packet.Parse(new BigEndianReader(stream)); } return(packet); }
static private DM_ModelWorkshop getWorkShop(UInt32 nWorkShopID) { PacketTable[] TableArray = new PacketTable[1]; PacketTable table = new PacketTable(); table.AddField("WorkshopID", PacketTable.FieldType.TypeUint); table.AddField("WorkshopName", PacketTable.FieldType.TypeString); table.MakeTable(1); table.SetValue(0, 0, nWorkShopID); table.SetValue(0, 1, ""); TableArray[0] = table; ServerConnection connect = new ServerConnection(); Packet packet = connect.ExecuteCommand(24, TableArray); DataTable dt = outWorkInfo(packet); DM_ModelWorkshop workshop = new DM_ModelWorkshop(); workshop.WorkshopID = (UInt32)dt.Rows[0]["WorkshopID"]; workshop.WorkshopNO = dt.Rows[0]["WorkshopNO"].ToString(); workshop.WorkshopName = dt.Rows[0]["WorkshopName"].ToString(); return(workshop); }
//统计分类合格率 static protected Packet StatGroupPassRate(byte nOption, HttpContext context, int nCommand, ref string strError) { try { UInt32 nProjectID = CommandTool.ReqUint(context, "ProjectID"); UInt32 nPartID = CommandTool.ReqUint(context, "PartID"); UInt32 nProgressID = CommandTool.ReqUint(context, "ProgressID"); UInt32 nClassID = 0; byte bIsFD = 0; int nLastNum = 10; PacketTable table = new PacketTable(); table.AddField("ProjectID", PacketTable.FieldType.TypeUint); table.AddField("PartID", PacketTable.FieldType.TypeUint); table.AddField("ProgressID", PacketTable.FieldType.TypeUint); table.AddField("ClassID", PacketTable.FieldType.TypeUint); table.AddField("IsFD", PacketTable.FieldType.TypeByte); table.AddField("LastNum", PacketTable.FieldType.TypeInt); table.MakeTable(1); table.SetValue(0, 0, nProjectID); table.SetValue(0, 1, nPartID); table.SetValue(0, 2, nProgressID); table.SetValue(0, 3, nClassID); table.SetValue(0, 4, (byte)bIsFD); table.SetValue(0, 5, nLastNum); PacketTable[] arrTable = new PacketTable[1]; arrTable[0] = table; //连接服务器 ServerConnection conn = new ServerConnection(); Packet recvPacket = conn.ExecuteCommand(nCommand, arrTable, nOption); return(recvPacket); } catch (Exception ex) { strError = "CmdQuery_GetPartArray:错误" + ex.Message; return(null); } }
static private DM_ModelProject getProjectInfo(UInt32 nProjectID) { string strProjectName = ""; PacketTable[] TableArray = new PacketTable[1]; PacketTable table = new PacketTable(); table.AddField("ProjectID", PacketTable.FieldType.TypeUint); table.AddField("ProjectName", PacketTable.FieldType.TypeString); table.MakeTable(1); table.SetValue(0, 0, nProjectID); table.SetValue(0, 1, strProjectName); TableArray[0] = table; ServerConnection connect = new ServerConnection(); Packet packet = connect.ExecuteCommand(13, TableArray); DataTable dt = outWorkInfo(packet); DM_ModelProject model = new DM_ModelProject(); model.ProjectID = (UInt32)dt.Rows[0]["ProjectID"]; model.ProjectName = dt.Rows[0]["ProjectName"].ToString(); model.ProjectNo = dt.Rows[0]["ProjectNo"].ToString(); model.ProjectOrder = (int)dt.Rows[0]["ProjectOrder"]; return(model); }
//查询零件 static public Packet GetPartArray(HttpContext context, int nCommand, ref string strError) { try { UInt32 nProjectID = CommandTool.ReqUint(context, "ProjectID"); PacketTable table = new PacketTable(); table.AddField("ProjectID", PacketTable.FieldType.TypeUint); table.MakeTable(1); table.SetValue(0, 0, nProjectID); PacketTable[] arrTable = new PacketTable[1]; arrTable[0] = table; //连接服务器 ServerConnection conn = new ServerConnection(); Packet recvPacket = conn.ExecuteCommand(nCommand, arrTable); return(recvPacket); } catch (Exception ex) { strError = "CmdQuery_GetPartArray:错误" + ex.Message; return(null); } }
static public string OutReportPDF(Packet packet) { if (packet == null) { Export handler = new Export(); return(handler.Error("服务器错误")); } byte nResult = 0; if (!packet.Read(ref nResult)) { Export handler = new Export(); return(handler.Error("无法读取执行的结果")); } string strMessage = ""; if (!packet.Read(ref strMessage)) { Export handler = new Export(); return(handler.Error("无法读取执行结果提示信息!")); } int nTableCount = 0; if (!packet.Read(ref nTableCount)) { Export handler = new Export(); return(handler.Error("无法读取参数表的数量")); } if (nTableCount == 0) { Export handler = new Export(); return(null); } else { PacketTable paramTable = new PacketTable(); if (packet.Read(ref paramTable)) { int[] arrFieldIndex = new int[1]; arrFieldIndex[0] = paramTable.GetFieldIndex("PDF"); byte[] ByPDF = (byte[])paramTable.GetValue(0, arrFieldIndex[0]); string Fileurl = System.Web.HttpContext.Current.Server.MapPath("../"); string FileName = Fileurl + "Asset\\pluginPdf\\Test.pdf"; // 创建新的、空的数据文件. if (File.Exists(FileName)) { File.Delete(FileName); } try { FileStream fs = new FileStream(FileName, FileMode.CreateNew); // 创建数据编写器. BinaryWriter w = new BinaryWriter(fs); // 写数据来测试。 w.Write(ByPDF); w.Close(); fs.Close(); } catch (Exception e) { string see = e.Message; return(null); } } return(null); } }
static public List <DM_ModelPassRate> StatPassRate(ServerConnection conn, UInt32 nProjectID, UInt32 nPartID, Period period, ref string strError) { if (conn == null) { conn = new ServerConnection(); } PacketTable sendTable = new PacketTable(); sendTable.AddField("LastNum", PacketTable.FieldType.TypeInt); sendTable.AddField("FromDate", PacketTable.FieldType.TypeDateTime); sendTable.AddField("ToDate", PacketTable.FieldType.TypeDateTime); sendTable.AddField("ProjectID", PacketTable.FieldType.TypeUint); sendTable.AddField("PartID", PacketTable.FieldType.TypeUint); sendTable.AddField("ClassID", PacketTable.FieldType.TypeUint); sendTable.AddField("IsFD", PacketTable.FieldType.TypeByte); sendTable.AddField("DataStatus", PacketTable.FieldType.TypeByte); sendTable.MakeTable(1); sendTable.SetValue(0, 0, period.LastNum); sendTable.SetValue(0, 1, period.DateFrom); sendTable.SetValue(0, 2, period.DateTo); sendTable.SetValue(0, 3, nProjectID); sendTable.SetValue(0, 4, nPartID); sendTable.SetValue(0, 5, (uint)0); sendTable.SetValue(0, 6, (byte)0); sendTable.SetValue(0, 7, (byte)1); PacketTable[] arrSendTable = new PacketTable[1]; arrSendTable[0] = sendTable; Packet recvPacket = conn.ExecuteCommand(201, arrSendTable); PacketTable[] arrRecvTable = conn.ReadTable(recvPacket); if (arrRecvTable == null) { strError = conn.ErrorMessage; return(null); } PacketTable recvTable = arrRecvTable[0]; List <DM_ModelPassRate> arrPassrate = new List <DM_ModelPassRate>(); int nIndexDate = recvTable.GetFieldIndex("Date"); int nIndexSeriesNO = recvTable.GetFieldIndex("SeriesNO"); int nIndexFileName = recvTable.GetFieldIndex("FileName"); int nIndexPassrate = recvTable.GetFieldIndex("Passrate"); int nIndexFileID = recvTable.GetFieldIndex("FileID"); int nIndexPass = recvTable.GetFieldIndex("Pass"); int nIndexTotal = recvTable.GetFieldIndex("Total"); for (int i = 0; i < recvTable.Rows; i++) { //double dDateTime = (double)recvTable.GetValue(i, nIndexDate); DM_ModelPassRate passrate = new DM_ModelPassRate(); passrate.MeasureDate = (DateTime)recvTable.GetValue(i, nIndexDate); passrate.MeasureFileID = (uint)recvTable.GetValue(i, nIndexFileID); passrate.PassRate = (float)recvTable.GetValue(i, nIndexPassrate); passrate.PassTotal = (int)recvTable.GetValue(i, nIndexPass); passrate.SampleTotal = (int)recvTable.GetValue(i, nIndexTotal); passrate.SeriesNo = (string)recvTable.GetValue(i, nIndexSeriesNO); arrPassrate.Add(passrate); } return(arrPassrate); }
public DataTable ToTable(Packet packet, int count = 1) { DataTable dt = new DataTable(); PacketTable table = new PacketTable(); table.Clear(); if (!packet.Read(ref table)) { return(null); } int nRows = table.Rows; int nCols = table.Cols; for (int m = 0; m < nCols; m++) { PacketTable.FieldType Type = table.GetField(m).Type; string strName = table.GetField(m).Name; if (Type == PacketTable.FieldType.TypeByte) { dt.Columns.Add(table.GetField(m).Name, typeof(byte)); } else if (table.GetField(m).Type == PacketTable.FieldType.TypeDateTime) { dt.Columns.Add(table.GetField(m).Name, typeof(DateTime)); } else if (table.GetField(m).Type == PacketTable.FieldType.TypeDouble) { dt.Columns.Add(table.GetField(m).Name, typeof(double)); } else if (table.GetField(m).Type == PacketTable.FieldType.TypeFloat) { dt.Columns.Add(table.GetField(m).Name, typeof(float)); } else if (table.GetField(m).Type == PacketTable.FieldType.TypeImage) { dt.Columns.Add(table.GetField(m).Name, typeof(byte[])); } else if (table.GetField(m).Type == PacketTable.FieldType.TypeInt) { dt.Columns.Add(table.GetField(m).Name, typeof(int)); } else if (table.GetField(m).Type == PacketTable.FieldType.TypeString) { dt.Columns.Add(table.GetField(m).Name, typeof(string)); } else if (table.GetField(m).Type == PacketTable.FieldType.TypeUint) { dt.Columns.Add(table.GetField(m).Name, typeof(uint)); } } for (int nRow = 0; nRow < nRows; nRow++) { DataRow row = dt.NewRow(); for (int nCol = 0; nCol < nCols; nCol++) { PacketTable.Field field = table.GetField(nCol); if (field.Type == PacketTable.FieldType.TypeByte) { row[nCol] = (byte)table.GetValue(nRow, nCol); } else if (field.Type == PacketTable.FieldType.TypeDouble) { row[nCol] = (double)table.GetValue(nRow, nCol); } else if (field.Type == PacketTable.FieldType.TypeFloat) { row[nCol] = (float)table.GetValue(nRow, nCol); } else if (field.Type == PacketTable.FieldType.TypeImage) { byte[] data = (byte[])table.GetValue(nRow, nCol); row[nCol] = data; } else if (field.Type == PacketTable.FieldType.TypeInt) { row[nCol] = (int)table.GetValue(nRow, nCol); } else if (field.Type == PacketTable.FieldType.TypeUint) { row[nCol] = (UInt32)table.GetValue(nRow, nCol); } else if (field.Type == PacketTable.FieldType.TypeString) { row[nCol] = (string)table.GetValue(nRow, nCol); } else if (field.Type == PacketTable.FieldType.TypeDateTime) { row[nCol] = (DateTime)table.GetValue(nRow, nCol); } } dt.Rows.Add(row); } return(dt); }
public string ToJson(int count, Packet packet) { string result = ""; ExportData ajaxJson = new ExportData(); PacketTable table = new PacketTable(); for (int i = 0; i < count; i++) { table.Clear(); if (!packet.Read(ref table)) { return("PackTable不完整"); } int nRows = table.Rows; int nCols = table.Cols; DataTable dt = new DataTable(); for (int m = 0; m < nCols; m++) { PacketTable.FieldType Type = table.GetField(m).Type; string strName = table.GetField(m).Name; if (Type == PacketTable.FieldType.TypeByte) { dt.Columns.Add(table.GetField(m).Name, typeof(byte)); } else if (table.GetField(m).Type == PacketTable.FieldType.TypeDateTime) { dt.Columns.Add(table.GetField(m).Name, typeof(DateTime)); } else if (table.GetField(m).Type == PacketTable.FieldType.TypeDouble) { dt.Columns.Add(table.GetField(m).Name, typeof(double)); } else if (table.GetField(m).Type == PacketTable.FieldType.TypeFloat) { dt.Columns.Add(table.GetField(m).Name, typeof(float)); } else if (table.GetField(m).Type == PacketTable.FieldType.TypeImage) { dt.Columns.Add(table.GetField(m).Name, typeof(byte[])); } else if (table.GetField(m).Type == PacketTable.FieldType.TypeInt) { dt.Columns.Add(table.GetField(m).Name, typeof(int)); } else if (table.GetField(m).Type == PacketTable.FieldType.TypeString) { dt.Columns.Add(table.GetField(m).Name, typeof(string)); } else if (table.GetField(m).Type == PacketTable.FieldType.TypeUint) { dt.Columns.Add(table.GetField(m).Name, typeof(uint)); } } for (int nRow = 0; nRow < nRows; nRow++) { DataRow row = dt.NewRow(); for (int nCol = 0; nCol < nCols; nCol++) { PacketTable.Field field = table.GetField(nCol); if (field.Type == PacketTable.FieldType.TypeByte) { row[nCol] = (byte)table.GetValue(nRow, nCol); } else if (field.Type == PacketTable.FieldType.TypeDouble) { row[nCol] = (double)table.GetValue(nRow, nCol); } else if (field.Type == PacketTable.FieldType.TypeFloat) { row[nCol] = (float)table.GetValue(nRow, nCol); } else if (field.Type == PacketTable.FieldType.TypeImage) { byte[] data = (byte[])table.GetValue(nRow, nCol); row[nCol] = data; } else if (field.Type == PacketTable.FieldType.TypeInt) { row[nCol] = (int)table.GetValue(nRow, nCol); } else if (field.Type == PacketTable.FieldType.TypeUint) { row[nCol] = (UInt32)table.GetValue(nRow, nCol); } else if (field.Type == PacketTable.FieldType.TypeString) { row[nCol] = (string)table.GetValue(nRow, nCol); } else if (field.Type == PacketTable.FieldType.TypeDateTime) { row[nCol] = (DateTime)table.GetValue(nRow, nCol); } } dt.Rows.Add(row); } ajaxJson.arrTable.Add(dt); } ajaxJson.Status = "1"; ajaxJson.Msg = "执行成功!"; result = JsonConvert.SerializeObject(ajaxJson); return(result); }
public static string AnalyzePackets(IToolInstance tool, long ts, ABCFile abc) { var zip = abc.instances.Zip(abc.classes, (inst, cls) => new { Instance = inst, Class = cls }); // Find version var parameter = zip .SingleOrDefault(type => { var qName = abc.multinames[type.Instance.name]; return(abc.strings[abc.namespaces[qName.QName.ns].name] == "com.company.assembleegameclient.parameters"); }); if (parameter == null) { return(null); } var stringTraits = parameter.Class.traits .Where(trait => trait.kind == TraitKind.Const && trait.Slot.vkind == ASType.Utf8) .ToList(); var versionTrait = stringTraits.Single(trait => trait.Slot.slotId == 1); string version = abc.strings[versionTrait.Slot.vindex]; var buildTrait = stringTraits.Single(trait => trait.Slot.slotId == 2); string build = abc.strings[buildTrait.Slot.vindex]; // Find gsc_ var gscTrait = abc.instances .SelectMany(inst => inst.traits) .Single(trait => { var qName = abc.multinames[trait.name]; return(abc.strings[qName.QName.name] == "gsc_"); }); var handlerType = zip.Single(type => type.Instance.name == gscTrait.Slot.typeName); var table = new PacketTable(ts); var tableType = typeof(PacketTable); foreach ( var packetEntry in handlerType.Class.traits.Where(trait => trait.kind == TraitKind.Const && trait.Slot.vkind == ASType.Integer)) { int packetIndex = (int)packetEntry.Slot.slotId - 1; var packetId = (int)abc.ints[packetEntry.Slot.vindex]; string name = null; if (packetIndex < packetNames.Length && packetIndex >= 0) { name = packetNames[packetIndex]; } if (name == null) { name = string.Format("_PACKET{0:X2}", packetIndex); } tableType.GetField(name).SetValue(table, (byte)packetId); } tool.PacketTable = table; return(version + "." + build); }