-
Notifications
You must be signed in to change notification settings - Fork 0
/
EopyLibrary.cs
168 lines (142 loc) · 5.31 KB
/
EopyLibrary.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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Reflection;
namespace EopyLibrary
{
class EopyStreamFiling
{
private static String execPath;
public static String ExecPath
{
get
{
return execPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase) ; ;
}
set { execPath = value; }
}
public static string AssemblyDirectory
{
get
{
string codeBase = Assembly.GetExecutingAssembly().CodeBase;
UriBuilder uri = new UriBuilder(codeBase);
string path = Uri.UnescapeDataString(uri.Path);
return Path.GetDirectoryName(path);
}
}
private FileStream aFile;
private StreamWriter sw;
private StreamReader sr;
private List<string[,]> _myData; // Dosya içeriğinin listelenmiş şekli
public List<string[,]> MyData
{
get { return _myData; }
set { _myData = value; }
}
private string _fileANT;
public string FileANT
{
get { return _fileANT; }
set { _fileANT = value.Replace("\\", "/"); }
}
public EopyStreamFiling(string fileANT)
{
this.FileANT = fileANT;
} // initialize
public void openFileRead()
{
this.aFile = new FileStream(this.FileANT, FileMode.Open);
this.sr = new StreamReader(this.aFile);
}
public void openFileAppend()
{
this.aFile = new FileStream(this.FileANT, FileMode.Append);
this.sw = new StreamWriter(this.aFile);
}
public void closeFile()
{
if (this.sw != null) this.sw.Close();
if (this.sr != null) this.sr.Close();
}
private List<string[,]> GetData(out List<string> columns)
{
string strLine; // Dosya Sonuna Kadar Tek Tek Satırları Tutar
string[] strArray; // Satırları Okur
char[] charArray = new char[] { ',' }; // Satırları Kolonlara Bölen Karakter
//List<Dictionary<string, string>> data = new List<Dictionary<string, string>>(); // List arrayın her eklenen elemanı Key(kolon ismi) ve Value(değeri) olarak 2elemanlı string tutar bir tablo yapısı oluşturur
columns = new List<string>(); //
List<string[,]> TrendArray = new List<string[,]>(); // içinde 2 boyutlu her elemanının 2 boyutlu dizisi olan list array oluşturur
int k = 0;
// Obtain the columns from the first line.
// Split row of data into string array
//strLine = this.sr.ReadLine();
//strLine = "DateTime,Value"; // kolonları el ile ekledim normalde ilk kayıttan alıyordu
//strArray = strLine.Split(charArray);
//for (int x = 0; x <= strArray.GetUpperBound(0); x++)
//{
// columns.Add(strArray[x]);
//}
strLine = this.sr.ReadLine();
while (strLine != null)
{
// Split row of data into string array
strArray = strLine.Split(charArray);
//Dictionary<string, string> dataRow = new Dictionary<string, string>();
string[,] satir = new string[1, strArray.Length];
for (int x = 0; x <= strArray.GetUpperBound(0); x++)
{
//dataRow.Add(columns[x], strArray[x]);
satir[0, x] = strArray[x]; //
}
TrendArray.Add(satir);
//data.Add(dataRow);
strLine = this.sr.ReadLine();
k++;
}
return TrendArray;
}
public void dataWriter(String Date, String MilliSecond, String Value1, String Value2, String Value3, String Value4)
{
// Write data to file.
this.sw.WriteLine(Date + "," + MilliSecond + "," + Value1 + "," + Value2 + "," + Value3 + "," + Value4);
}
public void dataWriter(String Date, String MilliSecond, String Value)
{
// Write data to file.
this.sw.WriteLine(Date + "," + MilliSecond + "," + Value);
}
public void dataWriter(String Key, String Value)
{
// Write data to file.
this.sw.WriteLine(Key + "," + Value);
}
public void dataWriter(String Value1)
{
// Write data to file.
this.sw.WriteLine(Value1);
}
public void dataReader()
{
// Dosyadan Okuyup Consol a Yazdırma
List<string> columns;
this.MyData = GetData(out columns);
//// Kolon isimlerini okur
//foreach (string column in columns)
//{
// Console.Write("{0,-25}", column);
//}
//// Satır ve Kolonları Okur
//foreach (Dictionary<string, string> row in myData)
//{
// foreach (string column in columns)
// {
// Console.Write("{0,-25}", row[column]);
// }
//}
}
}
}