コード例 #1
0
        /// <summary>
        /// Gets template page from database manager data reader.
        /// </summary>
        /// <param name="dbm">Database manager.</param>
        /// <returns>A populated template page object.</returns>
        private TemplatePage GetTemplatePageFromDatabaseManager(IDatabaseManager dbm)
        {
            TemplatePage templatePage = new TemplatePage
            {
                TenantId                 = (long)dbm.DataReaderValue("TenantId"),
                TemplatePageId           = (long)dbm.DataReaderValue("TemplatePageId"),
                Name                     = (string)dbm.DataReaderValue("Name"),
                PageName                 = (string)dbm.DataReaderValue("PageName"),
                PageDescription          = dbm.DataReaderValue("PageDescription") == DBNull.Value ? null : (string)dbm.DataReaderValue("PageDescription"),
                PageType                 = (PageType)(int)dbm.DataReaderValue("PageType"),
                HasOccurred              = (bool)dbm.DataReaderValue("HasOccurred"),
                HasImage                 = (bool)dbm.DataReaderValue("HasImage"),
                ThumbnailImageWidth      = dbm.DataReaderValue("ThumbnailImageWidth") == DBNull.Value ? null : (int?)dbm.DataReaderValue("ThumbnailImageWidth"),
                ThumbnailImageHeight     = dbm.DataReaderValue("ThumbnailImageHeight") == DBNull.Value ? null : (int?)dbm.DataReaderValue("ThumbnailImageHeight"),
                ThumbnailImageResizeMode = dbm.DataReaderValue("ThumbnailImageResizeMode") == DBNull.Value ? null : (ResizeMode?)(int)dbm.DataReaderValue("ThumbnailImageResizeMode"),
                PreviewImageWidth        = dbm.DataReaderValue("PreviewImageWidth") == DBNull.Value ? null : (int?)dbm.DataReaderValue("PreviewImageWidth"),
                PreviewImageHeight       = dbm.DataReaderValue("PreviewImageHeight") == DBNull.Value ? null : (int?)dbm.DataReaderValue("PreviewImageHeight"),
                PreviewImageResizeMode   = dbm.DataReaderValue("PreviewImageResizeMode") == DBNull.Value ? null : (ResizeMode?)(int)dbm.DataReaderValue("PreviewImageResizeMode"),
                ImageMinWidth            = dbm.DataReaderValue("ImageMinWidth") == DBNull.Value ? null : (int?)dbm.DataReaderValue("ImageMinWidth"),
                ImageMinHeight           = dbm.DataReaderValue("ImageMinHeight") == DBNull.Value ? null : (int?)dbm.DataReaderValue("ImageMinHeight"),
                AncestorPageLevel        = dbm.DataReaderValue("AncestorPageLevel") == DBNull.Value ? null : (PageLevel?)(int)dbm.DataReaderValue("AncestorPageLevel"),
                ParentTemplatePageId     = dbm.DataReaderValue("ParentTemplatePageId") == DBNull.Value ? null : (long?)dbm.DataReaderValue("ParentTemplatePageId"),
                ShowOnNavigation         = (bool)dbm.DataReaderValue("ShowOnNavigation"),
                Creatable                = (bool)dbm.DataReaderValue("Creatable"),
                Deletable                = (bool)dbm.DataReaderValue("Deletable"),
                Taggable                 = (bool)dbm.DataReaderValue("Taggable"),
                Administration           = (bool)dbm.DataReaderValue("Administration"),
                BeginRender              = dbm.DataReaderValue("BeginRender") == DBNull.Value ? null : (string)dbm.DataReaderValue("BeginRender"),
                EndRender                = dbm.DataReaderValue("EndRender") == DBNull.Value ? null : (string)dbm.DataReaderValue("EndRender"),
                ChildTemplatePages       = new List <TemplatePage>(),
                TemplatePageZones        = new List <TemplatePageZone>()
            };

            return(templatePage);
        }
コード例 #2
0
        /// <summary>
        /// Gets template from database manager result.
        /// </summary>
        /// <param name="dbm">Database manager.</param>
        /// <param name="loadAll">Set true to load template template pages, zones, configurable element types and elements. Otherwise only main template details loaded.</param>
        /// <returns>Template (or null if template not found).</returns>
        private Template GetTemplate(IDatabaseManager dbm, bool loadAll)
        {
            // Get template
            Template template = GetTemplateFromDatabaseManager(dbm);

            // If we are not reading entire template we can return result now
            if (!loadAll)
            {
                return(template);
            }

            // Get template pages and then construct template page hierarchy
            dbm.Read();
            Dictionary <long, TemplatePage> templatePagesById = new Dictionary <long, TemplatePage>();

            while (dbm.Read())
            {
                TemplatePage templatePage = GetTemplatePageFromDatabaseManager(dbm);
                templatePagesById.Add(templatePage.TemplatePageId, templatePage);
            }
            template.Page = GetTemplatePageHierarchy(templatePagesById);

            // Get template page zones
            Dictionary <long, TemplatePageZone> templatePageZonesById = new Dictionary <long, TemplatePageZone>();

            while (dbm.Read())
            {
                TemplatePageZone templatePageZone = GetTemplatePageZoneFromDatabaseManager(dbm);
                templatePagesById[templatePageZone.TemplatePageId].TemplatePageZones.Add(templatePageZone);
                templatePageZonesById.Add(templatePageZone.TemplatePageZoneId, templatePageZone);
            }

            // Get the element types that can exist in a template page zone when admin type is configurable
            while (dbm.Read())
            {
                TemplatePageZoneElementType templatePageZoneElementType = GetTemplatePageZoneElementTypeFromDatabaseManager(dbm);
                templatePageZonesById[templatePageZoneElementType.TemplatePageZoneId].TemplatePageZoneElementTypes.Add(templatePageZoneElementType);
            }

            // Get template page zone elements
            while (dbm.Read())
            {
                TemplatePageZoneElement templatePageZoneElement = GetTemplatePageZoneElementFromDatabaseManager(dbm);
                templatePageZonesById[templatePageZoneElement.TemplatePageZoneId].TemplatePageZoneElements.Add(templatePageZoneElement);
            }

            // Return the result
            return(template);
        }
コード例 #3
0
        /// <summary>
        /// Turns templatePagesById into a hierarchy of pages.
        /// </summary>
        /// <param name="templatePagesById">Template pages keyed by template page ID.</param>
        /// <returns>Root template page, with child template pages populated.</returns>
        private TemplatePage GetTemplatePageHierarchy(Dictionary <long, TemplatePage> templatePagesById)
        {
            TemplatePage root = null;

            foreach (KeyValuePair <long, TemplatePage> kvp in templatePagesById)
            {
                TemplatePage page = kvp.Value;
                if (!page.ParentTemplatePageId.HasValue)
                {
                    root = page;
                }
                else
                {
                    templatePagesById[page.ParentTemplatePageId.Value].ChildTemplatePages.Add(page);
                }
            }
            return(root);
        }