/// <inheritdoc/> /// <remarks>This signature uses types that are AspNetCore-specific.</remarks> public override string SelectAction(RouteContext routeContext, SelectControllerResult controllerResult, IEnumerable <ControllerActionDescriptor> actionDescriptors) { return(SelectActionImpl( routeContext.HttpContext.ODataFeature().Path, new WebApiControllerContext(routeContext, controllerResult), new WebApiActionMap(actionDescriptors))); }
/// <inheritdoc /> /// <remarks>This signature uses types that are AspNet-specific.</remarks> public string SelectAction(ODataPath odataPath, HttpControllerContext controllerContext, ILookup <string, HttpActionDescriptor> actionMap) { if (odataPath == null) { throw Error.ArgumentNull("odataPath"); } if (controllerContext == null) { throw Error.ArgumentNull("controllerContext"); } if (actionMap == null) { throw Error.ArgumentNull("actionMap"); } object value = null; controllerContext.Request.Properties.TryGetValue("AttributeRouteData", out value); SelectControllerResult controllerResult = new SelectControllerResult( controllerContext.ControllerDescriptor.ControllerName, value as IDictionary <string, object>); return(SelectActionImpl(new WebApiControllerContext(controllerContext, controllerResult))); }
/// <inheritdoc/> public IEnumerable <ControllerActionDescriptor> SelectAction(RouteContext routeContext) { // Get a IActionDescriptorCollectionProvider from the global service provider. IActionDescriptorCollectionProvider actionCollectionProvider = routeContext.HttpContext.RequestServices.GetRequiredService <IActionDescriptorCollectionProvider>(); Contract.Assert(actionCollectionProvider != null); ODataPath odataPath = routeContext.HttpContext.ODataFeature().Path; HttpRequest request = routeContext.HttpContext.Request; SelectControllerResult controllerResult = SelectControllerImpl( odataPath, new WebApiRequestMessage(request)); if (controllerResult != null) { IEnumerable <ControllerActionDescriptor> actionDescriptors = actionCollectionProvider .ActionDescriptors.Items.OfType <ControllerActionDescriptor>() .Where(c => c.ControllerName == controllerResult.ControllerName); string actionName = SelectActionImpl( odataPath, new WebApiControllerContext(routeContext, controllerResult), new WebApiActionMap(actionDescriptors)); if (!String.IsNullOrEmpty(actionName)) { return(actionDescriptors.Where( c => String.Equals(c.ActionName, actionName, StringComparison.OrdinalIgnoreCase))); } } return(null); }
/// <summary> /// Selects the action for OData requests. /// </summary> /// <param name="odataPath">The OData path.</param> /// <param name="controllerContext">The controller context.</param> /// <param name="actionMap">The action map.</param> /// <returns> /// <c>null</c> if the request isn't handled by this convention; otherwise, the name of the selected action /// </returns> public string SelectAction(ODataPath odataPath, HttpControllerContext controllerContext, ILookup <string, HttpActionDescriptor> actionMap) { if (odataPath == null) { throw Error.ArgumentNull("odataPath"); } if (controllerContext == null) { throw Error.ArgumentNull("controllerContext"); } if (actionMap == null) { throw Error.ArgumentNull("actionMap"); } SelectControllerResult controllerResult = new SelectControllerResult( controllerContext.ControllerDescriptor.ControllerName, null); return(SelectActionImpl( odataPath, new WebApiControllerContext(controllerContext, controllerResult), new WebApiActionMap(actionMap))); }
/// <inheritdoc /> internal static SelectControllerResult SelectControllerImpl(ODataPath odataPath, IWebApiRequestMessage request, IDictionary <ODataPathTemplate, IWebApiActionDescriptor> attributeMappings) { Dictionary <string, object> values = new Dictionary <string, object>(); foreach (KeyValuePair <ODataPathTemplate, IWebApiActionDescriptor> attributeMapping in attributeMappings) { ODataPathTemplate template = attributeMapping.Key; IWebApiActionDescriptor action = attributeMapping.Value; if (action.IsHttpMethodSupported(request.GetRequestMethodOrPreflightMethod()) && template.TryMatch(odataPath, values)) { values["action"] = action.ActionName; SelectControllerResult result = new SelectControllerResult(action.ControllerName, values); return(result); } // It's possible that template.TryMatch inserted values in the values dict even if // it did not match the current path. So let's clear the dict before trying // the next template values.Clear(); } return(null); }
/// <summary> /// Selects the controller for OData requests. /// </summary> /// <param name="odataPath">The OData path.</param> /// <param name="request">The request.</param> /// <returns> /// <c>null</c> if the request isn't handled by this convention; otherwise, the name of the selected controller /// </returns> public string SelectController(ODataPath odataPath, HttpRequestMessage request) { SelectControllerResult controllerResult = SelectControllerImpl( odataPath, new WebApiRequestMessage(request)); return(controllerResult != null ? controllerResult.ControllerName : null); }
/// <inheritdoc /> /// <remarks>This signature uses types that are AspNet-specific.</remarks> public string SelectController(ODataPath odataPath, HttpRequestMessage request) { SelectControllerResult controllerResult = SelectControllerImpl( odataPath, new WebApiRequestMessage(request), this.AttributeMappings); if (controllerResult != null) { request.Properties["AttributeRouteData"] = controllerResult.Values; } return(controllerResult != null ? controllerResult.ControllerName : null); }
/// <inheritdoc/> /// <remarks>This signature uses types that are AspNetCore-specific.</remarks> public IEnumerable <ControllerActionDescriptor> SelectAction(RouteContext routeContext) { if (routeContext == null) { throw Error.ArgumentNull("routeContext"); } ODataPath odataPath = routeContext.HttpContext.ODataFeature().Path; if (odataPath == null) { throw Error.ArgumentNull("odataPath"); } HttpRequest request = routeContext.HttpContext.Request; SelectControllerResult controllerResult = SelectControllerImpl(odataPath); if (controllerResult != null) { // Get a IActionDescriptorCollectionProvider from the global service provider. IActionDescriptorCollectionProvider actionCollectionProvider = routeContext.HttpContext.RequestServices.GetRequiredService <IActionDescriptorCollectionProvider>(); Contract.Assert(actionCollectionProvider != null); IEnumerable <ControllerActionDescriptor> actionDescriptors = actionCollectionProvider .ActionDescriptors.Items.OfType <ControllerActionDescriptor>() .Where(c => c.ControllerName == controllerResult.ControllerName); if (actionDescriptors != null) { string actionName = SelectAction(routeContext, controllerResult, actionDescriptors); if (!String.IsNullOrEmpty(actionName)) { return(actionDescriptors.Where( c => String.Equals(c.ActionName, actionName, StringComparison.OrdinalIgnoreCase))); } } } return(null); }
/// <inheritdoc /> internal static SelectControllerResult SelectControllerImpl(ODataPath odataPath, IWebApiRequestMessage request, IDictionary <ODataPathTemplate, IWebApiActionDescriptor> attributeMappings) { Dictionary <string, object> values = new Dictionary <string, object>(); foreach (KeyValuePair <ODataPathTemplate, IWebApiActionDescriptor> attributeMapping in attributeMappings) { ODataPathTemplate template = attributeMapping.Key; IWebApiActionDescriptor action = attributeMapping.Value; if (action.IsHttpMethodSupported(request.GetRequestMethodOrPreflightMethod()) && template.TryMatch(odataPath, values)) { values["action"] = action.ActionName; SelectControllerResult result = new SelectControllerResult(action.ControllerName, values); return(result); } } return(null); }
/// <summary> /// Selects the controller for OData requests. /// </summary> /// <param name="odataPath">The OData path.</param> /// <param name="request">The request.</param> /// <returns> /// <c>null</c> if the request isn't handled by this convention; otherwise, the name of the selected controller /// </returns> /// <remarks>This signature uses types that are AspNet-specific.</remarks> public virtual string SelectController(ODataPath odataPath, HttpRequestMessage request) { if (odataPath == null) { throw Error.ArgumentNull("odataPath"); } if (request == null) { throw Error.ArgumentNull("request"); } SelectControllerResult controllerResult = SelectControllerImpl(odataPath); if (controllerResult != null) { request.Properties["AttributeRouteData"] = controllerResult.Values; } return(controllerResult != null ? controllerResult.ControllerName : null); }
/// <summary> /// Selects the action for OData requests. /// </summary> /// <param name="routeContext">The route context.</param> /// <param name="controllerResult">The result of selecting a controller.</param> /// <param name="actionDescriptors">The list of action descriptors.</param> /// <returns> /// <c>null</c> if the request isn't handled by this convention; otherwise, the action descriptor of the selected action. /// </returns> /// <remarks>This signature uses types that are AspNetCore-specific.</remarks> public abstract string SelectAction(RouteContext routeContext, SelectControllerResult controllerResult, IEnumerable <ControllerActionDescriptor> actionDescriptors);
/// <inheritdoc/> /// <remarks>This signature uses types that are AspNetCore-specific.</remarks> public override string SelectAction(RouteContext routeContext, SelectControllerResult controllerResult, IEnumerable <ControllerActionDescriptor> actionDescriptors) { return(SelectActionImpl(new WebApiActionMap(actionDescriptors))); }