Exemplo n.º 1
0
        public virtual void Parse()
        {
            if (!string.IsNullOrEmpty(_message))
            {
                SegmentFactoryManager segmentBuilder = new SegmentFactoryManager();
                SegmentFactory        segmentFactory = segmentBuilder.GetFactory(_driverType);

                List <string> segments = new List <string>(_message.Replace("\r\n", "\r").Split('\r'));

                foreach (string segment in segments)
                {
                    Segment newSegment = segmentFactory.CreateSegmentInstance(
                        ((SegmentTypes)EnumUtils.enumValueOf(segment.Substring(0, 3), typeof(SegmentTypes))),
                        segment);

                    _segments.Add(newSegment);
                }

                if (_segments != null && _segments.Count > 0)
                {
                    MSH msh = (MSH)_segments.Find(s => s.SegmentType == SegmentTypes.MSH);
                    _delimiters.FieldSeparator        = msh.GetFieldSeparator();
                    _delimiters.ComponentSeparator    = msh.GetComponentSeparator();
                    _delimiters.FieldRepeatSeparator  = msh.GetFieldRepeatSeparator();
                    _delimiters.EscapeCharacter       = msh.GetEscapeCharacter();
                    _delimiters.SubComponentSeparator = msh.GetSubComponentSeparator();

                    _versioinId       = msh.GetVersionId();
                    _messageDate      = msh.GetMessageDateTime();
                    _type             = msh.GetMessageType();
                    _messageControlId = msh.GetMessageControlId();
                    _processingId     = msh.GetProcessingId();
                }
            }
        }