Пример #1
0
        private void AppendStage(IResolveMiddleware stage)
        {
            var newDecl = new MiddlewareDeclaration(stage);

            if (_last is null)
            {
                _first = _last = newDecl;
            }
            else
            {
                newDecl.Previous = _last;
                _last.Next       = newDecl;
                _last            = newDecl;
            }
        }
Пример #2
0
        private void AddStage(IResolveMiddleware stage, MiddlewareInsertionMode insertionLocation)
        {
            VerifyPhase(stage.Phase);

            // Start at the beginning.
            var currentStage = _first;

            var newStageDecl = new MiddlewareDeclaration(stage);

            if (_first is null)
            {
                _first = _last = newStageDecl;
                return;
            }

            while (currentStage is object)
            {
                if (insertionLocation == MiddlewareInsertionMode.StartOfPhase ? currentStage.Middleware.Phase >= stage.Phase : currentStage.Middleware.Phase > stage.Phase)
                {
                    if (currentStage.Previous is object)
                    {
                        // Insert the node.
                        currentStage.Previous.Next = newStageDecl;
                        newStageDecl.Next          = currentStage;
                        newStageDecl.Previous      = currentStage.Previous;
                        currentStage.Previous      = newStageDecl;
                    }
                    else
                    {
                        _first.Previous   = newStageDecl;
                        newStageDecl.Next = _first;
                        _first            = newStageDecl;
                    }

                    return;
                }

                currentStage = currentStage.Next;
            }

            // Add at the end.
            newStageDecl.Previous = _last;
            _last !.Next          = newStageDecl;
            _last = newStageDecl;
        }
Пример #3
0
        /// <inheritdoc/>
        public IResolvePipelineBuilder UseRange(IEnumerable <IResolveMiddleware> stages, MiddlewareInsertionMode insertionMode = MiddlewareInsertionMode.EndOfPhase)
        {
            if (stages is null)
            {
                throw new ArgumentNullException(nameof(stages));
            }

            // Use multiple stages.
            // Start at the beginning.
            var currentStage = _first;

            using var enumerator = stages.GetEnumerator();

            if (!enumerator.MoveNext())
            {
                return(this);
            }

            var nextNewStage = enumerator.Current;
            var lastPhase    = nextNewStage.Phase;

            VerifyPhase(nextNewStage.Phase);

            while (currentStage is object)
            {
                if (insertionMode == MiddlewareInsertionMode.StartOfPhase ?
                    currentStage.Middleware.Phase >= nextNewStage.Phase :
                    currentStage.Middleware.Phase > nextNewStage.Phase)
                {
                    var newDecl = new MiddlewareDeclaration(enumerator.Current);

                    if (currentStage.Previous is object)
                    {
                        // Insert the node.
                        currentStage.Previous.Next = newDecl;
                        newDecl.Next          = currentStage;
                        newDecl.Previous      = currentStage.Previous;
                        currentStage.Previous = newDecl;
                    }
                    else
                    {
                        _first !.Previous = newDecl;
                        newDecl.Next      = _first;
                        _first            = newDecl;
                    }

                    currentStage = newDecl;

                    if (!enumerator.MoveNext())
                    {
                        // Done.
                        return(this);
                    }

                    nextNewStage = enumerator.Current;

                    VerifyPhase(nextNewStage.Phase);

                    if (nextNewStage.Phase < lastPhase)
                    {
                        throw new InvalidOperationException(ResolvePipelineBuilderMessages.MiddlewareMustBeInPhaseOrder);
                    }

                    lastPhase = nextNewStage.Phase;
                }

                currentStage = currentStage.Next;
            }

            do
            {
                nextNewStage = enumerator.Current;

                VerifyPhase(nextNewStage.Phase);

                if (nextNewStage.Phase < lastPhase)
                {
                    throw new InvalidOperationException(ResolvePipelineBuilderMessages.MiddlewareMustBeInPhaseOrder);
                }

                lastPhase = nextNewStage.Phase;

                var newStageDecl = new MiddlewareDeclaration(nextNewStage);

                if (_last is null)
                {
                    _first = _last = newStageDecl;
                }
                else
                {
                    newStageDecl.Previous = _last;
                    _last.Next            = newStageDecl;
                    _last = newStageDecl;
                }
            }while (enumerator.MoveNext());

            return(this);
        }