示例#1
0
        // Parse, filter and output a captured packet
        private void Process(TimestampedData timestampedData)
        {
            // Only parse the packet if we need to filter or raise an event
            if (PacketCaptured != null || this.filters.PropertyFilters.Any())
            {
                try
                {
                    var packet = this.packetParser.Parse(timestampedData.Data, timestampedData.Timestamp);

                    if (!this.filters.IsMatch(packet))
                    {
                        return;
                    }

                    try
                    {
                        PacketCaptured?.Invoke(packet);
                    }
                    catch (Exception ex)
                    {
                        this.logger.LogWarning(ex, "Unhandled error in event handler: {ErrorMessage}", ex.Message);
                    }
                }
                catch (Exception ex)
                {
                    this.logger.LogWarning(ex, "Unable to parse packet of {Length} bytes received at {Timestamp}: {ErrorMessage}",
                                           timestampedData.Data.Length, timestampedData.Timestamp, ex.Message);

                    return;
                }
            }

            this.output?.Output(timestampedData);
            this.Statistics.IncrementCaptured();
        }
示例#2
0
 /// <summary>
 /// Rises the PacketCaptured event with the given frame
 /// </summary>
 /// <param name="fFrame">The frame which was captured</param>
 protected void InvokePacketCaptured(Frame fFrame)
 {
     if (PacketCaptured != null)
     {
         foreach (Delegate dDelgate in PacketCaptured.GetInvocationList())
         {
             if (dDelgate.Target != null && dDelgate.Target is DirectInterfaceIOHandler)
             {
                 ((DirectInterfaceIOHandler)dDelgate.Target).OnPacketCaptured(fFrame, this);
             }
             else if (dDelgate.Target != null && dDelgate.Target is System.ComponentModel.ISynchronizeInvoke &&
                      ((System.ComponentModel.ISynchronizeInvoke)(dDelgate.Target)).InvokeRequired)
             {
                 ((System.ComponentModel.ISynchronizeInvoke)(dDelgate.Target)).BeginInvoke(dDelgate, new object[] { fFrame, this });
             }
             else
             {
                 ((PacketCapturedHandler)dDelgate)(fFrame, this);
             }
         }
     }
 }