private LoopSpecification GetLoopSpecification(string segmentString)
        {
            var segment = new Segment(this, this.DelimiterSet, segmentString);

            IList <LoopSpecification> matchingLoopSpecs = this.AllowedChildLoops
                                                          .Where(cl => cl.StartingSegment.SegmentId == segment.SegmentId)
                                                          .ToList();

            if (matchingLoopSpecs.Count == 0)
            {
                return(null);
            }

            if (segment.SegmentId == "NM1" || segment.SegmentId == "N1")
            {
                LoopSpecification spec = matchingLoopSpecs.FirstOrDefault(ls => ls.StartingSegment.EntityIdentifiers.Any(ei => ei.Code == segment.GetElement(1) || ei.Code == "Item" + segment.GetElement(1)));
                if (spec == null)
                {
                    if (matchingLoopSpecs.Count(ls => ls.StartingSegment.SegmentId == segment.SegmentId) == 1)
                    {
                        spec = matchingLoopSpecs.First(ls => ls.StartingSegment.SegmentId == segment.SegmentId);
                    }
                }

                return(spec);
            }

            return(matchingLoopSpecs.FirstOrDefault());
        }
Esempio n. 2
0
        private LoopSpecification GetLoopSpecification(string segmentString)
        {
            Segment segment = new Segment(this, _delimiters, segmentString);

            IList <LoopSpecification> matchingLoopSpecs = ((LoopContainer)this).AllowedChildLoops
                                                          .Where(cl => cl.StartingSegment.SegmentId == segment.SegmentId).ToList();

            if (matchingLoopSpecs == null || matchingLoopSpecs.Count == 0)
            {
                return(null);
            }
            else if (segment.SegmentId == "NM1" || segment.SegmentId == "N1")
            {
                LoopSpecification spec = matchingLoopSpecs.Where(ls => ls.StartingSegment.EntityIdentifiers.Any(ei => ei.Code.ToString() == segment.GetElement(1) || ei.Code.ToString() == "Item" + segment.GetElement(1))).FirstOrDefault();
                if (spec == null)
                {
                    if (matchingLoopSpecs.Where(ls => ls.StartingSegment.SegmentId == segment.SegmentId).Count() == 1)
                    {
                        spec = matchingLoopSpecs.Where(ls => ls.StartingSegment.SegmentId == segment.SegmentId).First();
                    }
                }
                return(spec);
            }
            else
            {
                return(matchingLoopSpecs.FirstOrDefault());
            }
        }
        /// <summary>
        /// Adds a loop specified by the provided segment string to the <see cref="LoopContainer"/>
        /// </summary>
        /// <param name="segmentString">String representing the loop to be added</param>
        /// <returns>Loop added to the container; otherwise, null</returns>
        public Loop AddLoop(string segmentString)
        {
            LoopSpecification loopSpec = this.GetLoopSpecification(segmentString);

            if (loopSpec != null)
            {
                var loop = new Loop(this, this.DelimiterSet, segmentString, loopSpec);
                this.Segments.Add(loop);
                this.Loops.Add(loop);
                return(loop);
            }

            return(null);
        }
Esempio n. 4
0
        public Loop AddLoop(string segmentString)
        {
            LoopSpecification loopSpec = GetLoopSpecification(segmentString);

            if (loopSpec != null)
            {
                var loop = new Loop(this, _delimiters, segmentString, loopSpec);
                _segments.Add(loop);
                _loops.Add(loop);
                return(loop);
            }
            else
            {
                return(null);
            }
        }
Esempio n. 5
0
        public T AddLoop <T>(T loop) where T : TypedLoop
        {
            string            segmentString = loop.GetSegmentString(_delimiters);
            LoopSpecification loopSpec      = GetLoopSpecification(segmentString);

            if (loopSpec != null)
            {
                loop.Initialize(this, _delimiters, loopSpec);
                _segments.Add(loop.Loop);
                _loops.Add(loop.Loop);
                return(loop);
            }
            else
            {
                throw new TransactionValidationException("Loop {3} could not be added because it could not be found in the specification for {2}",
                                                         null, null, this.SegmentId, segmentString);
            }
        }
Esempio n. 6
0
 internal Loop(Container parent, X12DelimiterSet delimiters, string startingSegment, LoopSpecification loopSpecification)
     : base(parent, delimiters, startingSegment)
 {
     Specification = loopSpecification;
 }
Esempio n. 7
0
 internal virtual void Initialize(Container parent, X12DelimiterSet delimiters, LoopSpecification loopSpecification)
 {
     Loop = new Loop(parent, delimiters, _segmentId, loopSpecification);
 }
Esempio n. 8
0
 internal override void  Initialize(Container parent, X12DelimiterSet delimiters, LoopSpecification loopSpecification)
 {
     base.Initialize(parent, delimiters, loopSpecification);
     this.CLM05 = new TypedElementServiceLocationInfo(this.Loop, 5);
     this.CLM11 = new TypedElementRelatedCausesInfo(this.Loop, 11);
 }
 internal override void Initialize(Container parent, X12DelimiterSet delimiters, LoopSpecification loopSpecification)
 {
     base.Initialize(parent, delimiters, loopSpecification);
     this.IK401 = new TypedElementPositionInSegment(this.Loop, 1);
 }
        internal override void Initialize(Container parent, X12DelimiterSet delimiters, LoopSpecification loopSpecification)
        {
            string segmentString = this.GetSegmentString(delimiters);

            this.Loop = new Loop(parent, delimiters, segmentString, loopSpecification);
        }