Esempio n. 1
0
 public override bool AppliesTo(RequestBinderContext context)
 {
     return(!context.RequestContext.Route.HasRequest &&
            context.RequestContext.Route.QuerystringParameters.Any() &&
            context.RequestContext.RequestMessage.ContentTypeIs(
                MimeTypes.ApplicationFormUrlEncoded));
 }
Esempio n. 2
0
        GetValues(RequestBinderContext context)
        {
            var data = await context.RequestContext
                       .RequestMessage.Content.ReadAsStringAsync();

            return(data.ParseQueryString());
        }
Esempio n. 3
0
        public async Task <BindResult> Bind(RequestBinderContext context)
        {
            var data = await _requestMessage.Content.ReadAsStringAsync();

            return(_argumentBinder.Bind(data.ParseQueryString(), context.ActionArguments,
                                        _routeDescriptor.Parameters));
        }
Esempio n. 4
0
        public Task <BindResult> Bind(RequestBinderContext context)
        {
            var parameters = _routeDescriptor.Parameters
                             .Where(x => IncludeParameter(x, _configuration.RequestInfoBindingMode)).ToArray();

            return(_argumentBinder.Bind(_requestProperties.GetProperties().ToLookup(),
                                        context.ActionArguments, parameters, MapParameterName).ToTaskResult());
        }
Esempio n. 5
0
        public async Task <BindResult> Bind(RequestBinderContext context)
        {
            var data = await _requestMessage.Content.ReadAsStringAsync();

            var values = JsonConvert.DeserializeObject <Dictionary <string, object> >(data).ToLookup();

            return(_argumentBinder.Bind(values, context.ActionArguments, _routeDescriptor.Parameters));
        }
Esempio n. 6
0
        public Task <BindResult> Bind(RequestBinderContext context)
        {
            var values     = _requestMessage.Headers.ToLookup();
            var parameters = _routeDescriptor.Parameters
                             .Where(x => IncludeParameter(x, _configuration.HeadersBindingMode)).ToArray();

            return(_argumentBinder.Bind(values, context.ActionArguments,
                                        parameters, MapParameterName).ToTaskResult());
        }
Esempio n. 7
0
        public virtual async Task Bind(RequestBinderContext context)
        {
            var route    = context.RequestContext.Route;
            var position = route.RequestParameter.Position;
            var reader   = _readers.ThatApplyTo(context.RequestContext, _configuration);

            if (reader != null)
            {
                context.ActionArguments[position] = await reader.Read(context);
            }
        }
Esempio n. 8
0
        public Task <BindResult> Bind(RequestBinderContext context)
        {
            var values = _urlParameters.SelectMany(x =>
                                                   ExpandWildcardParameters(x, _routeDescriptor
                                                                            .UrlParameters)).ToLookup();
            var parameters = _routeDescriptor.UrlParameters
                             .Concat(_routeDescriptor.Parameters).ToArray();

            return(_argumentBinder.Bind(values, context.ActionArguments,
                                        parameters).ToTaskResult());
        }
Esempio n. 9
0
 public Task <BindResult> Bind(RequestBinderContext context)
 {
     GetParameters().ForEach(x =>
     {
         if (x.GetArgument(context.ActionArguments) == null)
         {
             x.BindArgument(context.ActionArguments, _container
                            .GetInstance(x.TypeDescriptor.Type));
         }
     });
     return(BindResult.Success().ToTaskResult());
 }
Esempio n. 10
0
        public virtual async Task Bind(RequestBinderContext context)
        {
            var parameters = await GetValues(context);

            foreach (var parameter in GetParameters(context))
            {
                var values = parameters[parameter.Name].ToArray();
                var result = _mappers.Map(values, parameter, context.RequestContext, _configuration);
                if (result.Mapped)
                {
                    context.ActionArguments[parameter.Position] = result.Value;
                }
            }
        }
Esempio n. 11
0
        private object EnsureRequestValue(RequestBinderContext context,
                                          ParameterDescriptor requestParameter)
        {
            var instance = context.ActionArguments.EnsureValue(
                requestParameter.Position,
                requestParameter.ParameterType.TryCreate);

            if (instance == null)
            {
                throw new RequestTypeCreationException(requestParameter
                                                       .ParameterType, _actionDescriptor.Action);
            }

            return(instance);
        }
Esempio n. 12
0
        private void BindMultipartParameters(RequestBinderContext context,
                                             MultipartContent multipartContent)
        {
            var route     = _actionDescriptor.Route;
            var parameter = IsEnumerableStream(route.RequestParameter?.ParameterType)
                ? route.RequestParameter
                : route.Parameters.FirstOrDefault(x =>
                                                  IsEnumerableStream(x.TypeDescriptor))?.ParameterDescriptor;

            if (parameter == null)
            {
                return;
            }

            context.ActionArguments[parameter.Position] =
                parameter.ParameterType.Type == typeof(IEnumerable <InputStream>)
                    ? (object)multipartContent
                    : multipartContent.GetStreams();
        }
Esempio n. 13
0
        private BindResult BindValues(List <KeyValuePair <string, object> > values,
                                      RequestBinderContext context)
        {
            if (!values.Any())
            {
                return(BindResult.Success());
            }

            var valueLookup = values.ToLookup();

            if (_actionDescriptor.Route.Parameters.Any())
            {
                var result = _argumentBinder.Bind(valueLookup,
                                                  context.ActionArguments, _actionDescriptor.Route.Parameters);
                if (result.Status == BindingStatus.Failure)
                {
                    return(result);
                }
            }

            if (!_actionDescriptor.Route.HasRequest)
            {
                return(BindResult.Success());
            }

            var requestParameter = _actionDescriptor.Route.RequestParameter;

            if (IsEnumerableStream(requestParameter.ParameterType))
            {
                return(BindResult.Success());
            }

            var instance = EnsureRequestValue(context, requestParameter);

            var actionParameters = requestParameter.ParameterType.Properties
                                   .Select(x => new ActionParameter(_actionDescriptor.Action, requestParameter, x));

            return(_parameterBinder.Bind(valueLookup, actionParameters,
                                         (p, v) => p.BindProperty(instance, v),
                                         BindResult.Success, BindResult.Failure));
        }
Esempio n. 14
0
        private void BindMultipartProperties(ParameterDescriptor requestParameter,
                                             RequestBinderContext context, MultipartContent multipartContent)
        {
            if (!_actionDescriptor.Route.HasRequest)
            {
                return;
            }

            var property = requestParameter?.ParameterType.Properties
                           .FirstOrDefault(x => IsEnumerableStream(x.PropertyType));

            if (property == null)
            {
                return;
            }

            var instance = EnsureRequestValue(context, requestParameter);

            property.SetValue(instance,
                              property.PropertyType.Type == typeof(IEnumerable <InputStream>)
                    ? (object)multipartContent
                    : multipartContent.GetStreams());
        }
Esempio n. 15
0
        private async Task <BindResult> Read(HttpContent content,
                                             ParameterDescriptor requestParameter,
                                             RequestBinderContext context)
        {
            var readContext = content.CreateReaderContext(_actionDescriptor);
            var reader      = _actionDescriptor.RequestReaders
                              .ThatApplyToOrDefault(_readers, readContext)
                              .FirstOrDefault();

            if (reader == null)
            {
                return(BindResult.NoReader());
            }

            var result = await reader.Read(readContext);

            if (result.Status == ReadStatus.Failure)
            {
                return(BindResult.Failure(result.ErrorMessage));
            }
            context.ActionArguments[requestParameter.Position] = result.Value;
            return(BindResult.Success());
        }
Esempio n. 16
0
        public virtual async Task <BindResult> Bind(RequestBinderContext context)
        {
            var position = _actionDescriptor.Route.RequestParameter.Position;
            var headers  = _requestMessage.Content?.Headers;

            if ((headers?.ContentLength ?? 0) == 0)
            {
                if (_configuration.CreateEmptyRequestParameterValue)
                {
                    context.ActionArguments[position] = _actionDescriptor
                                                        .Route.RequestParameter.ParameterType.TryCreate();
                }
                return(BindResult.Success());
            }

            var readContext = _requestMessage.Content
                              .CreateReaderContext(_actionDescriptor);
            var reader = _actionDescriptor.RequestReaders
                         .ThatApplyToOrDefault(_readers, readContext)
                         .FirstOrDefault();

            if (reader == null)
            {
                return(BindResult.NoReader());
            }

            var result = await reader.Read(readContext);

            if (result.Status == ReadStatus.Failure)
            {
                return(BindResult.Failure(result.ErrorMessage));
            }

            context.ActionArguments[position] = result.Value;
            return(BindResult.Success());
        }
Esempio n. 17
0
 protected abstract ParameterDescriptor[] GetParameters(RequestBinderContext context);
Esempio n. 18
0
 GetParameters(RequestBinderContext context)
 {
     return(context.RequestContext.Route.QuerystringParameters);
 }
Esempio n. 19
0
 protected abstract Task <ILookup <string, string> > GetValues(RequestBinderContext context);
Esempio n. 20
0
 public bool AppliesTo(RequestBinderContext context)
 {
     return(GetParameters().Any());
 }
Esempio n. 21
0
 public override bool AppliesTo(RequestBinderContext context)
 {
     return(context.RequestContext.Route.QuerystringParameters.Any());
 }
Esempio n. 22
0
 public bool AppliesTo(RequestBinderContext context)
 {
     return(_requestMessage.HasMimeMultipartContent());
 }
Esempio n. 23
0
 public bool AppliesTo(RequestBinderContext context)
 {
     return(_routeDescriptor.UrlParameters.Any());
 }
Esempio n. 24
0
 public bool AppliesTo(RequestBinderContext context)
 {
     return(_routeDescriptor.Parameters.Any() &&
            _configuration.HeadersBindingMode != BindingMode.None);
 }
Esempio n. 25
0
 protected override ParameterDescriptor[] GetParameters(RequestBinderContext context)
 {
     return(context.RequestContext.Route.QuerystringParameters);
 }
Esempio n. 26
0
 public Task <BindResult> Bind(RequestBinderContext context)
 {
     return(_argumentBinder.Bind(_querystringParameters,
                                 context.ActionArguments, _routeDescriptor.Parameters)
            .ToTaskResult());
 }
Esempio n. 27
0
 public virtual bool AppliesTo(RequestBinderContext context)
 {
     return(context.RequestContext.Route.HasRequest);
 }
Esempio n. 28
0
 GetValues(RequestBinderContext context)
 {
     return(context.RequestContext.QuerystringParameters.ToTaskResult());
 }
Esempio n. 29
0
        public async Task <BindResult> Bind(RequestBinderContext context)
        {
            var route            = _actionDescriptor.Route;
            var requestParameter = route.RequestParameter;
            var stream           = await _requestMessage.Content.ReadAsStreamAsync();

            var multipartContent = new MultipartContent(stream,
                                                        _requestMessage.Content.Headers, _configuration);
            var values = new List <KeyValuePair <string, object> >();

            while (true)
            {
                var content = multipartContent.Peek();

                if (content == null)
                {
                    break;
                }

                if (content.Error)
                {
                    return(new BindResult(BindingStatus.Failure, content.ErrorMessage));
                }

                if (route.HasRequest)
                {
                    var result = await Read(content, requestParameter, context);

                    if (result.Status == BindingStatus.Failure)
                    {
                        return(result);
                    }
                    if (result.Status == BindingStatus.Success)
                    {
                        multipartContent.Pop();
                        continue;
                    }
                }

                if (route.HasParameterNamed(content.Name) ||
                    requestParameter.HasPropertyNamed(content.Name))
                {
                    values.Add(content.Name, await content.ReadAsStringAsync());
                    multipartContent.Pop();
                    continue;
                }

                break;
            }

            var bindResult = BindValues(values, context);

            if (bindResult.Status == BindingStatus.Failure)
            {
                return(bindResult);
            }

            BindMultipartParameters(context, multipartContent);
            BindMultipartProperties(requestParameter, context, multipartContent);

            return(BindResult.Success());
        }
Esempio n. 30
0
 public bool AppliesTo(RequestBinderContext context)
 {
     return(!_routeDescriptor.HasRequest && _routeDescriptor.Parameters.Any() &&
            _requestMessage.ContentTypeIs(MimeTypes.ApplicationFormUrlEncoded));
 }