예제 #1
0
        /// <summary>
        /// Retrieves only those ancestor folders that match the ancestor conditions in a master page.
        /// </summary>
        /// <param name="masterPage">The master page (ancestor page ID and ancestor page level must both be specified).</param>
        /// <param name="unitOfWork">Unit of work.</param>
        /// <returns>List of folders where a page with the specified master can be creted.</returns>
        private List <Page> GetAncestorPages(MasterPage masterPage, IUnitOfWork unitOfWork)
        {
            // The page list that we will return and other variables
            long        ancestorPageId    = masterPage.AncestorPageId.Value;
            PageLevel   ancestorPageLevel = masterPage.AncestorPageLevel.Value;
            int         integerPageLevel  = (int)ancestorPageLevel;
            List <Page> pages             = new List <Page>();

            // List of pages is determined by ancestor page level
            switch (ancestorPageLevel)
            {
            case PageLevel.Parent:      // The straightforward case, parent must be ancestor page ID
                pages.Add(Read(masterPage.TenantId, ancestorPageId, unitOfWork));
                break;

            default:     // For all other cases, we must return only those ancestor pages with the correct distance from the ancestor page specified
                ISearchParameters parameters = new SearchParameters {
                    PageIndex = 0, PageSize = 1000
                };                                                                                          // TODO: Need way to return all pages, not have some max bound upper limit
                ISearchResult <Page> result = List(masterPage.TenantId, parameters, ancestorPageId, PageSortBy.Name, true, true, PageType.Folder, false, unitOfWork);
                ConnectParentPages(result.Items);
                foreach (Page page in result.Items)
                {
                    if (GetPageDepth(page) == (integerPageLevel - 1))
                    {
                        pages.Add(page);
                    }
                }
                break;
            }

            // Return the result
            return(pages);
        }
예제 #2
0
        public void Analyze(PageDownloadContext context)
        {
            var links = context.HtmlDocument.DocumentNode.Descendants()
                .Where(lnks => lnks.Name == "a" &&
                             lnks.Attributes["href"] != null &&
                             lnks.InnerText.Trim().Length > 0);
            //.Select(lnks => UriHelper.GetInsideAbsoluteUrl(context.PageUrl, lnks.Attributes["href"].Value))
            //.Where(it => !string.IsNullOrEmpty(it));

            if (context.PageLevel.Level < context.SiteDownloadContext.Options.Deep)
            {
                int count = 0;
                foreach (var link in links)
                {
                    var insideUrl = UriHelper.GetInsideAbsoluteUrl(context.PageLevel.Url, link.Attributes["href"].Value);

                    if (!string.IsNullOrEmpty(insideUrl))
                    {
                        if (count < context.SiteDownloadContext.Options.Pages)
                        {
                            var absolutePath = new Uri(insideUrl).AbsolutePath;
                            link.Attributes["href"].Value = "/" + SiteExtensions.PREFIX_FRONT_PREVIEW_URL + context.SiteDownloadContext.Site.AbsoluteName + absolutePath;
                            var nextPageLevel = new PageLevel(insideUrl, context.PageLevel.Level + 1);
                            if (!new PageLevelComparer().Equals(context.PageLevel, nextPageLevel) && !context.SiteDownloadContext.DownloadedPages.Contains(nextPageLevel, new PageLevelComparer()) && !context.SiteDownloadContext.DownloadQueue.Contains(nextPageLevel, new PageLevelComparer()))
                            {
                                context.SiteDownloadContext.DownloadQueue.Enqueue(nextPageLevel);
                                count++;
                            }
                        }
                        else
                        {
                            link.Attributes["href"].Value = insideUrl;
                        }
                    }
                }
            }
        }
예제 #3
0
 /// <summary>
 /// Constructor
 /// </summary>
 private PageLevelModel(PageLevel pageLevel)
 {
     PageLevel = pageLevel;
 }
예제 #4
0
        /// <summary>
        /// Gets master page from a template page.
        /// </summary>
        /// <param name="tenantId">Website identifier.</param>
        /// <param name="page">The page that is about to be created. Contains hierarchy of pages created so far.</param>
        /// <param name="templatePage">Template page.</param>
        /// <param name="templateElements">Maintains dictionary of template elements and their corresponding master element copies.</param>
        /// <param name="unitOfWork">Unit of work.</param>
        private MasterPage GetMasterPageFromTemplatePage(long tenantId, Page page, TemplatePage templatePage, Dictionary <ElementKeyValue, ElementKeyValue> templateElements, IUnitOfWork unitOfWork)
        {
            // Get ancestor page ID?
            long?ancestorPageId = null;

            if (templatePage.AncestorPageLevel != null)
            {
                PageLevel ancestorPageLevel = templatePage.AncestorPageLevel.Value;
                int       numericPageLevel  = (int)ancestorPageLevel;
                while (numericPageLevel > 0)
                {
                    ancestorPageId = page.ParentPageId;
                    page           = page.ParentPage;
                    numericPageLevel--;
                }
            }

            // Create master page from template page
            MasterPage masterPage = new MasterPage
            {
                Administration           = templatePage.Administration,
                AncestorPageId           = ancestorPageId,
                AncestorPageLevel        = templatePage.AncestorPageLevel,
                Creatable                = templatePage.Creatable,
                Deletable                = templatePage.Deletable,
                HasOccurred              = templatePage.HasOccurred,
                HasImage                 = templatePage.HasImage,
                ThumbnailImageWidth      = templatePage.ThumbnailImageWidth,
                ThumbnailImageHeight     = templatePage.ThumbnailImageHeight,
                ThumbnailImageResizeMode = templatePage.ThumbnailImageResizeMode,
                PreviewImageWidth        = templatePage.PreviewImageWidth,
                PreviewImageHeight       = templatePage.PreviewImageHeight,
                PreviewImageResizeMode   = templatePage.PreviewImageResizeMode,
                ImageMinWidth            = templatePage.ImageMinWidth,
                ImageMinHeight           = templatePage.ImageMinHeight,
                Name            = templatePage.Name,
                PageName        = templatePage.PageName,
                PageDescription = templatePage.PageDescription,
                PageType        = templatePage.PageType,
                Taggable        = templatePage.Taggable,
                TenantId        = tenantId,
                BeginRender     = templatePage.BeginRender,
                EndRender       = templatePage.EndRender,
                MasterPageZones = new List <MasterPageZone>()
            };

            // Create master page zones from template page zones
            foreach (TemplatePageZone templatePageZone in templatePage.TemplatePageZones)
            {
                // Create master page zone
                MasterPageZone masterPageZone = new MasterPageZone
                {
                    Name        = templatePageZone.Name,
                    AdminType   = templatePageZone.AdminType,
                    ContentType = templatePageZone.ContentType,
                    TenantId    = tenantId,
                    BeginRender = templatePageZone.BeginRender,
                    EndRender   = templatePageZone.EndRender,
                    SortOrder   = templatePageZone.SortOrder,
                    MasterPageZoneElementTypes = new List <MasterPageZoneElementType>(),
                    MasterPageZoneElements     = new List <MasterPageZoneElement>()
                };
                masterPage.MasterPageZones.Add(masterPageZone);

                // Create master page zone element types from template page zone element types
                for (int index = 0; index < templatePageZone.TemplatePageZoneElementTypes.Count; index++)
                {
                    TemplatePageZoneElementType templatePageZoneElementType = templatePageZone.TemplatePageZoneElementTypes[index];
                    masterPageZone.MasterPageZoneElementTypes.Add(new MasterPageZoneElementType
                    {
                        TenantId      = tenantId,
                        ElementTypeId = templatePageZoneElementType.ElementTypeId
                    });
                }

                // Create master page zone elements from template page zone elements
                for (int index = 0; index < templatePageZone.TemplatePageZoneElements.Count; index++)
                {
                    // Template elements are copied to create master elements
                    TemplatePageZoneElement templatePageZoneElement = templatePageZone.TemplatePageZoneElements[index];
                    ElementKeyValue         templateElementKeyValue = new ElementKeyValue
                    {
                        ElementTypeId = templatePageZoneElement.ElementTypeId,
                        ElementId     = templatePageZoneElement.ElementId
                    };

                    // Where template elements are re-used, so master element copies should be re-used
                    if (!templateElements.ContainsKey(templateElementKeyValue))
                    {
                        long masterElementId = _elementService.Copy(templatePage.TenantId, templateElementKeyValue.ElementId, tenantId, templateElementKeyValue.ElementTypeId, unitOfWork);
                        templateElements.Add(templateElementKeyValue, new ElementKeyValue {
                            ElementTypeId = templateElementKeyValue.ElementTypeId, ElementId = masterElementId
                        });
                    }

                    // Get master element key value
                    ElementKeyValue masterElementKeyValue = templateElements[templateElementKeyValue];
                    masterPageZone.MasterPageZoneElements.Add(new MasterPageZoneElement
                    {
                        ElementId = masterElementKeyValue.ElementId,
                        Element   = new ElementSettings {
                            TenantId = tenantId, ElementId = masterElementKeyValue.ElementId, ElementTypeId = masterElementKeyValue.ElementTypeId
                        },
                        SortOrder   = index,
                        TenantId    = tenantId,
                        Parent      = masterPageZone,
                        BeginRender = templatePageZoneElement.BeginRender,
                        EndRender   = templatePageZoneElement.EndRender
                    });
                }
            }

            // Return the result
            return(masterPage);
        }
예제 #5
0
 public PageDownloadedEventArgs( PageLevel downloadPage)
 {
     this.DownloadedPage = downloadPage;
 }