/// <summary> /// Initializes a new instance of the <see cref="EdifactGroup{T}"/> class. /// </summary> /// <param name="header">The group header.</param> public EdifactGroup(S_UNG header) : base(header, (ung, i) => new S_UNE { D_0060_1 = i.ToString(), D_0048_2 = ung.D_0048_5 }, Separators.DefaultSeparatorsEdifact()) { }
/// <summary> /// Initializes a new instance of the <see cref="EdifactInterchange"/> class. /// </summary> /// <param name="header">The interchange header.</param> public EdifactInterchange(S_UNB header) : base(header, (unb, i) => new S_UNZ { D_0036_1 = i.ToString(), D_0020_2 = unb.D_0020_5 }, Separators.DefaultSeparatorsEdifact()) { if (header == null) { throw new Exception("UNB header is null."); } }
internal override bool TryReadControl(string segmentName, out string probed, out Separators separators) { probed = ""; separators = null; try { if (segmentName == "UNB") { probed = segmentName + StreamReader.Read(6); if (IsUnb(probed, Separators.DefaultSeparatorsEdifact().DataElement, Separators.DefaultSeparatorsEdifact().ComponentDataElement)) { separators = Separators.DefaultSeparatorsEdifact(); return(true); } } if (segmentName == "UNA") { var una = StreamReader.Read(6); probed = segmentName + una; var unaChars = una.ToArray(); var componentDataElement = unaChars[0]; var dataElement = unaChars[1]; char?escape = unaChars[3]; var repetitionDataElement = Separators.DefaultSeparatorsEdifact().RepetitionDataElement; var segment = unaChars[5]; var tmp = StreamReader.Read(9, Trims); probed += tmp; if (IsUnb(tmp, dataElement, componentDataElement)) { separators = Separators.SeparatorsEdifact(segment, componentDataElement, dataElement, repetitionDataElement, escape); probed = tmp; return(true); } } } catch { // ignored } return(false); }
public void TestGenerateWithNonDefaultSeparators() { // ARRANGE const string sample = "EdiFabric.Tests.Edi.Edifact_INVOIC_D00A.txt"; const string expectedResult = "EdiFabric.Tests.Edi.Edifact_INVOIC_D00A_NonDefaultSeparators.txt"; var interchange = TestHelper.GenerateEdifact <M_INVOIC>(sample); var defaultSeparators = Separators.DefaultSeparatorsEdifact(); var newSeparators = Separators.SeparatorsEdifact(defaultSeparators.Segment, defaultSeparators.ComponentDataElement, '|', defaultSeparators.RepetitionDataElement, defaultSeparators.Escape); // ACT var ediSegments = interchange.GenerateEdi(newSeparators); // ASSERT Assert.AreEqual(TestHelper.AsString(expectedResult), 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.DefaultSeparatorsEdifact(); if (separators != null) { result.Add(separators.ToUna()); } 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)); }