/// <summary> /// Default constructor calls base constructor with parameters for templatecontrol, /// templatepath and stylesheet. /// </summary> public ModuleAdminBasePage() : base("ModuleAdminTemplate.ascx", "~/Controls/", "~/Admin/Css/Admin.css") { this._node = null; this._section = null; this._moduleLoader = Container.Resolve<ModuleLoader>(); }
/// <summary> /// Get all articles for a given section. /// </summary> /// <param name="section"></param> /// <param name="sortBy"></param> /// <param name="sortDirection"></param> /// <returns></returns> public IList GetAllArticlesBySection(Section section, SortBy sortBy, SortDirection sortDirection) { string hql = "from Article a left join fetch a.Category where a.Section.Id = :sectionId " + GetOrderByClause(sortBy, sortDirection, "a"); IQuery q = this._sessionManager.OpenSession().CreateQuery(hql); q.SetInt32("sectionId", section.Id); return q.List(); }
/// <summary> /// Default constructor calls base constructor with parameters for templatecontrol, /// templatepath and stylesheet. /// </summary> public ModuleAdminBasePage() : base("ModuleAdminTemplate.ascx", "~/Modules/Shared/WebForms/Controls/", "~/Modules/Shared/WebForms/Css/ModuleAdmin.css") { this._node = null; this._section = null; this._moduleLoader = Container.Resolve<ModuleLoader>(); this._searchService = Container.Resolve<ISearchService>(); }
public void DeleteSection(Section section, ModuleBase module) { // Delete module content if the connected module allows this module.DeleteModuleContent(); // Remove connections this._commonDao.DeleteObject(section); // Invalidate cache this._commonDao.RemoveCollectionFromCache("Cuyahoga.Core.Domain.Node.Sections"); }
/// <summary> /// Get the full url of a Section with the host url resolved via the Site property. /// </summary> /// <param name="section"></param> /// <returns></returns> public static string GetFullUrlFromSectionViaSite(Section section) { if (section.Node != null) { return Text.EnsureTrailingSlash(section.Node.Site.SiteUrl) + section.Id.ToString() + "/section.aspx"; } else { return null; } }
public void AttachSectionToTemplate(Section section, Template template, string placeholder) { // First test if the section is already attached. If so, remove. if (template.Sections.Any(s => s.Value == section)) { RemoveSectionFromTemplate(section, template); } // Add the section to the template template.Sections.Add(placeholder, section); this._commonDao.UpdateObject(template); // Invalidate cache this._commonDao.RemoveCollectionFromCache("Cuyahoga.Core.Domain.Template.Sections", section.Id); }
/// <summary> /// Default constructor. /// </summary> public PageEngine() { this._activeNode = null; this._activeSection = null; this._templateControl = null; this._shouldLoadContent = true; // Get services from the container. Ideally, it should be possible to register the aspx page in the container // to automatically resolve dependencies but there were memory issues with registering pages in the container. this._moduleLoader = Container.Resolve<ModuleLoader>(); this._nodeService = Container.Resolve<INodeService>(); this._siteService = Container.Resolve<ISiteService>(); this._sectionService = Container.Resolve<ISectionService>(); }
/// <summary> /// Update the search index with the contents of the section. /// </summary> /// <param name="section"></param> public static void UpdateIndexFromSection(Section section) { CuyahogaContainer container = IoC.Container as CuyahogaContainer; // Get ModuleLoader from the container. This needs to happen explicit here because // this is a static method ModuleLoader moduleLoader = container.Resolve<ModuleLoader>(); ISearchService searchService = container.Resolve<ISearchService>(); IContentItemService<ContentItem> contentItemService = container.Resolve<IContentItemService<ContentItem>>(); if (moduleLoader == null) { throw new NullReferenceException("Unable to find the ModuleLoader instance"); } string indexDir = HttpContext.Current.Server.MapPath(Config.GetConfiguration()["SearchIndexDir"]); ModuleBase module = moduleLoader.GetModuleFromSection(section); if (module is ISearchable) { ISearchable searchableModule = module as ISearchable; if (searchableModule != null) { SearchContent[] searchContentList = searchableModule.GetAllSearchableContent(); foreach (SearchContent searchContent in searchContentList) { searchService.UpdateContent(searchContent); } } } //check for IContentItems else { IList<ContentItem> contents = contentItemService.FindContentItemsBySection(section); foreach (ContentItem content in contents) { if (content is ISearchableContent) { searchService.UpdateContent(content); } } } }
/// <summary> /// Update the search index with the contents of the section. /// </summary> /// <param name="section"></param> public static void UpdateIndexFromSection(Section section) { // Get ModuleLoader from the container. This needs to happen explicit here because // this is a static method ModuleLoader moduleLoader = ContainerAccessorUtil.GetContainer()[typeof(ModuleLoader)] as ModuleLoader; if (moduleLoader == null) { throw new NullReferenceException("Unable to find the ModuleLoader instance"); } string indexDir = HttpContext.Current.Server.MapPath(Config.GetConfiguration()["SearchIndexDir"]); IndexBuilder ib = new IndexBuilder(indexDir, false); ModuleBase module = moduleLoader.GetModuleFromSection(section); if (module is ISearchable) { ib.UpdateContentFromModule(module); } ib.Close(); }
/// <summary> /// Returns a formatted url for a given section (/{ApplicationPath}/{Section.Id}/section.aspx). /// </summary> /// <param name="section"></param> /// <returns></returns> public static string GetUrlFromSection(Section section) { return GetApplicationPath() + section.Id.ToString() + "/section.aspx"; }
/// <summary> /// Returns a formatted url for a given section (http://{hostname}/{ApplicationPath}/{Section.Id}/section.aspx). /// </summary> /// <param name="section"></param> /// <returns></returns> public static string GetFullUrlFromSection(Section section) { return GetHostUrl() + GetUrlFromSection(section); }
public ConnectionEdit() { _activeSection = SectionService.GetSectionById(Int32.Parse(base.Context.Request.QueryString["SectionId"])); }
/// <summary> /// Returns a formatted url for a rss feed for a given section /// (http://{hostname}/{ApplicationPath}/{Section.Id}/rss.aspx). /// </summary> /// <param name="section"></param> /// <returns></returns> public static string GetRssUrlFromSection(Section section) { return GetHostUrl() + GetApplicationPath() + section.Id.ToString() + "/feed.aspx"; }
/// <summary> /// In the OnInit method the Node and Section of every ModuleAdminPage is set. /// An exception is thrown when one of them cannot be set. /// </summary> /// <param name="e"></param> protected override void OnInit(EventArgs e) { try { int nodeId = Int32.Parse(Context.Request.QueryString["NodeId"]); this._node = (Node)base.CoreRepository.GetObjectById(typeof(Node), nodeId); int sectionId = Int32.Parse(Context.Request.QueryString["SectionId"]); this._section = (Section)base.CoreRepository.GetObjectById(typeof(Section), sectionId); this._module = this._moduleLoader.GetModuleFromSection(this._section); } catch (Exception ex) { throw new Exception("Unable to initialize the Module Admin page because a Node or a Section could not be created.", ex); } // Check permissions if (!Context.User.Identity.IsAuthenticated) { throw new AccessForbiddenException("You are not logged in."); } else { User user = (User) Context.User.Identity; if (!user.CanEdit(this._section)) { throw new ActionForbiddenException("You are not allowed to edit the section."); } } // Optional indexing event handlers if (this._module is ISearchable && Boolean.Parse(Config.GetConfiguration()["InstantIndexing"])) { ISearchable searchableModule = (ISearchable)this._module; searchableModule.ContentCreated += new IndexEventHandler(searchableModule_ContentCreated); searchableModule.ContentUpdated += new IndexEventHandler(searchableModule_ContentUpdated); searchableModule.ContentDeleted += new IndexEventHandler(searchableModule_ContentDeleted); } // Set FCKEditor context (used by some module admin pages) // It would be nicer if we could do this in the Global.asax, but there the // ultra-convenient ~/Path (ResolveUrl) isn't available :). string userFilesPath = Config.GetConfiguration()["FCKeditor:UserFilesPath"]; if (userFilesPath != null && HttpContext.Current.Application["FCKeditor:UserFilesPath"] == null) { HttpContext.Current.Application.Lock(); HttpContext.Current.Application["FCKeditor:UserFilesPath"] = ResolveUrl(userFilesPath); HttpContext.Current.Application.UnLock(); } base.OnInit(e); }
private BaseModuleControl CreateModuleControlForSection(Section section) { // Check view permissions before adding the section to the page. if (section.ViewAllowed(this.User.Identity)) { // Create the module that is connected to the section. ModuleBase module = this._moduleLoader.GetModuleFromSection(section); //this._moduleLoader.NHibernateModuleAdded -= new EventHandler(ModuleLoader_ModuleAdded); if (module != null) { if (Context.Request.PathInfo.Length > 0 && section == this._activeSection) { // Parse the PathInfo of the request because they can be the parameters // for the module that is connected to the active section. module.ModulePathInfo = Context.Request.PathInfo; } return LoadModuleControl(module); } } return null; }
protected void Page_Load(object sender, System.EventArgs e) { this.Title = "Attach section"; if (Context.Request.QueryString["SectionId"] != null) { // Get section data this._activeSection = SectionService.GetSectionById(Int32.Parse(Context.Request.QueryString["SectionId"])); } if (!this.IsPostBack) { BindSectionControls(); BindSites(); } else { if (this.ddlSites.SelectedIndex > -1) { this._selectedSite = SiteService.GetSiteById(Int32.Parse(this.ddlSites.SelectedValue)); } if (this.lbxAvailableNodes.SelectedIndex > -1) { this._selectedNode = NodeService.GetNodeById(Int32.Parse(this.lbxAvailableNodes.SelectedValue)); } } }
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> /// Get the module instance that is associated with the given section. /// </summary> /// <param name="section"></param> /// <returns></returns> public ModuleBase GetModuleFromSection(Section section) { ModuleBase module = this.GetModuleFromType(section.ModuleType); if (module != null) { module.Section = section; if (HttpContext.Current != null) { module.SectionUrl = UrlHelper.GetUrlFromSection(section); } module.ReadSectionSettings(); } return module; }
private SectionViewData BuildSectionViewData(Section section) { var sectionViewData = new SectionViewData(section); var module = _moduleLoader.GetModuleFromSection(section); if (module is IActionProvider) { sectionViewData.OutboundActions = ((IActionProvider) module).GetOutboundActions(); } if (module is IActionConsumer) { sectionViewData.InboundActions = ((IActionConsumer)module).GetInboundActions(); } return sectionViewData; }
private void Page_Load(object sender, System.EventArgs e) { if (Context.Request.QueryString["SectionId"] != null) { this.Title = "Add connection"; // Get section data this._activeSection = (Section)base.CoreRepository.GetObjectById(typeof(Section), Int32.Parse(Context.Request.QueryString["SectionId"])); ModuleBase moduleInstance = base.ModuleLoader.GetModuleFromSection(this._activeSection); if (moduleInstance is IActionProvider) { this._activeActionProvider = moduleInstance as IActionProvider; if (! this.IsPostBack) { BindSection(); BindCompatibleSections(); } } else { ShowError("The module that is connected to the section doesn't support outgoing connections."); } } }
/// <summary> /// Remove a section from the node and recalculate position of adjacent sections (with the same placeholder). /// </summary> /// <param name="sectionToRemove"></param> public virtual void RemoveSection(Section sectionToRemove) { this.Sections.Remove(sectionToRemove); sectionToRemove.Node = null; sectionToRemove.PlaceholderId = null; sectionToRemove.Position = -1; int position = 0; foreach (Section section in this.Sections) { if (section.PlaceholderId == sectionToRemove.PlaceholderId) { section.Position = position; position++; } } }
/// <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(); }
/// <summary> /// Get all templates where the given section is connected to. /// </summary> /// <param name="section"></param> /// <returns></returns> public virtual IList GetTemplatesBySection(Section section) { string hql = "from Template t where :section in elements(t.Sections)"; IQuery q = this._activeSession.CreateQuery(hql); q.SetParameter("section", section); return q.List(); }
/// <summary> /// Indicates if the user has view permissions for a certain Section. /// </summary> /// <param name="section"></param> /// <returns></returns> public virtual bool CanView(Section section) { foreach (Permission p in section.SectionPermissions) { if (p.ViewAllowed && IsInRole(p.Role)) { return true; } } return false; }
/// <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> /// Get the full url of a Section with the host url resolved via the Site property. /// </summary> /// <param name="section"></param> /// <returns></returns> public static string GetFullUrlFromSectionViaSite(Section section) { return UrlUtil.GetFullUrlFromSectionViaSite(section); }
/// <summary> /// Loads aan existing Section from the database or creates a new one if the SectionId = -1 /// </summary> private void LoadSection() { // NOTE: Called from OnInit! if (Context.Request.QueryString["SectionId"] != null) { if (Int32.Parse(Context.Request.QueryString["SectionId"]) == -1) { // Create a new section instance this._activeSection = new Section(); this._activeSection.Node = this.ActiveNode; if (! this.IsPostBack) { this._activeSection.CopyRolesFromNode(); } } else { // Get section data this._activeSection = (Section)base.CoreRepository.GetObjectById(typeof(Section), Int32.Parse(Context.Request.QueryString["SectionId"])); } } // Preload available ModuleTypes because we might need them to display the CustomSettings // of the first ModuleType if none is selected (when adding a brand new Section). this._availableModuleTypes = base.CoreRepository.GetAll(typeof(ModuleType), "Name"); // Create the controls for the ModuleType-specific settings. CreateCustomSettings(); }
/// <summary> /// Returns a formatted url for a rss feed for a given section /// (http://{hostname}/{ApplicationPath}/{Section.Id}/rss.aspx). /// </summary> /// <param name="section"></param> /// <returns></returns> public static string GetRssUrlFromSection(Section section) { return UrlUtil.GetRssUrlFromSection(section); }
public IList GetTemplatesBySection(Section section) { ISession session = this._sessionManager.OpenSession(); string hql = "from Template t where :section in elements(t.Sections)"; IQuery q = session.CreateQuery(hql); q.SetParameter("section", section); return q.List(); }
/// <summary> /// Load the content and the template as early as possible, so everything is in place before /// modules handle their own ASP.NET lifecycle events. /// </summary> /// <param name="e"></param> protected override void OnInit(EventArgs e) { base.OnInit(e); // Set context this._currentContext = Container.Resolve<ICuyahogaContext>(); // Load the current site string currentSiteUrl = UrlUtil.GetSiteUrl(); if (this.CurrentSite == null) { throw new SiteNullException("No site found at " + currentSiteUrl); } // Check if we're browsing via an alias. If so get the optional entry node. Node entryNode = null; if (currentSiteUrl != this.CurrentSite.SiteUrl.ToLower()) { SiteAlias siteAlias = this._siteService.GetSiteAliasByUrl(currentSiteUrl); if (siteAlias != null) { entryNode = siteAlias.EntryNode; } } // Load the active node // Query the cache by SectionId, ShortDescription and NodeId. if (Context.Request.QueryString["SectionId"] != null) { try { this._activeSection = this._sectionService.GetSectionById(Int32.Parse(Context.Request.QueryString["SectionId"])); this._activeNode = this._activeSection.Node; } catch { throw new SectionNullException("Section not found: " + Context.Request.QueryString["SectionId"]); } } else if (Context.Request.QueryString["ShortDescription"] != null) { this._activeNode = this._nodeService.GetNodeByShortDescriptionAndSite(Context.Request.QueryString["ShortDescription"], this.CurrentSite); } else if (Context.Request.QueryString["NodeId"] != null) { this._activeNode = this._nodeService.GetNodeById(Int32.Parse(Context.Request.QueryString["NodeId"])); } else if (entryNode != null) { this._activeNode = entryNode; } else { // Can't load a particular node, so the root node has to be the active node // Maybe we have culture information stored in a cookie, so we might need a different // root Node. string currentCulture = this.CurrentSite.DefaultCulture; if (Context.Request.Cookies["CuyahogaCulture"] != null) { currentCulture = Context.Request.Cookies["CuyahogaCulture"].Value; } this._activeNode = this._nodeService.GetRootNodeByCultureAndSite(currentCulture, this.CurrentSite); } // Raise an exception when there is no Node found. It will be handled by the global error handler // and translated into a proper 404. if (this._activeNode == null) { throw new NodeNullException(String.Format(@"No node found with the following parameters: NodeId: {0}, ShortDescription: {1}, SectionId: {2}" , Context.Request.QueryString["NodeId"] , Context.Request.QueryString["ShortDescription"] , Context.Request.QueryString["SectionId"])); } this._rootNode = this._activeNode.NodePath[0]; // Set culture // TODO: fix this because ASP.NET pages are not guaranteed to run in 1 thread (how?). Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(this._activeNode.Culture); Thread.CurrentThread.CurrentUICulture = CultureInfo.CreateSpecificCulture(this._activeNode.Culture); // Check node-level security if (! this._activeNode.ViewAllowed(this.User.Identity)) { throw new AccessForbiddenException("You are not allowed to view this page."); } // Check if the active node is a link. If so, redirect to the link if (this._activeNode.IsExternalLink) { Response.Redirect(this._activeNode.LinkUrl); } else { if (this._shouldLoadContent) { LoadContent(); LoadMenus(); } } // Check if the current user has access to the manager. If so, add manager toolbar to the template. if (this._templateControl != null && CuyahogaContext.Current.CurrentUser != null) { if (CuyahogaContext.Current.CurrentUser.HasRight(Rights.AccessAdmin)) { this._templateControl.Form.Controls.AddAt(0, LoadControl("~/Controls/ManagerToolbar.ascx")); } if (CuyahogaContext.Current.CurrentUser.CanEdit(this.ActiveNode)) { this._templateControl.Form.Controls.Add(LoadControl("~/Controls/InlineEditing.ascx")); } } }