Пример #1
0
        public void Publish(IEnumerable <RouteDescriptor> routes, RequestDelegate pipeline)
        {
            // Register one top level TenantRoute per tenant. Each instance contains all the routes
            // for this tenant.

            // In the case of several tenants, they will all be checked by ShellSettings. To optimize
            // the TenantRoute resolution we can create a single Router type that would index the
            // TenantRoute object by their ShellSetting. This way there would just be one lookup.
            // And the ShellSettings test in TenantRoute would also be useless.

            var orderedRoutes = routes
                                .OrderByDescending(r => r.Priority)
                                .ToList();

            string routePrefix = "";

            if (!string.IsNullOrWhiteSpace(_shellSettings.RequestUrlPrefix))
            {
                routePrefix = _shellSettings.RequestUrlPrefix + "/";
            }

            // The default route is added to each tenant as a template route, with a prefix
            orderedRoutes.Add(new RouteDescriptor
            {
                Route = new Orchard.Routes.Route("Default", "{area:exists}/{controller}/{action}/{id?}")
            });

            var inlineConstraint = _routeBuilder.ServiceProvider.GetService <IInlineConstraintResolver>();

            var templateRoutes = new List <IRouter>();

            foreach (var route in orderedRoutes)
            {
                IRouter router = new Microsoft.AspNetCore.Routing.Route(
                    _routeBuilder.DefaultHandler,
                    route.Route.RouteName,
                    routePrefix + route.Route.RouteTemplate,
                    route.Route.Defaults,
                    route.Route.Constraints,
                    route.Route.DataTokens,
                    inlineConstraint);

                templateRoutes.Add(router);
            }

            _routeBuilder.Routes.Add(new TenantRoute(_shellSettings, templateRoutes, pipeline));
        }
Пример #2
0
        public void Publish(IEnumerable<RouteDescriptor> routes, RequestDelegate pipeline)
        {
            // Register one top level TenantRoute per tenant. Each instance contains all the routes
            // for this tenant.

            // In the case of several tenants, they will all be checked by ShellSettings. To optimize
            // the TenantRoute resolution we can create a single Router type that would index the
            // TenantRoute object by their ShellSetting. This way there would just be one lookup.
            // And the ShellSettings test in TenantRoute would also be useless.

            var orderedRoutes = routes
                .OrderByDescending(r => r.Priority)
                .ToList();

            string routePrefix = "";
            if (!string.IsNullOrWhiteSpace(_shellSettings.RequestUrlPrefix))
            {
                routePrefix = _shellSettings.RequestUrlPrefix + "/";
            }

            // The default route is added to each tenant as a template route, with a prefix
            orderedRoutes.Add(new RouteDescriptor
            {
                Route = new Route("Default", "{area:exists}/{controller}/{action}/{id?}")
            });

            var inlineConstraint = _routeBuilder.ServiceProvider.GetService<IInlineConstraintResolver>();

            var templateRoutes = new List<IRouter>();

            foreach (var route in orderedRoutes)
            {
                IRouter router = new Microsoft.AspNetCore.Routing.Route(
                    _routeBuilder.DefaultHandler,
                    route.Route.RouteName,
                    routePrefix + route.Route.RouteTemplate,
                    route.Route.Defaults,
                    route.Route.Constraints,
                    route.Route.DataTokens,
                    inlineConstraint);

                templateRoutes.Add(router);
            }

            _routeBuilder.Routes.Add(new TenantRoute(_shellSettings, templateRoutes, pipeline));
        }