Exemple #1
0
            void InitializeStandardActions()
            {
                if (standardActions != null)
                {
                    return;
                }

                var selectionCache = new StandardActionSelectionCache();

                if (controllerDescriptor.IsAttributeRouted())
                {
                    selectionCache.StandardCandidateActions = new CandidateAction[0];
                }
                else
                {
                    var standardCandidateActions = new List <CandidateAction>();

                    for (var i = 0; i < combinedCandidateActions.Length; i++)
                    {
                        var candidate = combinedCandidateActions[i];
                        var action    = (ReflectedHttpActionDescriptor)candidate.ActionDescriptor;

                        if (action.MethodInfo.DeclaringType != controllerDescriptor.ControllerType || !candidate.ActionDescriptor.IsAttributeRouted())
                        {
                            standardCandidateActions.Add(candidate);
                        }
                    }

                    selectionCache.StandardCandidateActions = standardCandidateActions.ToArray();
                }

                selectionCache.StandardActionNameMapping = selectionCache.StandardCandidateActions.Select(c => c.ActionDescriptor).ToLookup(actionDesc => actionDesc.ActionName, OrdinalIgnoreCase);

                var len = cacheListVerbKinds.Length;

                selectionCache.CacheListVerbs = new CandidateAction[len][];

                for (var i = 0; i < len; i++)
                {
                    selectionCache.CacheListVerbs[i] = FindActionsForVerbWorker(cacheListVerbKinds[i], selectionCache.StandardCandidateActions);
                }

                standardActions = selectionCache;
            }
 private void ExploreRouteActions(IHttpRoute route, string localPath, HttpControllerDescriptor controllerDescriptor, Collection <ApiDescription> apiDescriptions)
 {
     // exclude controllers that are marked with route attributes.
     if (!controllerDescriptor.IsAttributeRouted())
     {
         ServicesContainer controllerServices = controllerDescriptor.Configuration.Services;
         ILookup <string, HttpActionDescriptor> actionMappings = controllerServices.GetActionSelector().GetActionMapping(controllerDescriptor);
         string actionVariableValue;
         if (actionMappings != null)
         {
             if (_actionVariableRegex.IsMatch(localPath))
             {
                 // unbound action variable, {action}
                 foreach (IGrouping <string, HttpActionDescriptor> actionMapping in actionMappings)
                 {
                     // expand {action} variable
                     actionVariableValue = actionMapping.Key;
                     string expandedLocalPath = _actionVariableRegex.Replace(localPath, actionVariableValue);
                     PopulateActionDescriptions(actionMapping, actionVariableValue, route, expandedLocalPath, apiDescriptions);
                 }
             }
             else if (route.Defaults.TryGetValue(RouteValueKeys.Action, out actionVariableValue))
             {
                 // bound action variable, { action = "actionName" }
                 PopulateActionDescriptions(actionMappings[actionVariableValue], actionVariableValue, route, localPath, apiDescriptions);
             }
             else
             {
                 // no {action} specified, e.g. {controller}/{id}
                 foreach (IGrouping <string, HttpActionDescriptor> actionMapping in actionMappings)
                 {
                     PopulateActionDescriptions(actionMapping, null, route, localPath, apiDescriptions);
                 }
             }
         }
     }
 }