internal HierarchicalLoop AddHLoop(string segmentString)
        {
            Transaction transaction = this.Transaction;

            var hl = new HierarchicalLoop(this, _delimiters, segmentString);

            hl.Specification = transaction.Specification.HierarchicalLoopSpecifications.FirstOrDefault(
                hls => hls.LevelCode == null || hls.LevelCode.ToString() == hl.LevelCode);

            if (hl.Specification == null)
                throw new TransactionValidationException("{0} Transaction does not expect {2} level code value {3} that appears in transaction control number {1}.",
                    transaction.IdentifierCode, transaction.ControlNumber, "HL03", hl.LevelCode);

            _hLoops.Add(hl.Id, hl);
            // loop id must be unique throughout the transaction
            try
            {
                transaction.AddToHLoopDictionary(hl);
            }
            catch (ArgumentException exc)
            {
                if (exc.Message == "An item with the same key has already been added.")
                    throw new TransactionValidationException("Hierarchical Loop ID {3} cannot be added to {0} transaction with control number {1} because it already exists.",
                        transaction.IdentifierCode, transaction.ControlNumber, "HL01", hl.Id);
                else
                    throw;
            }
            return hl;
        }
Exemple #2
0
        internal HierarchicalLoop AddHLoop(string segmentString)
        {
            Transaction transaction = this.Transaction;

            var hl = new HierarchicalLoop(this, _delimiters, segmentString);

            hl.Specification = transaction.Specification.HierarchicalLoopSpecifications.FirstOrDefault(
                hls => hls.LevelCode == null || hls.LevelCode.ToString() == hl.LevelCode);

            if (hl.Specification == null)
            {
                throw new TransactionValidationException("{0} Transaction does not expect {2} level code value {3} that appears in transaction control number {1}.",
                                                         transaction.IdentifierCode, transaction.ControlNumber, "HL03", hl.LevelCode);
            }

            _hLoops.Add(hl.Id, hl);
            // loop id must be unique throughout the transaction
            try
            {
                transaction.AddToHLoopDictionary(hl);
            }
            catch (ArgumentException exc)
            {
                if (exc.Message == "An item with the same key has already been added.")
                {
                    throw new TransactionValidationException("Hierarchical Loop ID {3} cannot be added to {0} transaction with control number {1} because it already exists.",
                                                             transaction.IdentifierCode, transaction.ControlNumber, "HL01", hl.Id);
                }
                else
                {
                    throw;
                }
            }
            return(hl);
        }
Exemple #3
0
        internal HierarchicalLoop AddHLoop(string segmentString)
        {
            Transaction transaction = this.Transaction;

            var hl = new HierarchicalLoop(this, _delimiters, segmentString);

            HierarchicalLoopContainer specContainer = this;

            while (!(specContainer is HierarchicalLoopContainer && specContainer.HasHierachicalSpecs()))
            {
                if (specContainer.Parent is HierarchicalLoopContainer)
                {
                    specContainer = (HierarchicalLoopContainer)specContainer.Parent;
                }
                else
                {
                    throw new InvalidOperationException(string.Format("Cannot find specification for hierarichal loop {0}", segmentString));
                }
            }

            if (specContainer is Transaction)
            {
                hl.Specification = transaction.Specification.HierarchicalLoopSpecifications.FirstOrDefault(
                    hls => hls.LevelCode == null || hls.LevelCode.ToString() == hl.LevelCode);
            }
            else if (specContainer is HierarchicalLoop)
            {
                HierarchicalLoop loopWithSpec = (HierarchicalLoop)specContainer;
                hl.Specification = loopWithSpec.Specification.HierarchicalLoopSpecifications.FirstOrDefault(
                    hls => hls.LevelCode == null || hls.LevelCode.ToString() == hl.LevelCode);
            }
            else if (specContainer is Loop)
            {
                Loop loopWithSpec = (Loop)specContainer;
                hl.Specification = loopWithSpec.Specification.HierarchicalLoopSpecifications.FirstOrDefault(
                    hls => hls.LevelCode == null || hls.LevelCode.ToString() == hl.LevelCode);
            }
            if (hl.Specification == null)
            {
                throw new TransactionValidationException("{0} Transaction does not expect {2} level code value {3} that appears in transaction control number {1}.",
                                                         transaction.IdentifierCode, transaction.ControlNumber, "HL03", hl.LevelCode);
            }

            _hLoops.Add(hl.Id, hl);
            // loop id must be unique throughout the transaction
            try
            {
                specContainer.AddToHLoopDictionary(hl);
            }
            catch (ArgumentException exc)
            {
                if (exc.Message == "An item with the same key has already been added.")
                {
                    throw new TransactionValidationException("Hierarchical Loop ID {3} cannot be added to {0} transaction with control number {1} because it already exists.",
                                                             transaction.IdentifierCode, transaction.ControlNumber, "HL01", hl.Id);
                }
                else
                {
                    throw;
                }
            }
            return(hl);
        }
Exemple #4
0
 internal void AddToHLoopDictionary(HierarchicalLoop hloop)
 {
     _allHLoops.Add(hloop.Id, hloop);
 }
 internal void AddToHLoopDictionary(HierarchicalLoop hloop)
 {
     _allHLoops.Add(hloop.Id, hloop);
 }