Exemple #1
0
        private T ExecuteComponent(IPipelineComponent <T> component, T payload, CancellationToken cancellationToken)
        {
            if (_componentExecutionStatusReceiver == null)
            {
                return(component.Execute(payload, cancellationToken));
            }

            var executionStartingInfo = new PipelineComponentExecutionStartingInfo(component.Name, payload);

            _componentExecutionStatusReceiver.ReceiveExecutionStarting(
                executionStartingInfo);
            var stopwatch = new Stopwatch();

            stopwatch.Start();
            try
            {
                var result = component.Execute(payload, cancellationToken);
                stopwatch.Stop();
                _componentExecutionStatusReceiver.ReceiveExecutionCompleted(
                    new PipelineComponentExecutionCompletedInfo(executionStartingInfo, stopwatch.Elapsed));
                return(result);
            }
            catch (Exception e)
            {
                stopwatch.Stop();
                _componentExecutionStatusReceiver.ReceiveExecutionCompleted(
                    new PipelineComponentExecutionCompletedInfo(executionStartingInfo, stopwatch.Elapsed, e));
                throw;
            }
        }
 /// <summary>
 /// Instantiate a new <see cref="PipelineComponentExecutionCompletedInfo"/> instance
 /// </summary>
 /// <param name="startingInfo"></param>
 /// <param name="executionTime"></param>
 /// <param name="exception"></param>
 public PipelineComponentExecutionCompletedInfo(
     PipelineComponentExecutionStartingInfo startingInfo,
     TimeSpan executionTime,
     Exception exception = null)
     : base(startingInfo.PipelineComponentName, startingInfo.Payload, startingInfo.TimeStamp)
 {
     ExecutionTime = executionTime;
     Exception     = exception;
 }
Exemple #3
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;
            }
        }