PufItemManager.cs 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. using Aitex.Core.Util;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using System.Xml;
  8. namespace MECF.Framework.Common.ToolLayout
  9. {
  10. public class PufItemManager : Singleton<PufItemManager>
  11. {
  12. #region 常量
  13. /// <summary>
  14. /// 前缀
  15. /// </summary>
  16. private const string PREFIX = "PUF";
  17. #endregion
  18. #region 内部变量
  19. /// <summary>
  20. /// 字典
  21. /// </summary>
  22. private Dictionary<string,PufItem> _pufItemDictionary=new Dictionary<string, PufItem>();
  23. #endregion
  24. #region 属性
  25. /// <summary>
  26. /// 已经安装模块
  27. /// </summary>
  28. public List<string> InstalledModules { get; private set; } = new List<string>();
  29. #endregion
  30. /// <summary>
  31. /// 初始化Puf Item
  32. /// </summary>
  33. /// <param name="xmlElement"></param>
  34. public void InitializePufItem(XmlElement xmlElement)
  35. {
  36. PufItem pufItem = new PufItem();
  37. pufItem.Installed = bool.Parse(xmlElement.SelectSingleNode("Installed").InnerText);
  38. pufItem.PufID = int.Parse(xmlElement.SelectSingleNode("PufID").InnerText);
  39. string key = $"{PREFIX}{pufItem.PufID}";
  40. if(pufItem.Installed&&!InstalledModules.Contains(key))
  41. {
  42. InstalledModules.Add(key);
  43. }
  44. _pufItemDictionary[key] = pufItem;
  45. }
  46. /// <summary>
  47. /// 获取PufItem对象
  48. /// </summary>
  49. /// <param name="moduleName"></param>
  50. /// <returns></returns>
  51. public PufItem GetPufItem(string moduleName)
  52. {
  53. return _pufItemDictionary.ContainsKey(moduleName) ? _pufItemDictionary[moduleName] : null;
  54. }
  55. }
  56. }