@@ -27,7 +27,7 @@ public class Orchestrator
27
27
{
28
28
private static readonly bool IsLinux = RuntimeInformation . IsOSPlatform ( OSPlatform . Linux ) ;
29
29
30
- public ScanResult Load ( string [ ] args )
30
+ public async Task < ScanResult > LoadAsync ( string [ ] args , CancellationToken cancellationToken = default )
31
31
{
32
32
var argumentHelper = new ArgumentHelper { ArgumentSets = new [ ] { new BaseArguments ( ) } } ;
33
33
BaseArguments baseArguments = null ;
@@ -65,19 +65,20 @@ public ScanResult Load(string[] args)
65
65
var shouldFailureBeSuppressed = false ;
66
66
67
67
// Don't use the using pattern here so we can take care not to clobber the stack
68
- var returnResult = BcdeExecutionTelemetryRecord . Track (
69
- ( record ) =>
70
- {
71
- var executionResult = this . HandleCommand ( args , record ) ;
72
- if ( executionResult . ResultCode == ProcessingResultCode . PartialSuccess )
68
+ var returnResult = await BcdeExecutionTelemetryRecord . TrackAsync (
69
+ async ( record , ct ) =>
73
70
{
74
- shouldFailureBeSuppressed = true ;
75
- record . HiddenExitCode = ( int ) executionResult . ResultCode ;
76
- }
71
+ var executionResult = await this . HandleCommandAsync ( args , record , ct ) ;
72
+ if ( executionResult . ResultCode == ProcessingResultCode . PartialSuccess )
73
+ {
74
+ shouldFailureBeSuppressed = true ;
75
+ record . HiddenExitCode = ( int ) executionResult . ResultCode ;
76
+ }
77
77
78
- return executionResult ;
79
- } ,
80
- true ) ;
78
+ return executionResult ;
79
+ } ,
80
+ true ,
81
+ cancellationToken ) ;
81
82
82
83
// The order of these things is a little weird, but done this way mostly to prevent any of the logic inside if blocks from being duplicated
83
84
if ( shouldFailureBeSuppressed )
@@ -126,35 +127,38 @@ private static void AddAssembliesWithType<T>(Assembly assembly, ContainerConfigu
126
127
[ Import ]
127
128
private static IArgumentHelper ArgumentHelper { get ; set ; }
128
129
129
- public ScanResult HandleCommand ( string [ ] args , BcdeExecutionTelemetryRecord telemetryRecord )
130
+ public async Task < ScanResult > HandleCommandAsync (
131
+ string [ ] args ,
132
+ BcdeExecutionTelemetryRecord telemetryRecord ,
133
+ CancellationToken cancellationToken = default )
130
134
{
131
135
var scanResult = new ScanResult ( )
132
136
{
133
137
ResultCode = ProcessingResultCode . Error ,
134
138
} ;
135
139
136
- var parsedArguments = ArgumentHelper . ParseArguments ( args )
137
- . WithParsed < IScanArguments > ( argumentSet =>
138
- {
139
- CommandLineArgumentsExporter . ArgumentsForDelayedInjection = argumentSet ;
140
+ var parsedArguments = ArgumentHelper . ParseArguments ( args ) ;
141
+ await parsedArguments . WithParsedAsync < IScanArguments > ( async argumentSet =>
142
+ {
143
+ CommandLineArgumentsExporter . ArgumentsForDelayedInjection = argumentSet ;
140
144
141
- // Don't set production telemetry if we are running the build task in DevFabric. 0.36.0 is set in the task.json for the build task in development, but is calculated during deployment for production.
142
- TelemetryConstants . CorrelationId = argumentSet . CorrelationId ;
143
- telemetryRecord . Command = this . GetVerb ( argumentSet ) ;
145
+ // Don't set production telemetry if we are running the build task in DevFabric. 0.36.0 is set in the task.json for the build task in development, but is calculated during deployment for production.
146
+ TelemetryConstants . CorrelationId = argumentSet . CorrelationId ;
147
+ telemetryRecord . Command = this . GetVerb ( argumentSet ) ;
144
148
145
- scanResult = this . SafelyExecute ( telemetryRecord , ( ) =>
146
- {
147
- this . GenerateEnvironmentSpecificTelemetry ( telemetryRecord ) ;
149
+ scanResult = await this . SafelyExecuteAsync ( telemetryRecord , async ( ) =>
150
+ {
151
+ await this . GenerateEnvironmentSpecificTelemetryAsync ( telemetryRecord ) ;
148
152
149
- telemetryRecord . Arguments = JsonConvert . SerializeObject ( argumentSet ) ;
150
- FileWritingService . Init ( argumentSet . Output ) ;
151
- Logger . Init ( argumentSet . Verbosity ) ;
152
- Logger . LogInfo ( $ "Run correlation id: { TelemetryConstants . CorrelationId . ToString ( ) } ") ;
153
+ telemetryRecord . Arguments = JsonConvert . SerializeObject ( argumentSet ) ;
154
+ FileWritingService . Init ( argumentSet . Output ) ;
155
+ Logger . Init ( argumentSet . Verbosity ) ;
156
+ Logger . LogInfo ( $ "Run correlation id: { TelemetryConstants . CorrelationId . ToString ( ) } ") ;
153
157
154
- return this . Dispatch ( argumentSet , CancellationToken . None ) . GetAwaiter ( ) . GetResult ( ) ;
155
- } ) ;
156
- } )
157
- . WithNotParsed ( errors =>
158
+ return await this . Dispatch ( argumentSet , cancellationToken ) ;
159
+ } ) ;
160
+ } ) ;
161
+ parsedArguments . WithNotParsed ( errors =>
158
162
{
159
163
if ( errors . Any ( e => e is HelpVerbRequestedError ) )
160
164
{
@@ -174,7 +178,7 @@ public ScanResult HandleCommand(string[] args, BcdeExecutionTelemetryRecord tele
174
178
return scanResult ;
175
179
}
176
180
177
- private void GenerateEnvironmentSpecificTelemetry ( BcdeExecutionTelemetryRecord telemetryRecord )
181
+ private async Task GenerateEnvironmentSpecificTelemetryAsync ( BcdeExecutionTelemetryRecord telemetryRecord )
178
182
{
179
183
telemetryRecord . AgentOSDescription = RuntimeInformation . OSDescription ;
180
184
@@ -204,7 +208,7 @@ private void GenerateEnvironmentSpecificTelemetry(BcdeExecutionTelemetryRecord t
204
208
throw new TimeoutException ( $ "The execution did not complete in the alotted time ({ taskTimeout } seconds) and has been terminated prior to completion") ;
205
209
}
206
210
207
- agentOSMeaningfulDetails [ LibSslDetailsKey ] = getLibSslPackages . GetAwaiter ( ) . GetResult ( ) ;
211
+ agentOSMeaningfulDetails [ LibSslDetailsKey ] = await getLibSslPackages ;
208
212
}
209
213
catch ( Exception ex )
210
214
{
@@ -259,11 +263,11 @@ private async Task<ScanResult> Dispatch(IScanArguments arguments, CancellationTo
259
263
return scanResult ;
260
264
}
261
265
262
- private ScanResult SafelyExecute ( BcdeExecutionTelemetryRecord record , Func < ScanResult > wrappedInvocation )
266
+ private async Task < ScanResult > SafelyExecuteAsync ( BcdeExecutionTelemetryRecord record , Func < Task < ScanResult > > wrappedInvocation )
263
267
{
264
268
try
265
269
{
266
- return wrappedInvocation ( ) ;
270
+ return await wrappedInvocation ( ) ;
267
271
}
268
272
catch ( Exception ae )
269
273
{
0 commit comments