public static void LoadLinks( ContentAdminLinksConfiguration config, XmlNode documentElement) { if (HttpContext.Current == null) { return; } if (documentElement.Name != "adminMenuLinks") { return; } foreach (XmlNode node in documentElement.ChildNodes) { if (node.Name == "adminMenuLink") { ContentAdminLink item = new ContentAdminLink(); XmlAttributeCollection attributeCollection = node.Attributes; if (attributeCollection["resourceFile"] != null) { item.resourceFile = attributeCollection["resourceFile"].Value; } if (attributeCollection["resourceKey"] != null) { item.resourceKey = attributeCollection["resourceKey"].Value; } if (attributeCollection["cssClass"] != null) { item.cssClass = attributeCollection["cssClass"].Value; } if (attributeCollection["url"] != null) { item.url = attributeCollection["url"].Value; } if (attributeCollection["visibleToRoles"] != null) { item.visibleToRoles = attributeCollection["visibleToRoles"].Value; } config.AdminLinks.Add(item); } } }
public static void LoadLinks( ContentAdminLinksConfiguration config, XmlNode documentElement) { if (HttpContext.Current == null) return; if (documentElement.Name != "adminMenuLinks") return; foreach (XmlNode node in documentElement.ChildNodes) { if (node.Name == "adminMenuLink") { ContentAdminLink item = new ContentAdminLink(); XmlAttributeCollection attributeCollection = node.Attributes; if (attributeCollection["resourceFile"] != null) { item.resourceFile = attributeCollection["resourceFile"].Value; } if (attributeCollection["resourceKey"] != null) { item.resourceKey = attributeCollection["resourceKey"].Value; } if (attributeCollection["cssClass"] != null) { item.cssClass = attributeCollection["cssClass"].Value; } if (attributeCollection["url"] != null) { item.url = attributeCollection["url"].Value; } if (attributeCollection["visibleToRoles"] != null) { item.visibleToRoles = attributeCollection["visibleToRoles"].Value; } config.AdminLinks.Add(item); } } }
public static ContentAdminLinksConfiguration GetConfig(int siteId) { ContentAdminLinksConfiguration config = null; string cacheKey = "ContentAdminLinksConfiguration-" + siteId.ToString(); if ( (HttpRuntime.Cache[cacheKey] != null) && (HttpRuntime.Cache[cacheKey] is ContentAdminLinksConfiguration) ) { return((ContentAdminLinksConfiguration)HttpRuntime.Cache[cacheKey]); } else { config = new ContentAdminLinksConfiguration(); String configFolderName = "~/Setup/initialcontent/supplementaladminmenulinks"; string pathToConfigFolder = HttpContext.Current.Server.MapPath(configFolderName); if (!Directory.Exists(pathToConfigFolder)) { return(config); } DirectoryInfo directoryInfo = new DirectoryInfo(pathToConfigFolder); FileInfo[] files = directoryInfo.GetFiles("*.config"); foreach (FileInfo fileInfo in files) { XmlDocument configFile = new XmlDocument(); configFile.Load(fileInfo.FullName); ContentAdminLink.LoadLinksFromXml( config, configFile.DocumentElement); } // now look for site specific links configFolderName = "~/Data/Sites/" + siteId.ToInvariantString() + "/supplementaladminmenulinks"; pathToConfigFolder = HttpContext.Current.Server.MapPath(configFolderName); if (Directory.Exists(pathToConfigFolder)) { directoryInfo = new DirectoryInfo(pathToConfigFolder); files = directoryInfo.GetFiles("*.config"); foreach (FileInfo fileInfo in files) { XmlDocument configFile = new XmlDocument(); configFile.Load(fileInfo.FullName); ContentAdminLink.LoadLinksFromXml( config, configFile.DocumentElement); } } // cache can be cleared by touching Web.config CacheDependency cacheDependency = new CacheDependency(HttpContext.Current.Server.MapPath("~/Web.config")); HttpRuntime.Cache.Insert( cacheKey, config, cacheDependency, DateTime.Now.AddYears(1), TimeSpan.Zero, CacheItemPriority.Default, null); return((ContentAdminLinksConfiguration)HttpRuntime.Cache[cacheKey]); } }
public static void LoadLinksFromXml( ContentAdminLinksConfiguration config, XmlNode documentElement) { if (HttpContext.Current == null) { return; } if (documentElement.Name != "adminMenuLinks") { return; } foreach (XmlNode node in documentElement.ChildNodes) { if (node.Name == "adminMenuLink") { ContentAdminLink item = new ContentAdminLink(); XmlAttributeCollection attributeCollection = node.Attributes; if (attributeCollection["resourceFile"] != null) { item.ResourceFile = attributeCollection["resourceFile"].Value; } if (attributeCollection["resourceKey"] != null) { item.ResourceKey = attributeCollection["resourceKey"].Value; } if (attributeCollection["cssClass"] != null) { item.CssClass = attributeCollection["cssClass"].Value; } if (attributeCollection["iconCssClass"] != null) { item.IconCssClass = attributeCollection["iconCssClass"].Value; } if (attributeCollection["url"] != null) { item.Url = WebUtils.ResolveUrl(attributeCollection["url"].Value); } if (attributeCollection["visibleToRoles"] != null) { item.visibleToRoles = attributeCollection["visibleToRoles"].Value; } if (attributeCollection["sortOrder"] != null) { item.SortOrder = Convert.ToInt32(attributeCollection["sortOrder"].Value); } if (attributeCollection["parent"] != null) { item.Parent = attributeCollection["parent"].Value; } if (WebUser.IsInRoles(item.visibleToRoles)) { config.AdminLinks.Add(item); } } } }