예제 #1
0
        public Menu Load()
        {
            Menu menu = new Menu();

            try
            {
                string fileName = Path.Combine(HostingEnvironment.MapPath("/App_Data"), "Menu.xml");

                XDocument document = XDocument.Load(fileName);

                if (document != null)
                {
                    XElement root = document.Element("menu");

                    if (root != null)
                    {
                        menu.DefaultIcon = this.GetAttrValue(root, "defaulticon");

                        foreach (XElement item in root.Elements())
                        {
                            this.ItemParse(item, menu.Items);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                throw e;
            }

            return menu;
        }
예제 #2
0
        private Menu FilterEmpty(Menu menu)
        {
            Action<MenuItem> func = null;
            func = menuItem =>
            {
                List<MenuItem> items = new List<MenuItem>();

                for (int i = 0; i < menuItem.Items.Count; i++)
                {
                    MenuItem item = menuItem.Items[i];

                    if (item.Items.SelectRecursive(x => x.Items, x => x.Item.Title != "-").Any())
                    {
                        items.Add(item);

                        func(item);
                    }
                    else if (item.Items.Count == 0 && item.Title != "-" && (!String.IsNullOrEmpty(item.URL) || !String.IsNullOrEmpty(item.Mnemonic)))
                    {
                        items.Add(item);
                    }
                    else if (item.Title == "-" && i < menuItem.Items.Count - 1 && menuItem.Items[i + 1].Title != "-")
                    {
                        items.Add(item);
                    }
                }

                menuItem.Items = items;
            };

            foreach (var item in menu.Items)
            {
                func(item);
            }

            return menu;
        }