/// <inheritdoc /> public string SelectController(ODataPath odataPath, HttpRequestMessage request) { Dictionary <string, object> values = new Dictionary <string, object>(); foreach (KeyValuePair <ODataPathTemplate, HttpActionDescriptor> attributeMapping in AttributeMappings) { ODataPathTemplate template = attributeMapping.Key; HttpActionDescriptor action = attributeMapping.Value; if (action.SupportedHttpMethods.Contains(request.Method) && template.TryMatch(odataPath, values)) { values["action"] = action.ActionName; request.Properties["AttributeRouteData"] = values; return(action.ControllerDescriptor.ControllerName); } } 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.Method) && template.TryMatch(odataPath, values)) { values["action"] = action.ActionName; SelectControllerResult result = new SelectControllerResult(action.ControllerName, values); return(result); } } return(null); }
/// <inheritdoc/> public virtual ActionDescriptor SelectAction(RouteContext routeContext) { if (routeContext == null) { throw Error.ArgumentNull("routeContext"); } if (_attributeMappings == null) { if (ActionDescriptorCollectionProvider == null) { ActionDescriptorCollectionProvider = routeContext.HttpContext.RequestServices.GetRequiredService <IActionDescriptorCollectionProvider> (); } if (ODataPathTemplateHandler == null) { ODataPathTemplateHandler = routeContext.HttpContext.RequestServices.GetRequiredService <IODataPathTemplateHandler>(); } IEdmModel model = routeContext.HttpContext.ODataFeature().Model; IEnumerable <ControllerActionDescriptor> actionDescriptors = ActionDescriptorCollectionProvider.ActionDescriptors.Items.OfType <ControllerActionDescriptor>(); _attributeMappings = BuildAttributeMappings(routeContext, actionDescriptors, model); } HttpRequest request = routeContext.HttpContext.Request; ODataPath odataPath = routeContext.HttpContext.ODataFeature().Path; Dictionary <string, object> values = new Dictionary <string, object>(); var routeData = routeContext.RouteData; var routingConventionsStore = request.ODataFeature().RoutingConventionsStore; foreach (KeyValuePair <ODataPathTemplate, ControllerActionDescriptor> attributeMapping in _attributeMappings) { ODataPathTemplate template = attributeMapping.Key; ControllerActionDescriptor actionDescriptor = attributeMapping.Value; if (IsHttpMethodMatch(actionDescriptor, request.Method) && template.TryMatch(odataPath, values)) { foreach (var item in values) { if (item.Key.StartsWith(ODataParameterValue.ParameterValuePrefix, StringComparison.Ordinal) && item.Value is ODataParameterValue) { routingConventionsStore.Add(item); } else { routeData.Values.Add(item.Key, item.Value); } } return(actionDescriptor); } } 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); } // 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); }