public static UrlMappingItemCollection Combin(UrlMappingItemCollection first, UrlMappingItemCollection second) { UrlMappingItemCollection col = new UrlMappingItemCollection(); // first things first foreach (var item in first) { var configed = second.FindByAction(item.Id, item.Action, item.UrlTemplate); if (configed == null) { col.Add(item); } else { if (second.Remove(configed)) { col.Add(configed); } else { col.Add(item); } } } col.AddRange(second); return(col); }
/// <summary> /// Refreshes the internally-cached collection of URL templates and redirection mappings. /// </summary> protected void RefreshUrlMappingData() { if (_coll != null) { _coll.Clear(); } else { _coll = new UrlMappingItemCollection(); } string file = HttpContext.Current.Server.MapPath(config.UrlMappingFile); ParseXml(file, _coll, MenuItems, config.IncomingQueryStringBehavior); _coll.Merge(_manualAdded); // using a file dependency, generate it now if (File.Exists(file)) { _fileDependency = new CacheDependency(file); HttpContext.Current.Cache.Insert(kCACHE_KEY, "dummyValue", _fileDependency, Cache.NoAbsoluteExpiration, Cache.NoSlidingExpiration, CacheItemPriority.High, null); } // remember the refresh time _latestRefresh = DateTime.Now; }
public void Merge(UrlMappingItemCollection items) { UrlMappingItemCollection col = Combin(items, this); Clear(); AddRange(col); }
public static void ParseXml(string file, UrlMappingItemCollection routes, Dictionary <int, NavigationItem> menuItems, IncomingQueryStringBehavior incomingQueryStringBehavior) { if (!File.Exists(file)) { return; } XmlDocument xml = new XmlDocument(); try { xml.Load(file); } catch (Exception ex) { throw new UrlMappingException("The error occurred while loading the route files. A virtual path is required and the file must be well-formed.", ex); } menuItems.Clear(); int i = -1, j = -1, k = -1; foreach (XmlNode node in xml.DocumentElement.ChildNodes) { if (node.Name == "menu") { i++; NavigationItem menuItem = getMenuItem(node); menuItem.Children = new Dictionary <int, NavigationItem>(); menuItems[i] = menuItem; foreach (XmlNode subNode in node.ChildNodes) { if (subNode.Name == "menu") { j++; NavigationItem sub_menuItem = getMenuItem(subNode); sub_menuItem.Children = new Dictionary <int, NavigationItem>(); menuItems[i].Children[j] = sub_menuItem; foreach (XmlNode subsubNode in subNode.ChildNodes) { if (subsubNode.Name == "menu") { k++; NavigationItem subsub_menuItem = getMenuItem(subsubNode); sub_menuItem.Children[k] = subsub_menuItem; foreach (XmlNode last_node in subsubNode.ChildNodes) { if (last_node.Name == "url") { UrlMappingItem url = getUrlInfo(last_node, subsub_menuItem, i, j, k, incomingQueryStringBehavior); routes.Add(url); } } } else if (subsubNode.Name == "url") { UrlMappingItem url = getUrlInfo(subsubNode, sub_menuItem, i, j, -1, incomingQueryStringBehavior); routes.Add(url); } } } else if (subNode.Name == "url") { UrlMappingItem url = getUrlInfo(subNode, menuItem, i, -1, -1, incomingQueryStringBehavior); routes.Add(url); } } } else if (node.Name == "url") { UrlMappingItem url = getUrlInfo(node, new NavigationItem(), -1, -1, -1, incomingQueryStringBehavior); routes.Add(url); } } }