示例#1
0
        //string json3 = @"{'Type': 'M',
        //    'Name': 'M_940',
        //    'Content': [{
        //        'Type': 'S',
        //        'Name': 'W05',
        //        'Content': [ { 'E': 'N' }, { 'E': '538686' }, { 'E': '' }, { 'E': '001001' }, { 'E': '538686' }]
        //    }]
        //}";
        //{'Type': 'M','Name': 'M_940','Content': [{'Type': 'S','Name': 'W05','Content': [ { 'E': 'N' }, { 'E': '538686' }, { 'E': '' }, { 'E': '001001' }, { 'E': '538686' }]}]}
        public string GetEDIDocFromJSON(string jsonEDIdata)
        {
            dynamic json = JsonConvert.DeserializeObject(jsonEDIdata, typeof(object));

            //TODO: convert logic to determine map to separate method

            MapLoop       map     = Factory.GetMap((string)json.Name); //TODO: add exception handling for the string cast operation
            JsonMapReader jReader = new JsonMapReader(map);
            EdiTrans      ediTxn  = jReader.ReadToEnd(jsonEDIdata);

            var eGroup = new EdiGroup("OW");

            eGroup.Transactions.Add(ediTxn);

            var eInterchange = new EdiInterchange();

            eInterchange.Groups.Add(eGroup);

            EdiBatch eBatch = new EdiBatch();

            eBatch.Interchanges.Add(eInterchange);

            //Add all service segments
            EdiDataWriterSettings settings = new EdiDataWriterSettings(
                new SegmentDefinitions.ISA(), new SegmentDefinitions.IEA(),
                new SegmentDefinitions.GS(), new SegmentDefinitions.GE(),
                new SegmentDefinitions.ST(), new SegmentDefinitions.SE(),
                "ZZ", "SENDER", "ZZ", "RECEIVER", "GSSENDER", "GSRECEIVER", "00401", "004010", "T", 100, 200, "\r\n", "*");

            EdiDataWriter ediWriter = new EdiDataWriter(settings);

            return(ediWriter.WriteToString(eBatch));
        }
示例#2
0
        public void EdiReader_ParseNestedLoopsEdi940()
        {
            using (Stream s = GetType().Assembly.GetManifestResourceStream("EdiEngine.Tests.TestData.940.2.OK.edi"))
            {
                EdiDataReader r = new EdiDataReader();
                EdiBatch      b = r.FromStream(s);

                EdiTrans t = b.Interchanges[0].Groups[0].Transactions[0];

                int w05Count = t.Content.Count(l => l.Definition.GetType() == typeof(W05));
                int w66Count = t.Content.Count(l => l.Definition.GetType() == typeof(W05));
                int llxCount = t.Content.Count(l => l.Definition.GetType() == typeof(M_940.L_LX));
                int slxCount = ((EdiLoop)t.Content.First(l => l.Definition.GetType() == typeof(M_940.L_LX)))
                               .Content.Count(c => c.Definition.GetType() == typeof(LX));
                int lw01Count = ((EdiLoop)t.Content.First(l => l.Definition.GetType() == typeof(M_940.L_LX)))
                                .Content.Count(l => l.Definition.GetType() == typeof(M_940.L_W01));
                int lw01N9Count = ((EdiLoop)((EdiLoop)t.Content.First(l => l.Definition.GetType() == typeof(M_940.L_LX)))
                                   .Content.First(l => l.Definition.GetType() == typeof(M_940.L_W01)))
                                  .Content.Count(l => l.Definition.GetType() == typeof(N9));

                Assert.AreEqual(0, t.ValidationErrors.Count);

                Assert.AreEqual(1, w05Count);
                Assert.AreEqual(1, w66Count);
                Assert.AreEqual(1, llxCount);
                Assert.AreEqual(1, slxCount);
                Assert.AreEqual(1, lw01Count);
                Assert.AreEqual(3, lw01N9Count);
            }
        }
示例#3
0
        private void BtnEdiTest_Click(object sender, EventArgs e)
        {
            bool   _OK = readEdiTest();
            string edi =
                @"ISA*01*0000000000*01*0000000000*ZZ*ABCDEFGHIJKLMNO*ZZ*123456789012345*101127*1719*U*00400*000003438*0*P*>
                GS*OW*7705551212*3111350000*20000128*0557*3317*T*004010
                ST*940*0001
                W05*N*538686**001001*538686
                LX*1
                W01*12*CA*000100000010*VN*000100*UC*DEC0199******19991205
                G69*11.500 STRUD BLUBRY
                W76*56*500*LB*24*CF
                SE*7*0001
                GE*1*3317
                IEA*1*000003438";


            EdiDataReader r = new EdiDataReader();
            EdiBatch      b = r.FromString(edi);

            //Serialize the whole batch to JSON
            JsonDataWriter w1   = new JsonDataWriter();
            string         json = w1.WriteToString(b);

            //OR Serialize selected EDI message to Json
            string jsonTrans = JsonConvert.SerializeObject(b.Interchanges[0].Groups[0].Transactions[0]);

            //Serialize the whole batch to XML
            XmlDataWriter w2  = new XmlDataWriter();
            string        xml = w2.WriteToString(b);
        }
        private string writeEdiEnvelope(EdiTrans t, string functionalCode, string mode, string receiver)
        {
            //string _Sender = "84352008TEST";
            //string _Receiver = "8174836888";
            string _Sender   = ConfigurationManager.AppSettings["Sender"];
            string _Receiver = receiver;
            string _Version  = "00401";
            //create batch
            EdiBatch b = new EdiBatch();

            b.Interchanges.Add(new EdiInterchange());
            b.Interchanges.First().Groups.Add(new EdiGroup(functionalCode));
            b.Interchanges.First().Groups.First().Transactions.Add(t);

            //Add all service segments
            EdiDataWriterSettings settings = new EdiDataWriterSettings(
                new EdiEngine.Standards.X12_004010.Segments.ISA(), new EdiEngine.Standards.X12_004010.Segments.IEA(),
                new EdiEngine.Standards.X12_004010.Segments.GS(), new EdiEngine.Standards.X12_004010.Segments.GE(),
                new EdiEngine.Standards.X12_004010.Segments.ST(), new EdiEngine.Standards.X12_004010.Segments.SE(),
                "ZZ", _Sender, "ZZ", _Receiver, _Sender, _Receiver,
                _Version, "004010", mode, 100, 200, "\r\n", "*");

            EdiDataWriter w = new EdiDataWriter(settings);

            return(w.WriteToString(b));
        }
示例#5
0
        public void JsonReadWrite_JsonSerializationTest()
        {
            using (Stream s = GetType().Assembly.GetManifestResourceStream("EdiEngine.Tests.TestData.940.OK.edi"))
            {
                EdiDataReader r = new EdiDataReader();
                EdiBatch      b = r.FromStream(s);

                //Write Json using newtonsoft
                //check no exception
                JsonConvert.SerializeObject(b);
                JsonConvert.SerializeObject(b.Interchanges[0].Groups[0].Transactions[0]);

                //or use writer to write to string or stream
                JsonDataWriter w      = new JsonDataWriter();
                string         str    = w.WriteToString(b);
                Stream         stream = w.WriteToStream(b);

                Assert.IsNotNull(str);

                Assert.IsNotNull(stream);
                Assert.AreEqual(0, stream.Position);
                Assert.IsTrue(stream.CanRead);

                Assert.AreEqual(str.Length, stream.Length);
            }
        }
示例#6
0
        public string GetJSONFromEDIDoc(string ediDoc)
        {
            string edi =
                @"ISA*01*0000000000*01*0000000000*ZZ*ABCDEFGHIJKLMNO*ZZ*123456789012345*101127*1719*U*00400*000003438*0*P*>
                GS*OW*7705551212*3111350000*20000128*0557*3317*T*004010
                ST*940*0001
                W05*N*538686**001001*538686
                LX*1
                W01*12*CA*000100000010*VN*000100*UC*DEC0199******19991205
                G69*11.500 STRUD BLUBRY
                W76*56*500*LB*24*CF
                SE*7*0001
                GE*1*3317
                IEA*1*000003438";

            EdiDataReader ediReader = new EdiDataReader();
            EdiBatch      ediBatch  = ediReader.FromString(ediDoc);

            //Serialize the whole batch to JSON
            JsonDataWriter w1   = new JsonDataWriter();
            string         json = w1.WriteToString(ediBatch);

            ////OR Serialize selected EDI message to Json
            //string jsonTrans = JsonConvert.SerializeObject(ediBatch.Interchanges[0].Groups[0].Transactions[0]);

            ////Serialize the whole batch to XML
            //XmlDataWriter w2 = new XmlDataWriter();
            //string xml = w2.WriteToString(ediBatch);
            return(JsonConvert.SerializeObject(json));
        }
示例#7
0
        public override string WriteToString(EdiBatch batch)
        {
            EdiBatch ackBatch = GetnerateAcknowledgment(batch);

            BuildAckControlSegments(ackBatch, batch);

            return(WriteToStringBuilder(ackBatch).ToString());
        }
示例#8
0
        private void readEdi()
        {
            string        edi = txtEDIinput.Text;
            EdiDataReader r   = new EdiDataReader();
            EdiBatch      b   = r.FromString(edi);

            MessageBox.Show(b.Interchanges.Count.ToString());
        }
        public override Stream WriteToStream(EdiBatch batch)
        {
            Stream       s = new MemoryStream();
            StreamWriter w = new StreamWriter(s);

            w.Write(WriteToStringBuilder(batch));
            w.Flush();
            s.Position = 0;
            return(s);
        }
示例#10
0
 public override string WriteToString(EdiBatch batch)
 {
     using (Stream s = WriteToStream(batch))
     {
         using (StreamReader r = new StreamReader(s, _settings.Encoding))
         {
             return(r.ReadToEnd());
         }
     }
 }
示例#11
0
        public void EdiReader_WrongGroupsAndTranCount()
        {
            using (Stream s = GetType().Assembly.GetManifestResourceStream("EdiEngine.Tests.TestData.WrongGroupsAndTranCount.edi"))
            {
                EdiDataReader r = new EdiDataReader();
                EdiBatch      b = r.FromStream(s);

                Assert.AreEqual("Expected 2 groups. Found 1. Interchange # 3438.", b.Interchanges[0].ValidationErrors.Last().Message);
                Assert.AreEqual("Expected 2 transactions. Found 1. Group # 3314.", b.Interchanges[0].Groups[0].ValidationErrors.Last().Message);
            }
        }
示例#12
0
        public void JsonReadWrite_SerializeComposite()
        {
            using (Stream s = GetType().Assembly.GetManifestResourceStream("EdiEngine.Tests.TestData.850.Composite.SLN.OK.edi"))
            {
                EdiDataReader r = new EdiDataReader();
                EdiBatch      b = r.FromStream(s);

                JsonDataWriter jsonWriter = new JsonDataWriter();
                jsonWriter.WriteToString(b);
            }
        }
示例#13
0
        public void JsonReadWrite_JsonSerializationHlLoopTest()
        {
            using (Stream s = GetType().Assembly.GetManifestResourceStream("EdiEngine.Tests.TestData.856.Crossdock.OK.edi"))
            {
                EdiDataReader r = new EdiDataReader();
                EdiBatch      b = r.FromStream(s);

                JsonDataWriter jsonWriter = new JsonDataWriter();
                jsonWriter.WriteToString(b);
            }
        }
        protected virtual StringBuilder WriteToStringBuilder(EdiBatch batch)
        {
            StringBuilder sb = new StringBuilder();

            int icn = _settings.IsaFirstControlNumber;
            int gcn = _settings.GsFirstControlNumber;

            foreach (EdiInterchange ich in batch.Interchanges)
            {
                ich.ISA = new ISA(_settings.IsaDef,
                                  _settings.IsaSenderQual, _settings.IsaSenderId,
                                  _settings.IsaReceiverQual, _settings.IsaReceiverId,
                                  _settings.IsaEdiVersion, icn, _settings.IsaUsageIndicator);

                WriteEntity(ich.ISA, ref sb);

                foreach (EdiGroup g in ich.Groups)
                {
                    int currentTranIdx = 1;
                    g.GS = new GS(_settings.GsDef, g.FunctionalCode, _settings.GsSenderId, _settings.GsReceiverId, gcn, _settings.GsEdiVersion);
                    WriteEntity(g.GS, ref sb);

                    foreach (EdiTrans t in g.Transactions)
                    {
                        _currentTranSegCount = 0;

                        t.ST = new ST(_settings.StDef, t.Definition.EdiName, currentTranIdx);
                        WriteEntity(t.ST, ref sb, t);

                        foreach (EdiBaseEntity ent in t.Content)
                        {
                            WriteEntity(ent, ref sb, t);
                        }

                        _currentTranSegCount++;
                        t.SE = new SE(_settings.SeDef, _currentTranSegCount, currentTranIdx);
                        WriteEntity(t.SE, ref sb, t);

                        currentTranIdx++;
                    }

                    g.GE = new GE(_settings.GeDef, g.Transactions.Count, gcn);
                    WriteEntity(g.GE, ref sb);
                    gcn++;
                }

                ich.IEA = new IEA(_settings.IeaDef, ich.Groups.Count, icn);
                WriteEntity(ich.IEA, ref sb);
                icn++;
            }

            return(sb);
        }
示例#15
0
        public void EdiReader_ParseGenericEdi940WithExternalMapAssembly()
        {
            using (Stream s = GetType().Assembly.GetManifestResourceStream("EdiEngine.Tests.TestData.940.W05.Only.edi"))
            {
                EdiDataReader r = new EdiDataReader("EdiEngine.Tests");
                EdiBatch      b = r.FromStream(s);

                EdiTrans t = b.Interchanges[0].Groups[0].Transactions[0];

                Assert.AreEqual(0, t.ValidationErrors.Count);
            }
        }
示例#16
0
        public void EdiWriter_WriteComposite()
        {
            //nonexisting map with just SLN segment to test composites
            M_001    map = new M_001();
            EdiTrans t   = new EdiTrans(map);

            var sDef = (MapSegment)map.Content.First(s => s.Name == "SLN");

            var seg = new EdiSegment(sDef);

            //create composite
            var c001 = new EdiCompositeDataElement(sDef.Content[4], null);

            c001.Content.AddRange(new[] {
                new EdiSimpleDataElement(c001.Definition.Content[0], "PC"),
                new EdiSimpleDataElement(c001.Definition.Content[1], "21.1"),
                new EdiSimpleDataElement(c001.Definition.Content[2], "22.2"),
                new EdiSimpleDataElement(c001.Definition.Content[3], "EA"),
                new EdiSimpleDataElement(c001.Definition.Content[4], "23.3"),
                new EdiSimpleDataElement(c001.Definition.Content[5], "24.4")
            });

            //create segment
            seg.Content.AddRange(new DataElementBase[]
            {
                new EdiSimpleDataElement(sDef.Content[0], "1.1"),
                new EdiSimpleDataElement(sDef.Content[1], null),
                new EdiSimpleDataElement(sDef.Content[2], "I"),
                new EdiSimpleDataElement(sDef.Content[3], "10000"),
                c001,
                new EdiSimpleDataElement(sDef.Content[5], "1.56"),
                new EdiSimpleDataElement(sDef.Content[6], "TP"),
                new EdiSimpleDataElement(sDef.Content[7], null),
                new EdiSimpleDataElement(sDef.Content[8], "VC"),
                new EdiSimpleDataElement(sDef.Content[9], "P-875OS")
            });
            t.Content.Add(seg);

            string data = TestUtils.WriteEdiEnvelope(t, "ZZ");

            EdiDataReader r = new EdiDataReader("EdiEngine.Tests");
            EdiBatch      b = r.FromString(data);

            EdiTrans t2 = b.Interchanges[0].Groups[0].Transactions[0];

            //1 error - unknown map
            Assert.AreEqual(1, t2.ValidationErrors.Count);

            var sln = (EdiSegment)t.Content.First();

            Assert.IsTrue(sln.Content[4] is EdiCompositeDataElement);
            Assert.AreEqual(6, ((EdiCompositeDataElement)sln.Content[4]).Content.Count);
        }
示例#17
0
        public void EdiReader_ParseFailedSegCount()
        {
            using (Stream s = GetType().Assembly.GetManifestResourceStream("EdiEngine.Tests.TestData.940_Failed_SE01.edi"))
            {
                EdiDataReader r = new EdiDataReader();
                EdiBatch      b = r.FromStream(s);

                EdiTrans t = b.Interchanges[0].Groups[0].Transactions[0];

                Assert.AreEqual("Expected 12 segments. Found 9. Trans # 20066.", t.ValidationErrors.Last().Message);
            }
        }
        public override Stream WriteToStream(EdiBatch batch)
        {
            MemoryStream s          = new MemoryStream();
            StreamWriter w          = new StreamWriter(s);
            var          serializer = new JsonSerializer();

            serializer.Serialize(w, batch);
            w.Flush();

            s.Position = 0;
            return(s);
        }
示例#19
0
        public void EdiReader_ParseGenericEdi940()
        {
            using (Stream s = GetType().Assembly.GetManifestResourceStream("EdiEngine.Tests.TestData.940.OK.edi"))
            {
                EdiDataReader r = new EdiDataReader();
                EdiBatch      b = r.FromStream(s);

                Assert.AreEqual(1, b.Interchanges.Count);
                Assert.AreEqual(1, b.Interchanges[0].Groups.Count);
                Assert.AreEqual(1, b.Interchanges[0].Groups[0].Transactions.Count);

                EdiTrans t = b.Interchanges[0].Groups[0].Transactions[0];

                int w05Count = t.Content.Count(l => l.Definition.GetType() == typeof(W05));
                int n1Count  = t.Content.Count(l => l.Definition.GetType() == typeof(M_940.L_N1));
                int n1FirstIterationCount =
                    ((EdiLoop)t.Content.First(l => l.Definition.GetType() == typeof(M_940.L_N1))).Content.Count;
                int n1SecondIterationCount =
                    ((EdiLoop)t.Content.Where(l => l.Definition.GetType() == typeof(M_940.L_N1)).Skip(1).First())
                    .Content.Count;
                int n1ThirdIterationCount =
                    ((EdiLoop)t.Content.Where(l => l.Definition.GetType() == typeof(M_940.L_N1)).Skip(2).First())
                    .Content.Count;
                int n9Count  = t.Content.Count(l => l.Definition.GetType() == typeof(N9));
                int g62Count = t.Content.Count(l => l.Definition.GetType() == typeof(G62));
                int nteCount = t.Content.Count(l => l.Definition.GetType() == typeof(NTE));
                int w66Count = t.Content.Count(l => l.Definition.GetType() == typeof(W66));
                int lxCount  = t.Content.Count(l => l.Definition.GetType() == typeof(M_940.L_LX));
                int lxFirstIterationCount =
                    ((EdiLoop)t.Content.First(l => l.Definition.GetType() == typeof(M_940.L_LX))).Content.Count;
                int lxFirstIterationW01Count =
                    ((EdiLoop)((EdiLoop)t.Content.First(l => l.Definition.GetType() == typeof(M_940.L_LX)))
                     .Content.Skip(1).First()).Content.Count;
                int w76Count = t.Content.Count(l => l.Definition.GetType() == typeof(W76));


                Assert.AreEqual(0, t.ValidationErrors.Count);

                Assert.AreEqual(1, w05Count);
                Assert.AreEqual(3, n1Count);
                Assert.AreEqual(3, n1FirstIterationCount);
                Assert.AreEqual(3, n1SecondIterationCount);
                Assert.AreEqual(2, n1ThirdIterationCount);
                Assert.AreEqual(1, n9Count);
                Assert.AreEqual(2, g62Count);
                Assert.AreEqual(1, nteCount);
                Assert.AreEqual(1, w66Count);
                Assert.AreEqual(3, lxCount);
                Assert.AreEqual(2, lxFirstIterationCount);
                Assert.AreEqual(3, lxFirstIterationW01Count);
                Assert.AreEqual(1, w76Count);
            }
        }
示例#20
0
        public void EdiReader_ControlNumbersMismatcht()
        {
            using (Stream s = GetType().Assembly.GetManifestResourceStream("EdiEngine.Tests.TestData.ControlNumbersMismatch.edi"))
            {
                EdiDataReader r = new EdiDataReader();
                EdiBatch      b = r.FromStream(s);

                Assert.AreEqual("Control numbers do not match. ISA 000003438. IEA 000003439.", b.Interchanges[0].ValidationErrors.Last().Message);
                Assert.AreEqual("Control numbers do not match. GS 3314. GE 3315.", b.Interchanges[0].Groups[0].ValidationErrors.Last().Message);
                Assert.AreEqual("Control numbers do not match. ST 0001. SE 0002.", b.Interchanges[0].Groups[0].Transactions[0].ValidationErrors.Last().Message);
            }
        }
示例#21
0
        public void AckBuilder_AcceptAll_WithAk2()
        {
            EdiBatch b;

            using (Stream s = GetType().Assembly.GetManifestResourceStream("EdiEngine.Tests.TestData.AckTest.edi"))
            {
                EdiDataReader r = new EdiDataReader();
                b = r.FromStream(s);
            }

            AckBuilderSettings ackSettings = new AckBuilderSettings(AckValidationErrorBehavour.AcceptAll, true, 100, 200);
            var ack = new AckBuilder(ackSettings);

            EdiBatch ackBatch = ack.GetnerateAcknowledgment(b);
            //string data = ack.WriteToString(b);

            EdiTrans ack1 = ackBatch.Interchanges[0].Groups[0].Transactions[0];
            EdiTrans ack2 = ackBatch.Interchanges[0].Groups[1].Transactions[0];

            EdiSegment ak1       = (EdiSegment)ack1.Content.FirstOrDefault(l => l.Definition.GetType() == typeof(AK1));
            EdiLoop    loopAk2_1 = (EdiLoop)ack1.Content.FirstOrDefault(l => l.Definition.GetType() == typeof(M_997.L_AK2));
            EdiLoop    loopAk2_2 = (EdiLoop)ack1.Content.LastOrDefault(l => l.Definition.GetType() == typeof(M_997.L_AK2));
            EdiSegment ak5_1     = (EdiSegment)loopAk2_1.Content.FirstOrDefault(l => l.Definition.GetType() == typeof(AK5));
            EdiSegment ak5_2     = (EdiSegment)loopAk2_2.Content.FirstOrDefault(l => l.Definition.GetType() == typeof(AK5));
            EdiSegment ak9       = (EdiSegment)ack1.Content.FirstOrDefault(l => l.Definition.GetType() == typeof(AK9));

            Assert.IsNotNull(ak1);
            Assert.IsNotNull(loopAk2_1);
            Assert.AreEqual("A", ak5_1.Content[0].Val);
            Assert.AreEqual("A", ak5_2.Content[0].Val);
            Assert.IsNotNull(loopAk2_2);
            Assert.IsNotNull(ak9);
            Assert.AreEqual("A", ak9.Content[0].Val);
            Assert.AreEqual("2", ak9.Content[1].Val);
            Assert.AreEqual("2", ak9.Content[2].Val);
            Assert.AreEqual("2", ak9.Content[3].Val);

            ak1       = (EdiSegment)ack2.Content.FirstOrDefault(l => l.Definition.GetType() == typeof(AK1));
            loopAk2_1 = (EdiLoop)ack1.Content.FirstOrDefault(l => l.Definition.GetType() == typeof(M_997.L_AK2));
            ak5_1     = (EdiSegment)loopAk2_1.Content.FirstOrDefault(l => l.Definition.GetType() == typeof(AK5));
            ak9       = (EdiSegment)ack2.Content.FirstOrDefault(l => l.Definition.GetType() == typeof(AK9));

            Assert.IsNotNull(ak1);
            Assert.IsNotNull(loopAk2_1);
            Assert.AreEqual("A", ak5_1.Content[0].Val);
            Assert.IsNotNull(ak9);
            Assert.AreEqual("A", ak9.Content[0].Val);
            Assert.AreEqual("1", ak9.Content[1].Val);
            Assert.AreEqual("1", ak9.Content[2].Val);
            Assert.AreEqual("1", ak9.Content[3].Val);
        }
示例#22
0
        /// <summary> _ediAdapterFactory
        /// read edi message to map order list
        /// </summary>
        /// <param name="parserFile"></param>
        /// <returns></returns>
        private void readEdi(string parserFile, Edi_Customer c, string s)
        {
            string        _EdiBasePath = ConfigurationManager.AppSettings["EdiBase"];
            string        edi          = System.IO.File.ReadAllText(parserFile);
            EdiDataReader r            = new EdiDataReader();
            EdiBatch      b            = r.FromString(edi);
            EdiTrans      _Trans       = b.Interchanges[0].Groups[0].Transactions[0];
            EdiBase       _EdiBase     = _ediAdapterFactory.CreateEdiAdapter(_Trans.Definition.ToString());
            string        _Log         = _EdiBase.Parse(b, c, parserFile);

            txtLog.Text += _Log;
            _Log         = _EdiBase.Process(c, s, _EdiBasePath);
            txtLog.Text += _Log;
        }
示例#23
0
        public override Stream WriteToStream(EdiBatch batch)
        {
            EdiBatch ackBatch = GetnerateAcknowledgment(batch);

            BuildAckControlSegments(ackBatch, batch);

            Stream       s = new MemoryStream();
            StreamWriter w = new StreamWriter(s);

            w.Write(WriteToStringBuilder(ackBatch));
            w.Flush();
            s.Position = 0;
            return(s);
        }
示例#24
0
        private void readEdibyEdifact()
        {
            //var grammar = EdiGrammar.NewTradacoms();
            //var interchange = default(Interchange);
            //using (var stream = new StreamReader(@"D:\Users\L180067\Desktop\EDI_C4782x_ORDERS_ATWE_20200423_sample.dat"))
            //{
            //    interchange = new EdiSerializer().Deserialize<Interchange>(stream, grammar);
            //}

            // return setSalesOrderByEdi(b, c, parserFile);

            string        edi = txtEDIinput.Text;
            EdiDataReader r   = new EdiDataReader();
            EdiBatch      b   = r.FromString(edi);
        }
示例#25
0
        private bool readEdiTest( )
        {
            bool _OK = false;

            try
            {
                EdiDataReader r = new EdiDataReader();
                EdiBatch      b = r.FromString(txtANSIX12.Text);
                _OK = true;
            }
            catch (Exception ex) {
                MessageBox.Show(ex.Message);
            }
            return(_OK);
        }
示例#26
0
        public void EdiReaderHL_ParseCrossDock856()
        {
            using (Stream s = GetType().Assembly.GetManifestResourceStream("EdiEngine.Tests.TestData.856.Crossdock.OK.edi"))
            {
                EdiDataReader r = new EdiDataReader();
                EdiBatch      b = r.FromStream(s);

                Assert.AreEqual(1, b.Interchanges.Count);
                Assert.AreEqual(1, b.Interchanges[0].Groups.Count);
                Assert.AreEqual(1, b.Interchanges[0].Groups[0].Transactions.Count);

                EdiTrans t = b.Interchanges[0].Groups[0].Transactions[0];

                Assert.AreEqual(0, t.ValidationErrors.Count);
            }
        }
示例#27
0
        public void XmlReadWrite_XmlSerializationHlLoopTest()
        {
            using (Stream s = GetType().Assembly.GetManifestResourceStream("EdiEngine.Tests.TestData.856.Crossdock.OK.edi"))
            {
                EdiDataReader r = new EdiDataReader();
                EdiBatch      b = r.FromStream(s);

                XmlDataWriter w    = new XmlDataWriter();
                string        data = w.WriteToString(b);

                XmlDocument xdoc = ValidateBySchema(data);

                //check parsed seg count
                int?segCount = xdoc.SelectNodes("//EdiSegment")?.Count;
                Assert.AreEqual(61, segCount);
            }
        }
示例#28
0
        public override Stream WriteToStream(EdiBatch batch)
        {
            Stream s = new MemoryStream();

            XmlWriter w = XmlWriter.Create(s, _settings);

            w.WriteStartDocument();

            WrtiteObject(batch, w);

            w.WriteEndDocument();
            w.Flush();
            w.Close();

            s.Position = 0;
            return(s);
        }
示例#29
0
        public void EdiReader_ParseMultipleInterchangesAndGroups()
        {
            using (Stream s = GetType().Assembly.GetManifestResourceStream("EdiEngine.Tests.TestData.MultipleInterchangesAndGroups.edi"))
            {
                EdiDataReader r = new EdiDataReader();
                EdiBatch      b = r.FromStream(s);

                Assert.AreEqual(2, b.Interchanges.Count);
                Assert.AreEqual(2, b.Interchanges[0].Groups.Count);

                Assert.AreEqual(2, b.Interchanges[0].Groups[0].Transactions.Count);
                Assert.AreEqual(1, b.Interchanges[0].Groups[1].Transactions.Count);

                Assert.AreEqual(2, b.Interchanges[1].Groups[0].Transactions.Count);
                Assert.AreEqual(1, b.Interchanges[1].Groups[1].Transactions.Count);
            }
        }
示例#30
0
        private void BuildAckControlSegments(EdiBatch ackBatch, EdiBatch originalBatch)
        {
            int icn = _settings.IsaFirstControlNumber;
            int gcn = _settings.GsFirstControlNumber;
            int i   = 0;

            foreach (EdiInterchange ich in ackBatch.Interchanges)
            {
                var isa = originalBatch.Interchanges[i].ISA;
                var iea = originalBatch.Interchanges[i].IEA;
                ich.ISA = new ISA((MapSegment)isa.Definition, isa.Content[6].Val, isa.Content[7].Val,
                                  isa.Content[4].Val, isa.Content[5].Val, isa.Content[11].Val, icn, isa.Content[14].Val);

                ich.SegmentSeparator = originalBatch.Interchanges[i].SegmentSeparator;
                ich.ElementSeparator = originalBatch.Interchanges[i].ElementSeparator;

                int j = 0;
                foreach (EdiGroup g in ich.Groups)
                {
                    var gs = originalBatch.Interchanges[i].Groups[j].GS;
                    var ge = originalBatch.Interchanges[i].Groups[j].GE;
                    var st = originalBatch.Interchanges[i].Groups[j].Transactions[0].ST;
                    var se = originalBatch.Interchanges[i].Groups[j].Transactions[0].SE;

                    g.GS = new GS((MapSegment)gs.Definition, "FA", gs.Content[2].Val, gs.Content[1].Val, gcn,
                                  gs.Content[7].Val);
                    g.GE = new GE((MapSegment)ge.Definition, g.Transactions.Count, gcn);

                    //always 1 tran per FA group
                    g.Transactions[0].ST = new ST((MapSegment)st.Definition, "997", 1);

                    int segCount = 2; //ST, SE
                    GetTranSegCount(g.Transactions[0], ref segCount);

                    g.Transactions[0].SE = new SE((MapSegment)se.Definition, segCount, 1);

                    gcn++;
                    j++;
                }

                ich.IEA = new IEA((MapSegment)iea.Definition, ich.Groups.Count, icn);
                icn++;
                i++;
            }
        }