Exemple #1
0
        /// <summary>
        /// Gets master page from database manager result.
        /// </summary>
        /// <param name="dbm">Database manager.</param>
        /// <param name="loadZonesAndElements">Indicates depth of data loaded.</param>
        /// <returns>Master page (or null if master page not found).</returns>
        private MasterPage GetMasterPage(IDatabaseManager dbm, bool loadZonesAndElements)
        {
            // Get master page
            if (loadZonesAndElements && !dbm.Read())
            {
                return(null);
            }
            MasterPage masterPage = GetMasterPageFromDatabaseManager(dbm);

            // If not read, we can return result now
            if (!loadZonesAndElements)
            {
                return(masterPage);
            }

            // Get master page zones
            dbm.Read();
            Dictionary <long, MasterPageZone> masterPageZonesById = new Dictionary <long, MasterPageZone>();

            while (dbm.Read())
            {
                MasterPageZone masterPageZone = GetMasterPageZoneFromDatabaseManager(dbm);
                masterPage.MasterPageZones.Add(masterPageZone);
                masterPageZonesById.Add(masterPageZone.MasterPageZoneId, masterPageZone);
            }

            // Get the element types that can exist in a master page zone when admin type is configurable
            while (dbm.Read())
            {
                MasterPageZoneElementType masterPageZoneElementType = GetMasterPageZoneElementTypeFromDatabaseManager(dbm);
                masterPageZonesById[masterPageZoneElementType.MasterPageZoneId].MasterPageZoneElementTypes.Add(masterPageZoneElementType);
            }

            // Get master page zone elements
            while (dbm.Read())
            {
                MasterPageZoneElement masterPageZoneElement = GetMasterPageZoneElementFromDatabaseManager(dbm);
                masterPageZonesById[masterPageZoneElement.MasterPageZoneId].MasterPageZoneElements.Add(masterPageZoneElement);
            }

            // Return the result
            return(masterPage);
        }
Exemple #2
0
        /// <summary>
        /// Ensure correct sort orders of zone elements. Ensure element types only specified for zones that are configurable.
        /// </summary>
        /// <param name="masterPageZone">Master page zone.</param>
        private void PrepareMasterPageZone(MasterPageZone masterPageZone)
        {
            // Only populate element types if master page zone admin type configurable
            if (masterPageZone.AdminType != MasterPageZoneAdminType.Configurable)
            {
                masterPageZone.MasterPageZoneElementTypes.Clear();
            }

            // Ensure correct zone element sort orders
            for (int zoneElementIndex = 0; zoneElementIndex < masterPageZone.MasterPageZoneElements.Count; zoneElementIndex++)
            {
                MasterPageZoneElement zoneElement = masterPageZone.MasterPageZoneElements[zoneElementIndex];
                zoneElement.SortOrder = zoneElementIndex;
                if (string.IsNullOrWhiteSpace(zoneElement.BeginRender))
                {
                    zoneElement.BeginRender = null;
                }
                if (string.IsNullOrWhiteSpace(zoneElement.EndRender))
                {
                    zoneElement.EndRender = null;
                }
            }
        }
Exemple #3
0
        /// <summary>
        /// Get elements for master pages belonging to the specified tenant.
        /// </summary>
        /// <param name="tenantId">Tenant identifier.</param>
        /// <param name="unitOfWork">Unit of work.</param>
        /// <returns>Collection of elements.</returns>
        public IEnumerable <MasterPage> ListElementsByMasterPage(long tenantId, IUnitOfWork unitOfWork = null)
        {
            IDatabaseManager dbm = _databaseManagerFactory.GetDatabaseManager(unitOfWork);

            try
            {
                List <MasterPage> masterPages = new List <MasterPage>();
                dbm.SetSQL(_sqlManager.GetSql("Sql.ListMasterPageElements.sql"));
                dbm.AddParameter("@TenantId", FieldType.BigInt, tenantId);
                dbm.ExecuteReader();
                MasterPage            masterPage            = null;
                MasterPageZone        masterPageZone        = null;
                MasterPageZoneElement masterPageZoneElement = null;
                while (dbm.Read())
                {
                    // Get master page details, create new master page each time master page identifier changes
                    long masterPageId = (long)dbm.DataReaderValue("MasterPageId");
                    if (masterPage == null || masterPage.MasterPageId != masterPageId)
                    {
                        masterPage = new MasterPage {
                            TenantId = tenantId, MasterPageId = masterPageId, Name = (string)dbm.DataReaderValue("MasterPageName"), MasterPageZones = new List <MasterPageZone>()
                        };
                        masterPages.Add(masterPage);
                        masterPageZone        = null;
                        masterPageZoneElement = null;
                    }

                    // Get master page zone details, create new master page zone each time master page zone identifier changes
                    long masterPageZoneId = (long)dbm.DataReaderValue("MasterPageZoneId");
                    if (masterPageZone == null || masterPageZone.MasterPageZoneId != masterPageZoneId)
                    {
                        masterPageZone = new MasterPageZone {
                            TenantId = tenantId, MasterPageId = masterPageId, MasterPageZoneId = masterPageZoneId, Name = (string)dbm.DataReaderValue("MasterPageZoneName"), MasterPageZoneElements = new List <MasterPageZoneElement>()
                        };
                        masterPage.MasterPageZones.Add(masterPageZone);
                        masterPageZoneElement = null;
                    }

                    // Get master page zone element details, create new master page zone element each time master page zone element identifier changes
                    long masterPageZoneElementId = (long)dbm.DataReaderValue("MasterPageZoneElementId");
                    if (masterPageZoneElement == null || masterPageZoneElement.MasterPageZoneElementId != masterPageZoneElementId)
                    {
                        masterPageZoneElement = new MasterPageZoneElement {
                            TenantId = tenantId, MasterPageId = masterPageId, MasterPageZoneId = masterPageZoneId, MasterPageZoneElementId = masterPageZoneElementId
                        };
                        masterPageZone.MasterPageZoneElements.Add(masterPageZoneElement);
                    }

                    // Get element details
                    masterPageZoneElement.Element = new ElementSettings {
                        TenantId = tenantId, ElementId = (long)dbm.DataReaderValue("ElementId"), ElementTypeId = (Guid)dbm.DataReaderValue("ElementTypeId"), Name = (string)dbm.DataReaderValue("Name")
                    };
                    masterPageZoneElement.ElementId = masterPageZoneElement.Element.ElementId;
                }
                return(masterPages);
            }
            finally
            {
                if (unitOfWork == null)
                {
                    dbm.Dispose();
                }
            }
        }