Beispiel #1
0
        internal void LoadConfig(MemuConfig config)
        {
            List <ManagementSubMenu> items = new List <ManagementSubMenu>(_list.Count);

            for (int i = 0; i < _list.Count; ++i)
            {
                if (!config.IsHideSubMenu(_channel, _number, i))
                {
                    items.Add(_list[i]);
                }
            }
            _list = items;
        }
Beispiel #2
0
        private static List <KeyValuePair <ManagementMainMenu, List <ManagementMenu> > > BuildMenus(Controller ctl)
        {
            List <KeyValuePair <ManagementMainMenu, List <ManagementMenu> > > list = new List <KeyValuePair <ManagementMainMenu, List <ManagementMenu> > >(6);

            list.Add(new KeyValuePair <ManagementMainMenu, List <ManagementMenu> >(new ManagementMainMenu("全局", "static/images/icon01.png"), new List <ManagementMenu>()));
            list.Add(new KeyValuePair <ManagementMainMenu, List <ManagementMenu> >(new ManagementMainMenu("功能", "static/images/icon06.png"), new List <ManagementMenu>()));
            list.Add(new KeyValuePair <ManagementMainMenu, List <ManagementMenu> >(new ManagementMainMenu("栏目", "static/images/icon05.png"), new List <ManagementMenu>()));
            list.Add(new KeyValuePair <ManagementMainMenu, List <ManagementMenu> >(new ManagementMainMenu("模板", "static/images/icon04.png"), new List <ManagementMenu>()));
            list.Add(new KeyValuePair <ManagementMainMenu, List <ManagementMenu> >(new ManagementMainMenu("用户", "static/images/icon03.png"), new List <ManagementMenu>()));
            list.Add(new KeyValuePair <ManagementMainMenu, List <ManagementMenu> >(new ManagementMainMenu("数据", "static/images/icon02.png"), new List <ManagementMenu>()));

            int             index;
            Type            type;
            string          asm;
            ManagementMenus instance;
            KeyValuePair <ManagementMainMenu, List <ManagementMenu> > pair;
            DirectoryInfo dir = new DirectoryInfo(ctl.Context.Server.MapPath("~/Bin"));

            foreach (FileInfo file in dir.GetFiles("*.dll", SearchOption.TopDirectoryOnly))
            {
                index = file.Name.LastIndexOf('.');
                asm   = file.Name.Substring(0, index);
                type  = Type.GetType(string.Concat(asm, asm.EndsWith(".Management") ? string.Empty : ".Management", ".MenuList,", asm), false, true);
                if (type != null)
                {
                    instance = Activator.CreateInstance(type) as ManagementMenus;
                    if (instance != null && instance.Menus != null && instance.Menus.Count > 0)
                    {
                        foreach (ManagementMenu item in instance.Menus)
                        {
                            pair = list[item.Channel];
                            pair.Value.Add(item);
                        }
                    }
                }
            }

            foreach (KeyValuePair <ManagementMainMenu, List <ManagementMenu> > item in list)
            {
                item.Value.Sort(new Comparison <ManagementMenu>(Compare));
                for (int i = 0; i < item.Value.Count; ++i)
                {
                    item.Value[i].Number = i;
                }
            }

            ManagementMenu menu;
            MemuConfig     config = new MemuConfig();

            for (int i = list.Count - 1; i >= 0; --i)
            {
                pair = list[i];
                if (config.IsHideMainMenu(i))
                {
                    list.RemoveAt(i);
                }
                else
                {
                    pair.Key.InitMenu(ctl);
                    for (int j = pair.Value.Count - 1; j >= 0; --j)
                    {
                        if (config.IsHideMenu(i, j))
                        {
                            pair.Value.RemoveAt(j);
                        }
                        else
                        {
                            menu = pair.Value[j];
                            for (int k = menu.Items.Count - 1; k >= 0; --k)
                            {
                                if (config.IsHideSubMenu(i, j, k))
                                {
                                    menu.Items.RemoveAt(k);
                                }
                            }
                        }
                    }
                }
            }

            return(list);
        }