예제 #1
0
        /// <summary>
        /// Virtual method called to execute the <paramref name="context"/>'s currently active <see cref="Processor"/>.
        /// </summary>
        /// <param name="context">The <see cref="PipelineContext"/> managing execution state.</param>
        /// <returns>The <see cref="ProcessorResult"/> returned by that <see cref="Processor"/>.</returns>
        protected virtual ProcessorResult OnExecuteProcessor(PipelineContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            Processor currentProcessor = context.CurrentProcessor;

            // The entry processor has no inputs and its "outputs" were already
            // set via OnSetPipelineInputs, so we can bypass its execution.
            // The exit processor's inputs have already been set by all the other
            // processors' execution, and it has no outputs of its own, so it can
            // be bypassed as well.
            if (currentProcessor == this.EntryProcessor || currentProcessor == this.ExitProcessor)
            {
                return(new ProcessorResult());
            }

            object[]        input  = context.ReadAllInputs(currentProcessor);
            ProcessorResult result = currentProcessor.Execute(input);

            switch (result.Status)
            {
            case ProcessorStatus.Error:
                break;

            case ProcessorStatus.Ok:
                context.SetProcessorOutputs(currentProcessor, result.Output);
                break;
            }

            return(result);
        }
예제 #2
0
        /// <summary>
        /// Override this method to override the main execution logic of the pipeline
        /// </summary>
        /// <param name="input">The list of input to the piepline</param>
        /// <returns>The result of pipeline processing</returns>
        protected override sealed ProcessorResult OnExecute(object[] input)
        {
            PipelineContext context = this.OnCreateContext();

            this.OnSetPipelineInputs(context, input);
            ProcessorResult result = new ProcessorResult();

            while (result.Status == ProcessorStatus.Ok && context.AdvanceToNextProcessor())
            {
                result = this.OnExecuteProcessor(context);
            }

            if (result.Status == ProcessorStatus.Ok)
            {
                result = new ProcessorResult()
                {
                    Output = this.OnGetPipelineOutputs(context)
                };
            }

            return(result);
        }
        public void Execute_Does_Not_Change_ProcessResult_If_Not_Null()
        {
            MockNonGenericProcessor processor = new MockNonGenericProcessor();
            Exception exception = new Exception();
            ProcessorResult resultFromOnExecute = null;
            processor.OnExecuteAction = input =>
                {
                    resultFromOnExecute = new ProcessorResult() { Status = ProcessorStatus.Ok, Output = input, Error = exception };
                    return resultFromOnExecute;
                };

            processor.Initialize();

            object[] inputObjArray = new object[1] { "hello" };
            ProcessorResult result = processor.Execute(inputObjArray);

            Assert.IsNotNull(result, "Processor.Execute should never return null.");
            Assert.AreEqual(ProcessorStatus.Ok, result.Status, "Processor.Execute should have returned the same value as returned from OnExecute.");
            Assert.AreSame(resultFromOnExecute, result, "Processor.Execute should have returned the same instance returned from OnExecute.");
            Assert.AreSame(inputObjArray, result.Output, "Processor.Execute should have returned the same instance returned from OnExecute.");
            Assert.AreSame(exception, result.Error, "Processor.Execute should have returned the same instance returned from OnExecute.");
        }
예제 #4
0
        /// <summary>
        /// Override this method to override the main execution logic of the pipeline
        /// </summary>
        /// <param name="input">The list of input to the piepline</param>
        /// <returns>The result of pipeline processing</returns>
        protected override sealed ProcessorResult OnExecute(object[] input)
        {
            PipelineContext context = this.OnCreateContext();

            this.OnSetPipelineInputs(context, input);
            ProcessorResult result = new ProcessorResult();
            while (result.Status == ProcessorStatus.Ok && context.AdvanceToNextProcessor())
            {
                result = this.OnExecuteProcessor(context);
            }

            if (result.Status == ProcessorStatus.Ok)
            {
                result = new ProcessorResult() { Output = this.OnGetPipelineOutputs(context) };
            }

            return result;
        }
예제 #5
0
 /// <summary>
 /// Invoked whenever the <see cref="ProcessorResult"/> returned from calling 
 /// <see cref="Processor.Execute"/> has a <see cref="ProcessorStatus"/>
 /// of <see cref="ProcessorStatus.Error"/>.
 /// </summary>
 /// <param name="result">
 /// The <see cref="ProcessorResult"/> returned from calling <see cref="Processor.Execute"/>
 /// </param>
 protected virtual void OnError(ProcessorResult result)
 {
 }
예제 #6
0
        public ProcessorResult Execute(object[] input)
        {
            if (input == null)
            {
                throw new ArgumentNullException("input");
            }

            if (!this.IsInitialized)
            {
                throw new InvalidOperationException(SR.ProcessorMustBeInitializedBeforeExecution);
            }

            ProcessorResult result = null;
            try
            {
                result = this.OnExecute(input);
            }
            catch (Exception e)
            {
                result = new ProcessorResult();
                result.Error = e;
                result.Status = ProcessorStatus.Error;
            }

            if (result == null)
            {
                result = new ProcessorResult();
                result.Status = ProcessorStatus.Error;
                result.Error = new InvalidOperationException(SR.ProcessorReturnedNullProcessorResult);
            }

            if (result.Status == ProcessorStatus.Error)
            {
                this.OnError(result);
            }

            return result;
        }
 protected override void OnError(ProcessorResult result)
 {
     if (this.OnErrorCalled != null)
     {
         this.OnErrorCalled(result);
     }
 }
        public void Pipeline_Execute_Throws_Wrong_Output_Length()
        {
            MockPipeline pipeline = TestPipelines.CreateMockProcessor1Pipeline();
            ProcessorResult errorResult = null;

            // Override the OnExecute to return a ProcessorResult
            // which contains the wrong
            ((MockProcessor1)pipeline.Processors[1]).OnExecuteCalled =
                i =>
                {
                    ProcessorResult pr = new ProcessorResult<string>() { };
                    pr.Output = new object[] { "string1", "string2" };
                    return pr as ProcessorResult<string>;
                };

            pipeline.OnErrorCalled = r => errorResult = r;

            // The final pipeline result should reflect that error status
            ProcessorResult result = pipeline.Execute(new object[] { 5 });
            Assert.IsNotNull(result, "Failed to get a result");
            Assert.AreEqual(ProcessorStatus.Error, result.Status, "Expected failure status");
            Assert.IsNotNull(result.Error, "Expected error result");
            Assert.AreEqual(typeof(InvalidOperationException), result.Error.GetType(), "Expected InvalidOperationException");

            Assert.IsNotNull(errorResult, "Pipeline.OnError should have been called");
        }
        protected override ProcessorResult OnExecute(object[] input)
        {
            ProcessorResult result = null;

            if (input == null)
            {
                throw new ArgumentNullException("input");
            }

            if (this.ignore)
            {
                result = new ProcessorResult();
            }

            if (this.mode == MediaTypeProcessorMode.Request)
            {
                result = this.ExecuteRequest(input);
            }
            else
            {
                this.ExecuteResponse(input);
            }

            if (result == null)
            {
                result = new ProcessorResult();
            }

            return result;
        }
        private ProcessorResult ExecuteRequest(object[] input)
        {
            var request = (HttpRequestMessage)input[0];
            ProcessorResult result = null;

            if (request.Content != null && request.Content.Headers.ContentType != null && this.SupportedMediaTypes.Contains(request.Content.Headers.ContentType.MediaType))
            {
                result = new ProcessorResult<object> { Output = this.ReadFromStream(request.Content.ContentReadStream, request) };
            }

            return result;
        }