-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
292 lines (251 loc) · 9.64 KB
/
Program.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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Data;
using System.Data.OleDb;
using System.Reflection;
using System.Collections;
using System.Text.RegularExpressions;
namespace eFlowFinder
{
public static class Program
{
static void Main(string[] args)
{
var pathDestino = @"C:\Users\fredericopranto\Downloads\DIFF\[tomcat-7.0.14][tomcat-7.0.16][analisado_par].csv";
var pathOrigem = @"C:\Users\fredericopranto\Downloads\DIFF\ChangeImpactApache.csv";
Console.WriteLine("Lendo arquivo....");
SerachInFile(pathOrigem, pathDestino);
Console.WriteLine("----------OK-------------");
}
public static void SerachInFile(string pathOrigem, string pathDestino)
{
var readerFile = new StreamReader(
File.OpenRead(pathOrigem));
int indice = 0;
string[] lines = File.ReadAllLines(pathOrigem);
while (!readerFile.EndOfStream)
{
var line = readerFile.ReadLine().Split(';');
var valor = line[0];
if (valor.Contains("("))
{
valor = valor.ToString().Substring(0, valor.ToString().IndexOf('('));
}
var ClasseComMetodo = valor.Split('.');
var metodo = "";
var classe = "";
if (ClasseComMetodo.Length > 1)
{
metodo = ClasseComMetodo[ClasseComMetodo.Length - 1];
classe = ClasseComMetodo[ClasseComMetodo.Length - 2];
}
else
{
if (ClasseComMetodo[0].Contains("("))
metodo = ClasseComMetodo[0];
else
classe = ClasseComMetodo[0];
}
FindInFile(pathDestino, pathOrigem, classe.Trim(), metodo.Trim(), indice, ref lines);
indice++;
}
File.WriteAllLines(@"C:\Users\fredericopranto\Downloads\DIFF\ChangeImpactApache2.csv", lines);
}
public static void FindInFile(string pathDestino, string pathOrigem, string className, string method, int indice, ref string[] lines)
{
ArrayList linhasOk = new ArrayList();
var readerFile = new StreamReader(
File.OpenRead(pathDestino));
while (!readerFile.EndOfStream)
{
var line = readerFile.ReadLine();
var hasvalues = line.Contains("." + className + ":") && line.Contains(" " + method + "(");
if (hasvalues)
{
linhasOk.Add(line);
Console.WriteLine(line);
}
}
if (linhasOk.Count == 1)
{
EditaArquivo(pathOrigem, linhasOk, indice, ref lines);
}
if (linhasOk.Count > 1)
{
SelecionaValor(pathOrigem, linhasOk, indice, ref lines);
}
}
public static void SelecionaValor(string pathOrigem, ArrayList linhasOk, int indice, ref string[] lines)
{
ArrayList opa = new ArrayList();
foreach (var item in linhasOk)
{
var itemteste = "";
if (item.ToString().Contains("("))
{
itemteste = item.ToString().ToString().Substring(0, item.ToString().ToString().IndexOf('('));
}
if (!itemteste.ToString().Contains("$"))
{
string[] itens = item.ToString().Split(';');
int count = Regex.Matches(itens[1], ",").Count;
bool metodovazio = itens[1].Contains("()");
string[] itens3 = lines[indice].ToString().Split(';');
int count3 = Regex.Matches(itens3[0], ",").Count;
bool metodovazio3 = itens3[0].Contains("()");
if (metodovazio && metodovazio3)
{
opa.Add(item);
break;
}
if (count == count3)
{
opa.Add(item);
}
}
}
if (opa.Count == 1)
{
EditaArquivo(pathOrigem, opa, indice, ref lines);
}
if (opa.Count > 1)
{
var parametrosOrigem = "";
var parametrosDestino = "";
if (lines[indice].ToString().Contains("("))
{
parametrosOrigem = lines[indice].ToString().ToString().Substring(lines[indice].ToString().ToString().IndexOf('('));
}
//TODO melhorar o codigo..procurar por todos os tipos nos parametros
foreach (var item in linhasOk)
{
if (item.ToString().Contains("("))
{
parametrosDestino = item.ToString().ToString().Substring(item.ToString().ToString().IndexOf('('));
}
var comparar = "";
if (parametrosOrigem.IndexOf(' ') != -1)
{
comparar = parametrosOrigem.Substring(1, parametrosOrigem.IndexOf(' '));
}
else
{
int i = 0;
}
if (parametrosDestino.Contains(comparar.Trim()))
{
EditaArquivo(pathOrigem, opa, indice, ref lines);
break;
}
}
}
}
public static string[] EditaArquivo(string pathOrigem, ArrayList linhasOk, int indice, ref string[] lines)
{
string[] splitLines = lines[indice].ToString().Split(';');
string[] splitLinha = linhasOk[0].ToString().Split(';');
string[] valores = { splitLinha[2], splitLinha[3], splitLinha[4] };
string[] x = splitLines, y = valores;
string[] z = x.Concatenar(y);
lines[indice] = String.Join(";", z);
return lines[indice].Split(';');
}
public static T[] Concatenar<T>(this T[] x, T[] y)
{
if (x == null) throw new ArgumentNullException("x");
if (y == null) throw new ArgumentNullException("y");
int oldLen = x.Length;
Array.Resize<T>(ref x, x.Length + y.Length);
Array.Copy(y, 0, x, oldLen, y.Length);
return x;
}
}
public class StringSearch
{
private readonly string value;
private readonly List<int> indexList = new List<int>();
public StringSearch(string value)
{
this.value = value;
}
public bool Found(int nextChar)
{
for (int index = 0; index < indexList.Count; )
{
int valueIndex = indexList[index];
if (value[valueIndex] == nextChar)
{
++valueIndex;
if (valueIndex == value.Length)
{
indexList[index] = indexList[indexList.Count - 1];
indexList.RemoveAt(indexList.Count - 1);
return true;
}
else
{
indexList[index] = valueIndex;
++index;
}
}
else
{ // next char does not match
indexList[index] = indexList[indexList.Count - 1];
indexList.RemoveAt(indexList.Count - 1);
}
}
if (value[0] == nextChar)
{
if (value.Length == 1)
return true;
indexList.Add(1);
}
return false;
}
public void Reset()
{
indexList.Clear();
}
public static DataTable ConvertExcelToDataTable(string FilePath)
{
string strConn = string.Empty;
if (FilePath.Trim().EndsWith(".xlsx"))
{
strConn = string.Format("Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties=\"Excel 12.0 Xml;HDR=YES;IMEX=1\";", FilePath);
}
else if (FilePath.Trim().EndsWith(".xls"))
{
strConn = string.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Extended Properties=\"Excel 8.0;HDR=Yes;IMEX=1\";", FilePath);
}
OleDbConnection conn = null;
OleDbCommand cmd = null;
OleDbDataAdapter da = null;
DataTable dt = new DataTable();
try
{
conn = new OleDbConnection(strConn);
conn.Open();
cmd = new OleDbCommand(@"SELECT * FROM [Sheet1$]", conn);
cmd.CommandType = CommandType.Text;
da = new OleDbDataAdapter(cmd);
da.Fill(dt);
}
catch (Exception exc)
{
Console.WriteLine(exc.ToString());
Console.ReadLine();
}
finally
{
if (conn.State == ConnectionState.Open)
conn.Close();
conn.Dispose();
cmd.Dispose();
da.Dispose();
}
return dt;
}
}
}