Esempio n. 1
0
        /// <summary>
        /// Gets the PageTemplateInfo for a given template and Display Version.
        /// </summary>
        /// <param name="templateName">The template we are looking for </param>
        /// <param name="version">The Display Version to get the PageTemplateInfo</param>
        /// <returns>The PageTemplateInfo for the given Display Version if defined, otherwise null
        /// </returns>
        public PageTemplateInfo GetPageTemplateInfo(string templateName, DisplayVersions version)
        {
            PageTemplateCollection col = PageTemplateCollections.FirstOrDefault(ptc => ptc.TemplateName == templateName);

            //If we could not find the page template col then return null, otherwise, ask the PTC for the template info
            return(col == null ? null : col.GetPageTemplateInfo(version));
        }
        /// <summary>
        /// Retrieves the LayoutTemplateInfo representing the named template.
        /// <remarks>
        /// So we will handle backwards compatibility by using the Theme approach if TemplateThemeCollection
        /// has something in it, OR fallback to the old PageTemplateCollection way if there are no themes.
        ///
        /// This way the DOCs can use the old mechanism, and CGov can use the new.  Also the go live for
        /// CGov will not require the new PTC to be published before the CDE code is deployed.
        /// </remarks>
        /// </summary>
        /// <param name="themeName">The name of the theme that the template belongs to.</param>
        /// <param name="templateName">The logical name of the page template we are looking for</param>
        /// <param name="version">The current display version that is being used.  This is used to choose the correct page template. </param>
        /// <returns></returns>
        public static PageTemplateInfo GetPageTemplateInfo(string themeName, string templateName, DisplayVersions version)
        {
            //Error if the templateName is null
            if (string.IsNullOrEmpty(templateName))
            {
                throw new ArgumentNullException("templateName", "The templateName parameter cannot be null or empty.");
            }

            //Error if we cannot get to the PTC
            if (PageTemplateConfiguration == null)
            {
                throw new Exception("PageTemplateConfiguration is null, Cannot determine page template");
            }

            //Check and see if we either have Template Themes or old school PageTemplateCollections and
            //if we do not have either, throw and exception
            if (!(
                    (PageTemplateConfiguration.TemplateThemeCollection != null && PageTemplateConfiguration.TemplateThemeCollection.Length > 0) ||
                    (PageTemplateConfiguration.PageTemplateCollections != null && PageTemplateConfiguration.PageTemplateCollections.Length > 0)
                    ))
            {
                throw new Exception("Neither Template Themes nor Page template collections exist in the PageTemplateConfiguration, cannot load page template.");
            }


            // Now we determine the way to get to the templateInfo.  Themes will take priority over old
            // way.
            PageTemplateInfo rtnTempInfo = null;

            if (PageTemplateConfiguration.TemplateThemeCollection.Length > 0)
            {
                //Check Theme Name
                if (String.IsNullOrWhiteSpace(themeName))
                {
                    throw new ArgumentNullException("themeName", "The themeName parameter cannot be null or empty.");
                }

                //Handle New
                TemplateThemeInfo themeInfo = PageTemplateConfiguration.TemplateThemeCollection.FirstOrDefault(tti => tti.ThemeName == themeName);

                if (themeInfo == null)
                {
                    throw new Exception("Cannot Find Theme named: " + themeName);
                }

                rtnTempInfo = themeInfo.GetPageTemplateInfo(templateName, version);
            }
            else if (PageTemplateConfiguration.PageTemplateCollections.Length > 0)
            {
                PageTemplateCollection tempColl = PageTemplateConfiguration.PageTemplateCollections.FirstOrDefault(ptc => ptc.TemplateName == templateName);

                if (tempColl != null)
                {
                    rtnTempInfo = tempColl.GetPageTemplateInfo(version);
                }
            }

            return(rtnTempInfo);
        }
Esempio n. 3
0
        /// <summary>
        /// Determines whether the specified <see cref="T:System.Object"/> is equal to the current <see cref="T:System.Object"/>.
        /// </summary>
        /// <param name="obj">The <see cref="T:System.Object"/> to compare with the current <see cref="T:System.Object"/>.</param>
        /// <returns>
        /// true if the specified <see cref="T:System.Object"/> is equal to the current <see cref="T:System.Object"/>; otherwise, false.
        /// </returns>
        /// <exception cref="T:System.NullReferenceException">
        /// The <paramref name="obj"/> parameter is null.
        /// </exception>
        public override bool Equals(object obj)
        {
            PageTemplateCollection target = obj as PageTemplateCollection;

            if (target == null)
            {
                return(false);
            }

            if (TemplateName != target.TemplateName)
            {
                return(false);
            }

            if (
                (PageTemplateInfos == null && target.PageTemplateInfos != null) ||
                (PageTemplateInfos != null && target.PageTemplateInfos == null)
                )
            {
                return(false);
            }

            if (PageTemplateInfos.Length != target.PageTemplateInfos.Length)
            {
                return(false);
            }

            for (int i = 0; i < PageTemplateInfos.Length; i++)
            {
                if (PageTemplateInfos[i] == null)
                {
                    if (target.PageTemplateInfos[i] != null)
                    {
                        return(false);
                    }

                    //If we did not return then we know that target.PageTemplateInfos[i] is also null
                }
                else
                {
                    if (!PageTemplateInfos[i].Equals(target.PageTemplateInfos[i]))
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }