示例#1
0
        public static IEnumerable <SiteRoute> DiscoverRoutesForSite(Site site)
        {
            var allRoutes = new List <SiteRoute>();


            var pageRepository          = new CmsPageRepository();
            var historicalPageLocations = pageRepository.GetHistoricalPageLocations(site);

            foreach (var location in historicalPageLocations)
            {
                allRoutes.Add(new RedirectPageRoute
                {
                    InternalRedirectPageId = location.PageId,
                    Authority   = site.UriAuthority,
                    Priority    = location.Priority,
                    SiteId      = location.SiteId,
                    VirtualPath = new Uri(location.VirtualPath, UriKind.Relative)
                });
            }

            var associatedSitemap = SitemapBuilder.BuildSitemap(site, ContentEnvironment.Live, SitemapBuilderFilters.All);



            if (associatedSitemap.HomePage != null)
            {
                var homePageRoute = new ContentPageRoute
                {
                    Authority   = site.UriAuthority,
                    Priority    = 0,
                    SiteId      = site.ContentId,
                    PageId      = site.HomepageId,
                    VirtualPath = MakeRelativeUri(site, string.Empty),
                    RequireSsl  = associatedSitemap.HomePage.RequireSsl
                };

                var homepageContentRoutes = DiscoverContentRoutes(associatedSitemap.HomePage, new[] { homePageRoute });
                allRoutes.Add(homePageRoute);
                allRoutes.AddRange(homepageContentRoutes);
            }

            foreach (var childNode in associatedSitemap.ChildNodes)
            {
                allRoutes.AddRange(DiscoverPageRoutesRecursive(childNode, site));
            }



            return(allRoutes);
        }
示例#2
0
        private static IEnumerable <SiteRoute> DiscoverContentRoutes(CmsPage page, IEnumerable <ContentPageRoute> pageRoutes)
        {
            var contentRoutes = new List <SiteRoute>();


            foreach (var content in page.PageContent)
            {
                var toolboxManager = new ToolboxManager();
                var toolboxItem    = toolboxManager.GetToolboxItemByCode(content.WidgetTypeCode);


                var toolboxItemType = default(Type);//todo: add content routing.
                continue;
                var contentRouteAttributes = toolboxItemType.GetCustomAttributes(typeof(ContentRouteAttribute)).Cast <ContentRouteAttribute>().ToList();

                foreach (var contentRouteAttribute in contentRouteAttributes)
                {
                    var pageRoutesToCopy = pageRoutes.ToList();
                    foreach (var pageRoute in pageRoutesToCopy)
                    {
                        var contentRoute = new ContentPageRoute
                        {
                            Authority       = pageRoute.Authority,
                            ContentTypeCode = contentRouteAttribute.ContentTypeCode,
                            PageId          = pageRoute.PageId,
                            Priority        = pageRoute.Priority,
                            SiteId          = pageRoute.SiteId,
                            VirtualPath     = new Uri(pageRoute.VirtualPath + "/" + contentRouteAttribute.RouteTemplate),
                            RequireSsl      = pageRoute.RequireSsl
                        };
                        contentRoutes.Add(contentRoute);
                    }
                }
            }
            return(contentRoutes);
        }
示例#3
0
        private static IEnumerable <SiteRoute> DiscoverPageRoutesRecursive(SitemapNode node, Site site)
        {
            if (node.Page.PageType == null)
            {
                throw new Exception("Undefined page type.");
            }

            var pageRoutes = new List <SiteRoute>();

            SiteRoute primaryRoute = null;

            if (PageType.RedirectPage == node.Page.PageType)
            {
                var redirectUri = node.Page.RedirectUri;
                if (redirectUri.IsWarpCoreDataScheme())
                {
                    primaryRoute = new RedirectPageRoute
                    {
                        InternalRedirectPageId     = new WarpCorePageUri(node.Page.RedirectUri.OriginalString).ContentId,
                        InternalRedirectParameters = node.Page.InternalRedirectParameters
                    }
                }
                ;
                else
                {
                    primaryRoute = new RedirectPageRoute
                    {
                        RedirectExternalUrl = node.Page.RedirectUri.ToString()
                    }
                };
            }

            if (PageType.GroupingPage == node.Page.PageType)
            {
                var first = node.ChildNodes.FirstOrDefault();
                primaryRoute = new GroupingPageRoute
                {
                    InternalRedirectPageId = first?.Page?.ContentId
                };
            }

            if (PageType.ContentPage == node.Page.PageType)
            {
                primaryRoute = new ContentPageRoute
                {
                    RequireSsl = node.Page.RequireSsl
                };

                //foreach (var route in node.Page.AlternateRoutes)
                //{
                //    var alternatePageRoute = new ContentPageRoute
                //    {
                //        Authority = site.UriAuthority,
                //        Priority = route.Priority,
                //        SiteId = site.ContentId.Value,
                //        PageId = node.Page.ContentId.Value,
                //        VirtualPath = MakeRelativeUri(site, route.VirtualPath),
                //        RequireSsl = node.Page.RequireSsl
                //    };
                //    pageRoutes.Add(alternatePageRoute);
                //}

                foreach (var content in node.Page.PageContent)
                {
                    var toolboxManager = new ToolboxManager();
                    var toolboxItem    = toolboxManager.GetToolboxItemByCode(content.WidgetTypeCode);

                    //todo: fix this, we need a separate toolbox item activator outside of the page composer.
                    //      add cache too.
                    var typeName = toolboxItem?.AssemblyQualifiedTypeName;
                    if (typeName != null)
                    {
                        var type         = Type.GetType(typeName);
                        var hasInterface = type.GetInterface(nameof(IHostsClientSideRoutes)) != null;
                        primaryRoute.HostsClientSideRoutes = hasInterface;
                    }
                }
            }

            if (primaryRoute == null)
            {
                throw new Exception("Unsupported page type: " + node.Page.PageType);
            }

            primaryRoute.Authority   = site.UriAuthority;
            primaryRoute.Priority    = (int)RoutePriority.Primary;
            primaryRoute.SiteId      = site.ContentId;
            primaryRoute.PageId      = node.Page.ContentId;
            primaryRoute.VirtualPath = MakeRelativeUri(site, node.VirtualPath.ToString());



            pageRoutes.Add(primaryRoute);

            var localRoutes = new List <SiteRoute>();

            if (PageType.ContentPage == node.Page.PageType)
            {
                var contentRoutes = DiscoverContentRoutes(node.Page, pageRoutes.Cast <ContentPageRoute>());
                localRoutes.AddRange(contentRoutes);
            }
            localRoutes.AddRange(pageRoutes);

            var allChildRoutes = new List <SiteRoute>();

            foreach (var child in node.ChildNodes)
            {
                var childRoutes = DiscoverPageRoutesRecursive(child, site).ToList();
                allChildRoutes.AddRange(childRoutes);
            }

            var allRoutes = new List <SiteRoute>();

            allRoutes.AddRange(localRoutes);
            allRoutes.AddRange(allChildRoutes);

            return(allRoutes);
        }