예제 #1
0
        public IDocumentFragment SelectSegment(SegmentPath segmentPath, string value)
        {
            IDocumentFragment segmentDocumentFragment = null;

            // If SegmentPath is conditional group then replace value with conditional value
            if (string.IsNullOrWhiteSpace(segmentPath.Value) == false)
            {
                value = segmentPath.Value;
            }

            if (CurrentSegments.TryGetValue(segmentPath.Path, out segmentDocumentFragment) == false)
            {
                List <IDocumentFragment> unusedSegmentsList;
                if (UnusedSegments.TryGetValue(segmentPath.Path, out unusedSegmentsList) == false)
                {
                    PopulateUnusedSegments(segmentPath);
                }

                List <IDocumentFragment> documentFragments;
                if (UnusedSegments.TryGetValue(segmentPath.Path, out documentFragments))
                {
                    if (documentFragments.Count > 0)
                    {
                        if (string.IsNullOrWhiteSpace(value) == false && documentFragments.Count != 1)
                        {
                            foreach (IDocumentFragment documentFragment in documentFragments)
                            {
                                string segmentValue = documentFragment.GetDataSegmentValue(segmentPath.DataSegmentName);
                                if (string.Equals(segmentValue, value, StringComparison.OrdinalIgnoreCase))
                                {
                                    segmentDocumentFragment = documentFragment;
                                }
                            }
                        }
                        else
                        {
                            segmentDocumentFragment = documentFragments[0];
                        }

                        if (segmentDocumentFragment != null)
                        {
                            documentFragments.Remove(segmentDocumentFragment);
                            CurrentSegments.Add(segmentPath.Path, segmentDocumentFragment);
                        }
                    }
                }
            }

            return(segmentDocumentFragment);
        }
예제 #2
0
        protected override EdiItem Process(string segment)
        {
            var segmentContext = new SegmentContext(segment.Substring(0, 3), segment, segment.Substring(3, 2), null,
                                                    false);
            var messageContext = MessageContext(segment);

            if (messageContext != null)
            {
                var result = Flush(segment + _postFix);
                if (result != null)
                {
                    return(result);
                }

                CurrentMessageContext = messageContext;
            }

            CurrentSegments.Add(segmentContext);

            return(null);
        }
예제 #3
0
        protected override EdiItem Process(string segment)
        {
            EdiItem result = null;

            var segmentContext = new SegmentContext(segment, Separators);

            switch (segmentContext.Name)
            {
            case "ISA":
            case "GS":
            case "ST":
            case "GE":
            case "IEA":
                result = Flush(segment);
                if (result != null)
                {
                    return(result);
                }
                break;
            }

            switch (segmentContext.Name)
            {
            case "ISA":
                var isa = ParseSegment <ISA>(segmentContext.Value, Separators);
                _currentIsa         = isa;
                result              = isa;
                _currentGroupHeader = null;
                break;

            case "TA1":
                result = ParseSegment <TA1>(segmentContext.Value, Separators);
                _currentGroupHeader = null;
                break;

            case "GS":
                result = ParseSegment <GS>(segmentContext.Value, Separators);
                _currentGroupHeader = segmentContext;
                break;

            case "ST":
                CurrentSegments.Add(segmentContext);
                CurrentMessageContext = BuildContext();
                SegmentIndex          = 0;
                PartsIndex            = 0;
                break;

            case "SE":
                CurrentSegments.Add(segmentContext);
                result = ParseSegments();
                CurrentMessageContext = null;
                SegmentIndex          = 0;
                PartsIndex            = 0;
                break;

            case "GE":
                result = ParseSegment <GE>(segmentContext.Value, Separators);
                _currentGroupHeader = null;
                break;

            case "IEA":
                result = ParseSegment <IEA>(segmentContext.Value, Separators);
                _currentGroupHeader = null;
                _currentIsa         = null;
                break;

            default:
                CurrentSegments.Add(segmentContext);
                break;
            }

            return(result);
        }
예제 #4
0
        protected override EdiItem Process(string segment)
        {
            EdiItem result = null;

            var segmentContext = new SegmentContext(segment, Separators);

            switch (segmentContext.Name)
            {
            case "UNA":
            case "UNB":
            case "UNG":
            case "UNH":
            case "UNE":
            case "UNZ":
                result = Flush(segment);
                if (result != null)
                {
                    return(result);
                }
                break;
            }

            switch (segmentContext.Name)
            {
            case "UNA":
                break;

            case "UNB":
                var unb = ParseSegment <UNB>(segmentContext.Value, Separators);
                _currentUnb = unb;
                result      = unb;
                break;

            case "UNG":
                result = ParseSegment <UNG>(segmentContext.Value, Separators);
                break;

            case "UNH":
                CurrentSegments.Add(segmentContext);
                CurrentMessageContext = BuildContext();
                SegmentIndex          = 0;
                PartsIndex            = 0;
                break;

            case "UNT":
                CurrentSegments.Add(segmentContext);
                result = ParseSegments();
                CurrentMessageContext = null;
                SegmentIndex          = 0;
                PartsIndex            = 0;
                break;

            case "UNE":
                result = ParseSegment <UNE>(segmentContext.Value, Separators);
                break;

            case "UNZ":
                result      = ParseSegment <UNZ>(segmentContext.Value, Separators);
                _currentUnb = null;
                break;

            default:
                CurrentSegments.Add(segmentContext);
                break;
            }

            return(result);
        }