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;
            }
        }
Exemple #2
0
        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;
            }
        }
Exemple #3
0
 public static IAsyncPipelineComponent <POut, NOut> AddStep <PIn, POut, NOut>(this IAsyncPipelineComponent <PIn, POut> component, Func <POut, IPipelineContext, Task <NOut> > step)
 {
     return(component.AddStep(PipelineComponent.CreateAsyncPipeline(step)));
 }
Exemple #4
0
 public static IAsyncPipelineComponent <POut, NOut> AddStep <PIn, POut, NOut>(this IAsyncPipelineComponent <PIn, POut> component, IAsyncPipelineStep <POut, NOut> step)
 {
     return(component.AddStep(PipelineComponent.CreateAsyncPipeline(step)));
 }
Exemple #5
0
 /// <summary>
 /// Adds the specified <see cref="IAsyncPipelineComponent{TPayload}"/> to the pipeline component resolver.
 /// /// </summary>
 /// <typeparam name="TPayload">Type defining the payload of the pipeline components being added.</typeparam>
 /// <param name="component">Pipeline component to be added to the resolver.</param>
 public void AddAsync <TPayload>(IAsyncPipelineComponent <TPayload> component)
 => AddInternal(component);