/// <summary> /// 获取一个菜单项实例(根据Id) /// 包括其所有子项 /// </summary> /// <param name="id"></param> /// <returns></returns> public MenuEntity GetMenuEntity(string id) { XElement cachingElement = (XElement)_cachingService.GetData(id); string strEntity; if (cachingElement == null) { string file = Path.Combine(Constant.PACKAGE_NAVIGATION_MENUSTRIP_FOLDER, id); bool fileExist = _packageService.Current.Container(file); Debug.Assert(fileExist, "菜单文件不存在"); if (fileExist == false) { return(null); } strEntity = _packageService.Current.GetFileContent(file); XElement entityElement = XElement.Parse(strEntity); _cachingService.Add(id, entityElement); } else { strEntity = cachingElement.ToString(); } MainMenuEntityDev entity = new MainMenuEntityDev(); entity.FromXml(strEntity); entity.Menus.AddRange(GetMenuEntityList(entity.Id).ToArray()); return(entity); }
/// <summary> /// 获取顶层菜单集合 /// 并递归构建菜单的所有子级 /// </summary> /// <returns></returns> public MenuEntityCollection GetMainMenuEntityCollection() { //先从索引文件中取出所有ParentId==""的顶层菜单 //然后递归构建所有子级菜单 MenuEntityCollection collection = new MenuEntityCollection(); foreach (XElement element in _indexXml.XPathSelectElements( String.Format(XPATH_Index_SelectMenuStrip_ByParentId, String.Empty))) { MainMenuEntityDev menu = (MainMenuEntityDev)GetMenuEntity(element.Attribute("Id").Value); collection.Add(menu); } return(collection); }
/// <summary> /// 获取属于指定菜单(Id)的子菜单项列表 /// </summary> /// <param name="parentId"></param> /// <returns></returns> public List <MenuEntity> GetMenuEntityList(string parentId) { XElement[] entityElements = _indexXml.XPathSelectElements( String.Format(XPATH_Index_SelectMenuStrip_ByParentId, parentId)).ToArray(); List <MenuEntity> list = new List <MenuEntity>(); foreach (XElement element in entityElements) { MainMenuEntityDev entity = (MainMenuEntityDev)GetMenuEntity(element.Attribute("Id").Value); if (entity != null) { list.Add(entity); } } return(list); }
public static void CheckWarning(MainMenuEntityDev entity) { entity.Warning.Clear(); WarningCheckerHelper.EventsValidate(entity); }