示例#1
0
        private static UrlMappingResult <Entity> GetResultFromQuery(IEnumerable <Entity> query)
        {
            // select only root pages or pages where isroot = null
            var duplicateCheckArray = query.Where(p => p.GetAttributeValue <bool?>("adx_isroot") != false).ToArray();
            var result = query.FirstOrDefault();

            return(duplicateCheckArray.Length > 1
                                ? UrlMappingResult <Entity> .DuplicateResult(result)
                                : UrlMappingResult <Entity> .MatchResult(result));
        }
示例#2
0
        private static UrlMappingResult <WebPageNode> FilterResultsOnLanguage(IEnumerable <WebPageNode> pages, Func <WebPageNode, bool> predicate, WebPageLookupOptions lookupOption, ContextLanguageInfo contextLanguageInfo)
        {
            var         results = pages.Where(predicate);
            WebPageNode retval  = null;

            if (contextLanguageInfo != null && contextLanguageInfo.IsCrmMultiLanguageEnabled)
            {
                if (lookupOption == WebPageLookupOptions.LanguageContentOnly)
                {
                    // when we have only a root webpage and 0 localized webpages.
                    // for example: creating new child page via portal CMS.
                    if (results.Where(p => p.IsRoot == false).Count() == 0)
                    {
                        retval = results.FirstOrDefault();
                    }
                    else
                    {
                        var websiteLanguageId = contextLanguageInfo.ContextLanguage.EntityReference.Id;
                        retval = results.FirstOrDefault(p => p.WebPageLanguage != null && p.WebPageLanguage.Id == websiteLanguageId && p.IsRoot == false);
                    }
                }
                else if (lookupOption == WebPageLookupOptions.RootOnly)
                {
                    retval = results.FirstOrDefault(p => p.IsRoot == true);
                }
                else
                {
                    retval = results.FirstOrDefault();
                }

                // If the found page is content, but the root page is deactivated, then return null as if the page itself doesn't exist.
                if (retval != null && retval.IsRoot == false && (retval.RootWebPage == null || retval.RootWebPage.IsReference))
                {
                    retval = null;
                }
            }
            else
            {
                // If multi-language is not supported, then do legacy behavior of returning first result.
                retval = results.FirstOrDefault();
            }

            // select only root pages or pages where isroot = null (MLP is not supported)
            var duplicateCheckArray = results.Where(p => p.IsRoot != false).ToArray();

            return(duplicateCheckArray.Length > 1
                                ? UrlMappingResult <WebPageNode> .DuplicateResult(retval)
                                : UrlMappingResult <WebPageNode> .MatchResult(retval));
        }
示例#3
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.
        /// This does NOT refer to the root "/" web page (typically Home page).</param>
        /// <param name="predicate"></param>
        /// <returns></returns>
        private static UrlMappingResult <WebPageNode> LookupPageByUrlPath(WebsiteNode website, string urlPath, WebPageLookupOptions lookupOption, ContextLanguageInfo languageContext, Func <WebPageNode, bool> predicate)
        {
            if (website.Id == Guid.Empty)
            {
                throw new ArgumentException(string.Format("Unable to retrieve the Id of the website. {0}", string.Empty), "website");
            }

            ADXTrace.Instance.TraceInfo(TraceCategory.Monitoring, "LookupPageByUrlPath ENTER URL");

            var pages = website.WebPages.Where(predicate).ToArray();

            // Use _pagePathRegex to extract the right-most path segment (child path), and the remaining left
            // part of the path (parent path), while enforcing that web page paths must end in a '/'.
            var pathMatch = UrlMapping._pagePathRegex.Match(urlPath);

            if (!pathMatch.Success)
            {
                // If we don't have a valid path match, still see if there is a page with the entire literal
                // path as its partial URL. (The previous iteration of this method has this behaviour, so we
                // maintain it here.)
                // NOTE: requests for web files (ex: .png, .css) and bad links all come here.
                var mappingResult = FilterResultsOnLanguage(pages, p => IsPartialUrlMatch(p, urlPath), lookupOption, languageContext);
                ADXTrace.Instance.TraceInfo(TraceCategory.Monitoring, string.Format("LookupPageByUrlPath (1)pathMatch.Fail URL {0}", mappingResult.Node == null ? "NULL" : "Found"));
                return(mappingResult);
            }

            var fullPath   = pathMatch.Groups["full"].Value;
            var parentPath = pathMatch.Groups["parent"].Value;
            var childPath  = pathMatch.Groups["child"].Value;

            // Check if we can find a page with the exact fullPath match. This may be a web page with a
            // partial URL that matches the entire path, but in the more common case, it will match the
            // root URL path "/".
            var fullPathMatchPageResult = FilterResultsOnLanguage(pages, p => IsPartialUrlMatch(p, fullPath), lookupOption, languageContext);

            if (fullPathMatchPageResult.Node != null)
            {
                ADXTrace.Instance.TraceInfo(TraceCategory.Monitoring, "LookupPageByUrlPath (2)fullPathMatchPage ");
                return(fullPathMatchPageResult);
            }

            // If we don't have non-empty parentPath and childPath, lookup fails.
            if (string.IsNullOrEmpty(parentPath) || string.IsNullOrEmpty(childPath))
            {
                ADXTrace.Instance.TraceInfo(TraceCategory.Monitoring, "LookupPageByUrlPath (3)parent/child path null ");
                return(UrlMappingResult <WebPageNode> .MatchResult(null));
            }

            // Look up the parent page, using the parent path. This will generally recurse until parentPath
            // is the root path "/", at which point fullPath will match the Home page and the recursion will
            // unwind.
            // Look for the "Root" (adx_isroot=true) web page because the parent-child relationships uses the Root web pages, not the translated Content web pages.
            // (Ignoring uniquence for parent page)
            var parentPageFilterResult = LookupPageByUrlPath(website, parentPath, WebPageLookupOptions.RootOnly, languageContext, predicate);

            // If we can't find a parent page, lookup fails.
            // Ignore IsUnique here, trying to find any possible match.
            if (parentPageFilterResult.Node == null)
            {
                ADXTrace.Instance.TraceInfo(TraceCategory.Monitoring, "LookupPageByUrlPath (4)parent page null ");
                return(parentPageFilterResult);
            }

            // Look for a partial URL match for childPath, among the children of the returned parent page.
            var result = FilterResultsOnLanguage(parentPageFilterResult.Node.WebPages, p => predicate(p) && IsPartialUrlMatch(p, childPath), lookupOption, languageContext);

            ADXTrace.Instance.TraceInfo(TraceCategory.Monitoring, string.Format("LookupPageByUrlPath (5)searchByParent {0}", result.Node == null ? "NULL" : "Found"));
            return(result);
        }
示例#4
0
        private static UrlMappingResult <Entity> LookupPageByUrlPath(OrganizationServiceContext context, Entity website, string urlPath, Func <Entity, bool> predicate)
        {
            website.AssertEntityName("adx_website");

            if (website.Id == Guid.Empty)
            {
                throw new ArgumentException(string.Format("Unable to retrieve the Id of the website. {0}", ""), "website");
            }

            var urlWithoutWebsitePath = WebsitePathUtility.ToRelative(website, urlPath);

            if (!context.IsAttached(website))
            {
                context.ReAttach(website);
            }

            var pages = website.GetRelatedEntities(context, "adx_website_webpage").Where(predicate).ToArray();

            // Use _pagePathRegex to extract the right-most path segment (child path), and the remaining left
            // part of the path (parent path), while enforcing that web page paths must end in a '/'.
            var pathMatch = _pagePathRegex.Match(urlWithoutWebsitePath);

            if (!pathMatch.Success)
            {
                // If we don't have a valid path match, still see if there is a page with the entire literal
                // path as its partial URL. (The previous iteration of this method has this behaviour, so we
                // maintain it here.)
                return(GetResultFromQuery(pages.Where(p => IsPartialUrlMatch(p, urlWithoutWebsitePath))));
            }

            var fullPath   = pathMatch.Groups["full"].Value;
            var parentPath = pathMatch.Groups["parent"].Value;
            var childPath  = pathMatch.Groups["child"].Value;

            // Check if we can find a page with the exact fullPath match. This may be a web page with a
            // partial URL that matches the entire path, but in the more common case, it will match the
            // root URL path "/".
            var fullPathMatchPageResult = GetResultFromQuery(pages.Where(p => IsPartialUrlMatch(p, fullPath)));

            if (fullPathMatchPageResult.Node != null)
            {
                return(fullPathMatchPageResult);
            }

            // If we don't have non-empty parentPath and childPath, lookup fails.
            if (string.IsNullOrEmpty(parentPath) || string.IsNullOrEmpty(childPath))
            {
                return(UrlMappingResult <Entity> .MatchResult(null));
            }

            // Look up the parent page, using the parent path. This will generally recurse until parentPath
            // is the root path "/", at which point fullPath will match the Home page and the recursion will
            // unwind.
            var parentPageFilterResult = LookupPageByUrlPath(context, website, parentPath, predicate);

            // If we can't find a parent page, lookup fails.
            if (parentPageFilterResult.Node == null)
            {
                return(parentPageFilterResult);
            }

            // Look for a partial URL match for childPath, among the children of the returned parent page.
            var query = context.GetChildPages(parentPageFilterResult.Node).Where(p => predicate(p) && IsPartialUrlMatch(p, childPath));

            return(GetResultFromQuery(query));
        }