Repository navigation
Expand file tree
/
Copy pathProgram.cs
More file actions
154 lines (131 loc) · 5.29 KB
/
Copy pathProgram.cs
File metadata and controls
154 lines (131 loc) · 5.29 KB
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
using System.Collections.Generic;
using System.Xml;
using System.IO;
namespace GXSQLDifference
{
internal class Program
{
private static Dictionary<string, SqlData> _preEjecValues = new Dictionary<string, SqlData>();
private static Dictionary<string, SqlData> _postEjecValues = new Dictionary<string, SqlData>();
private static void Main(string[] args)
{
string path1, path2;
if (args.Length == 2)
{
path1 = args[0];
path2 = args[1];
}
else
{
const string f1 = "before.xml";
const string f2 = "after.xml";
System.Console.WriteLine("File names missed. Using default file names in current folder: " + f1 + ", " + f2);
const string path = @"";
path1 = path + f1;
path2 = path + f2;
}
var succes = LoadData(path1, path2);
if (!succes)
{
System.Console.WriteLine("Couldn't load the data");
return;
}
if (_preEjecValues.Count == 0)
{
System.Console.WriteLine("File is empty: " + path1);
return;
}
if (_postEjecValues.Count == 0)
{
System.Console.WriteLine("File is empty: " + path2);
return;
}
var result = "objeto;sql;totaltime(dif);count(dif);post average;pre averga;best time (post);worstTime(post)\n";
foreach (var item in _postEjecValues)
{
// Poner condición para que el value no sea null
if (_preEjecValues.ContainsKey(item.Key))
{
var objectAndSql = item.Key.Split('@');
result += objectAndSql[0] + ";" + objectAndSql[1] + ";" +
item.Value.GetDifData(_preEjecValues[item.Key]);
}
else
{
var objectAndSql = item.Key.Split('@');
result += objectAndSql[0] + ";" + objectAndSql[1] + ";" + item.Value.GetDifData(null);
}
result += "\n";
}
System.Console.Write(result);
var fs = new FileStream(@"salida.csv", FileMode.Create);
var sw = new StreamWriter(fs);
sw.Write(result);
sw.Close();
}
private static bool LoadData(string f1, string f2)
{
if (File.Exists(f1))
{
_preEjecValues = LoadValuesFromXml(f1);
}
else
{
System.Console.WriteLine("File doesn't exists: " + f1);
return false;
}
if (File.Exists(f2))
{
_postEjecValues = LoadValuesFromXml(f2);
}
else
{
System.Console.WriteLine("File doesn't exists: " + f2);
return false;
}
return true;
}
private static Dictionary<string, SqlData> LoadValuesFromXml(string path)
{
var result = new Dictionary<string, SqlData>();
var doc = new XmlDocument();
doc.Load(path);
var xmlElement = doc["DataStoreProviders_Information"];
if (xmlElement != null)
{
foreach (XmlNode node in xmlElement.GetElementsByTagName("DataStoreProvider"))
{
if (node.Attributes == null) continue;
var objectNAme = node.Attributes["Name"].Value;
foreach (XmlNode sqlNode in node.ChildNodes)
{
if (sqlNode.Name != "SQLStatement") continue;
var element = sqlNode["SQLStatement"];
if (element == null) continue;
var sql = element.InnerText;
if (string.IsNullOrEmpty(sql)) continue;
var datos = new SqlData
{
TotalTime = GetDoubleOrDefault(sqlNode, "TotalTime", -1),
WorstTime = GetDoubleOrDefault(sqlNode, "WorstTime", -1),
BestTime = GetDoubleOrDefault(sqlNode, "BestTime", -1),
Average = GetDoubleOrDefault(sqlNode, "AverageTime", -1),
Count = GetDoubleOrDefault(sqlNode, "Count", -1),
};
var key = objectNAme + "@" + sql;
if (!result.ContainsKey(key))
{
result.Add(key, datos);
}
}
}
}
return result;
}
private static double GetDoubleOrDefault(XmlNode sqlNode, string attrName, int defaultValue)
{
var xmlElement = sqlNode[attrName];
return xmlElement != null ? double.Parse(xmlElement.InnerText) : defaultValue;
}
}
}