void UpdateBindingInfo( ControllerActionDescriptor action, ApiVersion apiVersion, ODataRouteMapping mapping, ICollection <ODataAttributeRouteInfo> routeInfos) { var routeContext = new ODataRouteBuilderContext(mapping, apiVersion, action, Options); if (routeContext.IsRouteExcluded) { return; } var routeBuilder = new ODataRouteBuilder(routeContext); var parameterContext = new ActionParameterContext(routeBuilder, routeContext); if (!parameterContext.IsSupported) { return; } for (var i = 0; i < action.Parameters.Count; i++) { UpdateBindingInfo(parameterContext, action.Parameters[i]); } var templates = parameterContext.Templates; for (var i = 0; i < templates.Count; i++) { var template = templates[i]; var routeInfo = new ODataAttributeRouteInfo() { Template = template.RouteTemplate, ODataTemplate = template.PathTemplate, RouteName = mapping.RouteName, RoutePrefix = mapping.RoutePrefix, }; routeInfos.Add(routeInfo); } if (routeContext.IsOperation) { EnsureOperationHttpMethod(action, routeContext.Operation !); } }
void UpdateBindingInfo(ControllerActionDescriptor action, ODataRouteMapping mapping, ICollection <ODataAttributeRouteInfo> routeInfos) { var routeContext = new ODataRouteBuilderContext(mapping, action, Options); var routeBuilder = new ODataRouteBuilder(routeContext); var parameterContext = new ActionParameterContext(routeBuilder, routeContext); for (var i = 0; i < action.Parameters.Count; i++) { UpdateBindingInfo(parameterContext, action.Parameters[i]); } var routeInfo = new ODataAttributeRouteInfo() { Template = routeBuilder.BuildPath(includePrefix: true), ODataTemplate = parameterContext.PathTemplate, }; routeInfos.Add(routeInfo); }
void UpdateBindingInfo(ControllerActionDescriptor action, ODataRouteMapping mapping, ICollection <ODataAttributeRouteInfo> routeInfos) { Contract.Requires(action != null); Contract.Requires(mapping != null); Contract.Requires(routeInfos != null); var routeContext = new ODataRouteBuilderContext(mapping, action, Options); var routeBuilder = new ODataRouteBuilder(routeContext); var parameterContext = new ActionParameterContext(routeBuilder, routeContext); foreach (var parameter in action.Parameters) { UpdateBindingInfo(parameterContext, parameter); } var routeInfo = new ODataAttributeRouteInfo() { Template = routeBuilder.BuildPath(includePrefix: true), ODataTemplate = parameterContext.PathTemplate, }; routeInfos.Add(routeInfo); }
void UpdateBindingInfo(ActionParameterContext context, ParameterDescriptor parameter) { var parameterType = parameter.ParameterType; var bindingInfo = parameter.BindingInfo; if (bindingInfo == null || bindingInfo.BindingSource == null) { var metadata = ModelMetadataProvider.GetMetadataForType(parameterType); if (bindingInfo == null) { parameter.BindingInfo = bindingInfo = new BindingInfo() { BindingSource = metadata.BindingSource }; } else { bindingInfo.BindingSource = metadata.BindingSource; } } if (bindingInfo.BindingSource == Custom) { if (parameterType.IsODataQueryOptions() || parameterType.IsODataPath()) { bindingInfo.BindingSource = Special; } } if (bindingInfo.BindingSource != null) { return; } var key = default(IEdmNamedElement); var paramName = parameter.Name; var source = Query; switch (context.RouteContext.ActionType) { case EntitySet: var keys = context.RouteContext.EntitySet.EntityType().Key().ToArray(); key = keys.FirstOrDefault(k => k.Name.Equals(paramName, OrdinalIgnoreCase)); if (key == null) { var template = context.Templates[0].PathTemplate; var segments = template.Segments.OfType <KeySegmentTemplate>(); if (segments.SelectMany(s => s.ParameterMappings.Values).Any(name => name.Equals(paramName, OrdinalIgnoreCase))) { source = Path; } } else { source = Path; } break; case BoundOperation: case UnboundOperation: var operation = context.RouteContext.Operation; if (operation == null) { break; } key = operation.Parameters.FirstOrDefault(p => p.Name.Equals(paramName, OrdinalIgnoreCase)); if (key == null) { if (operation.IsBound) { goto case EntitySet; } } else { source = Path; } break; } bindingInfo.BindingSource = source; }
static void UpdateBindingInfo(ActionParameterContext context, ParameterDescriptor parameter) { Contract.Requires(context != null); Contract.Requires(parameter != null); var bindingInfo = parameter.BindingInfo; if (bindingInfo != null && bindingInfo.BindingSource != Custom) { return; } bindingInfo = parameter.BindingInfo ?? new BindingInfo(); var paramType = parameter.ParameterType; if (paramType.IsODataQueryOptions() || paramType.IsODataPath()) { bindingInfo.BindingSource = ModelBinding; parameter.BindingInfo = bindingInfo; return; } else if (paramType.IsDelta()) { bindingInfo.BindingSource = Body; parameter.BindingInfo = bindingInfo; return; } var key = default(IEdmNamedElement); var paramName = parameter.Name; var source = Query; switch (context.RouteContext.ActionType) { case EntitySet: var keys = context.RouteContext.EntitySet.EntityType().Key().ToArray(); key = keys.FirstOrDefault(k => k.Name.Equals(paramName, OrdinalIgnoreCase)); if (key == null) { var template = context.PathTemplate; if (template != null) { var segments = template.Segments.OfType <KeySegmentTemplate>(); if (segments.SelectMany(s => s.ParameterMappings.Values).Any(name => name.Equals(paramName, OrdinalIgnoreCase))) { source = Path; } } } else { source = Path; } break; case BoundOperation: case UnboundOperation: var operation = context.RouteContext.Operation; if (operation == null) { break; } if (paramType.IsODataActionParameters()) { source = Body; } else { key = operation.Parameters.FirstOrDefault(p => p.Name.Equals(paramName, OrdinalIgnoreCase)); if (key == null) { if (operation.IsBound) { goto case EntitySet; } } else { source = Path; } } break; } bindingInfo.BindingSource = source; parameter.BindingInfo = bindingInfo; }