コード例 #1
0
        public ICollection <RouteSelection> Select(ApplicationModel applicationModel)
        {
            ICollection <RouteSelection> routeSelections = ParentRouteSelector.Select(applicationModel);

            // Filter on controller level only
            if (string.IsNullOrEmpty(Action))
            {
                return(routeSelections
                       .Where(selection => !selection.ControllerModel.MatchesController(Controller, ControllerNamespace)).ToList());
            }

            // Filter actions on controller level
            routeSelections = routeSelections.Select(selection =>
            {
                if (selection.ControllerModel.MatchesController(Controller, ControllerNamespace))
                {
                    selection.ActionModels = selection.ActionModels
                                             .Where(action => !(action.MatchesActionName(Action) && action.MatchesActionArguments(ActionArguments))).ToList();
                }

                return(selection);
            }).ToList();

            if (FilterControllerOrActionWhenNoTranslatedRouteLeft)
            {
                return(routeSelections.Where(selection => selection.ControllerModel.IsOriginalModel(Localizer) &&
                                             (TranslatedRoutesRouteSelector.HasPartiallyTranslatedControllerOnlyAttributeRoute(selection.ControllerModel, selection.ActionModels,
                                                                                                                               Cultures, Localizer) ||
                                              TranslatedRoutesRouteSelector.HasPartiallyTranslatedActionAttributeRoutes(selection.ActionModels, Cultures,
                                                                                                                        Localizer))).Select(selection => new RouteSelection()
                {
                    ControllerModel = selection.ControllerModel,
                    ActionModels = selection.ActionModels
                                   .Where(action => TranslatedRoutesRouteSelector.IsPartiallyTranslatedAction(action, Cultures, Localizer)).ToList(),
                }).ToList());
            }

            if (FilterControllerOrActionWhenNoUntranslatedRouteLeft)
            {
                return(routeSelections.Where(selection => selection.ControllerModel.IsOriginalModel(Localizer) &&
                                             (UntranslatedRoutesRouteSelector.HasNotCompletelyTranslatedControllerAttributeRoute(selection.ControllerModel,
                                                                                                                                 Cultures.Single(), Localizer) ||
                                              UntranslatedRoutesRouteSelector.HasNotCompletelyTranslatedActionAttributeRoute(selection.ActionModels,
                                                                                                                             Cultures.Single(), Localizer))).Select(selection => new RouteSelection()
                {
                    ControllerModel = selection.ControllerModel,
                    ActionModels = selection.ActionModels
                                   .Where(action => UntranslatedRoutesRouteSelector.IsNotCompletelyTranslatedAction(action, Cultures.Single(),
                                                                                                                    Localizer)).ToList(),
                }).ToList());
            }

            return(routeSelections);
        }