/// <summary> /// Initializes a new instance of the <see cref="X12Interchange"/> class. /// </summary> /// <param name="header">The interchange header.</param> public X12Interchange(S_ISA header) : base(header, (gs, i) => new S_IEA { D_405_1 = i.ToString(), D_709_2 = header.D_709_13 }, Separators.DefaultSeparatorsX12()) { if (header == null) { throw new Exception("ISA header is null."); } }
/// <summary> /// Initializes a new instance of the <see cref="X12Group{T}"/> class. /// </summary> /// <param name="header">The group header.</param> public X12Group(S_GS header) : base(header, (gs, i) => new S_GE { D_97_1 = i.ToString(), D_28_2 = gs.D_28_6 }, Separators.DefaultSeparatorsX12()) { if (header == null) { throw new Exception("GS header is null."); } }
public void TestGenerateWithSegmentSeparatorLf() { // ARRANGE const string sample = "EdiFabric.Tests.Edi.X12_810_00204_SegmentSeparatorLF.txt"; var interchange = TestHelper.GenerateX12 <M_810>(sample); // ACT var defaultSeparators = Separators.DefaultSeparatorsX12(); var newSeparators = Separators.SeparatorsX12('\n', '>', defaultSeparators.DataElement, defaultSeparators.RepetitionDataElement); var ediSegments = interchange.GenerateEdi(newSeparators); // ASSERT Assert.AreEqual(TestHelper.AsString(sample, false), TestHelper.AsString(ediSegments, null)); }
public void TestGenerateWithRepetitionSeparator() { // ARRANGE const string sample = "EdiFabric.Tests.Edi.X12_810_00204_RepetitionSeparator.txt"; var interchange = TestHelper.GenerateX12 <Rules.Rep.X12002040810.M_810>(sample, "EdiFabric.Rules.Rep"); // ACT var defaultSeparators = Separators.DefaultSeparatorsX12(); var newSeparators = Separators.SeparatorsX12(defaultSeparators.Segment, '>', defaultSeparators.DataElement, '!'); var ediSegments = interchange.GenerateEdi(newSeparators); // ASSERT Assert.AreEqual(TestHelper.AsString(sample), TestHelper.AsString(ediSegments, Environment.NewLine)); }
/// <summary> /// Generates a collection of EDI segments. /// </summary> /// <param name="separators">The EDI separators.</param> /// <returns>The collection of EDI segments.</returns> public override IEnumerable <string> GenerateEdi(Separators separators = null) { var result = new List <string>(); var currentSeparators = separators ?? Separators.DefaultSeparatorsX12(); Header.D_701_16 = currentSeparators.ComponentDataElement.ToString(); if (Header.D_726_11 != "U") { Header.D_726_11 = currentSeparators.RepetitionDataElement.ToString(); } result.AddRange(ToEdi(Header, currentSeparators)); foreach (var item in Items) { result.AddRange(item.GenerateEdi(currentSeparators)); } result.AddRange(ToEdi(Trailer, currentSeparators)); return(result); }
internal static Tuple <string, Separators> ReadHeader(this StreamReader reader, string segmentName) { char dataElement; char componentDataElement; char repetitionDataElement; char segment; char? escape; string header = null; Separators separators = null; switch (segmentName.ToSegmentTag()) { case SegmentTags.ISA: try { dataElement = reader.Read(1)[0]; var isa = reader.ReadIsa(dataElement); var isaElements = isa.Split(dataElement); if (isaElements[15].Count() != 2) { throw new Exception("Can't find the segment terminator."); } componentDataElement = isaElements[15].First(); repetitionDataElement = isaElements[10].First() != 'U' ? isaElements[10].First() : Separators.DefaultSeparatorsX12().RepetitionDataElement; segment = isaElements[15].Last(); separators = Separators.SeparatorsX12(segment, componentDataElement, dataElement, repetitionDataElement); header = segmentName + dataElement + isa; } catch (Exception ex) { throw new ParserException("Unable to extract X12 interchange delimiters", ex); } break; case SegmentTags.UNB: var defaultSeparators = Separators.DefaultSeparatorsEdifact(); componentDataElement = defaultSeparators.ComponentDataElement; dataElement = defaultSeparators.DataElement; escape = defaultSeparators.Escape; repetitionDataElement = defaultSeparators.RepetitionDataElement; segment = defaultSeparators.Segment; separators = Separators.SeparatorsEdifact(segment, componentDataElement, dataElement, repetitionDataElement, escape); header = segmentName + reader.ReadSegment(separators); break; case SegmentTags.UNA: try { var una = reader.Read(6); var unaChars = una.ToArray(); componentDataElement = unaChars[0]; dataElement = unaChars[1]; escape = unaChars[3]; repetitionDataElement = Separators.DefaultSeparatorsEdifact().RepetitionDataElement; segment = unaChars[5]; separators = Separators.SeparatorsEdifact(segment, componentDataElement, dataElement, repetitionDataElement, escape); header = segmentName + una; } catch (Exception ex) { throw new ParserException("Unable to extract UNA interchange delimiters", ex); } break; } return(new Tuple <string, Separators>(header, separators)); }