Ejemplo n.º 1
0
        /// <summary>
        /// Batch multiple transactions under multiple functional groups in the same EDI stream.
        /// </summary>
        public static void Run()
        {
            Debug.WriteLine("******************************");
            Debug.WriteLine(MethodBase.GetCurrentMethod().Name);
            Debug.WriteLine("******************************");

            using (var stream = new MemoryStream())
            {
                using (var writer = new EdifactWriter(stream))
                {
                    writer.Write(SegmentBuilders.BuildUnb("1"));

                    //  1.  Write the first group
                    writer.Write(SegmentBuilders.BuildUng("1", "INVOIC"));
                    writer.Write(SegmentBuilders.BuildInvoice("1"));

                    //  2.  Write the second group
                    //  No need to close the previous group with a UNE
                    writer.Write(SegmentBuilders.BuildUng("2", "ORDERS"));
                    writer.Write(SegmentBuilders.BuildPurchaseOrder("1"));
                }

                Debug.Write(stream.LoadToString());
            }
        }
        /// <summary>
        /// Validate EDI transactions before writing them out, skipping the trailer validation because trailers hadn't been set just yet
        /// </summary>
        public static void Run()
        {
            Debug.WriteLine("******************************");
            Debug.WriteLine(MethodBase.GetCurrentMethod().Name);
            Debug.WriteLine("******************************");

            var purchaseOrder = SegmentBuilders.BuildPurchaseOrder("1");

            //  Validate using EDI codes map
            MessageErrorContext errorContext;

            if (!purchaseOrder.IsValid(out errorContext, new ValidationSettings {
                SkipTrailerValidation = true
            }))
            {
                //  Report it back to the sender, log, etc.
                var errors = errorContext.Flatten();
            }
            else
            {
                //  purchaseOrder is valid, handle it downstream
            }
        }