Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
49 lines (43 sloc) 1.58 KB
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using EdiFabric.Core.Model.Edi;
using EdiFabric.Core.Model.Edi.ErrorContexts;
using EdiFabric.Framework.Readers;
using EdiFabric.Templates.X12004010;
namespace EdiFabric.Examples.X12.ValidateEDI
{
class ValidateEDITransationsAfterRead
{
/// <summary>
/// Validate EDI transactions from file after read
/// </summary>
public static void Run()
{
Debug.WriteLine("******************************");
Debug.WriteLine(MethodBase.GetCurrentMethod().Name);
Debug.WriteLine("******************************");
Stream ediStream = File.OpenRead(Directory.GetCurrentDirectory() + @"\..\..\..\Files\X12\MixedTransactions.txt");
List<IEdiItem> ediItems;
using (var reader = new X12Reader(ediStream, "EdiFabric.Examples.X12.Templates.V4010"))
ediItems = reader.ReadToEnd().ToList();
var purchaseOrders = ediItems.OfType<TS850>();
foreach (var purchaseOrder in purchaseOrders)
{
// Validate
MessageErrorContext errorContext;
if (!purchaseOrder.IsValid(out errorContext))
{
// Report it back to the sender, log, etc.
var errors = errorContext.Flatten();
}
else
{
// purchaseOrder is valid, handle it downstream
}
}
}
}
}
You can’t perform that action at this time.