コード例 #1
0
    // internal for testing
    internal void AddEntries(TreeRouteBuilder builder, ActionDescriptorCollection actions)
    {
        var routeInfos = GetRouteInfos(actions.Items);

        // We're creating one TreeRouteLinkGenerationEntry per action. This allows us to match the intended
        // action by expected route values, and then use the TemplateBinder to generate the link.
        foreach (var routeInfo in routeInfos)
        {
            if (routeInfo.SuppressLinkGeneration)
            {
                continue;
            }

            var defaults = new RouteValueDictionary();
            foreach (var kvp in routeInfo.ActionDescriptor.RouteValues)
            {
                defaults.Add(kvp.Key, kvp.Value);
            }

            try
            {
                // We use the `NullRouter` as the route handler because we don't need to do anything for link
                // generations. The TreeRouter does it all for us.
                builder.MapOutbound(
                    NullRouter.Instance,
                    routeInfo.RouteTemplate,
                    defaults,
                    routeInfo.RouteName,
                    routeInfo.Order);
            }
            catch (RouteCreationException routeCreationException)
            {
                throw new RouteCreationException(
                          "An error occurred while adding a route to the route builder. " +
                          $"Route name '{routeInfo.RouteName}' and template '{routeInfo.RouteTemplate!.TemplateText}'.",
                          routeCreationException);
            }
        }

        // We're creating one AttributeRouteMatchingEntry per group, so we need to identify the distinct set of
        // groups. It's guaranteed that all members of the group have the same template and precedence,
        // so we only need to hang on to a single instance of the RouteInfo for each group.
        var groups = GetInboundRouteGroups(routeInfos);

        foreach (var group in groups)
        {
            var handler = _handlerFactory(group.ToArray());

            // Note that because we only support 'inline' defaults, each routeInfo group also has the same
            // set of defaults.
            //
            // We then inject the route group as a default for the matcher so it gets passed back to MVC
            // for use in action selection.
            builder.MapInbound(
                handler,
                group.Key.RouteTemplate,
                group.Key.RouteName,
                group.Key.Order);
        }
    }
コード例 #2
0
 protected void CreateOutboundRouteEntry(TreeRouteBuilder treeRouteBuilder, RouteEndpoint endpoint)
 {
     treeRouteBuilder.MapOutbound(
         NullRouter.Instance,
         new RouteTemplate(RoutePatternFactory.Parse(
                               endpoint.RoutePattern.RawText,
                               defaults: endpoint.RoutePattern.Defaults,
                               parameterPolicies: null)),
         requiredLinkValues: new RouteValueDictionary(endpoint.RoutePattern.RequiredValues),
         routeName: null,
         order: 0);
 }
コード例 #3
0
        protected void CreateOutboundRouteEntry(TreeRouteBuilder treeRouteBuilder, RouteEndpoint endpoint)
        {
            var routeValuesAddressMetadata = endpoint.Metadata.GetMetadata <IRouteValuesAddressMetadata>();
            var requiredValues             = routeValuesAddressMetadata?.RequiredValues ?? new RouteValueDictionary();

            treeRouteBuilder.MapOutbound(
                NullRouter.Instance,
                new RouteTemplate(RoutePatternFactory.Parse(
                                      endpoint.RoutePattern.RawText,
                                      defaults: endpoint.RoutePattern.Defaults,
                                      parameterPolicies: null)),
                requiredLinkValues: new RouteValueDictionary(requiredValues),
                routeName: null,
                order: 0);
        }
コード例 #4
0
ファイル: AttributeRoute.cs プロジェクト: lodejard/AllNetCore
        // internal for testing
        internal void AddEntries(TreeRouteBuilder builder, ActionDescriptorCollection actions)
        {
            var routeInfos = GetRouteInfos(actions.Items);

            // We're creating one TreeRouteLinkGenerationEntry per action. This allows us to match the intended
            // action by expected route values, and then use the TemplateBinder to generate the link.
            foreach (var routeInfo in routeInfos)
            {
                builder.MapOutbound(
                    _handler,
                    routeInfo.RouteTemplate,
                    new RouteValueDictionary(routeInfo.ActionDescriptor.RouteValueDefaults),
                    routeInfo.RouteName,
                    routeInfo.Order);
            }

            // We're creating one AttributeRouteMatchingEntry per group, so we need to identify the distinct set of
            // groups. It's guaranteed that all members of the group have the same template and precedence,
            // so we only need to hang on to a single instance of the RouteInfo for each group.
            var distinctRouteInfosByGroup = GroupRouteInfosByGroupId(routeInfos);

            foreach (var routeInfo in distinctRouteInfosByGroup)
            {
                // Note that because we only support 'inline' defaults, each routeInfo group also has the same
                // set of defaults.
                //
                // We then inject the route group as a default for the matcher so it gets passed back to MVC
                // for use in action selection.
                var entry = builder.MapInbound(
                    _handler,
                    routeInfo.RouteTemplate,
                    routeInfo.RouteName,
                    routeInfo.Order);

                entry.Defaults[TreeRouter.RouteGroupKey] = routeInfo.RouteGroup;
            }
        }