VpwCellPersistentManager.cs 3.8 KB

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