Exemplo n.º 1
0
        private bool FindClientSideRouteHostForVirtualPath(Uri virtualPath, out SiteRoute route)
        {
            if (_routesByPath.Contains(virtualPath))
            {
                route = _routesByPath[virtualPath].Where(x => x.HostsClientSideRoutes).OrderBy(x => x.Priority).FirstOrDefault();
                if (route != null)
                {
                    return(true);
                }
            }


            var pathAsText = virtualPath.ToString();

            if (pathAsText.LastIndexOf("/") > 0)
            {
                var lastSlash = pathAsText.LastIndexOf("/");
                var newUrl    = pathAsText.Substring(0, lastSlash);
                var found     = FindClientSideRouteHostForVirtualPath(new Uri(newUrl, UriKind.Relative), out route);
                if (found)
                {
                    return(true);
                }
            }

            route = null;
            return(false);
        }
Exemplo n.º 2
0
        public bool TryGetRoute(Uri virtualPath, out SiteRoute route)
        {
            if (_routesByPath.Contains(virtualPath))
            {
                route = _routesByPath[virtualPath].OrderBy(x => x.Priority).First();
                return(true);
            }

            return(FindClientSideRouteHostForVirtualPath(virtualPath, out route));
        }
Exemplo n.º 3
0
        public bool TryGetRoute(Guid pageId, out SiteRoute route)
        {
            route = null;

            if (!_routesByPageId.Contains(pageId))
            {
                return(false);
            }


            route = _routesByPageId[pageId].OrderBy(x => x.Priority).First();
            return(true);
        }
Exemplo n.º 4
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);
        }