public async Task <ExecutionResult <EgressResult> > ExecuteAsync(IServiceProvider serviceProvider, CancellationToken token) { ILogger <EgressOperation> logger = serviceProvider .GetRequiredService <ILoggerFactory>() .CreateLogger <EgressOperation>(); using var _ = logger.BeginScope(_scope); return(await ExecutionHelper.InvokeAsync(async (token) => { IEgressService egressService = serviceProvider .GetRequiredService <IEgressService>(); EgressResult egressResult = await _egress(egressService, token); logger.EgressedArtifact(egressResult.Value); // The remaining code is creating a JSON object with a single property and scalar value // that indiates where the stream data was egressed. Because the name of the artifact is // automatically generated by the REST API and the caller of the endpoint might not know // the specific configuration information for the egress provider, this value allows the // caller to more easily find the artifact after egress has completed. return ExecutionResult <EgressResult> .Succeeded(egressResult); }, logger, token)); }
public static async Task InvokeAsync(this ActionContext context, Func <CancellationToken, Task> action, ILogger logger) { //We want to handle two scenarios: //1) These functions are part of an ExecuteResultAsync implementation, in which case //they don't need to return anything. (The delegate below handles this case). //2) They are part of deferred processing and return a result. Func <CancellationToken, Task <ExecutionResult <object> > > innerAction = async(CancellationToken token) => { await action(token); return(ExecutionResult <object> .Empty()); }; ExecutionResult <object> result = await ExecutionHelper.InvokeAsync(innerAction, logger, context.HttpContext.RequestAborted); if (result.ProblemDetails != null) { await context.ProblemAsync(new BadRequestObjectResult(result.ProblemDetails)); } }