private async Task <T> ExecuteComponentAsync(IAsyncPipelineComponent <T> component, T payload, CancellationToken cancellationToken) { if (_componentExecutionStatusReceiver == null) { return(await component.ExecuteAsync(payload, cancellationToken).ConfigureAwait(false)); } await _componentExecutionStatusReceiver.ReceiveExecutionStartingAsync(new PipelineComponentExecutionStartingInfo(component.Name)) .ConfigureAwait(false); var stopwatch = new Stopwatch(); stopwatch.Start(); try { var result = await component.ExecuteAsync(payload, cancellationToken).ConfigureAwait(false); stopwatch.Stop(); await _componentExecutionStatusReceiver.ReceiveExecutionCompletedAsync(new PipelineComponentExecutionCompletedInfo(component.Name, stopwatch.Elapsed)) .ConfigureAwait(false); return(result); } catch (Exception e) { stopwatch.Stop(); await _componentExecutionStatusReceiver.ReceiveExecutionCompletedAsync(new PipelineComponentExecutionCompletedInfo(component.Name, stopwatch.Elapsed, e)) .ConfigureAwait(false); throw; } }
private async Task <T> ExecuteComponentAsync(IAsyncPipelineComponent <T> component, T payload, CancellationToken cancellationToken) { if (_componentExecutionStatusReceiver == null) { var task = component.ExecuteAsync(payload, cancellationToken) ?? throw new InvalidOperationException(string.Format(NullTaskExceptionMessage, component.Name)); return(await task.ConfigureAwait(false)); } var executionStartingInfo = new PipelineComponentExecutionStartingInfo(component.Name, payload); await _componentExecutionStatusReceiver.ReceiveExecutionStartingAsync( executionStartingInfo) .ConfigureAwait(false); var stopwatch = new Stopwatch(); stopwatch.Start(); try { var task = component.ExecuteAsync(payload, cancellationToken) ?? throw new InvalidOperationException(string.Format(NullTaskExceptionMessage, component.Name)); var result = await task.ConfigureAwait(false); stopwatch.Stop(); await _componentExecutionStatusReceiver.ReceiveExecutionCompletedAsync( new PipelineComponentExecutionCompletedInfo(executionStartingInfo, stopwatch.Elapsed)) .ConfigureAwait(false); return(result); } catch (Exception e) { stopwatch.Stop(); await _componentExecutionStatusReceiver.ReceiveExecutionCompletedAsync( new PipelineComponentExecutionCompletedInfo(executionStartingInfo, stopwatch.Elapsed, e)) .ConfigureAwait(false); throw; } }