-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFinder.cs
More file actions
204 lines (184 loc) · 6.73 KB
/
Finder.cs
File metadata and controls
204 lines (184 loc) · 6.73 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
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
using System;
using System.Drawing;
using System.IO;
namespace ChangelogCreator
{
public class Finder
{
private const string StartChars = "// +";
private const string EndChars = "// -";
private const string ModuleFilePattern = "*.bsl";
private readonly string _selectedPath;
private readonly string _toFind;
public event EventHandler<(string Text, Color color)> LinesAdded;
public event EventHandler<int> ProgressChanged;
public Finder(string selectedPath, string toFind)
{
_selectedPath = selectedPath;
_toFind = toFind;
}
public void FindChanges()
{
ProgressChanged?.Invoke(null, 0);
var modules = FindAllModules();
if (modules.Length == 0)
{
AddText($"Не найдено файлов с маской {ModuleFilePattern}");
return;
}
var modulesCount = modules.Length;
for (var index = 0; index < modulesCount; index++)
{
var module = modules[index];
var progress = index / (float)modulesCount * 100;
ProgressChanged?.Invoke(null, (int)progress);
FindChanges(module);
Console.WriteLine("File number: {0} from {1}", index, modulesCount);
}
ProgressChanged?.Invoke(null, 0);
}
private void FindChanges(string file)
{
var fileStream =
new StreamReader(file);
string line;
var counter = 0;
var currentStart = 0;
//var currentEnd = 0;
var code = string.Empty;
while ((line = fileStream.ReadLine()) != null)
{
if (line.Contains(StartChars) && line.Contains(_toFind))
{
if (currentStart != 0)
{
var (module, type) = GetModuleTypeName(file);
AddText($"ОШИБКА: Строка {counter} модуля {module} категории объекта {type} не содержит закрывающего комментария:\r\n{line}\r\n\r\n\r\n", Color.Red);
currentStart = 0;
code = string.Empty;
continue;
}
currentStart = counter;
}
if (currentStart != 0)
{
code += line + "\r\n";
}
if (line.Contains(EndChars) && line.Contains(_toFind))
{
var (module, type) = GetModuleTypeName(file);
if (currentStart == 0)
{
AddText($"ОШИБКА: Строка {counter} модуля {module} категории объекта {type} не содержит открывающего комментария:\r\n{line}\r\n\r\n\r\n", Color.Red);
currentStart = 0;
//currentEnd = 0;
code = string.Empty;
continue;
}
//currentEnd = counter;
AddText($"Изменен модуль {module} категории объекта {type}\r\nНачало изменения - строка {currentStart}\r\nКонец изменения - строка {counter}\r\nКод:\r\n{code}\r\n\r\n\r\n");
currentStart = 0;
//currentEnd = 0;
code = string.Empty;
continue;
}
counter++;
}
fileStream.Close();
}
private (string Module, string Type) GetModuleTypeName(string file)
{
var path = new DirectoryInfo(file);
var name = path?.Parent?.Parent?.Name;
var type = GetModuleTypeTranslation(path?.Parent?.Parent?.Parent?.Name);
return (name, type);
}
private string GetModuleTypeTranslation(string type)
{
switch (type)
{
case "AccountingRegister":
{
return "РегистрБухгалтерии";
}
case "AccumulationRegister":
{
return "РегистрНакопления";
}
case "BusinessProcess":
{
return "БизнесПроцесс";
}
case "CalculationRegister":
{
return "РегистрРасчета";
}
case "Catalog":
{
return "Справочник";
}
case "ChartOfAccounts":
{
return "ПланСчетов";
}
case "ChartOfCalculationTypes":
{
return "ПланВидовРасчета";
}
case "ChartOfCharacteristicTypes":
{
return "ПланВидовХарактеристик";
}
case "CommonModules":
{
return "ОбщийМодуль";
}
case "Constant":
{
return "Константа";
}
case "Document":
{
return "Документ";
}
case "ExchangePlan":
{
return "ПланОбмена";
}
case "InformationRegister":
{
return "РегистрСведений";
}
case "Task":
{
return "Задача";
}
case "Sequence":
{
return "Последовательность";
}
case "Report":
{
return "Отчет";
}
default:
{
return type;
}
}
}
private string[] FindAllModules()
{
var files = Directory.GetFiles(_selectedPath, ModuleFilePattern, SearchOption.AllDirectories);
return files;
}
private void AddText(string text)
{
AddText(text, Color.Black);
}
private void AddText(string text, Color color)
{
LinesAdded?.Invoke(null, (text, color));
}
}
}