예제 #1
0
        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);
        }
예제 #2
0
        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);
                }
            }
        }
예제 #3
0
 public void AddMapping(string siteKey, UrlMappingItem item)
 {
     _manualAdded.Add(item);
     _coll.Merge(item);
 }