public HttpParameterBindingTracer(HttpParameterBinding innerBinding, ITraceWriter traceWriter) : base(innerBinding.Descriptor)
        {
            Contract.Assert(innerBinding != null);
            Contract.Assert(traceWriter != null);

            InnerBinding = innerBinding;
            TraceWriter = traceWriter;
        }
        public void ParameterBindings_Uses_Inners()
        {
            // Arrange
            HttpActionBinding binding = new Mock<HttpActionBinding>() { CallBase = true }.Object;
            HttpParameterBinding[] parameterBindings = new HttpParameterBinding[0];
            binding.ParameterBindings = parameterBindings;
            HttpActionBindingTracer tracer = new HttpActionBindingTracer(binding, new TestTraceWriter());

            // Assert
            Assert.Same(parameterBindings, tracer.ParameterBindings);
        }
示例#3
0
        private async Task ExecuteBindingAsyncCore(
            HttpActionContext actionContext,
            CancellationToken cancellationToken
            )
        {
            // Execute all the binders.
            for (int index = 0; index < ParameterBindings.Length; index++)
            {
                HttpParameterBinding parameterBinder = ParameterBindings[index];

                await parameterBinder.ExecuteBindingAsync(
                    _metadataProvider,
                    actionContext,
                    cancellationToken
                    );
            }
        }
        // Creates wrapping tracers for all HttpParameterBindings
        HttpActionBinding IActionValueBinder.GetBinding(HttpActionDescriptor actionDescriptor)
        {
            HttpActionBinding actionBinding = _innerBinder.GetBinding(actionDescriptor);
            HttpParameterBinding[] parameterBindings = actionBinding.ParameterBindings;
            HttpParameterBinding[] newParameterBindings = new HttpParameterBinding[parameterBindings.Length];
            for (int i = 0; i < newParameterBindings.Length; i++)
            {
                HttpParameterBinding parameterBinding = parameterBindings[i];

                // Itercept FormatterParameterBinding to replace its formatters
                FormatterParameterBinding formatterParameterBinding = parameterBinding as FormatterParameterBinding;
                newParameterBindings[i] = formatterParameterBinding != null
                                            ? (HttpParameterBinding)new FormatterParameterBindingTracer(formatterParameterBinding, _traceWriter)
                                            : (HttpParameterBinding)new HttpParameterBindingTracer(parameterBinding, _traceWriter);
            }

            HttpActionBinding newActionBinding = new HttpActionBinding(actionDescriptor, newParameterBindings);
            return newActionBinding;
        }
        // Creates wrapping tracers for all HttpParameterBindings
        HttpActionBinding IActionValueBinder.GetBinding(HttpActionDescriptor actionDescriptor)
        {
            HttpActionBinding actionBinding = _innerBinder.GetBinding(actionDescriptor);
            HttpParameterBinding[] parameterBindings = actionBinding.ParameterBindings;
            HttpParameterBinding[] newParameterBindings = new HttpParameterBinding[parameterBindings.Length];
            for (int i = 0; i < newParameterBindings.Length; i++)
            {
                HttpParameterBinding parameterBinding = parameterBindings[i];

                // Itercept FormatterParameterBinding to replace its formatters
                FormatterParameterBinding formatterParameterBinding = parameterBinding as FormatterParameterBinding;
                newParameterBindings[i] = formatterParameterBinding != null
                                            ? (HttpParameterBinding)new FormatterParameterBindingTracer(formatterParameterBinding, _traceWriter)
                                            : (HttpParameterBinding)new HttpParameterBindingTracer(parameterBinding, _traceWriter);
            }

            // Replace the inner HttpActionBinding's parameter bindings with our tracing versions.
            // This allows each individual parameter binding to trace.
            actionBinding.ParameterBindings = newParameterBindings;

            // Then create an HttpActionBindingTracer to wrap the actual HttpActionBinding
            return new HttpActionBindingTracer(actionBinding, _traceWriter);
        }
 public HttpActionBinding(HttpActionDescriptor actionDescriptor, HttpParameterBinding[] bindings)
 {
     ActionDescriptor = actionDescriptor;
     ParameterBindings = bindings;
 }
        private ApiParameterDescription CreateParameterDescriptionFromBinding(HttpParameterBinding parameterBinding)
        {
            ApiParameterDescription parameterDescription = CreateParameterDescriptionFromDescriptor(parameterBinding.Descriptor);
            if (parameterBinding.WillReadBody)
            {
                parameterDescription.Source = ApiParameterSource.FromBody;
            }
            else if (parameterBinding.WillReadUri())
            {
                parameterDescription.Source = ApiParameterSource.FromUri;
            }

            return parameterDescription;
        }
        private static ApiParameterDescription CreateParameterDescriptionFromBinding(HttpParameterBinding parameterBinding)
        {
            Contract.Requires(parameterBinding != null);

            Contract.Assume(parameterBinding.Descriptor?.Configuration != null);

            var parameterDescription = CreateParameterDescriptionFromDescriptor(parameterBinding.Descriptor);
            if (parameterBinding.WillReadBody)
            {
                parameterDescription.Source = ApiParameterSource.FromBody;
            }
            else if (parameterBinding.WillReadUri())
            {
                parameterDescription.Source = ApiParameterSource.FromUri;
            }

            return parameterDescription;
        }
 public FromUriOrBodyParameterBinding(HttpParameterDescriptor desc)
     : base(desc)
 {
     _defaultUriBinding = new FromUriAttribute().GetBinding(desc);
     _defaultFormatterBinding = new FromBodyAttribute().GetBinding(desc);
 }
 public HttpParameterBindingTracer(HttpParameterBinding innerBinding, ITraceWriter traceWriter) : base(innerBinding.Descriptor)
 {
     InnerBinding = innerBinding;
     TraceWriter = traceWriter;
 }