/// <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);
        }
Пример #2
0
        /// <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);
        }