PrewetPersistentManager.cs 3.9 KB

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