示例#1
0
        private void AddPacket(Packet packet)
        {
            packets.Add(packet);

            if (PacketRecorded != null)
            {
                PacketRecorded(packet);
            }
        }
示例#2
0
        /// <summary>
        /// Adds newly received packet to packet lists
        /// </summary>
        /// <param name="newPacket">Packet to be added to packet lists</param>
        private void ReceiveNewPacket(IPPacket newPacket)
        {
            newPacket.PacketID = (uint)PacketList.Count + 1;

            lock (PacketList)
            {
                PacketList.Add(newPacket);
            }
            IsClearEnabled = true;

            lock (filteredPacketList)
            {
                AddToFilteredList(newPacket);
            }

            StatsHandler.UpdateStats(newPacket);
        }
示例#3
0
 public static PacketList Create(Protocol protocol, List<byte> data)
 {
     switch (protocol)
     {
         case Protocol.Delimited:
             {
                 string buffer = Encoding.ASCII.GetString(data.ToArray());
                 string[] parameters = buffer.Split((char)1);
                 string[] arguments = new string[parameters.Length - 1];
                 Array.Copy(parameters, 1, arguments, 0, arguments.Length);
                 Packet packet = new Packet(parameters[0], arguments);
                 return new PacketList(Cast(packet));
             }
         case Protocol.Xml:
             {
                 MemoryStream stream = new MemoryStream(data.ToArray());
                 XmlTextReader reader = new XmlTextReader(stream);
                 if (reader.Read())
                 {
                     PacketList packetList = new PacketList();
                     while (reader.Read() && reader.NodeType == XmlNodeType.Element)
                     {
                         string command = reader.GetAttribute(1);
                         string[] arguments = new string[reader.AttributeCount - 2];
                         for (int index = 2; index < reader.AttributeCount; index++)
                             arguments[index - 2] = reader.GetAttribute(index);
                         Packet packet = new Packet(command, arguments);
                         packetList.Add(Cast(packet));
                     }
                     return packetList;
                 }
                 throw new InvalidDataException();
             }
         default: throw new ArgumentOutOfRangeException();
     }
 }