/// <summary> /// Generate and write EDI document to a stream async. /// </summary> public static async void WriteSingleInvoiceToStreamAsync() { Debug.WriteLine("******************************"); Debug.WriteLine(MethodBase.GetCurrentMethod().Name); Debug.WriteLine("******************************"); // 1. Construct the invoice var invoice = EdifactTransactionBuilders.BuildInvoice("1"); // 2. Validate it by skipping trailer validation MessageErrorContext errorContext; if (invoice.IsValid(out errorContext, new ValidationSettings { SkipTrailerValidation = true })) { Debug.WriteLine("Message {0} with control number {1} is valid.", errorContext.Name, errorContext.ControlNumber); using (var stream = new MemoryStream()) { using (var writer = new EdifactWriter(stream)) { // 3. Begin with UNB segment await writer.WriteAsync(SegmentBuilders.BuildUnb("1")); // 4. Then write the invoice(s) await writer.WriteAsync(invoice); } Debug.Write(stream.LoadToString()); } } else { // The invoice 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); } } }
/// <summary> /// Generate and write EDI document to a stream async. /// </summary> public static async void Run() { Debug.WriteLine("******************************"); Debug.WriteLine(MethodBase.GetCurrentMethod().Name); Debug.WriteLine("******************************"); // 1. Construct the invoice var invoice = EF_EDIFACT_D96A_INVOIC_Builder.BuildInvoice("1"); using (var stream = new MemoryStream()) { using (var writer = new EdifactWriter(stream)) { // 2. Begin with UNB segment await writer.WriteAsync(SegmentBuilders.BuildUnb("1")); // 3. Then write the invoice(s) await writer.WriteAsync(invoice); } Debug.Write(stream.LoadToString()); } }