99using System . IO ;
1010using System . IO . Abstractions ;
1111using System . Linq ;
12+ using System . Threading ;
1213using System . Threading . Tasks ;
1314using AET . ModVerify . Pipeline ;
14- using AnakinRaW . CommonUtilities . SimplePipeline . Progress ;
15+ using AET . ModVerifyTool . Reporting ;
16+ using PG . StarWarsGame . Engine ;
1517
1618namespace AET . ModVerifyTool ;
1719
@@ -48,20 +50,68 @@ public async Task<int> RunApplication()
4850 return 0 ;
4951 }
5052
51- private async Task < IReadOnlyCollection < VerificationError > > Verify ( VerifyGameInstallationData installData )
53+ private async Task < IReadOnlyCollection < VerificationError > > Verify ( VerifyInstallationInformation installInformation )
5254 {
55+ var gameEngineService = services . GetRequiredService < IPetroglyphStarWarsGameEngineService > ( ) ;
56+ var engineErrorReporter = new ConcurrentGameEngineErrorReporter ( ) ;
57+
58+ IStarWarsGameEngine gameEngine ;
59+
60+ try
61+ {
62+ var initProgress = new Progress < string > ( ) ;
63+ var initProgressReporter = new EngineInitializeProgressReporter ( initProgress ) ;
64+
65+ try
66+ {
67+ _logger ? . LogInformation ( $ "Creating Game Engine '{ installInformation . EngineType } '") ;
68+ gameEngine = await gameEngineService . InitializeAsync (
69+ installInformation . EngineType ,
70+ installInformation . GameLocations ,
71+ engineErrorReporter ,
72+ initProgress ,
73+ false ,
74+ CancellationToken . None ) . ConfigureAwait ( false ) ;
75+ _logger ? . LogInformation ( $ "Game Engine created") ;
76+ }
77+ finally
78+ {
79+ initProgressReporter . Dispose ( ) ;
80+ }
81+ }
82+ catch ( Exception e )
83+ {
84+ _logger ? . LogError ( e , $ "Creating game engine failed: { e . Message } ") ;
85+ throw ;
86+ }
87+
88+ var progressReporter = new VerifyConsoleProgressReporter ( installInformation . Name ) ;
89+
5390 using var verifyPipeline = new GameVerifyPipeline (
54- installData . EngineType ,
55- installData . GameLocations ,
91+ gameEngine ,
92+ engineErrorReporter ,
5693 settings . VerifyPipelineSettings ,
5794 settings . GlobalReportSettings ,
58- new VerifyConsoleProgressReporter ( ) ,
95+ progressReporter ,
5996 services ) ;
6097
6198 try
6299 {
63- _logger ? . LogInformation ( $ "Verifying '{ installData . Name } '...") ;
64- await verifyPipeline . RunAsync ( ) . ConfigureAwait ( false ) ;
100+ try
101+ {
102+ _logger ? . LogInformation ( $ "Verifying '{ installInformation . Name } '...") ;
103+ await verifyPipeline . RunAsync ( ) . ConfigureAwait ( false ) ;
104+ progressReporter . Report ( string . Empty , 1.0 ) ;
105+ }
106+ catch
107+ {
108+ progressReporter . ReportError ( "Verification failed" , null ) ;
109+ throw ;
110+ }
111+ finally
112+ {
113+ progressReporter . Dispose ( ) ;
114+ }
65115 }
66116 catch ( OperationCanceledException )
67117 {
@@ -72,11 +122,8 @@ private async Task<IReadOnlyCollection<VerificationError>> Verify(VerifyGameInst
72122 _logger ? . LogError ( e , $ "Verification failed: { e . Message } ") ;
73123 throw ;
74124 }
75- finally
76- {
77- _logger ? . LogInformation ( "Finished verification" ) ;
78- }
79125
126+ _logger ? . LogInformation ( "Finished verification" ) ;
80127 return verifyPipeline . FilteredErrors ;
81128 }
82129
@@ -91,8 +138,7 @@ private async Task ReportErrors(IReadOnlyCollection<VerificationError> errors)
91138 if ( errors . Any ( x => x . Severity >= settings . AppThrowsOnMinimumSeverity ) )
92139 throw new GameVerificationException ( errors ) ;
93140 }
94-
95-
141+
96142 private async Task WriteBaseline ( IEnumerable < VerificationError > errors , string baselineFile )
97143 {
98144 var baseline = new VerificationBaseline ( settings . GlobalReportSettings . MinimumReportSeverity , errors ) ;
@@ -106,16 +152,4 @@ private async Task WriteBaseline(IEnumerable<VerificationError> errors, string b
106152 using var fs = _fileSystem . FileStream . New ( fullPath , FileMode . Create , FileAccess . Write , FileShare . None ) ;
107153 await baseline . ToJsonAsync ( fs ) ;
108154 }
109- }
110-
111- public class VerifyConsoleProgressReporter : IVerifyProgressReporter
112- {
113- public void Report ( string progressText , double progress , ProgressType type , VerifyProgressInfo detailedProgress )
114- {
115- if ( type != VerifyProgress . ProgressType )
116- return ;
117-
118-
119- Console . WriteLine ( progressText ) ;
120- }
121155}
0 commit comments