using Aitex.Common.Util; using Aitex.Core.RT.Log; using Aitex.Core.Util; using DocumentFormat.OpenXml; using MECF.Framework.Common.Persistent.Prewet; using MECF.Framework.Common.Persistent.Reservoirs; using MECF.Framework.Common.ToolLayout; using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; namespace MECF.Framework.Common.Persistent.SRD { public class SRDPersistentManager : Singleton { #region 内部变量 private Dictionary _persistentValueDic = new Dictionary(); private Dictionary _persistentValuePathDic = new Dictionary(); #endregion /// /// 初始化 /// public void Initialize() { try { List installedModules = SrdItemManager.Instance.InstalledModules; foreach (string module in installedModules) { string foldStr = PathManager.GetCfgDir() + $"Persistent\\SRD"; if (!Directory.Exists(foldStr)) { Directory.CreateDirectory(foldStr); } string str = $"{foldStr}\\{module}Persistent.xml"; _persistentValuePathDic[module] = str; if (File.Exists(str)) { SRDPersistentValue srdPersistentValue = CustomXmlSerializer.Deserialize(new FileInfo(str)); if (srdPersistentValue != null) { _persistentValueDic[module] = srdPersistentValue; } } else { SRDPersistentValue persistentValue = new SRDPersistentValue(); persistentValue.Name = module; _persistentValueDic[module] = persistentValue; UpdateModulePersistentValue(module); } } } catch { LOG.WriteLog(eEvent.ERR_SRD, "System", "Load SRDPersistent xml exception"); } } /// /// 获取PersistentValue值 /// /// /// public SRDPersistentValue GetModulePersistentValue(string module) { return _persistentValueDic.ContainsKey(module)?_persistentValueDic[module]:null; } /// /// 更新数值 /// /// public void UpdateModulePersistentValue(string module) { if (_persistentValueDic.ContainsKey(module)) { try { CustomXmlSerializer.Serialize(_persistentValueDic[module], _persistentValuePathDic[module]); } catch (Exception ex) { LOG.WriteLog(eEvent.ERR_SRD, module, "Save SRD Persistent xml file excepetion"); } } else { LOG.WriteLog(eEvent.ERR_METAL, module, "Update SRD Persistent xml file excepetion"); } } /// /// 更新操作模式状态 /// /// /// public void UpdateOperationModeValue(string module,string currentOperationMode) { _persistentValueDic[module].OperatingMode = currentOperationMode; try { CustomXmlSerializer.Serialize(_persistentValueDic[module], _persistentValuePathDic[module]); } catch (Exception ex) { LOG.WriteLog(eEvent.ERR_SRD, "System", "Update SRDPersistent xml file excepetion"); } } /// /// 更新Recipe操作模式状态 /// /// public void UpdateRecipeOperationModeValue(string module, string currentRecipeOperationMode) { _persistentValueDic[module].RecipeOperatingMode = currentRecipeOperationMode; try { CustomXmlSerializer.Serialize(_persistentValueDic[module], _persistentValuePathDic[module]); } catch (Exception ex) { LOG.WriteLog(eEvent.ERR_SRD, "System", "Update SRDPersistent xml file excepetion"); } } } }