예제 #1
0
        /// <summary>
        /// Reads the EDI stream from start to end
        /// The 4905 message is postfixed for clarity. Remove the CR\LF to test a real message if needed.
        /// </summary>
        public static void Read4905()
        {
            Debug.WriteLine("******************************");
            Debug.WriteLine(MethodBase.GetCurrentMethod().Name);
            Debug.WriteLine("******************************");

            //  1.  Load the sample 4905 to a stream
            var vdaStream = File.OpenRead(Directory.GetCurrentDirectory() + @"\..\..\..\Files.Vda\Vda_4905_02.txt");

            //  2.  Read all the contents at once
            //  Remove the last parameter Environment.NewLine when reading messages without postfix
            List <IEdiItem> ediItems;

            using (var ediReader = new VdaReader(vdaStream, TemplateFactory.FullTemplateFactory, Encoding.UTF8, Environment.NewLine))
            {
                ediItems = ediReader.ReadToEnd().ToList();
            }

            //  3. Check that the stream contains a recognizable message and the contents can be parsed
            var readerErrors = ediItems.OfType <ReaderErrorContext>();

            if (readerErrors.Any())
            {
                //  The stream is corrupt. Reject it and report back to the sender
                foreach (var readerError in readerErrors)
                {
                    //  Respond with the error context, which contains the standard EDI error code and fault reason
                    var error = readerError.MessageErrorContext.Flatten();
                }
            }

            //  4.  Pull the transactions that are needed
            var vda4905s = ediItems.OfType <TS4905>();
        }
예제 #2
0
        /// <summary>
        /// Reads the EDI stream from start to end
        /// The 4905 message is postfixed for clarity. Remove the CR\LF to test a real message if needed.
        /// </summary>
        public static void Read4905()
        {
            Debug.WriteLine("******************************");
            Debug.WriteLine(MethodBase.GetCurrentMethod().Name);
            Debug.WriteLine("******************************");

            //  1.  Load the sample 4905 to a stream
            var vdaStream = File.OpenRead(Directory.GetCurrentDirectory() + @"\..\..\..\Files.Vda\Vda_4905_02.txt");

            //  2.  Read all the contents at once
            //  Remove the last parameter Environment.NewLine when reading messages without postfix
            List <IEdiItem> vdaItems;

            using (var vdaReader = new VdaReader(vdaStream, TemplateFactory.FullTemplateFactory, Encoding.UTF8, Environment.NewLine))
            {
                vdaItems = vdaReader.ReadToEnd().ToList();
            }

            //  3. Check that the stream contains a recognizable message and the contents can be parsed
            var readerErrors = vdaItems.OfType <ReaderErrorContext>();

            if (readerErrors.Any())
            {
                //  The stream is corrupt. Reject it and report back to the sender
                foreach (var readerError in readerErrors)
                {
                    //  Respond with the error context, which contains the standard EDI error code and fault reason
                    var error = readerError.MessageErrorContext.Flatten();
                }
            }

            //  4.  Pull the transactions that are needed
            var vda4905s = vdaItems.OfType <TS4905>();

            //  5.  Validate each 4950
            foreach (var item in vda4905s)
            {
                MessageErrorContext errorContext;
                if (item.IsValid(out errorContext))
                {
                    //  The 4950 is valid, process it downstream
                }
                else
                {
                    //  The 4950 order is invalid
                    Debug.WriteLine("Message {0} with control number {1} is invalid with errors:", errorContext.Name,
                                    errorContext.ControlNumber);

                    //  List all error messages
                    var errors = errorContext.Flatten();
                    foreach (var error in errors)
                    {
                        Debug.WriteLine(error);
                    }
                }
            }
        }
예제 #3
0
        static TS4905 Create4905()
        {
            Stream vda4905Stream =
                Assembly.GetExecutingAssembly()
                .GetManifestResourceStream("EdiFabric.Sdk.Vda.Edi.Vda_4905_02.txt");

            List <EdiItem> ediItems = new List <EdiItem>();

            using (var ediReader = new VdaReader(vda4905Stream, MessageContextFactory, Encoding.UTF8, Environment.NewLine))
            {
                ediItems = ediReader.ReadToEnd().ToList();
            }

            return(ediItems.OfType <TS4905>().SingleOrDefault());
        }
예제 #4
0
        /// <summary>
        /// Reads 4905.
        /// </summary>
        public static void Run()
        {
            Debug.WriteLine("******************************");
            Debug.WriteLine(MethodBase.GetCurrentMethod().Name);
            Debug.WriteLine("******************************");

            //  1.  Load to a stream
            Stream ediStream = File.OpenRead(Directory.GetCurrentDirectory() + @"\..\..\..\Files\Vda_4905_02.txt");

            //  2.  Read a single transaction
            List <IEdiItem> ediItems;

            using (var ediReader = new VdaReader(ediStream, MessageContextFactory))
            {
                ediItems = ediReader.ReadToEnd().ToList();
            }
        }
예제 #5
0
        /// <summary>
        /// Reads multiple 4905 batched in the same file.
        /// </summary>
        public static void Run()
        {
            Debug.WriteLine("******************************");
            Debug.WriteLine(MethodBase.GetCurrentMethod().Name);
            Debug.WriteLine("******************************");

            //  1.  Load to a stream
            Stream ediStream = File.OpenRead(Directory.GetCurrentDirectory() + @"\..\..\..\Files\Vda_4905_02_Batch.txt");

            //  2.  Read multiple transactions batched up in the same file
            List <IEdiItem> ediItems;

            using (var ediReader = new VdaReader(ediStream, MessageContextFactory, Encoding.UTF8, Environment.NewLine))
            {
                ediItems = ediReader.ReadToEnd().ToList();
            }
        }
예제 #6
0
        public void TestShortSegment()
        {
            // ARRANGE
            const string   sample    = "EdiWeave.UnitTests.Vda.Edi.Vda_4905_02_ShortSegment.txt";
            var            ediStream = CommonHelper.LoadStream(sample);
            List <EdiItem> ediItems;

            // ACT
            using (var ediReader = new VdaReader(ediStream, MessageContextFactory, Encoding.UTF8, Environment.NewLine))
            {
                ediItems = ediReader.ReadToEnd().ToList();
            }

            // ASSERT
            Assert.IsNotNull(ediItems);
            Assert.IsTrue(!ediItems.OfType <TS4905>().Any());
            Assert.IsNotNull(ediItems.OfType <ReaderErrorContext>().SingleOrDefault());
        }
예제 #7
0
        public void TestWithUnexpectedPostfix()
        {
            // ARRANGE
            const string   sample    = "EdiWeave.UnitTests.Vda.Edi.Vda_4905_02.txt";
            var            ediStream = CommonHelper.LoadStream(sample);
            List <EdiItem> ediItems;

            // ACT
            using (var ediReader = new VdaReader(ediStream, MessageContextFactory))
            {
                ediItems = ediReader.ReadToEnd().ToList();
            }

            // ASSERT
            Assert.IsNotNull(ediItems);
            Assert.IsNotNull(ediItems.OfType <TS4905>().SingleOrDefault());
            Assert.IsTrue(ediItems.OfType <TS4905>().Single().HasErrors);
            Assert.IsNull(ediItems.OfType <ErrorContext>().SingleOrDefault());
        }
예제 #8
0
        public void TestMultipleInvalidMessages()
        {
            // ARRANGE
            const string   sample    = "EdiFabric.UnitTests.Vda.Edi.Vda_4905_02_MultipleInvalidMessages.txt";
            var            ediStream = CommonHelper.LoadStream(sample);
            List <EdiItem> ediItems;

            // ACT
            using (var ediReader = new VdaReader(ediStream, MessageContextFactory, Encoding.UTF8, Environment.NewLine))
            {
                ediItems = ediReader.ReadToEnd().ToList();
            }

            // ASSERT
            Assert.IsNotNull(ediItems);
            Assert.IsTrue(ediItems.OfType <TS4905>().Count() == 2);
            Assert.IsNotNull(ediItems.OfType <TS4905>().FirstOrDefault());
            Assert.IsTrue(ediItems.OfType <TS4905>().First().HasErrors);
            Assert.IsNull(ediItems.OfType <ErrorContext>().SingleOrDefault());
        }
예제 #9
0
        public void TestMultipleMessages()
        {
            // ARRANGE
            const string   sample    = "EdiWeave.UnitTests.Vda.Edi.Vda_4905_02_MultipleMessages.txt";
            var            ediStream = CommonHelper.LoadStream(sample);
            var            expected  = CommonHelper.LoadString(sample);
            List <EdiItem> ediItems;

            // ACT
            using (var ediReader = new VdaReader(ediStream, MessageContextFactory, Encoding.UTF8, Environment.NewLine))
            {
                ediItems = ediReader.ReadToEnd().ToList();
            }
            var actual = VdaHelper.Generate(ediItems, Environment.NewLine);

            // ASSERT
            Assert.IsNotNull(ediItems);
            Assert.IsTrue(ediItems.OfType <TS4905>().Count() == 2);
            Assert.IsNull(ediItems.OfType <ErrorContext>().SingleOrDefault());
            Assert.AreEqual(expected, actual);
        }
예제 #10
0
        public void TestNoPostfix()
        {
            // ARRANGE
            const string   sample    = "EdiFabric.UnitTests.Vda.Edi.Vda_4905_02_NoPostfix.txt";
            var            ediStream = CommonHelper.LoadStream(sample);
            var            expected  = CommonHelper.LoadString(sample);
            List <EdiItem> ediItems;

            // ACT
            using (var ediReader = new VdaReader(ediStream, MessageContextFactory))
            {
                ediItems = ediReader.ReadToEnd().ToList();
            }
            var actual = VdaHelper.Generate(ediItems);

            // ASSERT
            Assert.IsNotNull(ediItems);
            Assert.IsTrue(ediItems.OfType <TS4905>().Count() == 1);
            Assert.IsNull(ediItems.OfType <ErrorContext>().SingleOrDefault());
            Assert.AreEqual(expected, actual);
        }
예제 #11
0
        /// <summary>
        /// Reads the EDI stream from start to end
        /// The 4905 message is postfixed for clarity. Remove the CR\LF to test a real message if needed.
        /// </summary>
        private static void Read4905()
        {
            Debug.WriteLine("******************************");
            Debug.WriteLine(MethodBase.GetCurrentMethod().Name);
            Debug.WriteLine("******************************");

            //  1.  Load the sample 4905 to a stream
            Stream vda4905Stream =
                Assembly.GetExecutingAssembly()
                .GetManifestResourceStream("EdiFabric.Sdk.Vda.Edi.Vda_4905_02.txt");

            //  2.  Read all the contents at once
            //  Remove the last parameter Environment.NewLine when reading messages without postfix
            List <EdiItem> ediItems;

            using (var ediReader = new VdaReader(vda4905Stream, MessageContextFactory, Encoding.UTF8, Environment.NewLine))
            {
                ediItems = ediReader.ReadToEnd().ToList();
            }

            //  3. Check that the stream contains a recognizable message and the contents can be parsed
            var readerErrors = ediItems.OfType <ReaderErrorContext>();

            if (readerErrors.Any())
            {
                //  The stream is corrupt. Reject it and report back to the sender
                foreach (var readerError in readerErrors)
                {
                    //  Respond with the error context, which contains the standard EDI error code and fault reason
                    var error = readerError.MessageErrorContext.Flatten();
                }
            }

            //  4.  Pull the transactions that are needed
            var vda4905s = ediItems.OfType <TS4905>();
        }