public static void CreatePage(SiteSettings siteSettings, ContentPage contentPage, PageSettings parentPage) { PageSettings pageSettings = new PageSettings(); pageSettings.PageGuid = Guid.NewGuid(); if (parentPage != null) { pageSettings.ParentGuid = parentPage.PageGuid; pageSettings.ParentId = parentPage.PageId; } pageSettings.SiteId = siteSettings.SiteId; pageSettings.SiteGuid = siteSettings.SiteGuid; pageSettings.AuthorizedRoles = contentPage.VisibleToRoles; pageSettings.EditRoles = contentPage.EditRoles; pageSettings.DraftEditOnlyRoles = contentPage.DraftEditRoles; pageSettings.CreateChildPageRoles = contentPage.CreateChildPageRoles; pageSettings.MenuImage = contentPage.MenuImage; pageSettings.PageMetaKeyWords = contentPage.PageMetaKeyWords; pageSettings.PageMetaDescription = contentPage.PageMetaDescription; CultureInfo uiCulture = Thread.CurrentThread.CurrentUICulture; if (WebConfigSettings.UseCultureOverride) { uiCulture = SiteUtils.GetDefaultUICulture(siteSettings.SiteId); } if (contentPage.ResourceFile.Length > 0) { pageSettings.PageName = ResourceHelper.GetResourceString(contentPage.ResourceFile, contentPage.Name, uiCulture, false); if (contentPage.Title.Length > 0) { pageSettings.PageTitle = ResourceHelper.GetResourceString(contentPage.ResourceFile, contentPage.Title, uiCulture, false); } } else { pageSettings.PageName = contentPage.Name; pageSettings.PageTitle = contentPage.Title; } pageSettings.PageOrder = contentPage.PageOrder; pageSettings.Url = contentPage.Url; pageSettings.RequireSsl = contentPage.RequireSsl; pageSettings.ShowBreadcrumbs = contentPage.ShowBreadcrumbs; pageSettings.BodyCssClass = contentPage.BodyCssClass; pageSettings.MenuCssClass = contentPage.MenuCssClass; pageSettings.IncludeInMenu = contentPage.IncludeInMenu; pageSettings.IsClickable = contentPage.IsClickable; pageSettings.IncludeInSiteMap = contentPage.IncludeInSiteMap; pageSettings.IncludeInChildSiteMap = contentPage.IncludeInChildPagesSiteMap; pageSettings.AllowBrowserCache = contentPage.AllowBrowserCaching; pageSettings.ShowChildPageBreadcrumbs = contentPage.ShowChildPageBreadcrumbs; pageSettings.ShowHomeCrumb = contentPage.ShowHomeCrumb; pageSettings.ShowChildPageMenu = contentPage.ShowChildPagesSiteMap; pageSettings.HideAfterLogin = contentPage.HideFromAuthenticated; pageSettings.EnableComments = contentPage.EnableComments; pageSettings.Save(); if (!FriendlyUrl.Exists(siteSettings.SiteId, pageSettings.Url)) { if (!WebPageInfo.IsPhysicalWebPage(pageSettings.Url)) { FriendlyUrl friendlyUrl = new FriendlyUrl(); friendlyUrl.SiteId = siteSettings.SiteId; friendlyUrl.SiteGuid = siteSettings.SiteGuid; friendlyUrl.PageGuid = pageSettings.PageGuid; friendlyUrl.Url = pageSettings.Url.Replace("~/", string.Empty); friendlyUrl.RealUrl = "~/Default.aspx?pageid=" + pageSettings.PageId.ToInvariantString(); friendlyUrl.Save(); } } foreach (ContentPageItem pageItem in contentPage.PageItems) { // tni-20130624: moduleGuidxxxx handling Guid moduleGuid2Use = Guid.Empty; bool updateModule = false; Module findModule = null; if (pageItem.ModuleGuidToPublish != Guid.Empty) { Module existingModule = new Module(pageItem.ModuleGuidToPublish); if (existingModule.ModuleGuid == pageItem.ModuleGuidToPublish && existingModule.SiteId == siteSettings.SiteId) { Module.Publish(pageSettings.PageGuid, existingModule.ModuleGuid, existingModule.ModuleId, pageSettings.PageId, pageItem.Location, pageItem.SortOrder, DateTime.UtcNow, DateTime.MinValue); // tni: I assume there's nothing else to do now so let's go to the next content... continue; } } else if (pageItem.ModuleGuid != Guid.Empty) { findModule = new Module(pageItem.ModuleGuid); if (findModule.ModuleGuid == Guid.Empty) { // Module does not exist, we can create new one with the specified Guid moduleGuid2Use = pageItem.ModuleGuid; } if (findModule.ModuleGuid == pageItem.ModuleGuid && findModule.SiteId == siteSettings.SiteId) { // The module already exist, we'll update existing one updateModule = true; moduleGuid2Use = findModule.ModuleGuid; } } // ModuleDefinition moduleDef = new ModuleDefinition(pageItem.FeatureGuid); // this only adds if its not already there try { SiteSettings.AddFeature(siteSettings.SiteGuid, pageItem.FeatureGuid); } catch (Exception ex) { log.Error(ex); } if (moduleDef.ModuleDefId > -1) { Module module = null; if (updateModule && (findModule != null)) { module = findModule; } else { module = new Module(); module.ModuleGuid = moduleGuid2Use; } module.SiteId = siteSettings.SiteId; module.SiteGuid = siteSettings.SiteGuid; module.PageId = pageSettings.PageId; module.ModuleDefId = moduleDef.ModuleDefId; module.FeatureGuid = moduleDef.FeatureGuid; module.PaneName = pageItem.Location; if (contentPage.ResourceFile.Length > 0) { module.ModuleTitle = ResourceHelper.GetResourceString(contentPage.ResourceFile, pageItem.ContentTitle, uiCulture, false); } else { module.ModuleTitle = pageItem.ContentTitle; } module.ModuleOrder = pageItem.SortOrder; module.CacheTime = pageItem.CacheTimeInSeconds; module.Icon = moduleDef.Icon; module.ShowTitle = pageItem.ShowTitle; module.AuthorizedEditRoles = pageItem.EditRoles; module.DraftEditRoles = pageItem.DraftEditRoles; module.ViewRoles = pageItem.ViewRoles; module.IsGlobal = pageItem.IsGlobal; module.HeadElement = pageItem.HeadElement; module.HideFromAuthenticated = pageItem.HideFromAuthenticated; module.HideFromUnauthenticated = pageItem.HideFromAnonymous; module.Save(); if ((pageItem.Installer != null) && (pageItem.ConfigInfo.Length > 0)) { //this is the newer implementation for populating feature content pageItem.Installer.InstallContent(module, pageItem.ConfigInfo); } else { // legacy implementation for backward compatibility if ( (pageItem.FeatureGuid == HtmlContent.FeatureGuid) && (pageItem.ContentTemplate.EndsWith(".config")) ) { HtmlContent htmlContent = new HtmlContent(); htmlContent.ModuleId = module.ModuleId; htmlContent.Body = ResourceHelper.GetMessageTemplate(uiCulture, pageItem.ContentTemplate); htmlContent.ModuleGuid = module.ModuleGuid; HtmlRepository repository = new HtmlRepository(); repository.Save(htmlContent); } } // tni-20130624: handling module settings foreach (KeyValuePair<string, string> item in pageItem.ModuleSettings) { ModuleSettings.UpdateModuleSetting(module.ModuleGuid, module.ModuleId, item.Key, item.Value); } } } foreach (ContentPage childPage in contentPage.ChildPages) { CreatePage(siteSettings, childPage, pageSettings); } }
public static void LoadPageItem( ContentPage contentPage, XmlNode pageItemNode) { if (contentPage == null) return; if (pageItemNode == null) return; if (pageItemNode.Name == "contentFeature") { ContentPageItem pageItem = new ContentPageItem(); XmlAttributeCollection attributeCollection = pageItemNode.Attributes; if (attributeCollection["featureGuid"] != null) { pageItem.featureGuid = new Guid(attributeCollection["featureGuid"].Value); } if (attributeCollection["contentTitle"] != null) { pageItem.contentTitle = attributeCollection["contentTitle"].Value; } if (attributeCollection["contentTemplate"] != null) { pageItem.contentTemplate = attributeCollection["contentTemplate"].Value; } if (attributeCollection["configInfo"] != null) { pageItem.configInfo = attributeCollection["configInfo"].Value; } if (attributeCollection["viewRoles"] != null) { pageItem.viewRoles = attributeCollection["viewRoles"].Value; } if (attributeCollection["editRoles"] != null) { pageItem.editRoles = attributeCollection["editRoles"].Value; } if (attributeCollection["draftEditRoles"] != null) { pageItem.draftEditRoles = attributeCollection["draftEditRoles"].Value; } if (attributeCollection["headElement"] != null) { pageItem.headElement = attributeCollection["headElement"].Value; } if ( (attributeCollection["isGlobal"] != null) && (attributeCollection["isGlobal"].Value.ToLower() == "true") ) { pageItem.isGlobal = true; } if ( (attributeCollection["showTitle"] != null) && (attributeCollection["showTitle"].Value.ToLower() == "false") ) { pageItem.showTitle = false; } if ( (attributeCollection["hideFromAnonymous"] != null) && (attributeCollection["hideFromAnonymous"].Value.ToLower() == "true") ) { pageItem.hideFromAnonymous = true; } if ( (attributeCollection["hideFromAuthenticated"] != null) && (attributeCollection["hideFromAuthenticated"].Value.ToLower() == "true") ) { pageItem.hideFromAuthenticated = true; } try { if (attributeCollection["contentInstaller"] != null && typeof(IContentInstaller).IsAssignableFrom(Type.GetType(attributeCollection["contentInstaller"].Value))) { pageItem.installer = Activator.CreateInstance(Type.GetType(attributeCollection["contentInstaller"].Value)) as IContentInstaller; } } catch (Exception ex) // we don't want it to fail during site creation even if not all content is created due to errors here. { log.Error(ex); } if (attributeCollection["location"] != null) { string location = attributeCollection["location"].Value; switch (location) { case "right": case "rightpane": pageItem.location = "rightpane"; break; case "left": case "leftpane": pageItem.location = "leftpane"; break; case "top": case "altcontent1": pageItem.location = "altcontent1"; break; case "bottom": case "altcontent2": pageItem.location = "altcontent2"; break; case "center": case "contentpane": default: pageItem.location = "contentpane"; break; } } if (attributeCollection["sortOrder"] != null) { int sort = 1; if (int.TryParse(attributeCollection["sortOrder"].Value, out sort)) { pageItem.sortOrder = sort; } } if (attributeCollection["cacheTimeInSeconds"] != null) { int cacheTimeInSeconds = 1; if (int.TryParse(attributeCollection["cacheTimeInSeconds"].Value, out cacheTimeInSeconds)) { pageItem.cacheTimeInSeconds = cacheTimeInSeconds; } } // tni-20130624: handling module settings XmlNodeList moduleSettings = pageItemNode.SelectNodes("./moduleSetting"); foreach (XmlNode moduleSetting in moduleSettings) { #if NET35 if (moduleSetting.Attributes["settingKey"] != null && !string.IsNullOrEmpty(moduleSetting.Attributes["settingKey"].Value) && moduleSetting.Attributes["settingValue"] != null && moduleSetting.Attributes["settingValue"].Value != null) { pageItem.moduleSettings[moduleSetting.Attributes["settingKey"].Value] = moduleSetting.Attributes["settingValue"].Value; } #else if (moduleSetting.Attributes["settingKey"] != null && !string.IsNullOrWhiteSpace(moduleSetting.Attributes["settingKey"].Value) && moduleSetting.Attributes["settingValue"] != null && moduleSetting.Attributes["settingValue"].Value != null) { pageItem.moduleSettings[moduleSetting.Attributes["settingKey"].Value] = moduleSetting.Attributes["settingValue"].Value; } #endif } // No parse error handling like done above.. if (attributeCollection["moduleGuid"] != null) { #if NET35 pageItem.moduleGuid = new Guid(attributeCollection["moduleGuid"].Value); #else Guid.TryParse(attributeCollection["moduleGuid"].Value, out pageItem.moduleGuid); #endif } if (attributeCollection["moduleGuidToPublish"] != null) { #if NET35 pageItem.moduleGuidToPublish = new Guid(attributeCollection["moduleGuidToPublish"].Value); #else Guid.TryParse(attributeCollection["moduleGuidToPublish"].Value, out pageItem.moduleGuidToPublish); #endif } // contentPage.PageItems.Add(pageItem); } }
public static void LoadPageItem( ContentPage contentPage, XmlNode pageItemNode) { if (contentPage == null) { return; } if (pageItemNode == null) { return; } if (pageItemNode.Name == "contentFeature") { ContentPageItem pageItem = new ContentPageItem(); XmlAttributeCollection attributeCollection = pageItemNode.Attributes; if (attributeCollection["featureGuid"] != null) { pageItem.featureGuid = new Guid(attributeCollection["featureGuid"].Value); } if (attributeCollection["contentTitle"] != null) { pageItem.contentTitle = attributeCollection["contentTitle"].Value; } if (attributeCollection["contentTemplate"] != null) { pageItem.contentTemplate = attributeCollection["contentTemplate"].Value; } if (attributeCollection["configInfo"] != null) { pageItem.configInfo = attributeCollection["configInfo"].Value; } if (attributeCollection["viewRoles"] != null) { pageItem.viewRoles = attributeCollection["viewRoles"].Value; } if (attributeCollection["editRoles"] != null) { pageItem.editRoles = attributeCollection["editRoles"].Value; } if (attributeCollection["draftEditRoles"] != null) { pageItem.draftEditRoles = attributeCollection["draftEditRoles"].Value; } if (attributeCollection["headElement"] != null) { pageItem.headElement = attributeCollection["headElement"].Value; } if ( (attributeCollection["isGlobal"] != null) && (attributeCollection["isGlobal"].Value.ToLower() == "true") ) { pageItem.isGlobal = true; } if ( (attributeCollection["showTitle"] != null) && (attributeCollection["showTitle"].Value.ToLower() == "false") ) { pageItem.showTitle = false; } if ( (attributeCollection["hideFromAnonymous"] != null) && (attributeCollection["hideFromAnonymous"].Value.ToLower() == "true") ) { pageItem.hideFromAnonymous = true; } if ( (attributeCollection["hideFromAuthenticated"] != null) && (attributeCollection["hideFromAuthenticated"].Value.ToLower() == "true") ) { pageItem.hideFromAuthenticated = true; } try { if (attributeCollection["contentInstaller"] != null && typeof(IContentInstaller).IsAssignableFrom(Type.GetType(attributeCollection["contentInstaller"].Value))) { pageItem.installer = Activator.CreateInstance(Type.GetType(attributeCollection["contentInstaller"].Value)) as IContentInstaller; } } catch (Exception ex) // we don't want it to fail during site creation even if not all content is created due to errors here. { log.Error(ex); } if (attributeCollection["location"] != null) { string location = attributeCollection["location"].Value; switch (location) { case "right": case "rightpane": pageItem.location = "rightpane"; break; case "left": case "leftpane": pageItem.location = "leftpane"; break; case "top": case "altcontent1": pageItem.location = "altcontent1"; break; case "bottom": case "altcontent2": pageItem.location = "altcontent2"; break; case "center": case "contentpane": default: pageItem.location = "contentpane"; break; } } if (attributeCollection["sortOrder"] != null) { int sort = 1; if (int.TryParse(attributeCollection["sortOrder"].Value, out sort)) { pageItem.sortOrder = sort; } } if (attributeCollection["cacheTimeInSeconds"] != null) { int cacheTimeInSeconds = 1; if (int.TryParse(attributeCollection["cacheTimeInSeconds"].Value, out cacheTimeInSeconds)) { pageItem.cacheTimeInSeconds = cacheTimeInSeconds; } } // tni-20130624: handling module settings XmlNodeList moduleSettings = pageItemNode.SelectNodes("./moduleSetting"); foreach (XmlNode moduleSetting in moduleSettings) { #if NET35 if (moduleSetting.Attributes["settingKey"] != null && !string.IsNullOrEmpty(moduleSetting.Attributes["settingKey"].Value) && moduleSetting.Attributes["settingValue"] != null && moduleSetting.Attributes["settingValue"].Value != null) { pageItem.moduleSettings[moduleSetting.Attributes["settingKey"].Value] = moduleSetting.Attributes["settingValue"].Value; } #else if (moduleSetting.Attributes["settingKey"] != null && !string.IsNullOrWhiteSpace(moduleSetting.Attributes["settingKey"].Value) && moduleSetting.Attributes["settingValue"] != null && moduleSetting.Attributes["settingValue"].Value != null) { pageItem.moduleSettings[moduleSetting.Attributes["settingKey"].Value] = moduleSetting.Attributes["settingValue"].Value; } #endif } // No parse error handling like done above.. if (attributeCollection["moduleGuid"] != null) { #if NET35 pageItem.moduleGuid = new Guid(attributeCollection["moduleGuid"].Value); #else Guid.TryParse(attributeCollection["moduleGuid"].Value, out pageItem.moduleGuid); #endif } if (attributeCollection["moduleGuidToPublish"] != null) { #if NET35 pageItem.moduleGuidToPublish = new Guid(attributeCollection["moduleGuidToPublish"].Value); #else Guid.TryParse(attributeCollection["moduleGuidToPublish"].Value, out pageItem.moduleGuidToPublish); #endif } // contentPage.PageItems.Add(pageItem); } }
public static void LoadPage( ContentPageConfiguration contentPageConfig, XmlNode node, ContentPage parentPage) { ContentPage contentPage = new ContentPage(); XmlAttributeCollection attributeCollection = node.Attributes; if (attributeCollection["resourceFile"] != null) { contentPage.resourceFile = attributeCollection["resourceFile"].Value; } if (attributeCollection["name"] != null) { contentPage.name = attributeCollection["name"].Value; } if (attributeCollection["title"] != null) { contentPage.title = attributeCollection["title"].Value; } if (attributeCollection["url"] != null) { contentPage.url = attributeCollection["url"].Value; } if (attributeCollection["menuImage"] != null) { contentPage.menuImage = attributeCollection["menuImage"].Value; } if (attributeCollection["pageOrder"] != null) { int sort = 1; if (int.TryParse(attributeCollection["pageOrder"].Value, out sort)) { contentPage.pageOrder = sort; } } if (attributeCollection["visibleToRoles"] != null) { contentPage.visibleToRoles = attributeCollection["visibleToRoles"].Value; } if (attributeCollection["editRoles"] != null) { contentPage.editRoles = attributeCollection["editRoles"].Value; } if (attributeCollection["draftEditRoles"] != null) { contentPage.draftEditRoles = attributeCollection["draftEditRoles"].Value; } if (attributeCollection["createChildPageRoles"] != null) { contentPage.createChildPageRoles = attributeCollection["createChildPageRoles"].Value; } if (attributeCollection["pageMetaKeyWords"] != null) { contentPage.pageMetaKeyWords = attributeCollection["pageMetaKeyWords"].Value; } if (attributeCollection["pageMetaDescription"] != null) { contentPage.pageMetaDescription = attributeCollection["pageMetaDescription"].Value; } if ( (attributeCollection["requireSSL"] != null) && (attributeCollection["requireSSL"].Value.ToLower() == "true") ) { contentPage.requireSSL = true; } if ( (attributeCollection["showBreadcrumbs"] != null) && (attributeCollection["showBreadcrumbs"].Value.ToLower() == "true") ) { contentPage.showBreadcrumbs = true; } if ( (attributeCollection["includeInMenu"] != null) && (attributeCollection["includeInMenu"].Value.ToLower() == "false") ) { contentPage.includeInMenu = false; } if ( (attributeCollection["isClickable"] != null) && (attributeCollection["isClickable"].Value.ToLower() == "false") ) { contentPage.isClickable = false; } if ( (attributeCollection["includeInSiteMap"] != null) && (attributeCollection["includeInSiteMap"].Value.ToLower() == "false") ) { contentPage.includeInSiteMap = false; } if ( (attributeCollection["includeInChildPagesSiteMap"] != null) && (attributeCollection["includeInChildPagesSiteMap"].Value.ToLower() == "false") ) { contentPage.includeInChildPagesSiteMap = false; } if ( (attributeCollection["allowBrowserCaching"] != null) && (attributeCollection["allowBrowserCaching"].Value.ToLower() == "false") ) { contentPage.allowBrowserCaching = false; } if ( (attributeCollection["showChildPageBreadcrumbs"] != null) && (attributeCollection["showChildPageBreadcrumbs"].Value.ToLower() == "true") ) { contentPage.showChildPageBreadcrumbs = true; } if ( (attributeCollection["showHomeCrumb"] != null) && (attributeCollection["showHomeCrumb"].Value.ToLower() == "true") ) { contentPage.showHomeCrumb = true; } if ( (attributeCollection["showChildPagesSiteMap"] != null) && (attributeCollection["showChildPagesSiteMap"].Value.ToLower() == "true") ) { contentPage.showChildPagesSiteMap = true; } if ( (attributeCollection["hideFromAuthenticated"] != null) && (attributeCollection["hideFromAuthenticated"].Value.ToLower() == "true") ) { contentPage.hideFromAuthenticated = true; } if ( (attributeCollection["enableComments"] != null) && (attributeCollection["enableComments"].Value.ToLower() == "true") ) { contentPage.enableComments = true; } if (attributeCollection["bodyCssClass"] != null) { contentPage.bodyCssClass = attributeCollection["bodyCssClass"].Value; } if (attributeCollection["menuCssClass"] != null) { contentPage.menuCssClass = attributeCollection["menuCssClass"].Value; } foreach (XmlNode contentFeatureNode in node.ChildNodes) { if (contentFeatureNode.Name == "contentFeature") { ContentPageItem.LoadPageItem( contentPage, contentFeatureNode); } } XmlNode childPagesNode = null; foreach (XmlNode n in node.ChildNodes) { if (n.Name == "childPages") { childPagesNode = n; break; } } if (parentPage == null) { contentPageConfig.ContentPages.Add(contentPage); } else { parentPage.ChildPages.Add(contentPage); } if (childPagesNode != null) { foreach (XmlNode c in childPagesNode.ChildNodes) { if (c.Name == "page") { LoadPage(contentPageConfig, c, contentPage); } } } }