Skip to content

Commit 4399eef

Browse files
committed
Add final status counts, structure for more statistics and exit codes.
1 parent 0eaa584 commit 4399eef

File tree

8 files changed

+185
-58
lines changed

8 files changed

+185
-58
lines changed

CompatibilityChecker/Analyzer.cs

+61-52
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
namespace CompatibilityChecker
2+
{
3+
using System;
4+
using System.Collections.Generic;
5+
6+
internal class BasicListingReporter : IMessageReporter
7+
{
8+
IMessageLogger _logger;
9+
10+
List<Message> _reportedMessages;
11+
12+
int _severityError = 0;
13+
int _severityWarning = 0;
14+
int _severityInformation = 0;
15+
int _severityDisabled = 0;
16+
17+
IEnumerable<Message> IMessageReporter.ReportedMessages => _reportedMessages;
18+
19+
IReportStatistics IMessageReporter.Statistics => new BasicListingStatistics(_severityError, _severityWarning, _severityInformation, _severityDisabled);
20+
21+
public BasicListingReporter(IMessageLogger logger)
22+
{
23+
_logger = logger;
24+
25+
_reportedMessages = new List<Message>();
26+
}
27+
28+
void IMessageReporter.Report(Message message)
29+
{
30+
switch (message.Severity)
31+
{
32+
case Severity.Error:
33+
_severityError++;
34+
break;
35+
case Severity.Warning:
36+
_severityWarning++;
37+
break;
38+
case Severity.Information:
39+
_severityInformation++;
40+
break;
41+
case Severity.Disabled:
42+
_severityDisabled++;
43+
break;
44+
default:
45+
throw new ArgumentException(string.Format("Severity {0} is not supported by this Message Reporter.", message.Severity));
46+
}
47+
_reportedMessages.Add(message);
48+
_logger.Report(message);
49+
}
50+
}
51+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace CompatibilityChecker
8+
{
9+
class BasicListingStatistics : IReportStatistics
10+
{
11+
(int error, int warning, int information, int disabled) _severityCounts;
12+
(int error, int warning, int information, int disabled) IReportStatistics.SeverityCounts => _severityCounts;
13+
14+
public BasicListingStatistics(int SeverityError, int SeverityWarning, int SeverityInformation, int SeverityDisabled)
15+
{
16+
_severityCounts = (error: SeverityError, warning: SeverityWarning, information: SeverityInformation, disabled: SeverityDisabled);
17+
}
18+
}
19+
}
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using System.Collections.Generic;
2+
3+
namespace CompatibilityChecker
4+
{
5+
public interface IMessageReporter
6+
{
7+
IEnumerable<Message> ReportedMessages { get; }
8+
9+
IReportStatistics Statistics { get; }
10+
11+
void Report(Message message);
12+
13+
}
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace CompatibilityChecker
2+
{
3+
public interface IReportStatistics
4+
{
5+
(int error, int warning, int information, int disabled) SeverityCounts { get; }
6+
}
7+
}

CompatibilityChecker/Message.cs

+2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ internal Message(CompatibilityDescriptor descriptor, params object[] arguments)
1313
_arguments = arguments;
1414
}
1515

16+
internal Severity Severity => _descriptor.DefaultSeverity;
17+
1618
public override string ToString()
1719
{
1820
string message = string.Format(_descriptor.MessageFormat, _arguments);

CompatibilityCheckerCLI/Program.cs

+13-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ private static void Main(string[] args)
1818
}
1919
else
2020
{
21+
2122
FileInfo referenceFile = new FileInfo(args[0]);
2223
FileInfo newFile = new FileInfo(args[1]);
2324
if (referenceFile.Exists && newFile.Exists)
@@ -26,8 +27,19 @@ private static void Main(string[] args)
2627
{
2728
using (PEReader newAssembly = new PEReader(File.OpenRead(newFile.FullName)))
2829
{
29-
Analyzer analyzer = new Analyzer(referenceAssembly, newAssembly, null);
30+
Analyzer analyzer = new Analyzer(referenceAssembly, newAssembly, null, null);
3031
analyzer.Run();
32+
if (analyzer.HasRun)
33+
{
34+
Console.Error.WriteLine(string.Format("Analyzer done. {0} errors, {1} warnings, {2} informational items.",analyzer.ResultStatistics.SeverityCounts.error, analyzer.ResultStatistics.SeverityCounts.warning, analyzer.ResultStatistics.SeverityCounts.information));
35+
if(analyzer.ResultStatistics.SeverityCounts.error > 0)
36+
{
37+
Environment.ExitCode = -2;
38+
}
39+
} else
40+
{
41+
Environment.ExitCode = -1;
42+
}
3143
}
3244
}
3345
}

CompatibilityCheckerCoreCLI/Program.cs

+18-5
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace CompatibilityCheckerCoreCLI
66
{
77
using File = System.IO.File;
88
using FileInfo = System.IO.FileInfo;
9-
9+
1010
internal class Program
1111
{
1212
private static void Main(string[] args)
@@ -17,7 +17,8 @@ private static void Main(string[] args)
1717
Environment.ExitCode = 1;
1818
}
1919
else
20-
{
20+
{
21+
2122
FileInfo referenceFile = new FileInfo(args[0]);
2223
FileInfo newFile = new FileInfo(args[1]);
2324
if (referenceFile.Exists && newFile.Exists)
@@ -26,12 +27,24 @@ private static void Main(string[] args)
2627
{
2728
using (PEReader newAssembly = new PEReader(File.OpenRead(newFile.FullName)))
2829
{
29-
Analyzer analyzer = new Analyzer(referenceAssembly, newAssembly, null);
30-
analyzer.Run();
30+
Analyzer analyzer = new Analyzer(referenceAssembly, newAssembly, null, null);
31+
analyzer.Run();
32+
if (analyzer.HasRun)
33+
{
34+
Console.Error.WriteLine(string.Format("Analyzer done. {0} errors, {1} warnings, {2} informational items.", analyzer.ResultStatistics.SeverityCounts.error, analyzer.ResultStatistics.SeverityCounts.warning, analyzer.ResultStatistics.SeverityCounts.information));
35+
if (analyzer.ResultStatistics.SeverityCounts.error > 0)
36+
{
37+
Environment.ExitCode = -2;
38+
}
39+
}
40+
else
41+
{
42+
Environment.ExitCode = -1;
43+
}
3144
}
3245
}
3346
}
3447
}
3548
}
3649
}
37-
}
50+
}

0 commit comments

Comments
 (0)