public ConnectionStatisticsForm(ConnectionHistoryEntry entry, LogPacket[] packets)
        {
            InitializeComponent();

            if (entry != null)
            {
                foreach (KeyValuePair<string, object> pair in entry.Properties)
                {
                    ListViewItem item = listViewProperties.Items.Add(pair.Key);
                    item.SubItems.Add(pair.Value.ToString());
                    item.Tag = pair.Value;
                }
            }
            else
            {
                tabControl.TabPages.Remove(tabPageProperties);
            }

            if (packets != null && packets.Length > 0)
            {
                packetLogControl.SetPackets(packets);
                tagStatisticsChartControl.SetPackets(packets);
                histogramChartControl.SetPackets(packets);
                networkTrafficChartControl.SetPackets(packets);
            }
            else
            {
                tabControl.TabPages.Remove(tabPageHistogram);
                tabControl.TabPages.Remove(tabPagePackets);
                tabControl.TabPages.Remove(tabPageTagStatistics);
                tabControl.TabPages.Remove(tabPageNetworkTraffic);
            }
        }
Example #2
0
        /// <summary>
        /// Convert a packet to a hex string format
        /// </summary>
        /// <param name="p">The packet to convert</param>
        /// <returns>The converted string</returns>
        public static string ConvertBinaryPacketToString(LogPacket p)
        {
            using (TextWriter writer = new StringWriter())
            {
                writer.WriteLine(GetHeader(p));
                writer.WriteLine(GeneralUtils.BuildHexDump(16, p.Frame.ToArray()));
                writer.WriteLine();

                return writer.ToString();
            }
        }
Example #3
0
 /// <summary>
 /// Add a packet to the buffer to write
 /// </summary>
 /// <param name="packet">The packet to write</param>
 public void AddPacket(LogPacket packet)
 {
     lock (_packets)
     {
         _packets[_currPos++] = packet;
         if (_currPos == MAX_PACKETS)
         {
             Flush();
         }
     }
 }
        public PacketDiffLogViewerForm(LogPacket curr, IList<LogPacket> packets)
        {
            for (int i = 0; i < packets.Count; i++)
            {
                if (packets[i] == curr)
                {
                    _index = i;
                    break;
                }
            }

            _packets = packets;
            //_modifiedPackets = new PacketEntry[_packets.Count];
            //_newStyleLogViewer = GlobalControlConfig.NewStyleLogViewer;

            InitializeComponent();
        }
Example #5
0
        public void SetPackets(LogPacket[] packets)
        {
            _packets = packets;

            if (packets.Length > 0)
            {
                _bytag = packets.GroupBy(p => String.IsNullOrWhiteSpace(p.Tag) ? "Unknown Tag" : p.Tag).ToDictionary(g => g.Key, g => g.ToList());
                comboBoxTag.Items.Clear();

                comboBoxTag.Items.Add(Properties.Resources.HistogramChartControl_AllTags);
                foreach (KeyValuePair<string, List<LogPacket>> pair in _bytag)
                {
                    comboBoxTag.Items.Add(pair.Key);
                }
                comboBoxTag.SelectedIndex = 0;
            }
            else
            {
                _bytag = new Dictionary<string, List<LogPacket>>();
            }
        }
Example #6
0
 /// <summary>
 /// Dump a text packet to stdout
 /// </summary>
 /// <param name="packet">The packet to dump</param>
 public static void DumpTextPacket(LogPacket packet)
 {
     Console.Out.WriteLine(ConvertTextPacketToString(packet));
 }
Example #7
0
        /// <summary>
        /// Convert a packet to a text string format
        /// </summary>
        /// <param name="p">The packet to convert</param>
        /// <returns>The converted string</returns>
        public static string ConvertTextPacketToString(LogPacket p)
        {
            using (TextWriter writer = new StringWriter())
            {
                writer.WriteLine(GetHeader(p));
                writer.WriteLine(p.Frame.ToDataString());

                return writer.ToString();
            }
        }
Example #8
0
 protected override object GetValue(LogPacket p)
 {
     return p.Network ?? "";
 }
Example #9
0
        static void AddPacketsToDocument(IDocumentObject doc, LogPacket[] packets)
        {
            PacketLogDocument packetLog = doc as PacketLogDocument;
            TestDocument testDoc = doc as TestDocument;

            if (packetLog != null)
            {
                foreach (LogPacket packet in packets)
                {
                    packetLog.AddPacket((LogPacket)packet.Clone());
                }
            }
            else if (testDoc != null)
            {
                IEnumerable<LogPacket> newPackets = packets.Select(p => (LogPacket)p.Clone());
                testDoc.AddRangeInputPacket(newPackets);
            }
        }
Example #10
0
        private LogPacket[] GetSelectedPacket()
        {
            LogPacket[] packets = new LogPacket[1];

            packets[0] = new LogPacket("Text", Guid.NewGuid(), "Text Copy", new DataFrame(ActiveTextAreaControl.SelectionManager.SelectedText), ColorValue.White);

            return packets;
        }
Example #11
0
 // Not really implemented at the moment, special case
 protected override object GetValue(LogPacket p)
 {
     throw new NotImplementedException();
 }
Example #12
0
 private static void WritePacketsText(Stream stm, LogPacket[] ps)
 {
     using (TextWriter writer = new StreamWriter(stm, Encoding.UTF8))
     {
         foreach (LogPacket p in ps)
         {
             writer.WriteLine(GetHeader(p));
             writer.WriteLine(GeneralUtils.MakeByteString(p.Frame.ToArray()));
         }
     }
 }
Example #13
0
        protected override object GetValue(LogPacket p)
        {
            DataNode node = p.Frame.Root.SelectSingleNode(SelectionPath);

            if (node == null)
            {
                node = new StringDataValue("", "");
            }

            if (FormatExpression.IsValid)
            {
                ExpressionResolver _resolver = new ExpressionResolver(typeof(LogPacket));
                Dictionary<string, object> extras = new Dictionary<string,object>();
                extras["value"] = node;

                try
                {
                    return _resolver.Resolve(p, _formatExpression, extras) ?? String.Empty;
                }
                catch (Exception)
                {
                    return String.Empty;
                }
            }
            else
            {
                return RawValue ? node.Value : node;
            }
        }
Example #14
0
        protected override object GetValue(LogPacket p)
        {
            object ret = p.Timestamp;

            if (Ticks)
            {
                return p.Timestamp.Ticks;
            }
            else
            {
                return p.Timestamp;
            }
        }
Example #15
0
 protected override object GetValue(LogPacket p)
 {
     return p.Tag ?? "";
 }
Example #16
0
 protected abstract object GetValue(LogPacket p);
Example #17
0
        public virtual string ToString(LogPacket p, int index)
        {
            object value = GetValue(p);
            byte[] ba = value as byte[];

            if (ba != null)
            {
                int length = ba.Length;
                if (length > 64)
                {
                    length = 64;
                }

                if (!String.IsNullOrWhiteSpace(CustomFormat))
                {
                    try
                    {
                        StringBuilder builder = new StringBuilder();

                        for (int i = 0; i < length; ++i)
                        {
                            builder.AppendFormat(CustomFormat, ba[i]);
                        }

                        return builder.ToString();
                    }
                    catch (FormatException)
                    {
                        // Error in format
                    }
                }

                return GeneralUtils.EscapeString(BinaryEncoding.Instance.GetString(ba, 0, length));
            }
            else
            {
                if (!String.IsNullOrWhiteSpace(CustomFormat))
                {
                    try
                    {
                        return String.Format(CustomFormat, value);
                    }
                    catch (FormatException)
                    {
                        // Error in format
                    }
                }

                return value.ToString();
            }
        }
Example #18
0
 private static string GetHeader(LogPacket p)
 {
     return String.Format("Time {0} - Tag '{1}' - Network '{2}'",
             p.Timestamp.ToString(), p.Tag, p.Network);
 }
Example #19
0
 private static void WritePacketsHex(Stream stm, LogPacket[] ps)
 {
     using (TextWriter writer = new StreamWriter(stm, Encoding.UTF8))
     {
         foreach (LogPacket p in ps)
         {
             writer.WriteLine(GetHeader(p));
             writer.WriteLine(GeneralUtils.BuildHexDump(16, p.Frame.ToArray()));
             writer.WriteLine();
         }
     }
 }
Example #20
0
        public static string ConvertPacketToTreeString(LogPacket p)
        {
            using (TextWriter writer = new StringWriter())
            {
                writer.WriteLine(GetHeader(p));
                WriteNodeToTreeString(writer, "", p.Frame.Root);

                return writer.ToString();
            }
        }
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="packet">The packet being logged</param>
 /// <param name="graph">The graph associated with this packet</param>
 public FilterPacketLogEventArgs(LogPacket packet, NetGraph graph)
 {
     Packet = packet;
     Graph = graph;
 }
Example #22
0
        public override string ToString(LogPacket p, int index)
        {
            if (!String.IsNullOrWhiteSpace(CustomFormat))
            {
                try
                {
                    return String.Format(CustomFormat, index + 1);
                }
                catch (FormatException)
                {
                }
            }

            return (index + 1).ToString();
        }
Example #23
0
        private void log_AddLogPacket(object sender, LogPacketEventArgs e)
        {
            LogPacket packet = new LogPacket(e);

            if (FilterLogPacketEvent != null)
            {
                FilterPacketLogEventArgs args = new FilterPacketLogEventArgs(packet, sender as NetGraph);

                FilterLogPacketEvent.Invoke(this, args);

                if (args.Filter)
                {
                    packet = null;
                }
                else
                {
                    packet = args.Packet;
                }
            }

            if (packet != null)
            {
                lock (_packetLog)
                {
                    _packetLog.Add(packet);
                }
            }
        }
Example #24
0
        /// <summary>
        /// Add a simple packet with a tag and a frame
        /// </summary>
        /// <param name="tag">The tag to add</param>
        /// <param name="frame">The frame to add, this will be cloned before putting in log</param>
        /// <returns>The logged packet</returns>
        public LogPacket AddPacket(string tag, DataFrame frame)
        {
            LogPacket ret = new LogPacket(tag, Guid.NewGuid(), "Packet Log", frame.CloneFrame(), ColorValue.White);
            AddPacket(ret);

            return ret;
        }
Example #25
0
 /// <summary>
 /// Add a packet to the input
 /// </summary>
 /// <param name="packet">The packet</param>
 public void AddInputPacket(LogPacket packet)
 {
     lock (_inputPackets)
     {
         _inputPackets.Add(packet);
     }
 }
Example #26
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="packets"></param>
 public PacketLogDocument(LogPacket[] packets)
 {
     _packets = new LogPacketCollection(packets);
     SetupCollections();
 }
        public void SetPackets(LogPacket[] packets)
        {
            _packets = packets;

            if (packets.Length > 0)
            {
                _bytag = packets.GroupBy(p => String.IsNullOrWhiteSpace(p.Tag) ? "Unknown Tag" : p.Tag).ToDictionary(g => g.Key, g => g.ToList());

                _startTime = DateTime.MaxValue;
                _endTime = DateTime.MinValue;

                foreach (LogPacket packet in _packets)
                {
                    if (packet.Timestamp < _startTime)
                    {
                        _startTime = packet.Timestamp;
                    }

                    if (packet.Timestamp > _endTime)
                    {
                        _endTime = packet.Timestamp;
                    }
                }

                double secs = _endTime.Subtract(_startTime).TotalSeconds;
                double bucketLength = secs / (double)MAX_BUCKETS;
                int bucketCount = MAX_BUCKETS+1;

                if(bucketLength < MIN_TIME_DIVISION)
                {
                    bucketCount = (int)Math.Ceiling(secs / MIN_TIME_DIVISION) + 1;
                    bucketLength = MIN_TIME_DIVISION;
                }

                _bucketsByteCount = new Dictionary<string, long>[bucketCount];
                _bucketLength = bucketLength;

                for (int i = 0; i < bucketCount; ++i)
                {
                    _bucketsByteCount[i] = new Dictionary<string, long>();
                }

                foreach (LogPacket packet in _packets)
                {
                    TimeSpan currSpan = packet.Timestamp.Subtract(_startTime);

                    int bucketNumber = (int)Math.Truncate(currSpan.TotalSeconds / bucketLength);
                    string tag = packet.Tag ?? "Unknown Tag";

                    Dictionary<string, long> bucket = _bucketsByteCount[bucketNumber];

                    if (!bucket.ContainsKey(tag))
                    {
                        bucket[tag] = 0;
                    }

                    bucket[tag] = bucket[tag] + packet.Length;
                }
            }
            else
            {
                _bytag = new Dictionary<string, List<LogPacket>>();
            }

            UpdateChart();
        }
Example #28
0
 /// <summary>
 /// Add a packet to the log
 /// </summary>
 /// <param name="packet">The packet</param>
 public void AddPacket(LogPacket packet)
 {
     lock (_packets)
     {
         _packets.Add(packet);
     }
 }
Example #29
0
 static void AddToExistingDifflog(LogPacketCollection coll, LogPacket[] packets)
 {
     lock (coll)
     {
         foreach (LogPacket packet in packets)
         {
             coll.Add(packet.ClonePacket());
         }
     }
 }
        private void toolStripButtonCopyFrame_Click(object sender, EventArgs e)
        {
            LogPacket[] packets = new LogPacket[1] { new LogPacket("Copied", Guid.Empty, "Copied", _currFrame.CloneFrame(), _color.FromColor()) };

            try
            {
                Clipboard.SetData(LogPacket.LogPacketArrayFormat, packets);
            }
            catch (ExternalException)
            {
            }
            catch(ThreadStateException)
            {
            }
        }