private OutputValueInfo[] CreateOutputValueInfos(Processor processor)
        {
            int numberOfOutArgs = processor.OutArguments.Count;
            OutputValueInfo[] result = new OutputValueInfo[numberOfOutArgs];
            for (int outArgIndex = 0; outArgIndex < numberOfOutArgs; ++outArgIndex)
            {
                ProcessorArgument outArg = processor.OutArguments[outArgIndex];
                ProcessorArgument[] inArgs = this.Pipeline.GetBoundToArguments(processor.OutArguments[outArgIndex]).ToArray();
                int[] inputValueIndices = new int[inArgs.Length];
                for (int inArgIndex = 0; inArgIndex < inArgs.Length; ++inArgIndex)
                {
                    int slotOffset = this.SlotOffSetOfInArgument(inArgs[inArgIndex]);
                    inputValueIndices[inArgIndex] = slotOffset;
                }

                result[outArgIndex] = new OutputValueInfo(outArg, inputValueIndices, inArgs);
            }

            return result;
        }
        public HttpPipelineFormatter(Processor[] requestProcessors, Processor[] responseProcessors, HttpOperationDescription operationDescription, MessageProperties messageProperties = null)
        {
            this.messageProperties = messageProperties;
            if (requestProcessors == null)
            {
                throw new ArgumentNullException("requestProcessors");
            }

            this.requestProcessors = requestProcessors;

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

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

            this.responseProcessors = responseProcessors;
            this.requestProcessors = requestProcessors;
            this.OperationDescription = operationDescription;
        }
 private int IndexOfProcessor(Processor processor)
 {
     int index = this.Pipeline.Processors.IndexOf(processor);
     Debug.Assert(index >= 0, "Processor was not in pipeline");
     return index;
 }
        private void EnsureValidProcessor(Processor processor)
        {
            if (processor == null)
            {
                throw new ArgumentNullException("processor");
            }

            if (this.Pipeline.Processors.IndexOf(processor) < 0)
            {
                throw new ArgumentException(SR.ProcessorDoesNotBelongToCurrentPipeline, "processor");
            }
        }
 /// <summary>
 /// Called to obtain the input values for the given <see cref="Processor"/>.
 /// </summary>
 /// <remarks>
 /// This base method obtains the values from an internal pool of values.
 /// Subclasses should call the base method if that behavior is desired,
 /// otherwise they can use custom logic to provide the values.
 /// </remarks>
 /// <param name="processor">The processor whose input values are needed.</param>
 /// <returns>The input values to provide to that processor's <see cref="Processor.Execute"/>
 /// method.
 /// </returns>
 protected virtual object[] OnReadAllInputs(Processor processor)
 {
     int processorIndex = this.IndexOfProcessor(processor);
     int inputValueOffset;
     int inputValueCount = this.ContextInfo.GetInputValueInfo(processorIndex, out inputValueOffset);
     object[] resultArray = new object[inputValueCount];
     Array.Copy(this.InputValues, inputValueOffset, resultArray, 0, resultArray.Length);
     return resultArray;
 }
        internal void SetProcessorOutputs(Processor processor, object[] output)
        {
            // A null or empty output array is taken to mean "ignore my outputs"
            // for processors that normally produce output.
            if (output == null || output.Length == 0)
            {
                return;
            }

            int outArgCount = processor.OutArguments.Count;
            if (output.Length != outArgCount)
            {
                throw new InvalidOperationException(
                    string.Format(
                        CultureInfo.InvariantCulture,
                        SR.ProcessorReceivedWrongNumberOfValues,
                        processor.GetType().Name,
                        outArgCount,
                        output.Length));
            }

            Debug.Assert(outArgCount == output.Length, "SetProcessorOutput -- array length does not match output value count");

            int processorIndex = this.IndexOfProcessor(processor);
            for (int outArgIndex = 0; outArgIndex < outArgCount; ++outArgIndex)
            {
                ProcessorArgument outArg;
                ProcessorArgument[] inArgs;
                int[] inputValueOffsets = this.ContextInfo.GetOutputValueInfo(processorIndex, outArgIndex, out outArg, out inArgs);

                for (int inArgIndex = 0; inArgIndex < inputValueOffsets.Length; ++inArgIndex)
                {
                    object value = output[outArgIndex];
                    this.OnWriteInput(outArg, inArgs[inArgIndex], value);
                }
            }
        }
 /// <summary>
 /// Reads all the data values for all the input <see cref="ProcessorArgument"/>s for
 /// the given <see cref="Processor"/>.
 /// </summary>
 /// <param name="processor">The <see cref="Processor"/> whose values should be read.</param>
 /// <returns>An array containing those values.  The array will contain one element per
 /// <see cref="ProcessorArgument"/>, in the order they appear in their respective
 /// <see cref="ProcessorArgumentCollection"/>.  The array will not be <c>null</c> but
 /// it can contain <c>null values.</c></returns>
 public object[] ReadAllInputs(Processor processor)
 {
     this.EnsureValidProcessor(processor);
     return this.OnReadAllInputs(processor);
 }