/// <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); }
/// <summary> /// Virtual method called from <see cref="OnExecute"/> to get the pipeline /// output values from the <see cref="PipelineContext"/>. /// </summary> /// <param name="context">The <see cref="PipelineContext"/> for the current execution of the pipeline.</param> /// <returns>The outputs that the pipeline will return for the current execution.</returns> protected virtual object[] OnGetPipelineOutputs(PipelineContext context) { if (context == null) { throw new ArgumentNullException("context"); } return(context.ReadAllInputs(this.ExitProcessor)); }
/// <summary> /// Virtual method called from <see cref="OnExecute"/> to get the pipeline /// output values from the <see cref="PipelineContext"/>. /// </summary> /// <param name="context">The <see cref="PipelineContext"/> for the current execution of the pipeline.</param> /// <returns>The outputs that the pipeline will return for the current execution.</returns> protected virtual object[] OnGetPipelineOutputs(PipelineContext context) { if (context == null) { throw new ArgumentNullException("context"); } return context.ReadAllInputs(this.ExitProcessor); }
/// <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; }
public void PipelineContext_SetProcessorOutput_Fanout_2_Processors() { Pipeline pipeline = TestPipelines.CreateDoubleMockProcessor1Pipeline(); PipelineContext context = new PipelineContext(pipeline); Assert.IsTrue(context.AdvanceToNextProcessor(), "Failed to advance to first"); // Mimic entry processor producing its output of an intValue=5 context.SetProcessorOutputs(context.CurrentProcessor, new object[] { 5 }); // This should have been copied to the input slots for second processor Assert.IsTrue(context.AdvanceToNextProcessor(), "Failed to advance to second"); object[] input = context.ReadAllInputs(context.CurrentProcessor); Assert.IsNotNull(input, "Input cannot be null"); Assert.AreEqual(1, input.Length, "Expected 1 element in input"); Assert.AreEqual(5, input[0], "Input should have contained a 5"); // Mimic second processor setting its output to "aString1" context.SetProcessorOutputs(context.CurrentProcessor, new object[] { "aString1" }); // Move to 3rd processor and ensure it got the same inputs as 2nd Assert.IsTrue(context.AdvanceToNextProcessor(), "Failed to advance to third"); input = context.ReadAllInputs(context.CurrentProcessor); Assert.IsNotNull(input, "Input cannot be null"); Assert.AreEqual(1, input.Length, "Expected 1 element in input"); Assert.AreEqual(5, input[0], "Input should have contained a 5"); // Mimic third processor setting its output to "aString2" context.SetProcessorOutputs(context.CurrentProcessor, new object[] { "aString2" }); // This should have been copied to the input slots for final processor Assert.IsTrue(context.AdvanceToNextProcessor(), "Failed to advance to third"); input = context.ReadAllInputs(context.CurrentProcessor); Assert.IsNotNull(input, "Input cannot be null"); Assert.AreEqual(2, input.Length, "Expected 2 elements in input"); Assert.AreEqual("aString1", input[0], "Input[0] should have contained this string"); Assert.AreEqual("aString2", input[1], "Input[1] should have contained this string"); }
public void PipelineContext_SetProcessorOutput() { Pipeline pipeline = TestPipelines.CreateMockProcessor1Pipeline(); PipelineContext context = new PipelineContext(pipeline); Assert.IsTrue(context.AdvanceToNextProcessor(), "Failed to advance to first"); // Mimic entry processor producing its output of an intValue=5 context.SetProcessorOutputs(context.CurrentProcessor, new object[] { 5 }); // This should have been copied to the input slots for second processor Assert.IsTrue(context.AdvanceToNextProcessor(), "Failed to advance to second"); object[] input = context.ReadAllInputs(context.CurrentProcessor); Assert.IsNotNull(input, "Input cannot be null"); Assert.AreEqual(1, input.Length, "Expected 1 element in input"); Assert.AreEqual(5, input[0], "Input should have contained a 5"); // Mimic processor 1 producing an output of theResult="aString" context.SetProcessorOutputs(context.CurrentProcessor, new object[] { "aString" }); // This should have been copied to the input slots for third processor Assert.IsTrue(context.AdvanceToNextProcessor(), "Failed to advance to third"); input = context.ReadAllInputs(context.CurrentProcessor); Assert.IsNotNull(input, "Input cannot be null"); Assert.AreEqual(1, input.Length, "Expected 1 element in input"); Assert.AreEqual("aString", input[0], "Input should have contained this string"); }
public void PipelineContext_ReadAllInputs_Throws_If_Processor_Not_In_Pipeline() { Processor processor = new MockProcessor1(); MockPipeline pipeline = TestPipelines.CreateMockProcessor1Pipeline(); PipelineContext context = new PipelineContext(pipeline); ExceptionAssert.Throws( typeof(ArgumentException), "PipelineContext should throw if processor from different pipeline specified", () => context.ReadAllInputs(processor), "processor" ); }
public void PipelineContext_ReadAllInputs_Throws_If_Null_Processor() { MockPipeline pipeline = TestPipelines.CreateMockProcessor1Pipeline(); PipelineContext context = new PipelineContext(pipeline); ExceptionAssert.ThrowsArgumentNull( "PipelineContext should throw if null processor specified", "processor", () => context.ReadAllInputs(null) ); }