-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathReadCSVFile.cs
128 lines (114 loc) · 4.67 KB
/
ReadCSVFile.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
using EdiFabric.Framework.Readers;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Text;
using EdiFabric.Core.Model.Edi;
using System.Collections.Generic;
using EdiFabric.Framework;
using EdiFabric.Examples.FlatFile.Common;
namespace EdiFabric.Examples.FlatFile.Read
{
class ReadCSVFile
{
/// <summary>
/// Reads custom CSV file into the template.
/// </summary>
public static void Run()
{
Debug.WriteLine("******************************");
Debug.WriteLine(MethodBase.GetCurrentMethod().Name);
Debug.WriteLine("******************************");
Stream ediStream = File.OpenRead(Directory.GetCurrentDirectory() + Config.TestFilesPath + @"\Flat_PO.txt");
List<IEdiItem> items = new List<IEdiItem>();
using (StreamReader streamReader = new StreamReader(ediStream, Encoding.UTF8, true, 1024))
{
using (var flatReader = new FlatReader(streamReader, FlatFactory))
{
while (flatReader.Read())
{
items.Add(flatReader.Item);
}
}
}
}
/// <summary>
/// Reads custom CSV file into the template.
/// </summary>
public static void Run2()
{
Debug.WriteLine("******************************");
Debug.WriteLine(MethodBase.GetCurrentMethod().Name);
Debug.WriteLine("******************************");
Stream ediStream = File.OpenRead(Directory.GetCurrentDirectory() + Config.TestFilesPath + @"\Flat_Markers.txt");
List<IEdiItem> items = new List<IEdiItem>();
using (StreamReader streamReader = new StreamReader(ediStream, Encoding.UTF8, true, 1024))
{
using (var flatReader = new FlatReader(streamReader, FlatFactory))
{
while (flatReader.Read())
{
items.Add(flatReader.Item);
}
}
}
}
/// <summary>
/// Reads custom CSV file with multiple messages into templates.
/// The messages can be of any type.
/// </summary>
public static void Run3()
{
Debug.WriteLine("******************************");
Debug.WriteLine(MethodBase.GetCurrentMethod().Name);
Debug.WriteLine("******************************");
Stream ediStream = File.OpenRead(Directory.GetCurrentDirectory() + Config.TestFilesPath + @"\Flat_Multiple.txt");
List<IEdiItem> items = new List<IEdiItem>();
using (StreamReader streamReader = new StreamReader(ediStream, Encoding.UTF8, true, 1024))
{
using (var flatReader = new FlatReader(streamReader, FlatFactory))
{
while (flatReader.Read())
{
items.Add(flatReader.Item);
}
}
}
}
/// <summary>
/// Reads custom CSV file.
/// </summary>
public static void Run4()
{
Debug.WriteLine("******************************");
Debug.WriteLine(MethodBase.GetCurrentMethod().Name);
Debug.WriteLine("******************************");
Stream ediStream = File.OpenRead(Directory.GetCurrentDirectory() + Config.TestFilesPath + @"\CSV_PO.txt");
List<IEdiItem> items = new List<IEdiItem>();
using (StreamReader streamReader = new StreamReader(ediStream, Encoding.UTF8, true, 1024))
{
using (var flatReader = new FlatReader(streamReader, FlatFactory))
{
while (flatReader.Read())
{
items.Add(flatReader.Item);
}
}
}
}
private static MessageContext FlatFactory(string segment)
{
var id = segment.Substring(0, 2);
switch (id)
{
case "PO":
return new MessageContext("PO", "Flat", mc => Assembly.Load(new AssemblyName("EdiFabric.Examples.FlatFile.Common")));
case "H,":
return new MessageContext("Markers", "Flat", mc => Assembly.Load(new AssemblyName("EdiFabric.Examples.FlatFile.Common")));
case "LI":
return new MessageContext("PurchaseOrder", "Flat", mc => Assembly.Load(new AssemblyName("EdiFabric.Examples.FlatFile.Common")));
}
return null;
}
}
}