DryerPersistentManager.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. using Aitex.Common.Util;
  2. using Aitex.Core.RT.Log;
  3. using Aitex.Core.Util;
  4. using MECF.Framework.Common.Persistent.Prewet;
  5. using MECF.Framework.Common.Persistent.Reservoirs;
  6. using MECF.Framework.Common.Persistent.Rinse;
  7. using MECF.Framework.Common.Persistent.SRD;
  8. using MECF.Framework.Common.ToolLayout;
  9. using System;
  10. using System.Collections.Generic;
  11. using System.IO;
  12. using System.Linq;
  13. using System.Text;
  14. using System.Threading.Tasks;
  15. namespace MECF.Framework.Common.Persistent.Dryer
  16. {
  17. public class DryerPersistentManager: Singleton<DryerPersistentManager>
  18. {
  19. #region 内部变量
  20. private Dictionary<string, DryerPersistentValue> _persistentValueDic = new Dictionary<string, DryerPersistentValue>();
  21. private Dictionary<string, string> _persistentValuePathDic = new Dictionary<string, string>();
  22. #endregion
  23. /// <summary>
  24. /// 初始化
  25. /// </summary>
  26. public void Initialize()
  27. {
  28. try
  29. {
  30. List<string> lst = DryerItemManager.Instance.InstalledModules;
  31. foreach (string item in lst)
  32. {
  33. string foldStr = PathManager.GetCfgDir() + $"Persistent\\Dryer";
  34. if (!Directory.Exists(foldStr))
  35. {
  36. Directory.CreateDirectory(foldStr);
  37. }
  38. string path = PathManager.GetCfgDir() + $"Persistent\\Dryer\\{item}Persistent.xml";
  39. _persistentValuePathDic[item] = path;
  40. if (File.Exists(path))
  41. {
  42. DryerPersistentValue reservoirs1PersistentValue = CustomXmlSerializer.Deserialize<DryerPersistentValue>(new FileInfo(path));
  43. if (reservoirs1PersistentValue != null)
  44. {
  45. _persistentValueDic[item] = reservoirs1PersistentValue;
  46. }
  47. }
  48. else
  49. {
  50. DryerPersistentValue persistentValue = new DryerPersistentValue();
  51. persistentValue.Name = item;
  52. persistentValue.OperatingMode = "Manual";
  53. persistentValue.RecipeOperatingMode = "Engineering";
  54. _persistentValueDic[item] = persistentValue;
  55. UpdatePersistentValue(item);
  56. }
  57. }
  58. }
  59. catch (Exception ex)
  60. {
  61. LOG.WriteLog(eEvent.ERR_DRYER, "System", "Load DryerPersistent xml exception");
  62. }
  63. }
  64. /// <summary>
  65. /// 获取Dryer Persistent数值
  66. /// </summary>
  67. /// <returns></returns>
  68. public DryerPersistentValue GetDryerPersistentValue(string module)
  69. {
  70. DryerPersistentValue value = new DryerPersistentValue();
  71. if (_persistentValueDic.ContainsKey(module)==false)
  72. {
  73. return null;
  74. }
  75. else
  76. {
  77. value = _persistentValueDic[module];
  78. }
  79. return value;
  80. }
  81. /// <summary>
  82. /// 更新PersistentValue
  83. /// </summary>
  84. /// <returns></returns>
  85. public void UpdatePersistentValue(string module)
  86. {
  87. if (_persistentValueDic.ContainsKey(module))
  88. {
  89. try
  90. {
  91. CustomXmlSerializer.Serialize(_persistentValueDic[module], _persistentValuePathDic[module]);
  92. }
  93. catch (Exception ex)
  94. {
  95. LOG.WriteLog(eEvent.ERR_METAL, module, "Update DryersPersistent xml file excepetion");
  96. }
  97. }
  98. else
  99. {
  100. LOG.WriteLog(eEvent.ERR_METAL, module, "Update DyersPersistent xml file excepetion");
  101. }
  102. }
  103. }
  104. }