Exemple #1
0
        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));
        }
Exemple #2
0
        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));
        }
Exemple #3
0
        internal override bool TryReadControl(string segmentName, out string probed, out Separators separators)
        {
            probed     = "";
            separators = null;

            try
            {
                if (segmentName == "ISA")
                {
                    var dataElement = StreamReader.Read(1)[0];
                    var isa         = StreamReader.ReadIsa(dataElement);
                    probed = segmentName + dataElement + isa;
                    var isaElements = isa.Split(dataElement);
                    if (isaElements.Length != 16)
                    {
                        throw new Exception("ISA is invalid. Too little data elements.");
                    }
                    if (isaElements[15].Count() != 2)
                    {
                        throw new Exception("ISA is invalid. Segment terminator was not found.");
                    }
                    var  componentDataElement  = isaElements[15].First();
                    char?repetitionDataElement = null;
                    if (isaElements[10].First() != 'U')
                    {
                        repetitionDataElement = isaElements[10].First();
                    }
                    var segment = isaElements[15].Last();

                    separators = Separators.SeparatorsX12(segment, componentDataElement, dataElement,
                                                          repetitionDataElement);

                    return(true);
                }
            }
            catch
            {
                // ignored
            }

            return(false);
        }
Exemple #4
0
        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));
        }