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); }
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); } }
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); } }
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)); }
public void EdiReader_ParseNonEDI() { using (Stream s = GetType().Assembly.GetManifestResourceStream("EdiEngine.Tests.TestData.NonEdi.edi")) { EdiDataReader r = new EdiDataReader(); r.FromStream(s); } }
private void readEdi() { string edi = txtEDIinput.Text; EdiDataReader r = new EdiDataReader(); EdiBatch b = r.FromString(edi); MessageBox.Show(b.Interchanges.Count.ToString()); }
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); } }
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); } }
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); } }
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); }
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 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); } }
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); } }
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); } }
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); }
/// <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; }
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); }
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); }
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); } }
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); } }
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); } }
static void Main(string[] args) { TextReader tIn = Console.In; String ediData = tIn.ReadLine(); EdiDataReader r = new EdiDataReader(); EdiBatch ediBatch = r.FromString(ediData); //control whether you need to accept all transaction or report error if such. AckBuilderSettings ackSettings = new AckBuilderSettings(AckValidationErrorBehavour.AcceptAll, false, 100, 200); var ack = new AckBuilder(ackSettings); //create FA object structure EdiBatch ackBatch = ack.GetnerateAcknowledgment(ediBatch); string data = ack.WriteToString(ediBatch); Console.WriteLine(data); }
public void SyntaxNote_Edi850Fail() { using (Stream s = GetType().Assembly.GetManifestResourceStream("EdiEngine.Tests.TestData.850.SyntaxNotes.ERR.edi")) { EdiDataReader r = new EdiDataReader(); EdiBatch b = r.FromStream(s); EdiTrans t = b.Interchanges[0].Groups[0].Transactions[0]; Assert.AreEqual(3, t.ValidationErrors.Count); Assert.AreEqual(13, t.ValidationErrors[0].SegmentPos); Assert.IsTrue(t.ValidationErrors[0].Message.Contains("P0607")); Assert.AreEqual(30, t.ValidationErrors[1].SegmentPos); Assert.IsTrue(t.ValidationErrors[1].Message.Contains("C0506")); Assert.AreEqual(30, t.ValidationErrors[2].SegmentPos); Assert.IsTrue(t.ValidationErrors[2].Message.Contains("P0607")); } }
public void XmlReadWrite_XmlSerializationTest() { using (Stream s = GetType().Assembly.GetManifestResourceStream("EdiEngine.Tests.TestData.940.OK.edi")) { EdiDataReader r = new EdiDataReader(); EdiBatch b = r.FromStream(s); XmlDataWriter w = new XmlDataWriter(); string data = w.WriteToString(b); Stream stream = w.WriteToStream(b); Assert.IsNotNull(stream); Assert.AreEqual(0, stream.Position); Assert.IsTrue(stream.CanRead); XmlDocument xdoc = ValidateBySchema(data); //check parsed seg count int?segCount = xdoc.SelectNodes("//EdiSegment")?.Count; Assert.AreEqual(33, segCount); } }
public void EdiWriter_CreateEdi940() { M_940 map = new M_940(); EdiTrans t = new EdiTrans(map); // W05 var sDef = (MapSegment)map.Content.First(s => s.Name == "W05"); var seg = new EdiSegment(sDef); seg.Content.AddRange(new[] { new EdiDataElement(sDef.Content[0], "N"), new EdiDataElement(sDef.Content[1], "538686"), new EdiDataElement(sDef.Content[2], null), new EdiDataElement(sDef.Content[3], "001001"), new EdiDataElement(sDef.Content[4], "538686") }); t.Content.Add(seg); //LX*1 var lDef = (MapLoop)map.Content.First(s => s.Name == "L_LX"); sDef = (MapSegment)lDef.Content.First(s => s.Name == "LX"); EdiLoop lx = new EdiLoop(lDef, null); t.Content.Add(lx); seg = new EdiSegment(sDef); seg.Content.Add(new EdiDataElement(sDef.Content[0], "1")); lx.Content.Add(seg); //LX > W01 loop lDef = (MapLoop)lDef.Content.First(s => s.Name == "L_W01"); sDef = (MapSegment)lDef.Content.First(s => s.Name == "W01"); EdiLoop w01 = new EdiLoop(lDef, null); lx.Content.Add(w01); seg = new EdiSegment(sDef); seg.Content.AddRange(new[] { new EdiDataElement(sDef.Content[0], "12"), new EdiDataElement(sDef.Content[1], "CA"), new EdiDataElement(sDef.Content[1], "000100033330") }); w01.Content.Add(seg); //LX*2 lDef = (MapLoop)map.Content.First(s => s.Name == "L_LX"); sDef = (MapSegment)lDef.Content.First(s => s.Name == "LX"); lx = new EdiLoop(lDef, null); t.Content.Add(lx); seg = new EdiSegment(sDef); seg.Content.Add(new EdiDataElement(sDef.Content[0], "2")); lx.Content.Add(seg); //LX > W01 loop lDef = (MapLoop)lDef.Content.First(s => s.Name == "L_W01"); sDef = (MapSegment)lDef.Content.First(s => s.Name == "W01"); w01 = new EdiLoop(lDef, null); lx.Content.Add(w01); seg = new EdiSegment(sDef); seg.Content.AddRange(new[] { new EdiDataElement(sDef.Content[0], "10"), new EdiDataElement(sDef.Content[1], "CA"), new EdiDataElement(sDef.Content[1], "000100033332") }); w01.Content.Add(seg); //write test envelope string data = TestUtils.WriteEdiEnvelope(t, "OW"); //read produced results and check for errors. EdiDataReader r = new EdiDataReader(); EdiBatch batch = r.FromString(data); Assert.AreEqual(1, batch.Interchanges.Count); Assert.AreEqual(0, batch.Interchanges[0].ValidationErrors.Count); Assert.AreEqual(1, batch.Interchanges[0].Groups.Count); Assert.AreEqual(0, batch.Interchanges[0].Groups[0].ValidationErrors.Count); EdiTrans trans = batch.Interchanges[0].Groups[0].Transactions[0]; Assert.AreEqual(0, trans.ValidationErrors.Count); }
public string X12_855(Edi_SalesOrder_855 sapSalesOrder, string mode, string receiver) { M_855 map = new M_855(); EdiTrans t = new EdiTrans(map); var sDef = (MapSegment)map.Content.First(s => s.Name == "BAK"); var seg = new EdiSegment(sDef); seg.Content.AddRange(new[] { new EdiSimpleDataElement((MapSimpleDataElement)sDef.Content[0], "00"), new EdiSimpleDataElement((MapSimpleDataElement)sDef.Content[1], sapSalesOrder.Header.Status), //AD:No change AC:with change RD:rejected new EdiSimpleDataElement((MapSimpleDataElement)sDef.Content[2], sapSalesOrder.Header.PURCH_NO_C), //set 850 order number new EdiSimpleDataElement((MapSimpleDataElement)sDef.Content[3], sapSalesOrder.Header.PURCH_DATE), new EdiSimpleDataElement((MapSimpleDataElement)sDef.Content[7], sapSalesOrder.Header.OrderNumber), new EdiSimpleDataElement((MapSimpleDataElement)sDef.Content[8], sapSalesOrder.Header.DateTime) }); t.Content.Add(seg); //create segment var lDef = (MapLoop)map.Content.First(s => s.Name == "L_PO1"); sDef = (MapSegment)lDef.Content.First(s => s.Name == "PO1"); EdiLoop p01 = new EdiLoop(lDef, null); t.Content.Add(p01); //get sap order price? foreach (Edi_SalesItem_855 i in sapSalesOrder.ItemList) { seg = new EdiSegment(sDef); seg.Content.AddRange(new[] { new EdiSimpleDataElement((MapSimpleDataElement)sDef.Content[0], i.CustomerItemNumber), new EdiSimpleDataElement((MapSimpleDataElement)sDef.Content[1], i.TARGET_QTY), new EdiSimpleDataElement((MapSimpleDataElement)sDef.Content[2], i.CustomerUnit), //ok new EdiSimpleDataElement((MapSimpleDataElement)sDef.Content[3], i.Price), new EdiSimpleDataElement((MapSimpleDataElement)sDef.Content[4], i.CustomerUnitOfPrice), //ok new EdiSimpleDataElement((MapSimpleDataElement)sDef.Content[5], "BP"), new EdiSimpleDataElement((MapSimpleDataElement)sDef.Content[6], i.CUST_MAT35), new EdiSimpleDataElement((MapSimpleDataElement)sDef.Content[7], "VP"), new EdiSimpleDataElement((MapSimpleDataElement)sDef.Content[8], i.MATERIAL) }); p01.Content.Add(seg); var lDef_L_ACK = (MapLoop)lDef.Content.First(s => s.Name == "L_ACK"); var sDef_ACK = (MapSegment)lDef_L_ACK.Content.First(s => s.Name == "ACK"); EdiLoop w = new EdiLoop(lDef_L_ACK, p01); p01.Content.Add(w); foreach (Edi_SalesSchedule_855 j in sapSalesOrder.ScheduleList) { if (i.ITM_NUMBER == j.ITM_NUMBER) { seg = new EdiSegment(sDef_ACK); seg.Content.AddRange(new[] { new EdiSimpleDataElement((MapSimpleDataElement)sDef.Content[0], j.Status), //IA:accept IR:reject new EdiSimpleDataElement((MapSimpleDataElement)sDef.Content[1], j.REQ_QTY), new EdiSimpleDataElement((MapSimpleDataElement)sDef.Content[2], i.CustomerUnit), //ok new EdiSimpleDataElement((MapSimpleDataElement)sDef.Content[2], j.DateTimeCode), new EdiSimpleDataElement((MapSimpleDataElement)sDef.Content[2], j.DateTime) }); w.Content.Add(seg); } } } string data = writeEdiEnvelope(t, "PR", mode, receiver); //read produced results and check for errors. EdiDataReader r = new EdiDataReader(); EdiBatch batch = r.FromString(data); EdiTrans trans = batch.Interchanges[0].Groups[0].Transactions[0]; return(data); }
public void EdiWriter_FromJson() { //get sample json string jsonTrans; using ( Stream s = GetType().Assembly.GetManifestResourceStream("EdiEngine.Tests.TestData.940.OK.json")) { if (s == null) { throw new InvalidDataException("stream is null"); } using (StreamReader sr = new StreamReader(s)) { jsonTrans = sr.ReadToEnd(); } } //Read json and convert it to trans M_940 map = new M_940(); JsonMapReader r = new JsonMapReader(map); EdiTrans t = r.ReadToEnd(jsonTrans); //write EDI string data = TestUtils.WriteEdiEnvelope(t, "OW"); //Read produced results and check for errors and correct parsing EdiDataReader reader = new EdiDataReader(); EdiBatch batch = reader.FromString(data); Assert.AreEqual(1, batch.Interchanges.Count); Assert.AreEqual(0, batch.Interchanges[0].ValidationErrors.Count); Assert.AreEqual(1, batch.Interchanges[0].Groups.Count); Assert.AreEqual(0, batch.Interchanges[0].Groups[0].ValidationErrors.Count); EdiTrans trans = batch.Interchanges[0].Groups[0].Transactions[0]; Assert.AreEqual(0, trans.ValidationErrors.Count); int w05Count = trans.Content.Count(l => l.Definition.GetType() == typeof(SegmentDefinitions.W05)); int n1Count = trans.Content.Count(l => l.Definition.GetType() == typeof(M_940.L_N1)); int n1FirstIterationCount = ((EdiLoop)trans.Content.First(l => l.Definition.GetType() == typeof(M_940.L_N1))).Content.Count; int n1SecondIterationCount = ((EdiLoop)trans.Content.Where(l => l.Definition.GetType() == typeof(M_940.L_N1)).Skip(1).First()) .Content.Count; int n1ThirdIterationCount = ((EdiLoop)trans.Content.Where(l => l.Definition.GetType() == typeof(M_940.L_N1)).Skip(2).First()) .Content.Count; int n9Count = trans.Content.Count(l => l.Definition.GetType() == typeof(SegmentDefinitions.N9)); int g62Count = trans.Content.Count(l => l.Definition.GetType() == typeof(SegmentDefinitions.G62)); int nteCount = trans.Content.Count(l => l.Definition.GetType() == typeof(SegmentDefinitions.NTE)); int w66Count = trans.Content.Count(l => l.Definition.GetType() == typeof(SegmentDefinitions.W66)); int lxCount = trans.Content.Count(l => l.Definition.GetType() == typeof(M_940.L_LX)); int lxFirstIterationCount = ((EdiLoop)trans.Content.First(l => l.Definition.GetType() == typeof(M_940.L_LX))).Content.Count; int lxFirstIterationW01Count = ((EdiLoop)((EdiLoop)trans.Content.First(l => l.Definition.GetType() == typeof(M_940.L_LX))) .Content.Skip(1).First()).Content.Count; int w76Count = trans.Content.Count(l => l.Definition.GetType() == typeof(SegmentDefinitions.W76)); 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); }
public void EdiReader_ParseGenericEdi850() { using (Stream s = GetType().Assembly.GetManifestResourceStream("EdiEngine.Tests.TestData.850.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); 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 rootSegCount = t.Content.Count(seg => seg is EdiSegment); int rootLoopCount = t.Content.Count(l => l is EdiLoop); int n1LoopCount = t.Content.Count(l => l.Definition.GetType() == typeof(M_850.L_N1)); int n1ContentCount = ((EdiLoop)t.Content.First(l => l.Definition.GetType() == typeof(M_850.L_N1))).Content.Count(); int po1LoopCount = t.Content.Count(l => l.Definition.GetType() == typeof(M_850.L_PO1)); int pidLoopCount = t.Content.Where(l => l.Definition.GetType() == typeof(M_850.L_PO1)) .Select(l2 => l2.Definition.GetType() == typeof(M_850.L_PID)).Count(); int po1Count = 0; int pidCount = 0; int po4Count = 0; var lst = t.Content.Where(l => l.Definition.GetType() == typeof(M_850.L_PO1)).Select(l => l).ToList(); lst.ForEach(l => { var po1Loop = (EdiLoop)l; if (po1Loop.Content[0].Definition.GetType() == typeof(PO1)) { po1Count++; } if (po1Loop.Content[2].Definition.GetType() == typeof(PO4)) { po4Count++; } EdiLoop pidLoop = (EdiLoop)po1Loop.Content.First(l2 => l2.Definition.GetType() == typeof(M_850.L_PID)); if (pidLoop.Content[0].Definition.GetType() == typeof(PID)) { pidCount++; } }); int cttLoopCount = t.Content.Count(l => l.Definition.GetType() == typeof(M_850.L_CTT)); int cttCount = ((EdiLoop)t.Content.First(l => l.Definition.GetType() == typeof(M_850.L_CTT))) .Content.Count(s2 => s2.Definition.GetType() == typeof(CTT)); Assert.AreEqual(0, t.ValidationErrors.Count); Assert.AreEqual(8, rootSegCount); Assert.AreEqual(8, rootLoopCount); Assert.AreEqual(1, n1LoopCount); Assert.AreEqual(3, n1ContentCount); Assert.AreEqual(6, po1LoopCount); Assert.AreEqual(6, po1Count); Assert.AreEqual(6, pidLoopCount); Assert.AreEqual(6, pidCount); Assert.AreEqual(6, po4Count); Assert.AreEqual(1, cttLoopCount); Assert.AreEqual(1, cttCount); } }
public static async Task <String> SplitEDIFile(string BLOBFileName, string splitHalf, ILogger log) { log.LogInformation("SplitEDIFile function processing a request."); //Incoming JSON Payload: //{ "ediFileName":"916386MS210_202001190125_000000001.raw","splitHalf":"1"} // Parse the connection string and get a reference to the blob. var storageCredentials = new StorageCredentials("jbupsbtspaassagenv2", "Pi5FpNwJgcwJiAj7fxyCc4ncM4llKu3184a0OrTE1Jn0VxSYLGPIOZAO1j36DjT1Plmw8udLR3NXUBVNUWnucA=="); var cloudStorageAccount = new CloudStorageAccount(storageCredentials, true); var cloudBlobClient = cloudStorageAccount.CreateCloudBlobClient(); //Define BlobIN Stream CloudBlobClient blobINClient = cloudStorageAccount.CreateCloudBlobClient(); CloudBlobContainer blobINContainer = blobINClient.GetContainerReference("edi-process-split"); CloudBlockBlob blobIN = blobINContainer.GetBlockBlobReference(BLOBFileName); Stream blobINStream = await blobIN.OpenReadAsync(); //Define BlobOUT FileName - for FIRST OR SECOND half of transactions string blobOUTPreFix = ""; if (splitHalf == "1") { blobOUTPreFix = "A_"; } else { blobOUTPreFix = "B_"; } CloudBlobClient blobOUTClient = cloudStorageAccount.CreateCloudBlobClient(); CloudBlobContainer blobOUTContainer = blobOUTClient.GetContainerReference("edi-process-split"); CloudBlockBlob blobOUT = blobOUTContainer.GetBlockBlobReference(blobOUTPreFix + BLOBFileName); //Read blobIN EdiDataReader r = new EdiDataReader(); EdiBatch b = r.FromStream(blobINStream); int totEDITransCtr = 0; totEDITransCtr = b.Interchanges[0].Groups[0].Transactions.Count(); // ********************************************************** // ** SAVE Original EDI Interchange: Data & Transactions // ********************************************************** EdiInterchange OrigInter = new EdiInterchange(); OrigInter = b.Interchanges[0]; List <EdiTrans> OrigTrans = new List <EdiTrans>(); OrigTrans = b.Interchanges[0].Groups[0].Transactions; // ********************************************************** // ** Calculate SPLIT // ********************************************************** //1st Half int EDI_Trans_Ctr1 = totEDITransCtr / 2; //2nd Half int EDI_Trans_Ctr2 = totEDITransCtr - (totEDITransCtr / 2); // ********************************************************** // ** Write-Out 1st Half to file // ********************************************************** List <EdiTrans> HalfTrans = new List <EdiTrans>(); //Define LOOP Parameters - for FIRST OR SECOND half of transactions int loopStart = 0; int loopEnd = 0; if (splitHalf == "1") { loopStart = 0; loopEnd = EDI_Trans_Ctr1; } else { loopStart = EDI_Trans_Ctr1 + 1; loopEnd = totEDITransCtr; } //Process TRANSACTIONS for (int i = loopStart; i < loopEnd; i++) { EdiTrans ediItem = new EdiTrans(); ediItem = b.Interchanges[0].Groups[0].Transactions[i]; HalfTrans.Add(ediItem); } EdiBatch b2 = new EdiBatch(); //Handle InterChange EdiInterchange ediInterChgItem = new EdiInterchange(); ediInterChgItem = b.Interchanges[0]; //Remove existing EdiGroup jbEdiGroupItem = new EdiGroup(""); jbEdiGroupItem = b.Interchanges[0].Groups[0]; ediInterChgItem.Groups.RemoveRange(0, 1); //Add Interchange b2.Interchanges.Add(ediInterChgItem); //Handle Group jbEdiGroupItem.Transactions.RemoveRange(0, totEDITransCtr); ediInterChgItem.Groups.Add(jbEdiGroupItem); //Add Transactions for (int i = 0; i < HalfTrans.Count(); i++) //Hardcoded to 91 { EdiTrans ediItem = new EdiTrans(); ediItem = HalfTrans[i]; b2.Interchanges[0].Groups[0].Transactions.Add(ediItem); } EdiDataWriterSettings settings = new EdiDataWriterSettings( new SegmentDefinitions.ISA(), new SegmentDefinitions.IEA(), new SegmentDefinitions.GS(), new SegmentDefinitions.GE(), new SegmentDefinitions.ST(), new SegmentDefinitions.SE(), OrigInter.ISA.Content[4].ToString(), //isaSenderQual OrigInter.ISA.Content[5].ToString(), //isaSenderId OrigInter.ISA.Content[6].ToString(), //isaReceiverQual // OrigInter.ISA.Content[7].ToString(), //isaReceiverId "9163863M210", //isaReceiverId OrigInter.ISA.Content[8].ToString(), //gsSenderId OrigInter.ISA.Content[9].ToString(), //gsReceiverId // OrigInter.ISA.Content[10].ToString(), //JB Test OrigInter.ISA.Content[11].ToString(), //isaEdiVersion OrigInter.ISA.Content[12].ToString(), //gsEdiVersion // "00403", //gsEdiVersion OrigInter.ISA.Content[14].ToString(), //P //isaUsageIndicator //[ 000, //isaFirstControlNumber 001, //gsFirstControlNumber OrigInter.SegmentSeparator.ToString(), //segmentSeparator OrigInter.ElementSeparator.ToString()); //elementSeparator EdiDataWriter w = new EdiDataWriter(settings); string JBData = w.WriteToString(b2); log.LogInformation("trigger function - WRITING SPLIT FILE : " + blobOUT.Name.ToString()); await blobOUT.UploadTextAsync(JBData); blobINStream.Close(); return(" "); }