/// <summary> /// Creates a new node that comes under the given parent node and copies the contents of this node. /// </summary> /// <param name="parentNode"></param> /// <returns>The newly created node.</returns> public virtual Node Copy(Node parentNode) { Node newNode = new Node(); newNode.Site = this.Site; newNode.Title = "Copy of " + this.Title; newNode.ParentNode = parentNode; newNode.CreateShortDescription(); newNode.Culture = parentNode.Culture; newNode.Template = this.Template; newNode.ShowInNavigation = this.ShowInNavigation; newNode.LinkUrl = this.LinkUrl; newNode.LinkTarget = this.LinkTarget; newNode.MetaDescription = this.MetaDescription; newNode.MetaKeywords = this.MetaKeywords; // Add to children parent newNode.Position = parentNode.ChildNodes.Count; newNode.ParentNode = parentNode; parentNode.ChildNodes.Add(newNode); // Apply permissions from parent node newNode.CopyRolesFromParent(); // Add sections foreach (Section section in this.Sections) { Section newSection = section.Copy(); newNode.Sections.Add(newSection); newSection.Node = newNode; newSection.CopyRolesFromNode(); } return(newNode); }
/// <summary> /// Add a new section to the Node. /// </summary> /// <param name="section"></param> public virtual void AddSection(Section section) { section.Node = this; // First, try to determine the position of the section. if (section.PlaceholderId != null) { section.CalculateNewPosition(); } // Add to collection. this.Sections.Add(section); // Apply security section.CopyRolesFromNode(); }
private void CopySectionsFromNode(Node node, Node nodeTarget) { foreach (Section section in node.Sections) { Section newsection = new Section(); newsection.Node = nodeTarget; newsection.CacheDuration = section.CacheDuration; foreach (KeyValuePair<string, Section> entry in section.Connections) { newsection.Connections.Add(entry.Key, entry.Value); } newsection.ModuleType = section.ModuleType; newsection.PlaceholderId = section.PlaceholderId; newsection.Position = section.Position; // copy module settings foreach (DictionaryEntry sectionitem in section.Settings) { newsection.Settings.Add(sectionitem.Key, sectionitem.Value); } // newsection.Settings = section.Settings; if (section.ModuleType.Name.ToLower() == "html") { } newsection.ShowTitle = section.ShowTitle; newsection.Title = section.Title; newsection.CopyRolesFromNode(); newsection.CalculateNewPosition(); //nodeTarget.Sections.Add(newsection); SectionService.SaveSection(newsection); } }
/// <summary> /// Copies the sections from node. /// </summary> /// <param name="node">The node.</param> /// <param name="nodeTarget">The node target.</param> private void CopySectionsFromNode( Node node, Node nodeTarget ) { foreach( Section section in node.Sections ) { Section newsection = new Section(); newsection.Node = nodeTarget; newsection.CacheDuration = section.CacheDuration; foreach( DictionaryEntry sectionconnection in section.Connections ) { newsection.Connections.Add( sectionconnection.Key, sectionconnection.Value ); } newsection.ModuleType = section.ModuleType; newsection.PlaceholderId = section.PlaceholderId; newsection.Position = section.Position; // copy module settings foreach( DictionaryEntry sectionitem in section.Settings ) { newsection.Settings.Add( sectionitem.Key, sectionitem.Value ); } // newsection.Settings = section.Settings; if( section.ModuleType.Name.ToLower() == "html" ) { } newsection.ShowTitle = section.ShowTitle; newsection.Title = section.Title; newsection.CopyRolesFromNode(); newsection.CalculateNewPosition(); //nodeTarget.Sections.Add(newsection); base.CoreRepository.SaveObject( newsection ); //foreach (SectionPermission sp in section.SectionPermissions) //{ // SectionPermission secperm = new SectionPermission(); // secperm.Role = sp.Role; // secperm.Section = newsection; // secperm.EditAllowed = sp.EditAllowed; // secperm.ViewAllowed = sp.ViewAllowed; // newsection.SectionPermissions.Add(secperm); //} } }
/// <summary> /// Add a new section to the Node. /// </summary> /// <param name="section"></param> public virtual void AddSection(Section section) { section.Node = this; // First, try to determine the position of the section. if (section.PlaceholderId != null) { section.CalculateNewPosition(); } // Add to collection. this.Sections.Add(section); // Apply security section.CopyRolesFromNode(); }
private void CreateSite() { Role defaultAuthenticatedRole = this._commonDao.GetObjectByDescription(typeof(Role), "Name", "Authenticated user") as Role; // Site Site site = new Site(); site.Name = "Cuyahoga Sample Site"; site.SiteUrl = UrlHelper.GetSiteUrl(); site.WebmasterEmail = "*****@*****.**"; site.UseFriendlyUrls = true; site.DefaultCulture = "en-US"; site.DefaultPlaceholder = "maincontent"; site.DefaultRole = defaultAuthenticatedRole; string systemTemplatePath = Server.MapPath(Config.GetConfiguration()["TemplateDir"]); this._siteService.CreateSite(site, Server.MapPath("~/SiteData"), this._commonDao.GetAll<Template>(), systemTemplatePath); // Template Template defaultTemplate = this._commonDao.GetAll<Template>().Where(t => t.Site == site && t.BasePath == "Templates/AnotherRed").Single(); site.DefaultTemplate = defaultTemplate; this._commonDao.UpdateObject(site); // Root node Node rootNode = new Node(); rootNode.Culture = site.DefaultCulture; rootNode.Position = 0; rootNode.ShortDescription = "home"; rootNode.ShowInNavigation = true; rootNode.Site = site; rootNode.Template = defaultTemplate; rootNode.Title = "Home"; IList allRoles = this._commonDao.GetAll(typeof(Role)); foreach (Role role in allRoles) { NodePermission np = new NodePermission(); np.Node = rootNode; np.Role = role; np.ViewAllowed = true; np.EditAllowed = role.HasRight(Rights.Administrator); rootNode.NodePermissions.Add(np); } this._commonDao.SaveOrUpdateObject(rootNode); // Sections on root Node Section loginSection = new Section(); loginSection.Site = site; loginSection.ModuleType = this._commonDao.GetObjectByDescription(typeof(ModuleType), "Name", "User") as ModuleType; loginSection.Title = "Login"; loginSection.CacheDuration = 0; loginSection.Node = rootNode; loginSection.PlaceholderId = "side1content"; loginSection.Position = 0; loginSection.ShowTitle = true; loginSection.Settings.Add("SHOW_EDIT_PROFILE", "True"); loginSection.Settings.Add("SHOW_RESET_PASSWORD", "True"); loginSection.Settings.Add("SHOW_REGISTER", "True"); loginSection.CopyRolesFromNode(); rootNode.Sections.Add(loginSection); this._commonDao.SaveOrUpdateObject(loginSection); Section introSection = new Section(); introSection.Site = site; introSection.ModuleType = this._commonDao.GetObjectByDescription(typeof(ModuleType), "Name", "StaticHtml") as ModuleType; introSection.Title = "Welcome"; introSection.CacheDuration = 0; introSection.Node = rootNode; introSection.PlaceholderId = "maincontent"; introSection.Position = 0; introSection.ShowTitle = true; introSection.CopyRolesFromNode(); rootNode.Sections.Add(introSection); this._commonDao.SaveOrUpdateObject(introSection); // Pages Node page1 = new Node(); page1.Culture = site.DefaultCulture; page1.Position = 0; page1.ShortDescription = "page1"; page1.ShowInNavigation = true; page1.Site = site; page1.Template = defaultTemplate; page1.Title = "Articles"; page1.ParentNode = rootNode; page1.CopyRolesFromParent(); this._commonDao.SaveOrUpdateObject(page1); ModuleType articlesModuleType = this._commonDao.GetObjectByDescription(typeof(ModuleType), "Name", "Articles") as ModuleType; // Check if the articles module is installed if (articlesModuleType != null) { Section articleSection = new Section(); articleSection.Site = site; articleSection.ModuleType = articlesModuleType; articleSection.Title = "Articles"; articleSection.CacheDuration = 0; articleSection.Node = page1; articleSection.PlaceholderId = "maincontent"; articleSection.Position = 0; articleSection.ShowTitle = true; articleSection.Settings.Add("DISPLAY_TYPE", "FullContent"); articleSection.Settings.Add("ALLOW_ANONYMOUS_COMMENTS", "True"); articleSection.Settings.Add("ALLOW_COMMENTS", "True"); articleSection.Settings.Add("SORT_BY", "DateOnline"); articleSection.Settings.Add("SORT_DIRECTION", "DESC"); articleSection.Settings.Add("ALLOW_SYNDICATION", "True"); articleSection.Settings.Add("NUMBER_OF_ARTICLES_IN_LIST", "5"); articleSection.CopyRolesFromNode(); page1.Sections.Add(articleSection); this._commonDao.SaveOrUpdateObject(articleSection); } Node page2 = new Node(); page2.Culture = site.DefaultCulture; page2.Position = 1; page2.ShortDescription = "page2"; page2.ShowInNavigation = true; page2.Site = site; page2.Template = defaultTemplate; page2.Title = "Page 2"; page2.ParentNode = rootNode; page2.CopyRolesFromParent(); this._commonDao.SaveOrUpdateObject(page2); Section page2Section = new Section(); page2Section.Site = site; page2Section.ModuleType = this._commonDao.GetObjectByDescription(typeof(ModuleType), "Name", "StaticHtml") as ModuleType; page2Section.Title = "Page 2"; page2Section.CacheDuration = 0; page2Section.Node = page2; page2Section.PlaceholderId = "maincontent"; page2Section.Position = 0; page2Section.ShowTitle = true; page2Section.CopyRolesFromNode(); rootNode.Sections.Add(page2Section); this._commonDao.SaveOrUpdateObject(page2Section); // User Profile node Node userProfileNode = new Node(); userProfileNode.Culture = site.DefaultCulture; userProfileNode.Position = 2; userProfileNode.ShortDescription = "userprofile"; userProfileNode.ShowInNavigation = false; userProfileNode.Site = site; userProfileNode.Template = defaultTemplate; userProfileNode.Title = "User Profile"; userProfileNode.ParentNode = rootNode; userProfileNode.CopyRolesFromParent(); this._commonDao.SaveOrUpdateObject(userProfileNode); Section userProfileSection = new Section(); userProfileSection.Site = site; userProfileSection.ModuleType = this._commonDao.GetObjectByDescription(typeof(ModuleType), "Name", "UserProfile") as ModuleType; userProfileSection.Title = "User Profile"; userProfileSection.CacheDuration = 0; userProfileSection.Node = userProfileNode; userProfileSection.PlaceholderId = "maincontent"; userProfileSection.Position = 0; userProfileSection.ShowTitle = false; userProfileSection.CopyRolesFromNode(); userProfileNode.Sections.Add(userProfileSection); this._commonDao.SaveOrUpdateObject(userProfileSection); // Connections from Login to User Profile loginSection.Connections.Add("Register", userProfileSection); loginSection.Connections.Add("ResetPassword", userProfileSection); loginSection.Connections.Add("ViewProfile", userProfileSection); loginSection.Connections.Add("EditProfile", userProfileSection); this._commonDao.SaveOrUpdateObject(loginSection); }
private void CreateSite() { this._commonDao.Flush();//TEST User adminUser = (User) this._commonDao.GetObjectById(typeof(User), 1); //If SiteData/1/ exists then delete it if(Directory.Exists(Server.MapPath("~/SiteData/1/"))) this._fileService.DeleteDirectory(Server.MapPath("~/SiteData/1/")); #region Sections for Templates //Template defaultTemplate = this._commonDao.GetObjectByDescription(typeof(Template), "Name", "Another Red") as Template; Template defaultTemplate = this._commonDao.GetObjectByDescription(typeof(Template), "Name", "Cuyahoga") as Template; //Other templates list here Template Corporate = this._commonDao.GetObjectByDescription(typeof(Template), "Name", "Corporate") as Template; Template CityLights = this._commonDao.GetObjectByDescription(typeof(Template), "Name", "CityLights") as Template; Template ImpactDroppy = this._commonDao.GetObjectByDescription(typeof(Template), "Name", "Impact(Droppy)") as Template; #endregion Role defaultAuthenticatedRole = this._commonDao.GetObjectByDescription(typeof(Role), "Name", "Authenticated User") as Role; #region Region for default site // Site Site site = new Site(); site.Name = "Cuyahoga Sample Site"; site.SiteUrl = UrlHelper.GetSiteUrl(); site.WebmasterEmail = "*****@*****.**"; site.UseFriendlyUrls = true; site.DefaultCulture = "en-US"; site.DefaultTemplate = defaultTemplate; site.DefaultPlaceholder = "Content_Main"; site.DefaultRole = defaultAuthenticatedRole; string systemTemplatePath = Server.MapPath(Config.GetConfiguration()["TemplateDir"]); this._siteService.CreateSite(site, Server.MapPath("~/SiteData"), this._commonDao.GetAll<Template>(), systemTemplatePath); //Assign admin user to site adminUser.Sites.Add(site); this._commonDao.SaveObject(adminUser); #endregion #region Region for Templates //Menu_Sub Section Menu_Sub = new Section(); Menu_Sub.Site = site; Menu_Sub.ModuleType = this._commonDao.GetObjectByDescription(typeof(ModuleType), "Name", "Menu") as ModuleType; Menu_Sub.Title = "Menu_Sub"; Menu_Sub.CacheDuration = 0; Menu_Sub.PlaceholderId = "Navigation_Sub"; Menu_Sub.Position = 0; Menu_Sub.ShowTitle = false; Menu_Sub.Settings.Add("LAST_LEVEL", "-1"); Menu_Sub.Settings.Add("FIRST_LEVEL", "1"); Menu_Sub.Settings.Add("TYPE_RENDER", "NavigationTree"); Menu_Sub.Settings.Add("REQUIRES_JQUERY", "False"); //Menu_Main Section Menu_Main = new Section(); Menu_Main.Site = site; Menu_Main.ModuleType = this._commonDao.GetObjectByDescription(typeof(ModuleType), "Name", "Menu") as ModuleType; Menu_Main.Title = "Menu_Main"; Menu_Main.CacheDuration = 0; Menu_Main.PlaceholderId = "Navigation_Main"; Menu_Main.Position = 0; Menu_Main.ShowTitle = false; Menu_Main.Settings.Add("LAST_LEVEL", "-1"); Menu_Main.Settings.Add("FIRST_LEVEL", "0"); Menu_Main.Settings.Add("TYPE_RENDER", "NavigationTree"); Menu_Main.Settings.Add("REQUIRES_JQUERY", "True"); //Section Permissions for all sections IList allRolesSection = this._commonDao.GetAll(typeof(Role)); foreach (Role role in allRolesSection) { SectionPermission spMenu_Sub = new SectionPermission(); spMenu_Sub.Section = Menu_Sub; spMenu_Sub.Role = role; spMenu_Sub.ViewAllowed = true; spMenu_Sub.EditAllowed = role.HasRight(Rights.EditSections); Menu_Sub.SectionPermissions.Add(spMenu_Sub); SectionPermission spMenu_Main = new SectionPermission(); spMenu_Main.Section = Menu_Main; spMenu_Main.Role = role; spMenu_Main.ViewAllowed = true; spMenu_Main.EditAllowed = role.HasRight(Rights.EditSections); Menu_Main.SectionPermissions.Add(spMenu_Main); } //Save the sections this._commonDao.SaveOrUpdateObject(Menu_Sub); this._commonDao.SaveOrUpdateObject(Menu_Main); //Attach Sections to 'defaulttemplate' Sections[PlaceHolderName Key] defaultTemplate.Sections["Navigation_Sub"] = Menu_Sub; defaultTemplate.Sections["Navigation_Main"] = Menu_Main; this._commonDao.SaveOrUpdateObject(defaultTemplate); //Attach Sections to other templates Sections[PlaceHolderName Key] CityLights.Sections["Navigation_Sub"] = Menu_Sub; CityLights.Sections["Navigation_Main"] = Menu_Main; this._commonDao.SaveOrUpdateObject(CityLights); ImpactDroppy.Sections["Navigation_Sub"] = Menu_Sub; ImpactDroppy.Sections["Navigation_Main"] = Menu_Main; this._commonDao.SaveOrUpdateObject(ImpactDroppy); Corporate.Sections["Navigation_Sub"] = Menu_Sub; Corporate.Sections["Navigation_Main"] = Menu_Main; this._commonDao.SaveOrUpdateObject(ImpactDroppy); //Attach these Sections to all the sites templates foreach (Template t in site.Templates) { t.Sections["Navigation_Sub"] = Menu_Sub; t.Sections["Navigation_Main"] = Menu_Main; this._commonDao.UpdateObject(t); } #endregion // Root node Node rootNode = new Node(); rootNode.Culture = site.DefaultCulture; rootNode.Position = 0; rootNode.ShortDescription = "home"; rootNode.ShowInNavigation = true; rootNode.Site = site; rootNode.Template = site.DefaultTemplate; rootNode.Title = "Home"; IList allRoles = this._commonDao.GetAll(typeof(Role)); foreach (Role role in allRoles) { NodePermission np = new NodePermission(); np.Node = rootNode; np.Role = role; np.ViewAllowed = true; np.EditAllowed = role.HasRight(Rights.EditSections); rootNode.NodePermissions.Add(np); } this._commonDao.SaveOrUpdateObject(rootNode); // Sections on root Node Section loginSection = new Section(); loginSection.Site = site; loginSection.ModuleType = this._commonDao.GetObjectByDescription(typeof(ModuleType), "Name", "User") as ModuleType; loginSection.Title = "Login"; loginSection.CacheDuration = 0; loginSection.Node = rootNode; loginSection.PlaceholderId = "Login_Main"; loginSection.Position = 0; loginSection.ShowTitle = true; loginSection.Settings.Add("SHOW_EDIT_PROFILE", "True"); loginSection.Settings.Add("SHOW_RESET_PASSWORD", "True"); loginSection.Settings.Add("SHOW_REGISTER", "True"); loginSection.CopyRolesFromNode(); rootNode.Sections.Add(loginSection); this._commonDao.SaveOrUpdateObject(loginSection); Section introSection = new Section(); introSection.Site = site; introSection.ModuleType = this._commonDao.GetObjectByDescription(typeof(ModuleType), "Name", "StaticHtml") as ModuleType; introSection.Title = "Welcome"; introSection.CacheDuration = 0; introSection.Node = rootNode; introSection.PlaceholderId = "Content_Main"; introSection.Position = 0; introSection.ShowTitle = true; introSection.CopyRolesFromNode(); rootNode.Sections.Add(introSection); this._commonDao.SaveOrUpdateObject(introSection); // Pages Node page1 = new Node(); page1.Culture = site.DefaultCulture; page1.Position = 0; page1.ShortDescription = "page1"; page1.ShowInNavigation = true; page1.Site = site; page1.Template = site.DefaultTemplate; page1.Title = "Articles"; page1.ParentNode = rootNode; page1.CopyRolesFromParent(); this._commonDao.SaveOrUpdateObject(page1); ModuleType articlesModuleType = this._commonDao.GetObjectByDescription(typeof(ModuleType), "Name", "Articles") as ModuleType; // Check if the articles module is installed if (articlesModuleType != null) { Section articleSection = new Section(); articleSection.Site = site; articleSection.ModuleType = articlesModuleType; articleSection.Title = "Articles"; articleSection.CacheDuration = 0; articleSection.Node = page1; articleSection.PlaceholderId = "Content_Main"; articleSection.Position = 0; articleSection.ShowTitle = true; articleSection.Settings.Add("DISPLAY_TYPE", "FullContent"); articleSection.Settings.Add("ALLOW_ANONYMOUS_COMMENTS", "True"); articleSection.Settings.Add("ALLOW_COMMENTS", "True"); articleSection.Settings.Add("SORT_BY", "DateOnline"); articleSection.Settings.Add("SORT_DIRECTION", "DESC"); articleSection.Settings.Add("ALLOW_SYNDICATION", "True"); articleSection.Settings.Add("NUMBER_OF_ARTICLES_IN_LIST", "5"); articleSection.CopyRolesFromNode(); page1.Sections.Add(articleSection); this._commonDao.SaveOrUpdateObject(articleSection); } Node page2 = new Node(); page2.Culture = site.DefaultCulture; page2.Position = 1; page2.ShortDescription = "page2"; page2.ShowInNavigation = true; page2.Site = site; page2.Template = site.DefaultTemplate; page2.Title = "Page 2"; page2.ParentNode = rootNode; page2.CopyRolesFromParent(); this._commonDao.SaveOrUpdateObject(page2); Section page2Section = new Section(); page2Section.Site = site; page2Section.ModuleType = this._commonDao.GetObjectByDescription(typeof(ModuleType), "Name", "StaticHtml") as ModuleType; page2Section.Title = "Page 2"; page2Section.CacheDuration = 0; page2Section.Node = page2; page2Section.PlaceholderId = "Content_Main"; page2Section.Position = 0; page2Section.ShowTitle = true; page2Section.CopyRolesFromNode(); rootNode.Sections.Add(page2Section); this._commonDao.SaveOrUpdateObject(page2Section); // User Profile node Node userProfileNode = new Node(); userProfileNode.Culture = site.DefaultCulture; userProfileNode.Position = 2; userProfileNode.ShortDescription = "userprofile"; userProfileNode.ShowInNavigation = false; userProfileNode.Site = site; userProfileNode.Template = site.DefaultTemplate; userProfileNode.Title = "User Profile"; userProfileNode.ParentNode = rootNode; userProfileNode.CopyRolesFromParent(); this._commonDao.SaveOrUpdateObject(userProfileNode); Section userProfileSection = new Section(); userProfileSection.Site = site; userProfileSection.ModuleType = this._commonDao.GetObjectByDescription(typeof(ModuleType), "Name", "UserProfile") as ModuleType; userProfileSection.Title = "User Profile"; userProfileSection.CacheDuration = 0; userProfileSection.Node = userProfileNode; userProfileSection.PlaceholderId = "Content_Main"; userProfileSection.Position = 0; userProfileSection.ShowTitle = false; userProfileSection.CopyRolesFromNode(); userProfileNode.Sections.Add(userProfileSection); this._commonDao.SaveOrUpdateObject(userProfileSection); // Connections from Login to User Profile loginSection.Connections.Add("Register", userProfileSection); loginSection.Connections.Add("ResetPassword", userProfileSection); loginSection.Connections.Add("ViewProfile", userProfileSection); loginSection.Connections.Add("EditProfile", userProfileSection); this._commonDao.SaveOrUpdateObject(loginSection); }