コード例 #1
0
ファイル: Pipeline.cs プロジェクト: mruppen/Abb.Pipeline
        public async Task <IPipelineExecutionContext> Execute(IPipelineExecutionContext executionContext, CancellationToken cancellationToken = default)
        {
            if (executionContext == null)
            {
                throw new ArgumentNullException(nameof(executionContext));
            }

            var behaviors = ResolveBehaviors();

            foreach (var step in _stepDescriptors)
            {
                ExecuteStepDelegate @delegate = s_boundDelegates.GetOrAdd(step.Id, _ => step.CreateDelegate());
                await ExecuteStep(step, executionContext, cancellationToken, @delegate, behaviors);
            }

            return(executionContext);
        }
コード例 #2
0
ファイル: Pipeline.cs プロジェクト: mruppen/Abb.Pipeline
        private Task ExecuteStep(StepDescriptor step, IPipelineExecutionContext executionContext, CancellationToken cancellationToken, ExecuteStepDelegate @delegate, IPipelineBehavior[] behaviors)
        {
            var stepInstance = _factory(step.TypeInfo);

            executionContext.CurrentStep = stepInstance;

            Func <CancellationToken, Task> currentFunc = token => @delegate(stepInstance, executionContext, _namingStrategy, _unknownParameterBehavior, token);

            for (var i = behaviors.Length - 1; i >= 0; i--)
            {
                var behavior     = behaviors[i];
                var previousFunc = currentFunc;
                currentFunc = token => behavior.Handle(executionContext, cancellationToken, previousFunc);
            }

            return(currentFunc(cancellationToken));
        }