Пример #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="website"></param>
        /// <param name="urlPath"></param>
        /// <param name="getRootWebPage">Whether to get the Root version of a group of translated web pages where adx_isroot = true.
        /// This should only be set to true in specific cases where we are explicitly looking for the non-translated root page,
        /// ex: we're looking for a web file which only hangs off from root web pages, or the provided urlPath is from a SiteMapNode which is not language-aware so the url will be the root's.
        /// This does NOT refer to the website root "/" (aka Home) web page.</param>
        /// <returns></returns>
        public static UrlMappingResult <WebPageNode> LookupPageByUrlPath(WebsiteNode website, string urlPath, WebPageLookupOptions lookupOption, ContextLanguageInfo languageContext)
        {
            var applicationPath = UrlMapping.GetApplicationPath(urlPath);

            CrmEntityInactiveInfo inactiveInfo;

            var filter = CrmEntityInactiveInfo.TryGetInfo("adx_webpage", out inactiveInfo)
                                ? page => !inactiveInfo.IsInactive(page.ToEntity())
                                : new Func <WebPageNode, bool>(entity => true);

            var result = LookupPageByUrlPath(website, applicationPath.PartialPath, lookupOption, languageContext, filter);

            return(result);
        }
        public override SiteMapNode GetParentNode(SiteMapNode node)
        {
            TraceInfo("GetParentNode({0})", node.Key);

            var portal  = PortalContext;
            var context = portal.ServiceContext;
            var website = portal.Website;

            var pageMappingResult = UrlMapping.LookupPageByUrlPath(context, website, node.Url);

            if (pageMappingResult.Node == null)
            {
                return(null);
            }

            var parentPage = pageMappingResult.Node.GetRelatedEntity(context, "adx_webpage_webpage", EntityRole.Referencing);

            if (parentPage == null)
            {
                return(null);
            }

            return(GetAccessibleNodeOrAccessDeniedNode(context, parentPage));
        }
Пример #3
0
        private static IMatch FindPage(OrganizationServiceContext context, Entity website, string path)
        {
            var mappedPageResult = UrlMapping.LookupPageByUrlPath(context, website, path);

            if (mappedPageResult.Node != null)
            {
                return(new NonHistoryMatch(mappedPageResult.Node));
            }

            var historyMatchPage = FindHistoryMatchPage(context, website, path);

            if (historyMatchPage != null)
            {
                return(new HistoryMatch(historyMatchPage));
            }

            // find the last slash in the path
            var lastSlash = path.LastIndexOf('/');

            if (lastSlash != -1)
            {
                // we found a slash
                var pathBeforeSlash = path.Substring(0, lastSlash);
                var pathAfterSlash  = path.Substring(lastSlash + 1);

                var parentMatch = (string.IsNullOrWhiteSpace(pathBeforeSlash) || _homePaths.Contains(pathBeforeSlash))
                                  // do a final traversal against the home page
                                        ? GetHomePage(context, website)
                                  // see if we can find a path for the parent url
                                        : FindPage(context, website, pathBeforeSlash);

                if (parentMatch.Success)
                {
                    var foundParentPageID = parentMatch.WebPage.ToEntityReference();

                    var fetch = new Fetch
                    {
                        Entity = new FetchEntity("adx_webpage")
                        {
                            Filters = new List <Filter>
                            {
                                new Filter
                                {
                                    Conditions = new[]
                                    {
                                        new Condition("statecode", ConditionOperator.Equal, 0),
                                        new Condition("adx_parentpageid", ConditionOperator.Equal, foundParentPageID.Id),
                                        new Condition("adx_partialurl", ConditionOperator.Equal, pathAfterSlash)
                                    }
                                }
                            }
                        }
                    };

                    // we found a parent path, now rebuild the path of the child
                    var child = context.RetrieveSingle(fetch);

                    if (child != null)
                    {
                        return(new SuccessfulMatch(child, parentMatch.UsedHistory));
                    }

                    var parentPath = context.GetApplicationPath(parentMatch.WebPage);

                    if (parentPath == null)
                    {
                        return(new FailedMatch());
                    }

                    if (parentPath.AppRelativePath.TrimEnd('/') == path)
                    {
                        // prevent stack overflow
                        return(new FailedMatch());
                    }

                    var newPath = parentPath.AppRelativePath + (parentPath.AppRelativePath.EndsWith("/") ? string.Empty : "/") + pathAfterSlash;

                    if (newPath == path)
                    {
                        return(new FailedMatch());
                    }

                    var childMatch = FindPage(context, website, newPath);

                    if (childMatch.Success)
                    {
                        return(new HistoryMatch(childMatch.WebPage));
                    }
                }
            }

            return(new FailedMatch());
        }
        public override SiteMapNode FindSiteMapNode(string rawUrl)
        {
            var clientUrl = ExtractClientUrlFromRawUrl(rawUrl);

            TraceInfo("FindSiteMapNode({0})", clientUrl.PathWithQueryString);

            var portal  = PortalContext;
            var context = portal.ServiceContext;
            var website = portal.Website;

            // Find any possible SiteMarkerRoutes (or other IPortalContextRoutes) that match this path.
            var contextPath = RouteTable.Routes.GetPortalContextPath(portal, clientUrl.Path) ?? clientUrl.Path;

            // If the URL matches a web page, try to look up that page and return a node.
            var pageMappingResult = UrlMapping.LookupPageByUrlPath(context, website, contextPath);

            if (pageMappingResult.Node != null && pageMappingResult.IsUnique)
            {
                return(GetAccessibleNodeOrAccessDeniedNode(context, pageMappingResult.Node));
            }
            else if (!pageMappingResult.IsUnique)
            {
                return(GetNotFoundNode());
            }

            // If the URL matches a web file, try to look up that file and return a node.
            var file = UrlMapping.LookupFileByUrlPath(context, website, clientUrl.Path);

            if (file != null)
            {
                return(GetAccessibleNodeOrAccessDeniedNode(context, file));
            }

            // If there is a pageid Guid on the querystring, try to look up a web page by
            // that ID and return a node.
            Guid pageid;

            if (TryParseGuid(clientUrl.QueryString["pageid"], out pageid))
            {
                var foundPage = context.CreateQuery("adx_webpage")
                                .FirstOrDefault(wp => wp.GetAttributeValue <Guid>("adx_webpageid") == pageid &&
                                                wp.GetAttributeValue <EntityReference>("adx_websiteid") == website.ToEntityReference());

                if (foundPage != null)
                {
                    return(GetAccessibleNodeOrAccessDeniedNode(context, foundPage));
                }
            }

            // If the above lookups failed, try find a node in any other site map providers.
            foreach (SiteMapProvider subProvider in SiteMap.Providers)
            {
                // Skip this provider if it is the same as this one.
                if (subProvider.Name == Name)
                {
                    continue;
                }

                var node = subProvider.FindSiteMapNode(clientUrl.PathWithQueryString);

                if (node != null)
                {
                    return(node);
                }
            }

            return(GetNotFoundNode());
        }
        public override SiteMapNodeCollection GetChildNodes(SiteMapNode node)
        {
            TraceInfo("GetChildNodes({0})", node.Key);

            var children = new List <SiteMapNode>();

            var portal  = PortalContext;
            var context = portal.ServiceContext;
            var website = portal.Website;

            // Shorcuts do not have children, may have the same Url as a web page.
            if (IsShortcutNode(node))
            {
                return(new SiteMapNodeCollection());
            }

            var pageMappingResult = UrlMapping.LookupPageByUrlPath(context, website, node.Url);

            // If the node URL is that of a web page...
            if (pageMappingResult.Node != null && pageMappingResult.IsUnique)
            {
                var childEntities = context.GetChildPages(pageMappingResult.Node).Union(context.GetChildFiles(pageMappingResult.Node)).Union(context.GetChildShortcuts(pageMappingResult.Node));

                foreach (var entity in childEntities)
                {
                    try
                    {
                        if (entity.LogicalName == "adx_shortcut")
                        {
                            var targetNode        = GetShortcutTargetNode(context, entity);
                            var shortcutChildNode = GetShortcutCrmNode(context, entity, targetNode);

                            if (shortcutChildNode != null && ChildNodeValidator.Validate(context, shortcutChildNode))
                            {
                                children.Add(shortcutChildNode);
                            }
                        }
                        else
                        {
                            var childNode = GetNode(context, entity);

                            if (childNode != null && ChildNodeValidator.Validate(context, childNode))
                            {
                                children.Add(childNode);
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        ADXTrace.Instance.TraceError(TraceCategory.Application, string.Format(@"Exception creating child node for node child entity [{0}:{1}]: {2}", EntityNamePrivacy.GetEntityName(entity.LogicalName), entity.Id, e.ToString()));

                        continue;
                    }
                }
            }

            // Append values from other site map providers.
            foreach (SiteMapProvider subProvider in SiteMap.Providers)
            {
                // Skip this provider if it is the same as this one.
                if (subProvider.Name == Name)
                {
                    continue;
                }

                var subProviderChildNodes = subProvider.GetChildNodes(node);

                if (subProviderChildNodes == null)
                {
                    continue;
                }

                foreach (SiteMapNode childNode in subProviderChildNodes)
                {
                    children.Add(childNode);
                }
            }

            children.Sort(new SiteMapNodeDisplayOrderComparer());

            return(new SiteMapNodeCollection(children.ToArray()));
        }