コード例 #1
0
 private UInt16 GetDynamicSize(ServerPacket packet, PacketInformation packetInformation)
 {
     if (packetInformation.DynamicSizeField != null)
     {
         return((UInt16)packetInformation.DynamicSizeField.GetValue(packet));
     }
     return(0);
 }
コード例 #2
0
 public int CompareTo(object obj)
 {
     if (obj is PacketInformation)
     {
         PacketInformation ab = obj as PacketInformation;
         if (ab.id > this.id)
         {
             return(-1);
         }
     }
     return(0);
 }
コード例 #3
0
 private void ParseFiles()
 {
     try
     {
         foreach (ITaskItem item in Source)
         {
             if (item.ItemSpec.Length > 0)
             {
                 string filename = Path.GetFileName(item.ItemSpec);
                 if (filename.StartsWith("CMSG"))
                 {
                     try
                     {
                         PacketInformation current = PacketInformation.GenerateFromFile(item.ItemSpec);
                         if (current != null)
                         {
                             CMSG.Add(current);
                         }
                     }
                     catch (Exception e)
                     {
                         Log.LogErrorFromException(e, false, true, item.ItemSpec);
                     }
                 }
                 else if (filename.StartsWith("SMSG"))
                 {
                     try
                     {
                         PacketInformation current = PacketInformation.GenerateFromFile(item.ItemSpec);
                         if (current != null)
                         {
                             SMSG.Add(current);
                         }
                     }
                     catch (Exception e)
                     {
                         Log.LogErrorFromException(e, false, true, item.ItemSpec);
                     }
                 }
                 else
                 {
                     Log.LogWarning("Filename is not regonized: {0}", filename);
                 }
             }
         }
     }
     catch (Exception e)
     {
         Log.LogErrorFromException(e, false, true, null);
     }
 }
コード例 #4
0
        public object CreatePacket(byte[] rawData)
        {
            PacketInformation packetInformation = packetInformationDict[(ServerPacketHeader)rawData[0]];

            if (rawData.Length != packetInformation.Size)
            {
                throw new Exception("Error while marshalling bytes to packet. Byte length is wrong");
            }
            object packet = Activator.CreateInstance(packetInformation.PacketType);
            IntPtr intPtr = Marshal.AllocHGlobal(packetInformation.Size);

            Marshal.Copy(rawData, 0, intPtr, packetInformation.Size);
            packet = Marshal.PtrToStructure(intPtr, packet.GetType());
            Marshal.FreeHGlobal(intPtr);
            return(packet);
        }
コード例 #5
0
 public void SetUp()
 {
     packet                                = new PacketInformation(new VendorInfo("00-11-22-33-44-55", "Amazon"), PhysicalAddress.Parse("00-11-22-33-44-55"));
     serviceConfig                         = new ServiceConfig();
     serviceConfig.Bridges                 = new Dictionary <string, BridgeConfig>();
     serviceConfig.Bridges["One"]          = new BridgeConfig();
     serviceConfig.Buttons                 = new Dictionary <string, ButtonConfig>();
     serviceConfig.Buttons["Main"]         = new ButtonConfig();
     serviceConfig.Buttons["Main"].Mac     = "00-11-22-33-44-55";
     serviceConfig.Buttons["Main"].Actions = new[] { new ButtonAction {
                                                         Groups = new[] { "TestMain" }, Type = ButtonActionType.Simple
                                                     } };
     mockMonitoringManager    = new Mock <IMonitoringManager>();
     mockLightsManagerFactory = new Mock <ILightsManagerFactory>();
     scheduler = new TestScheduler();
     instance  = CreateService();
 }
コード例 #6
0
        private PacketInformation GetPacketInformation(ServerPacketHeader serverPacketHeader)
        {
            PacketInformation packetInformation = null;

            try
            {
                packetInformation = packetParser.GetPacketInformation(serverPacketHeader);
            }
            catch
            {
                lock (Logger.LastLogs)
                {
                    foreach (String lastLogs in Logger.LastLogs)
                    {
                        Console.WriteLine(lastLogs);
                    }
                }
            }
            return(packetInformation);
        }
コード例 #7
0
            public static PacketInformation GenerateFromFile(string filename)
            {
                PacketInformation c = new PacketInformation();

                c.id    = ++i;
                c.notes = "None";
                c.name  = Path.GetFileNameWithoutExtension(filename);

                Regex reg = new Regex("(C|SMSG_)([A-F0-9]*_)([a-zA-Z0-9]*)");

                c.name = reg.Replace(c.name, "$1$3");


                bool          class_started = false;
                StringBuilder sb            = new StringBuilder();

                {
                    sb.Append("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
                    sb.Append("<packets>");

                    using (StringWriter writer = new StringWriter(sb))
                        using (FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.Read))
                            using (StreamReader reader = new StreamReader(fs))
                            {
                                while (reader.Peek() > -1 && class_started == false)
                                {
                                    string line  = reader.ReadLine();
                                    string line2 = line.TrimStart(' ', '\t');
                                    if (line2.Length >= 3 && line2.Substring(0, 3) == "///")
                                    {
                                        writer.WriteLine(line2.Substring(3));
                                    }
                                }
                            }
                    sb.Append("</packets>");
                }
                {
                    XmlReaderSettings settings = new XmlReaderSettings();
                    settings.ValidationType   = ValidationType.None;
                    settings.ValidationFlags |= XmlSchemaValidationFlags.None;
                    settings.ValidationFlags |= XmlSchemaValidationFlags.ProcessInlineSchema;

                    using (StringReader reader = new StringReader(sb.ToString()))
                        using (XmlReader xmlreader = XmlReader.Create(reader, settings))
                        {
                            string value = "";
                            while (xmlreader.Read())
                            {
                                switch (xmlreader.NodeType)
                                {
                                case XmlNodeType.Element:
                                    value = null;
                                    break;

                                case XmlNodeType.Text:
                                    value = xmlreader.Value;
                                    break;

                                case XmlNodeType.EndElement:
                                    switch (xmlreader.Name.ToLowerInvariant())
                                    {
                                    case "remarks": c.notes = value; break;

                                    case "example": c.example = value.Trim(' ', '\t', '\n', '\r'); break;

                                    case "id": c.id = uint.Parse(value, System.Globalization.NumberStyles.HexNumber, null); break;
                                    }
                                    break;
                                }
                            }
                        }
                }
                return(c);
            }