public EdiMapReader(MapLoop map, EdiTrans currentTrans) { _trans = currentTrans; _currentLoopInstance = currentTrans; _currentLoopInstance.Definition = map; _currentLoopDef = map; }
//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)); }
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)); }
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); } }
private EdiSegment CreateAk5Segment(MapLoop map, EdiTrans t) { var sDef = (MapSegment)map.Content.First(s => s.Name == "AK5"); var status = "A"; var seg = new EdiSegment(sDef); switch (_settings.AckValidationErrorBehavour) { case AckValidationErrorBehavour.AcceptButNoteErrors: if (t.ValidationErrors.Any()) { status = "E"; } break; case AckValidationErrorBehavour.RejectValidationErrors: if (t.ValidationErrors.Any()) { status = "R"; } break; } seg.Content.Add(new EdiSimpleDataElement((MapSimpleDataElement)sDef.Content[0], status)); if (status == "R") { seg.Content.Add(new EdiSimpleDataElement((MapSimpleDataElement)sDef.Content[1], "5")); //AK502 = One or more segments in error } return(seg); }
public void XmlReadWrite_DeserializeXmlWithValidationErrors() { string xml = TestUtils.ReadResourceStream("EdiEngine.Tests.TestData.940.ERR.xml"); M_940 map = new M_940(); XmlMapReader r = new XmlMapReader(map); EdiTrans t = r.ReadToEnd(xml); Assert.AreEqual(2, t.ValidationErrors.Count); }
public void JsonReadWrite_DeserializeJsonWithValidationErrors() { string json = TestUtils.ReadResourceStream("EdiEngine.Tests.TestData.940.ERR.json"); M_940 map = new M_940(); JsonMapReader r = new JsonMapReader(map); EdiTrans t = r.ReadToEnd(json); Assert.AreEqual(2, t.ValidationErrors.Count); }
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 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_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); } }
private EdiSegment CreateAk2Segment(MapLoop map, EdiTrans t) { var sDef = (MapSegment)map.Content.First(s => s.Name == "AK2"); var seg = new EdiSegment(sDef); seg.Content.AddRange(new[] { new EdiSimpleDataElement((MapSimpleDataElement)sDef.Content[0], t.ST.Content[0].Val), new EdiSimpleDataElement((MapSimpleDataElement)sDef.Content[1], t.ST.Content[1].Val), }); return(seg); }
public void JsonReadWrite_DeserializeJsonHlLoopOk() { string json = TestUtils.ReadResourceStream("EdiEngine.Tests.TestData.856.Crossdock.OK.json"); M_856 map = new M_856(); JsonMapReader r = new JsonMapReader(map); EdiTrans t = r.ReadToEnd(json); Assert.AreEqual(0, t.ValidationErrors.Count); //string edi = TestUtils.WriteEdiEnvelope(t, "SH"); }
public void XmlReadWrite_DeserializeXmlOK() { string xml = TestUtils.ReadResourceStream("EdiEngine.Tests.TestData.940.OK.xml"); M_940 map = new M_940(); XmlMapReader r = new XmlMapReader(map); EdiTrans t = r.ReadToEnd(xml); Assert.AreEqual(0, t.ValidationErrors.Count); //string edi = TestUtils.WriteEdiEnvelope(t, "SH"); }
public virtual EdiTrans ReadToEnd(string rawData) { Trans = new EdiTrans(CurrentLoopDef); CurrentLoopInstance = Trans; CurrentLoopInstance.Definition = CurrentLoopDef; EdiIntermediateEntity intermediateTree = ReadIntermediateTree(rawData); ParseTree(intermediateTree); return(Trans); }
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); }
public void XmlReadWrite_DeserializeXmlHlLoopOk() { string xml = TestUtils.ReadResourceStream("EdiEngine.Tests.TestData.856.Crossdock.OK.xml"); M_856 map = new M_856(); XmlMapReader r = new XmlMapReader(map); EdiTrans t = r.ReadToEnd(xml); Assert.AreEqual(0, t.ValidationErrors.Count); //write complete envelope //string edi = TestUtils.WriteEdiEnvelope(t, "SH"); }
/// <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; }
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 XmlReadWrite_DeserializeComposite() { string xml = TestUtils.ReadResourceStream("EdiEngine.Tests.TestData.001.Fake.Composite.xml"); M_001 map = new M_001(); XmlMapReader r = new XmlMapReader(map); EdiTrans t = r.ReadToEnd(xml); Assert.AreEqual(0, t.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 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 static string WriteEdiEnvelope(EdiTrans t, string functionalCode) { //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 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 w = new EdiDataWriter(settings); return(w.WriteToString(b)); }
/// <summary> /// for mouser /// </summary> /// <param name="b"></param> /// <returns></returns> public override string Parse(EdiBatch b, Edi_Customer c, string parserFile) { int _ItemNumber = 1; string _CustomerName = ""; string _Log = ""; SapSalesOrder _SapSalesOrder = new SapSalesOrder(); List <SalesItem> _ItemList = new List <SalesItem>(); List <SalesPartner> _PartnerList = new List <SalesPartner>(); List <SalesSchedule> _ScheduleList = new List <SalesSchedule>(); SalesHeader _Header = new SalesHeader(); _Header.DOC_TYPE = c.DOC_TYPE; //need to discuss _Header.SALES_ORG = c.SALES_ORG; //need to discuss _Header.DISTR_CHAN = c.DISTR_CHAN; //need to discuss _Header.DIVISION = c.DIVISION; //need to discuss try { EdiTrans _PO = b.Interchanges[0].Groups[0].Transactions[0]; EdiSegment _BEG = (EdiSegment)_PO.Content.FirstOrDefault(l => l.Definition.Name == "BEG"); if (_BEG != null) { _Header.PURCH_NO_C = _BEG.Content[2].ToString(); _Header.PURCH_DATE = _BEG.Content[4].ToString(); } _SapSalesOrder.Header = _Header; var listL_N1 = _PO.Content.Where(l => l.Definition.GetType() == typeof(M_850.L_N1)).Select(l => l).ToList(); foreach (EdiLoop n1 in listL_N1) { SalesPartner _Partner = new SalesPartner(); // var _N1Loop = (EdiLoop)n1; EdiSegment _N1 = (EdiSegment)n1.Content.FirstOrDefault(l => l.Definition.Name == "N1"); if (_N1 != null) { if ((_N1.Content[0].ToString() == "BT") || (_N1.Content[0].ToString() == "BY")) { _Partner.PARTN_ROLE = "AG"; } else if (_N1.Content[0].ToString() == "ST") { _Partner.PARTN_ROLE = "WE"; } if (c.EdiType == 1) { _Partner.PARTN_NUMB = c.SapCustomerId; //how to know what code in altw sap ,loop edi table } else { _Partner.PARTN_NUMB = _N1.Content[3].ToString(); } _CustomerName = _N1.Content[1].ToString(); } EdiSegment _N3 = (EdiSegment)n1.Content.FirstOrDefault(l => l.Definition.Name == "N3"); if (_N3 != null) { _Partner.STREET = _N3.Content[0].ToString(); } EdiSegment _N4 = (EdiSegment)n1.Content.FirstOrDefault(l => l.Definition.Name == "N4"); if (_N4 != null) { _Partner.CITY = _N4.Content[0].ToString(); _Partner.POSTL_CODE = _N4.Content[2].ToString(); _Partner.COUNTRY = _N4.Content[3].ToString(); _Partner.REGION = _N4.Content[1].ToString(); } EdiSegment _PER = (EdiSegment)n1.Content.FirstOrDefault(l => l.Definition.Name == "PER"); if (_PER != null) { _Partner.NAME = _PER.Content[1].ToString(); _Partner.TELEPHONE = _PER.Content[3].ToString(); } _PartnerList.Add(_Partner); } _SapSalesOrder.PartnerList = _PartnerList; var listL_PO1 = _PO.Content.Where(l => l.Definition.GetType() == typeof(M_850.L_PO1)).Select(l => l).ToList(); foreach (EdiLoop po1 in listL_PO1) { int _SchedLine = 1; SalesItem _Item = new SalesItem(); // var _PO1Loop = (EdiLoop)po1; EdiSegment _PO1 = (EdiSegment)po1.Content.FirstOrDefault(l => l.Definition.Name == "PO1"); if (_PO1 != null) { _Item.ITM_NUMBER = (_ItemNumber * 10).ToString().PadLeft(6, '0'); //need use altw rule 000010 //mouser special logic PO111 is part number // if(c.SapCustomerId== "0010000136") _Item.MATERIAL = _PO1.Content[10].ToString(); //else _Item.MATERIAL = _PO1.Content[8].ToString(); _Item.MATERIAL = _PO1.Content[Convert.ToInt32(c.PartNumberIndex)].ToString(); _Item.TARGET_QTY = _PO1.Content[1].ToString(); _Item.CUST_MAT35 = _PO1.Content[6].ToString(); _Item.CustomerItemNumber = _PO1.Content[0].ToString(); _Item.CustomerPrice = _PO1.Content[3].ToString(); _Item.CustomerUnit = _PO1.Content[2].ToString(); _Item.CustomerUnitOfPrice = _PO1.Content[4].ToString(); } _ItemList.Add(_Item); var listL_SCH = po1.Content.Where(l => l.Definition.GetType() == typeof(M_850.L_SCH)).Select(l => l).ToList(); foreach (EdiLoop sch in listL_SCH) { SalesSchedule _Schedule = new SalesSchedule(); // var _SCHLoop = (EdiLoop)sch; EdiSegment _SCH = (EdiSegment)sch.Content.FirstOrDefault(l => l.Definition.Name == "SCH"); if (_SCH != null) { _Schedule.REQ_QTY = _SCH.Content[0].ToString(); _Schedule.ITM_NUMBER = _Item.ITM_NUMBER; _Schedule.SCHED_LINE = _SchedLine.ToString().PadLeft(4, '0'); _Schedule.REQ_DATE = _SCH.Content[5].ToString(); } _ScheduleList.Add(_Schedule); _SchedLine++; } _ItemNumber++; } _SapSalesOrder.ItemList = _ItemList; _SapSalesOrder.ScheduleList = _ScheduleList; _SapSalesOrder.CustomerName = _CustomerName; _SapSalesOrder.CreateBy = "Edi"; _SapSalesOrder.SalesEmail = c.SalesEmail; edi.SapSalesOrder = _SapSalesOrder; } catch (Exception ex) { _Log = "\r\n" + DateTime.Now.ToString("yyyy/MM/dd hh:mm:ss") + " setSalesOrderByEdi: Customer Id:" + c.SapCustomerId + " File :" + parserFile + "\r\n" + ex.Message; logger.Error(_Log); edi.Log = _Log; } return(_Log); }
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 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_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 EdiBatch FromString(string fileContent) { if (string.IsNullOrWhiteSpace(fileContent)) { throw new EdiParsingException("Empty File"); } if (!fileContent.StartsWith("ISA")) { throw new EdiParsingException("ISA NOT FOUND"); } _elementSeparator = fileContent[3].ToString(); _segmentSeparator = fileContent.Substring(105, fileContent.IndexOf($"GS{_elementSeparator}", StringComparison.Ordinal) - 105); string[] segments = fileContent.Split(new [] { _segmentSeparator }, StringSplitOptions.RemoveEmptyEntries); EdiBatch batch = new EdiBatch(); EdiInterchange currentInterchange = null; EdiGroup currentGroup = null; EdiTrans currentTrans = null; EdiMapReader mapReader = null; int tranSegCount = 0; int groupsCount = 0; int transCount = 0; foreach (string seg in segments) { string[] elements = seg.Split(new [] { _elementSeparator }, StringSplitOptions.None); MapSegment segDef; switch (elements[0]) { case "ISA": groupsCount = 0; currentInterchange = new EdiInterchange { SegmentSeparator = _segmentSeparator, ElementSeparator = _elementSeparator }; segDef = GetSegDefinition("ISA", $"{elements[12]}0", MissingStandardFallbackVersion); currentInterchange.ISA = MapReader.ProcessSegment(segDef, elements, 0, currentInterchange); break; case "IEA": if (currentInterchange == null) { throw new EdiParsingException("MALFORMED DATA"); } segDef = GetSegDefinition("IEA", $"{currentInterchange.ISA.Content[11].Val}0", MissingStandardFallbackVersion); currentInterchange.IEA = MapReader.ProcessSegment(segDef, elements, 0, currentInterchange); batch.Interchanges.Add(currentInterchange); int declaredGroupCount; int.TryParse(elements[1], out declaredGroupCount); if (declaredGroupCount != groupsCount) { AddValidationError(currentInterchange, $"Expected {declaredGroupCount} groups. Found {groupsCount}. Interchange # {elements[2]}."); } if (!CheckControlNumbersAreEgual(currentInterchange.ISA.Content[12].Val, elements[2])) { AddValidationError(currentInterchange, $"Control numbers do not match. ISA {currentInterchange.ISA.Content[12].Val}. IEA {elements[2]}."); } currentInterchange = null; break; case "GS": groupsCount++; transCount = 0; currentGroup = new EdiGroup(elements[1]); segDef = GetSegDefinition("GS", $"{elements[8]}", MissingStandardFallbackVersion); currentGroup.GS = MapReader.ProcessSegment(segDef, elements, 0, currentGroup); break; case "GE": if (currentInterchange == null || currentGroup == null) { throw new EdiParsingException("MALFORMED DATA"); } segDef = GetSegDefinition("GE", $"{currentGroup.GS.Content[7].Val}", MissingStandardFallbackVersion); currentGroup.GE = MapReader.ProcessSegment(segDef, elements, 0, currentGroup); currentInterchange.Groups.Add(currentGroup); int declaredTransCount; int.TryParse(elements[1], out declaredTransCount); if (declaredTransCount != transCount) { AddValidationError(currentGroup, $"Expected {declaredTransCount} transactions. Found {transCount}. Group # {elements[2]}."); } if (!CheckControlNumbersAreEgual(currentGroup.GS.Content[5].Val, elements[2])) { AddValidationError(currentGroup, $"Control numbers do not match. GS {currentGroup.GS.Content[5].Val}. GE {elements[2]}."); } currentGroup = null; break; case "ST": if (currentInterchange == null || currentGroup == null) { throw new EdiParsingException("MALFORMED DATA"); } string asmName = $"EdiEngine.Standards.X12_{currentGroup.GS.Content[7].Val}"; string typeName = $"{asmName}.Maps.M_{elements[1]}"; var map = Activator.CreateInstance(asmName, typeName).Unwrap(); if (!(map is MapLoop)) { AddValidationError(currentTrans, $"Can not find map {elements[1]} for standard {currentGroup.GS.Content[7].Val}. Skipping Transaction."); break; } transCount++; currentTrans = new EdiTrans((MapBaseEntity)map); segDef = GetSegDefinition("ST", $"{currentGroup.GS.Content[7].Val}", MissingStandardFallbackVersion); currentTrans.ST = MapReader.ProcessSegment(segDef, elements, 0, currentTrans); tranSegCount = 1; mapReader = new EdiMapReader((MapLoop)map, currentTrans); break; case "SE": if (currentInterchange == null || currentGroup == null || currentTrans == null) { throw new EdiParsingException("MALFORMED DATA"); } tranSegCount++; int declaredSegCount; int.TryParse(elements[1], out declaredSegCount); if (declaredSegCount != tranSegCount) { AddValidationError(currentTrans, $"Expected {declaredSegCount} segments. Found {tranSegCount}. Trans # {elements[2]}."); } if (!CheckControlNumbersAreEgual(currentTrans.ST.Content[1].Val, elements[2])) { AddValidationError(currentTrans, $"Control numbers do not match. ST {currentTrans.ST.Content[1].Val}. SE {elements[2]}."); } segDef = GetSegDefinition("SE", $"{currentGroup.GS.Content[7].Val}", MissingStandardFallbackVersion); currentTrans.SE = MapReader.ProcessSegment(segDef, elements, 0, currentTrans); currentGroup.Transactions.Add(currentTrans); currentTrans = null; break; default: tranSegCount++; mapReader?.ProcessRawSegment(elements[0], elements, tranSegCount); break; } } return(batch); }
public EdiBatch GetnerateAcknowledgment(EdiBatch input) { string mapVersion = null; var firstGroup = input?.Interchanges?.FirstOrDefault()?.Groups?.FirstOrDefault(); if (firstGroup != null) { mapVersion = firstGroup.GS.Content[7].Val; } if (string.IsNullOrWhiteSpace(mapVersion)) { throw new InvalidDataException( "Can not determine EDI X12 version from batch. Check there is at least one interchange with at least one group in it"); } EdiBatch b997 = new EdiBatch(); foreach (EdiInterchange ich in input.Interchanges) { var ich997 = new EdiInterchange(); b997.Interchanges.Add(ich997); string asmName = $"EdiEngine.Standards.X12_{mapVersion}"; string typeName = $"{asmName}.Maps.M_997"; var map = (MapLoop)Activator.CreateInstance(asmName, typeName).Unwrap(); var lAk2Def = (MapLoop)map.Content.First(s => s.Name == "L_AK2"); foreach (EdiGroup g in ich.Groups) { var g997 = new EdiGroup("FA"); ich997.Groups.Add(g997); var t997 = new EdiTrans(map); g997.Transactions.Add(t997); int includedTranCount = int.Parse(g.GE.Content[0].Val); int receivedTranCount = g.Transactions.Count; int acceptedTranCount = g.Transactions.Count(t => !t.ValidationErrors.Any()); t997.Content.Add(CreateAk1Segment(map, g)); if (((_settings.AckValidationErrorBehavour == AckValidationErrorBehavour.AcceptButNoteErrors || _settings.AckValidationErrorBehavour == AckValidationErrorBehavour.RejectValidationErrors) && acceptedTranCount < receivedTranCount) || (_settings.AlwaysGenerateAk2Loop)) { foreach (EdiTrans t in g.Transactions) { EdiLoop lAk2 = new EdiLoop(lAk2Def, null); t997.Content.Add(lAk2); lAk2.Content.Add(CreateAk2Segment(lAk2Def, t)); lAk2.Content.Add(CreateAk5Segment(lAk2Def, t)); } } t997.Content.Add(CreateAk9Segment(map, g, includedTranCount, receivedTranCount)); } } return(b997); }
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(" "); }
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); } }