-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathCheckHelper.cs
104 lines (88 loc) · 2.56 KB
/
CheckHelper.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
using System.Text.RegularExpressions;
class CheckHelper
{
public static readonly Dictionary<uint, HashSet<string>> NoWarn = new();
public static readonly HashSet<string> sDuplicateMessages = new();
private bool mFail;
private bool mWarn;
private bool mFailAny;
public bool IsFail
{
get { return mFailAny; }
}
public void Reset()
{
mFail = false;
mWarn = false;
}
public static bool AddNoWarn(uint iId, string iRegex)
{
bool lResult = false;
if (NoWarn.ContainsKey(iId) && !NoWarn[iId].Contains(iRegex))
{
NoWarn[iId].Add(iRegex);
lResult = true;
}
else
{
NoWarn[iId] = new() { iRegex };
lResult = true;
}
return lResult;
}
public void WriteFail(string iFormat, params object[] iParams)
{
string lMessage = string.Format(iFormat, iParams);
if (!sDuplicateMessages.Contains(lMessage))
{
if (!mFail && !mWarn) Console.WriteLine();
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(" --> " + lMessage);
Console.ResetColor();
sDuplicateMessages.Add(lMessage);
mFail = true;
mFailAny = true;
}
}
public void WriteWarn(uint iWarnId, string iFormat, params object[] iParams)
{
bool lSuppress = false;
string lMessage = String.Format($" --> WARN {iWarnId:d03}: " + iFormat, iParams);
if (sDuplicateMessages.Contains(lMessage))
lSuppress = true;
else if (NoWarn.ContainsKey(iWarnId))
{
foreach (var lPattern in NoWarn[iWarnId])
{
Regex lRegex = new(lPattern);
Match lMatch = lRegex.Match(lMessage);
lSuppress = lMatch.Success;
if (lSuppress) break;
}
}
if (!lSuppress)
{
if (!mFail && !mWarn) Console.WriteLine();
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine(lMessage);
Console.ResetColor();
sDuplicateMessages.Add(lMessage);
mWarn = true;
}
}
public void Start(string iTitle)
{
Reset();
Console.Write(iTitle);
}
public void Finish(string iOk = "OK")
{
if (!mFail && !mWarn)
{
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine(" " + iOk);
Console.ResetColor();
}
Reset();
}
}