/// <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); }
/// <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) { TemplateThemeInfo target = obj as TemplateThemeInfo; if (target == null) { return(false); } if ( (PageTemplateCollections == null && target.PageTemplateCollections != null) || (PageTemplateCollections != null && target.PageTemplateCollections == null) ) { return(false); } if (PageTemplateCollections.Length != target.PageTemplateCollections.Length) { return(false); } for (int i = 0; i < PageTemplateCollections.Length; i++) { if (PageTemplateCollections[i] == null) { if (target.PageTemplateCollections[i] != null) { return(false); } //If we did not return then we know that target.PageTemplateCollections[i] is also null } else { if (!PageTemplateCollections[i].Equals(target.PageTemplateCollections[i])) { return(false); } } } return(true); }
/// <summary> /// Initializes a new instance of the <see cref="PageTemplateConfiguration"/> class. /// </summary> public PageTemplateConfiguration() { TemplateThemeCollection = new TemplateThemeInfo[] { }; PageTemplateCollections = new PageTemplateCollection[] { }; }