LinmotItemManager.cs 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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 LinmotItemManager : Singleton<LinmotItemManager>
  11. {
  12. #region 常量
  13. /// <summary>
  14. /// 前缀
  15. /// </summary>
  16. private const string PREFIX = "LNM";
  17. #endregion
  18. #region 内部变量
  19. /// <summary>
  20. /// 字典
  21. /// </summary>
  22. private Dictionary<string,LinmotItem> _linmotItemDictionary=new Dictionary<string, LinmotItem>();
  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. /// 初始化Linmot Item
  32. /// </summary>
  33. /// <param name="xmlElement"></param>
  34. public void InitializeLinmotItem(XmlElement xmlElement)
  35. {
  36. LinmotItem linmotItem = new LinmotItem();
  37. linmotItem.Installed = bool.Parse(xmlElement.SelectSingleNode("Installed").InnerText);
  38. linmotItem.LinmotID = int.Parse(xmlElement.SelectSingleNode("LinmotID").InnerText);
  39. linmotItem.SubType = xmlElement.SelectSingleNode("SubType").InnerText;
  40. linmotItem.ResetSwitchOff = int.Parse(xmlElement.SelectSingleNode("ResetSwitchOff").InnerText);
  41. linmotItem.Count = int.Parse(xmlElement.SelectSingleNode("Count").InnerText);
  42. string key = $"{PREFIX}{linmotItem.LinmotID}";
  43. if(linmotItem.Installed&&!InstalledModules.Contains(key))
  44. {
  45. InstalledModules.Add(key);
  46. }
  47. _linmotItemDictionary[key] = linmotItem;
  48. }
  49. /// <summary>
  50. /// 获取LinmotItem对象
  51. /// </summary>
  52. /// <param name="moduleName"></param>
  53. /// <returns></returns>
  54. public LinmotItem GetLinmotItem(string moduleName)
  55. {
  56. return _linmotItemDictionary.ContainsKey(moduleName) ? _linmotItemDictionary[moduleName] : null;
  57. }
  58. }
  59. }