public static List <ApplicationCategory> GetCategories() { List <ApplicationCategory> categories = null; string key = "WebApplicationCategories"; // look up in the cache if (HttpContext.Current != null) { categories = (List <ApplicationCategory>)HttpContext.Current.Cache[key]; } if (categories == null) { string catsPath = Path.Combine(ConfigSettings.WebApplicationsPath, "Applications.xml"); if (File.Exists(catsPath)) { categories = new List <ApplicationCategory>(); // parse file XmlDocument doc = new XmlDocument(); doc.Load(catsPath); XmlNodeList nodesCategories = doc.SelectNodes("categories/category"); foreach (XmlNode nodeCategory in nodesCategories) { ApplicationCategory category = new ApplicationCategory(); category.Id = nodeCategory.Attributes["id"].Value; category.Name = GetNodeValue(nodeCategory, "name", category.Id); categories.Add(category); // read applications List <string> catApps = new List <string>(); XmlNodeList nodesApps = nodeCategory.SelectNodes("applications/application"); foreach (XmlNode nodeApp in nodesApps) { catApps.Add(nodeApp.Attributes["name"].Value); } category.Applications = catApps.ToArray(); } } // place to the cache if (HttpContext.Current != null) { HttpContext.Current.Cache.Insert(key, categories, new CacheDependency(catsPath)); } } return(categories); }
public static List<ApplicationCategory> GetCategories() { List<ApplicationCategory> categories = null; string key = "WebApplicationCategories"; // look up in the cache if (HttpContext.Current != null) categories = (List<ApplicationCategory>)HttpContext.Current.Cache[key]; if (categories == null) { string catsPath = Path.Combine(ConfigSettings.WebApplicationsPath, "Applications.xml"); if (File.Exists(catsPath)) { categories = new List<ApplicationCategory>(); // parse file XmlDocument doc = new XmlDocument(); doc.Load(catsPath); XmlNodeList nodesCategories = doc.SelectNodes("categories/category"); foreach (XmlNode nodeCategory in nodesCategories) { ApplicationCategory category = new ApplicationCategory(); category.Id = nodeCategory.Attributes["id"].Value; category.Name = GetNodeValue(nodeCategory, "name", category.Id); categories.Add(category); // read applications List<string> catApps = new List<string>(); XmlNodeList nodesApps = nodeCategory.SelectNodes("applications/application"); foreach (XmlNode nodeApp in nodesApps) catApps.Add(nodeApp.Attributes["name"].Value); category.Applications = catApps.ToArray(); } } // place to the cache if (HttpContext.Current != null) HttpContext.Current.Cache.Insert(key, categories, new CacheDependency(catsPath)); } return categories; }