-
Notifications
You must be signed in to change notification settings - Fork 45
/
Copy pathReadEDIFileToEnd.cs
38 lines (34 loc) · 1.35 KB
/
ReadEDIFileToEnd.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using EdiFabric.Core.Model.Edi;
using EdiFabric.Examples.X12.Common;
using EdiFabric.Framework.Readers;
using EdiFabric.Templates.X12004010;
namespace EdiFabric.Examples.X12.ReadEDI
{
class ReadEDIFileToEnd
{
/// <summary>
/// Reads the EDI stream from start to end.
/// This method loads the file into memory. Do not use for large files.
/// The sample file contains two purchase orders - a valid one and an invalid one.
/// </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() + Config.TestFilesPath + @"\X12\PurchaseOrders.txt");
// 2. Read all the contents
List<IEdiItem> ediItems;
using (var ediReader = new X12Reader(ediStream, "EdiFabric.Templates.X12"))
ediItems = ediReader.ReadToEnd().ToList();
// 3. Pull the required transactions
var purchaseOrders = ediItems.OfType<TS850>();
}
}
}