public ODataFormatterParameterBinding(HttpParameterDescriptor descriptor, MediaTypeFormatter formatter)
     : base(descriptor)
 {
     if (formatter == null)
     {
         throw Error.ArgumentNull("formatter");
     }
     _formatter = formatter;
 }
        public string GetDocumentation(HttpParameterDescriptor parameterDescriptor)
        {
            var reflectedParameterDescriptor = parameterDescriptor as ReflectedHttpParameterDescriptor;

            if (reflectedParameterDescriptor != null)

            {
                XPathNavigator memberNode = GetMemberNode(reflectedParameterDescriptor.ActionDescriptor);

                if (memberNode != null)

                {
                    string parameterName = reflectedParameterDescriptor.ParameterInfo.Name;

                    XPathNavigator parameterNode =
                        memberNode.SelectSingleNode(string.Format("param[@name='{0}']", parameterName));

                    if (parameterNode != null)

                    {
                        return parameterNode.Value.Trim();
                    }
                }
            }

            return string.Empty;
        }
 public BodyAndUriParameterBinding(HttpParameterDescriptor descriptor)
     : base(descriptor)
 {
     var httpConfiguration = descriptor.Configuration;
     Formatters = httpConfiguration.Formatters;
     BodyModelValidator = httpConfiguration.Services.GetBodyModelValidator();
 }
 public ResourceParameterBinding(
     ScimServerConfiguration serverConfiguration,
     HttpParameterDescriptor parameter) 
     : base(parameter)
 {
     _ServerConfiguration = serverConfiguration;
 }
 public ODataParameterDescriptor(string parameterName, Type parameterType, bool isOptional, HttpParameterDescriptor reflectedHttpParameterDescriptor)
 {
     ParameterName = parameterName;
     ParameterType = parameterType;
     IsOptional = isOptional;
     ReflectedHttpParameterDescriptor = reflectedHttpParameterDescriptor;
 }
        public override HttpParameterBinding GetBinding(HttpParameterDescriptor parameter)
        {
            if (parameter == null)
                throw new ArgumentException("Invalid parameter");

            return new TransferujPlResponseModelBinder(parameter);
        }
    /// <summary>
    /// Method that implements parameter binding hookup to the global configuration object's
    /// ParameterBindingRules collection delegate.
    /// 
    /// This routine filters based on POST/PUT method status and simple parameter
    /// types.
    /// </summary>
    /// <example>
    /// GlobalConfiguration.Configuration.
    ///       .ParameterBindingRules
    ///       .Insert(0,SimplePostVariableParameterBinding.HookupParameterBinding);
    /// </example>    
    /// <param name="descriptor"></param>
    /// <returns></returns>
    public static HttpParameterBinding HookupParameterBinding(HttpParameterDescriptor descriptor)
    {
        //To see is it mark the flag
        if (descriptor.ActionDescriptor.GetCustomAttributes<System.Web.Http.MultiParameterSupportAttribute>().Count <= 0)
            return null;

        var supportedMethods = descriptor.ActionDescriptor.SupportedHttpMethods;

        // Only apply this binder on POST and PUT operations
        if (supportedMethods.Contains(HttpMethod.Post) ||
            supportedMethods.Contains(HttpMethod.Put))
        {
            var supportedTypes = new Type[] { typeof(string),
                                                typeof(int),
                                                typeof(int?),
                                                typeof(decimal),
                                                typeof(decimal?),
                                                typeof(double),
                                                typeof(double?),
                                                typeof(long),
                                                typeof(long?),
                                                typeof(bool),
                                                typeof(bool?),
                                                typeof(DateTime),
                                                typeof(DateTime?),
                                                typeof(byte[])
                                            };

            if (supportedTypes.Count(typ => typ == descriptor.ParameterType) > 0)
                return new SimplePostVariableParameterBinding(descriptor);
        }

        return null;
    }
Beispiel #8
0
        /// <summary>
        ///   Gets the parameter binding.
        /// </summary>
        /// <returns>The parameter binding.</returns>
        /// <param name="parameter">The parameter description.</param>
        public override HttpParameterBinding GetBinding(HttpParameterDescriptor parameter)
        {
            // Preconditions
            Raise.ArgumentNullException.IfIsNull(parameter, nameof(parameter));

            return new NakedBodyParameterBinding(parameter);
        }
 public CatchAllRouteParameterBinding(
     HttpParameterDescriptor descriptor, char delimiter)
     : base(descriptor)
 {
     _parameterName = descriptor.ParameterName;
     _delimiter = delimiter;
 }
        // Determine how a single parameter will get bound. 
        // This is all sync. We don't need to actually read the body just to determine that we'll bind to the body.         
        protected virtual HttpParameterBinding GetParameterBinding(HttpParameterDescriptor parameter)
        {
            // Attribute has the highest precedence
            // Presence of a model binder attribute overrides.
            ParameterBindingAttribute attr = parameter.ParameterBinderAttribute;
            if (attr != null)
            {
                return attr.GetBinding(parameter);
            }

            // No attribute, so lookup in global map.
            ParameterBindingRulesCollection pb = parameter.Configuration.ParameterBindingRules;
            if (pb != null)
            {
                HttpParameterBinding binding = pb.LookupBinding(parameter);
                if (binding != null)
                {
                    return binding;
                }
            }

            // Not explicitly specified in global map or attribute.
            // Use a default policy to determine it. These are catch-all policies. 
            Type type = parameter.ParameterType;
            if (TypeHelper.IsSimpleUnderlyingType(type) || TypeHelper.HasStringConverter(type))
            {
                // For simple types, the default is to look in URI. Exactly as if the parameter had a [FromUri] attribute.
                return parameter.BindWithAttribute(new FromUriAttribute());
            }

            // Fallback. Must be a complex type. Default is to look in body. Exactly as if this type had a [FromBody] attribute.
            attr = new FromBodyAttribute();
            return attr.GetBinding(parameter);
        }
 /// <summary>
 /// Gets the documentation based on <see cref="System.Web.Http.Controllers.HttpParameterDescriptor" />.
 /// </summary>
 /// <param name="parameterDescriptor">The parameter descriptor.</param>
 /// <returns>The documentation for the controller.</returns>
 public string GetDocumentation(HttpParameterDescriptor parameterDescriptor)
 {
     return this.sources
         .Select(source => source.GetDocumentation(parameterDescriptor))
         .Where(documentation => !string.IsNullOrEmpty(documentation))
         .FirstOrDefault();
 }
        public SimpleApiParameterDescriptor(HttpParameterDescriptor arg, string routePath)
        {
            this.Name = arg.ParameterName;
            this.IsOptional = arg.IsOptional;

            if (this.IsOptional)
            {
                this.DefaultValue = arg.DefaultValue;
            }

            var indexOfQueryString = routePath.IndexOf('?');

            if (arg.ParameterBinderAttribute is FromBodyAttribute)
            {
                this.CallingConvention = "body";
            }
            else
            {
                var indexOfParameter = routePath.IndexOf("{" + arg.ParameterName + "}", StringComparison.InvariantCultureIgnoreCase);

                if (indexOfQueryString > 0 && indexOfParameter > indexOfQueryString)
                {
                    this.CallingConvention = "query-string";
                }
                else if (indexOfParameter > 0)
                {
                    this.CallingConvention = "uri";
                }
                else
                {
                    this.CallingConvention = "unknown";
                }
            }
        }
 public ScimQueryOptionsParameterBinding(
     HttpParameterDescriptor descriptor,
     ScimServerConfiguration serverConfiguration) 
     : base(descriptor)
 {
     _ServerConfiguration = serverConfiguration;
 }
        public override HttpParameterBinding GetBinding(HttpParameterDescriptor parameter)
        {
            if (parameter == null)
                throw new ArgumentException("Invalid parameter");

            return new NakedBodyParameterBinding(parameter);
        }
Beispiel #15
0
 public string GetDocumentation(HttpParameterDescriptor parameterDescriptor)
 {
     var attr = parameterDescriptor.ActionDescriptor
                 .GetCustomAttributes<ApiParameterDocAttribute>()
                 .FirstOrDefault(p => p.Parameter == parameterDescriptor.ParameterName);
     return attr != null ? attr.Documentation : "";
 }
 protected HttpParameterBinding(HttpParameterDescriptor descriptor)
 {
     if (descriptor == null)
     {
         throw Error.ArgumentNull("descriptor");
     }
     _descriptor = descriptor;
 }
        public string GetDocumentation(HttpParameterDescriptor parameterDescriptor)
        {
            var parameterName = parameterDescriptor.ParameterName;
            var selector = string.Format(MEMBER_PARAM_XPATH_QUERY, parameterName);

            var rtn = GetActionDocumentation(parameterDescriptor.ActionDescriptor, selector);
            return rtn;
        }
 public override HttpParameterBinding GetBinding(HttpParameterDescriptor parameter)
 {
     if (parameter.ParameterType == typeof(ETag))
     {
         return new ETagParameterBinding(parameter, match);
     }
     return parameter.BindAsError("Wrong parameter type");
 }
Beispiel #19
0
        /// <summary>
        /// Get Binding Process
        /// </summary>
        /// <param name="parameter">Parameter Descriptor</param>
        /// <returns></returns>
        public override HttpParameterBinding GetBinding(HttpParameterDescriptor parameter)
        {
            if(String.IsNullOrEmpty(this._name)){
                this._name = parameter.ParameterName;
            }

            return new Gale.REST.Http.Binding.FromHeaderBinding(parameter, this._name );
        }
		internal static bool IsChangeSetEntityParameter(HttpParameterDescriptor parameterDescriptor)
		{
			Contract.Assert(parameterDescriptor != null);

			ModelBinderAttribute modelBinderAttr = parameterDescriptor.ParameterBinderAttribute as ModelBinderAttribute;
			return (modelBinderAttr != null)
				&& (modelBinderAttr.BinderType == typeof(ChangeSetEntityModelBinder));
		}
        public override HttpParameterBinding GetBinding(HttpParameterDescriptor parameter)
        {
            HttpConfiguration config = parameter.Configuration;
            IModelBinder binder = GetModelBinder(config, parameter.ParameterType);
            IEnumerable<ValueProviderFactory> valueProviderFactories = GetValueProviderFactories(config);

            return new ModelBinderParameterBinding(parameter, binder, valueProviderFactories);
        }
        public PerRequestParameterBinding(HttpParameterDescriptor descriptor,
            IEnumerable<MediaTypeFormatter> formatters)
            : base(descriptor) {
            if (formatters == null)
                throw new ArgumentNullException("formatters");

            _formatters = formatters;
        }
 public ErrorParameterBinding(HttpParameterDescriptor descriptor, string message)
     : base(descriptor)
 {
     if (message == null)
     {
         throw Error.ArgumentNull(message);
     }
     _message = message;
 }
        public string GetDocumentation(HttpParameterDescriptor parameterDescriptor)
        {
            var parameterDocumentation = parameterDescriptor.ActionDescriptor.GetCustomAttributes<ApiParameterDocumentationAttribute>().FirstOrDefault(param => param.ParameterName == parameterDescriptor.ParameterName);
            if (parameterDocumentation != null)
            {
                return parameterDocumentation.Description;
            }

            return String.Empty;
        }
        string IDocumentationProvider.GetDocumentation(HttpParameterDescriptor parameterDescriptor)
        {
            var actionDoc = parameterDescriptor.GetCustomAttributes<ParameterDocAttribute>().FirstOrDefault();
            if (actionDoc != null)
            {
                return actionDoc.Documentation;
            }

            return string.Format("Documentation for '{0}'.", parameterDescriptor.ParameterName);
        }
        public virtual bool GetRequired(HttpParameterDescriptor parameterDescriptor)
        {
            ReflectedHttpParameterDescriptor reflectedParameterDescriptor = parameterDescriptor as ReflectedHttpParameterDescriptor;
            if (reflectedParameterDescriptor != null)
            {
                return !reflectedParameterDescriptor.ParameterInfo.IsOptional;
            }

            return true;
        }
 public override HttpParameterBinding GetBinding(HttpParameterDescriptor parameter)
 {
     IEdmModel model;
     MediaTypeFormatter formatter = parameter.Configuration.GetODataFormatter(out model);
     if (formatter == null)
     {
         throw Error.InvalidOperation(SRResources.NoODataMediaTypeFormatterFound);
     }
     return new ODataFormatterParameterBinding(parameter, formatter);
 }
 public FormatterParameterBinding(HttpParameterDescriptor descriptor, IEnumerable<MediaTypeFormatter> formatters, IBodyModelValidator bodyModelValidator)
     : base(descriptor)
 {
     if (descriptor.IsOptional)
     {
         _errorMessage = Error.Format(SRResources.OptionalBodyParameterNotSupported, descriptor.Prefix ?? descriptor.ParameterName, GetType().Name);
     }
     Formatters = formatters;
     BodyModelValidator = bodyModelValidator;
 }
Beispiel #29
0
        public FromHeaderBinding(HttpParameterDescriptor parameter, string headerName)
            : base(parameter)
        {
            if (string.IsNullOrEmpty(headerName))
            {
                throw new ArgumentNullException("Header Name");
            }

            this.name = headerName;
        }
        public ODataFormatterParameterBinding(HttpParameterDescriptor descriptor,
            IEnumerable<MediaTypeFormatter> formatters)
            : base(descriptor)
        {
            if (formatters == null)
            {
                throw Error.ArgumentNull("formatters");
            }

            _formatters = formatters;
        }