Exemplo n.º 1
0
        private MessageContext BuildContext()
        {
            if (_currentIsa == null)
            {
                throw new Exception("Interchange header is missing.");
            }

            if (CurrentSegments.Count == 1)
            {
                var ta1 = CurrentSegments.SingleOrDefault(es => es.Name == "TA1");
                if (ta1 != null)
                {
                    return(new MessageContext("TA1", "", "", "X12", _currentIsa.InterchangeSenderID_6,
                                              _currentIsa.SenderIDQualifier_5, _currentIsa.InterchangeReceiverID_8,
                                              _currentIsa.ReceiverIDQualifier_7, RulesAssembly));
                }
            }

            if (_currentGroupHeader == null)
            {
                throw new Exception("GS was not found.");
            }

            var ediCompositeDataElementsGs = _currentGroupHeader.Value.GetDataElements(Separators);

            if (ediCompositeDataElementsGs.Count() < 8)
            {
                throw new Exception("GS is invalid. Too little data elements.");
            }

            var version = ediCompositeDataElementsGs[7];

            var st = CurrentSegments.SingleOrDefault(es => es.Name == "ST");

            if (st == null)
            {
                throw new Exception("ST was not found.");
            }

            var ediCompositeDataElementsSt = st.Value.GetDataElements(Separators);
            var tag = ediCompositeDataElementsSt[0];

            if (ediCompositeDataElementsSt.Count() == 3)
            {
                version = ediCompositeDataElementsSt[2];
            }
            if (ediCompositeDataElementsSt.Count() < 2)
            {
                throw new Exception("ST is invalid.Too little data elements.");
            }

            var controlNumber = ediCompositeDataElementsSt[1];

            return(new MessageContext(tag, controlNumber, version, "X12", _currentIsa.InterchangeSenderID_6,
                                      _currentIsa.SenderIDQualifier_5, _currentIsa.InterchangeReceiverID_8, _currentIsa.ReceiverIDQualifier_7, RulesAssembly));
        }
Exemplo n.º 2
0
        private MessageContext BuildContext()
        {
            if (_currentUnb == null)
            {
                throw new Exception("Interchange header is missing.");
            }

            var unh = CurrentSegments.SingleOrDefault(es => es.Name == "UNH");

            if (unh == null)
            {
                throw new Exception("UNH was not found.");
            }

            var ediCompositeDataElements = unh.Value.GetDataElements(Separators);

            if (ediCompositeDataElements.Count() < 2)
            {
                throw new Exception("UNH is invalid. Too little data elements.");
            }

            var ediDataElements = ediCompositeDataElements[1].GetComponentDataElements(Separators);

            if (ediDataElements.Count() < 3)
            {
                throw new Exception("UNH is invalid. Unable to read message type or version.");
            }

            var tag           = ediDataElements[0];
            var version       = ediDataElements[1] + ediDataElements[2];
            var controlNumber = ediCompositeDataElements[0];

            if (ediDataElements.Count() >= 5 && ediDataElements[4].StartsWith("EAN"))
            {
                version = version + "EAN";
                if (version.StartsWith("D01B"))
                {
                    version = version + _currentUnb.SYNTAXIDENTIFIER_1.SyntaxVersionNumber_2;
                }
            }

            return(new MessageContext(tag, controlNumber, version, "EDIFACT",
                                      _currentUnb.INTERCHANGESENDER_2.InterchangeSenderIdentification_1,
                                      _currentUnb.INTERCHANGESENDER_2.IdentificationCodeQualifier_2,
                                      _currentUnb.INTERCHANGERECIPIENT_3.InterchangeRecipientIdentification_1,
                                      _currentUnb.INTERCHANGERECIPIENT_3.IdentificationCodeQualifier_2, RulesAssembly));
        }