private void OnProcessingComplete(TapStreamDecoder.ProcessingResult result, TapStreamDecoder decoder, string direction, Map27ConnectionState theConnectionState)
 {
     switch (result)
     {
         case TapStreamDecoder.ProcessingResult.Ok:
             ReportDecodedSignal(decoder.Map27Packet.ToArray(), decoder.MessageEndTimeText, decoder.MessageEndTime, direction, theConnectionState);
             break;
         case TapStreamDecoder.ProcessingResult.FcsError:
             ReportError("FCS error", decoder.MessageEndTimeText, decoder.MessageEndTime, direction);
             break;
         case TapStreamDecoder.ProcessingResult.FormatError:
             ReportError("Format error", decoder.MessageEndTimeText, decoder.MessageEndTime, direction);
             break;
         case TapStreamDecoder.ProcessingResult.OutOfFrameBytesFound:
             ReportOutOfFrameBytes(decoder.OutOfFrameBytes, decoder.MessageEndTimeText, decoder.MessageEndTime, direction);
             break;
         default:
             ReportError("Unexpected processing result", decoder.MessageEndTimeText, decoder.MessageEndTime, direction);
             break;
     }
 }
        private void ReportDecodedSignal(byte[] map27Packet, string logTime, double timestamp, string direction, Map27ConnectionState theConnectionState)
        {
            StringBuilder sb = new StringBuilder();
            sb.AppendFormat("{0} {1:0000.000000} {2}  ", logTime, timestamp, direction);

            try
            {
                Value map27Signal = null;
                try
                {
                    map27Signal = m_SignalDecoder.GetSignalValue(map27Packet[0], map27Packet);
                }
                catch (PartialDecodeException partialDecodeException)
                {
                    map27Signal = partialDecodeException.ValueBeingDecoded;
                }

                StructureValue map27SignalStruct = map27Signal as StructureValue;
                if (map27SignalStruct != null && map27SignalStruct.Attributes.Count> 0)
                {
                    AttributeValue map27FrameAttribute = map27SignalStruct.Attributes[0];
                    StructureValue map27FrameStruct = map27FrameAttribute.Value as StructureValue;

                    if(map27FrameStruct != null)
                    {
                        string[] analysisResults = null;
                        if (ShowRetries)
                        {
                            analysisResults = theConnectionState.HandleFrame(map27SignalStruct, timestamp, direction);
                        }

                        // Report the elements of the MAP27 frame
                        foreach (var attribute in map27FrameStruct.Attributes)
                        {
                            EnumValue theEnumValue = attribute.Value as EnumValue;
                            if (theEnumValue != null)
                            {
                                sb.AppendFormat("{0}:{1} ", attribute.Name, theEnumValue.StringValue, theEnumValue.IntegerValue);
                            }
                            else
                            {
                                sb.AppendFormat("{0}:{1} ", attribute.Name, attribute.Value);
                            }
                        }

                        // Append the raw data to the end of the MAP27 frame
                        sb.AppendFormat("    {0}", Formatting.BinToHex(map27Packet, ' '));

                        // Report the contents of the TAP frame
                        if (map27SignalStruct.Attributes.Count > 1)
                        {
                            AttributeValue tapFrameAttribute = map27SignalStruct.Attributes[1];
                            StructureValue tapFrameStruct = tapFrameAttribute.Value as StructureValue;

                            if (tapFrameStruct != null)
                            {
                                // ShowStructOnSingleLine(sb, tapFrameStruct);
                                ShowTapFrameOnMultipleLines(sb, tapFrameStruct, sb.ToString().IndexOf("Type", StringComparison.Ordinal));
                            }
                            else
                            {
                                sb.AppendFormat("\n{0}", tapFrameAttribute.Value.ToString());
                            }
                        }

                        if (analysisResults != null)
                        {
                            sb.AppendFormat("\n[Analysis] {0}", string.Join("\n", analysisResults));
                        }
                    }
                }
            }
            catch (DataDictionaryException ex)
            {
                sb.AppendFormat("{0} [{1}]", Formatting.BinToHex(map27Packet, ' '), ex.Message);
            }

            if (OnSignalDecoded != null)
            {
                OnSignalDecoded(sb.ToString());
            }
        }