Esempio n. 1
0
        private static Entity LookupFileByUrlPath(OrganizationServiceContext context, Entity website, string urlPath, Func <Entity, bool> predicate)
        {
            website.AssertEntityName("adx_website");

            if (website.Id == Guid.Empty)
            {
                throw new NullReferenceException("Unable to retrieve the Id of the website.  Lookup failed.");
            }

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

            string parentPath;
            string thisPath;

            if (ParseParentPath(urlWithoutWebsitePath, out parentPath, out thisPath))
            {
                var parentPage = LookupPageByUrlPath(context, website, parentPath);

                if (parentPage != null)
                {
                    var file = context.GetChildFiles(parentPage).Where(f => predicate(f) && string.Equals(f.GetAttributeValue <string>("adx_partialurl"), thisPath, StringComparison.InvariantCultureIgnoreCase)).FirstOrDefault();

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

            return(null);
        }
Esempio n. 2
0
        private static Entity LookupPageByUrlPath(OrganizationServiceContext context, Entity website, string urlPath, Func <Entity, bool> predicate)
        {
            website.AssertEntityName("adx_website");

            if (website.Id == Guid.Empty)
            {
                throw new NullReferenceException("Unable to retrieve the Id of the website.  Lookup failed.");
            }

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

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

            // Check if we can find a page with the exact URL.
            var page = webPages.Where(wp => string.Compare(wp.GetAttributeValue <string>("adx_partialurl"), urlWithoutWebsitePath, StringComparison.InvariantCultureIgnoreCase) == 0).FirstOrDefault();

            if (page != null)
            {
                // We found the page (probably root).
                return(page);
            }

            string parentPath;
            string thisPath;

            if (ParseParentPath(urlWithoutWebsitePath, out parentPath, out thisPath))
            {
                var parentPage = LookupPageByUrlPath(context, website, parentPath, predicate);

                if (parentPage != null)
                {
                    page = context.GetChildPages(parentPage).Where(p => predicate(p) && string.Equals(p.GetAttributeValue <string>("adx_partialurl"), thisPath, StringComparison.InvariantCultureIgnoreCase)).FirstOrDefault();

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

            return(null);
        }