public WindowEntity GetWindowEntity(string id) { //首先尝试从缓存中获取 XElement cachingElement = (XElement)_cachingService.GetData(id); string strEntity; if (cachingElement == null) { string file = Path.Combine(Constant.PACKAGE_WINDOW_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(); } WindowEntity entity = _windowElementContainer.CreateWindowEntity(); entity.FromXml(strEntity); return(entity); }
/// <summary> /// 获取枚举 /// 可能返回 null /// </summary> /// <param name="id"></param> /// <returns></returns> public EnumEntity GetEnumEntity(string id) { //首先尝试从缓存中获取 XElement cachingElement = (XElement)_cachingService.GetData(id); string strEntity; if (cachingElement == null) { string file = Path.Combine(Constant.PACKAGE_DICTIONARY_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(); } EnumEntityDev enumEntity = new EnumEntityDev(); enumEntity.FromXml(strEntity); return(enumEntity); }
/// <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> /// <param name="resourceName"></param> /// <returns></returns> public Stream GetStream(string resourceName) { if (String.IsNullOrEmpty(resourceName)) { Debug.Assert(false, "resourceName 为空"); throw new ArgumentNullException(); } Stream stream = (Stream)_cachingService.GetData(resourceName); if (stream == null) { string file = Path.Combine(Constant.PACKAGE_RESOURCE_FOLDER, resourceName); if (_packageService.Current.Container(file) == false) { Debug.Assert(false, resourceName + " 不存在"); throw new FileNotFoundException(); } stream = _packageService.Current.GetFileStream(file); _cachingService.Add(resourceName, stream); } return(stream); }
/// <summary> /// 获取一个工具栏项实例(根据Id) /// </summary> /// <param name="id"></param> /// <returns></returns> public ToolStripItemAbstract GetEntity(string id) { XElement entityElement = (XElement)_cachingService.GetData(id); string strEntity; if (entityElement == null) { string file = Path.Combine(Constant.PACKAGE_NAVIGATION_TOOLSTRIP_FOLDER, id); bool fileExist = _packageService.Current.Container(file); Debug.Assert(fileExist, "工具栏项文件不存在"); if (fileExist == false) { return(null); } strEntity = _packageService.Current.GetFileContent(file); entityElement = XElement.Parse(strEntity); _cachingService.Add(id, entityElement); } else { strEntity = entityElement.ToString(); } int controlType = Convert.ToInt32(entityElement.Element("ControlType").Value); ToolStripItemAbstract entity = _toolStripItemEntityTypesFactory.CreateInstance(controlType); if (entity == null) { Debug.Assert(false, "_toolStripItemsContainer.Create(controlType) 失败,返回了null"); throw new Exception(); } entity.FromXml(strEntity); return(entity); }
public Data GetData() => _cachingService.GetData();