using Aitex.Common.Util; using Aitex.Core.RT.Log; using Aitex.Core.Util; using MECF.Framework.Common.Persistent.Reservoirs; using MECF.Framework.Common.Persistent.Rinse; using MECF.Framework.Common.Persistent.SRD; 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.Prewet { public class PrewetPersistentManager : Singleton { #region 内部变量 private Dictionary _persistentValueDic = new Dictionary(); private Dictionary _persistentValuePathDic = new Dictionary(); #endregion /// /// 初始化 /// public void Initialize() { try { List installedModules = PrewetItemManager.Instance.InstalledModules; foreach (string module in installedModules) { string foldStr = $"{PathManager.GetCfgDir()}Persistent\\Prewet"; if (!Directory.Exists(foldStr)) { Directory.CreateDirectory(foldStr); } string str = $"{foldStr}\\{module}Persistent.xml"; _persistentValuePathDic[module] = str; if (File.Exists(str)) { PrewetPersistentValue reservoirs1PersistentValue = CustomXmlSerializer.Deserialize(new FileInfo(str)); if (reservoirs1PersistentValue != null) { _persistentValueDic[module] = reservoirs1PersistentValue; } } else { //File.Create(str); PrewetPersistentValue persistentValue = new PrewetPersistentValue(); persistentValue.Name = module; persistentValue.OperatingMode = "Manual"; persistentValue.RecipeOperatingMode = "Engineering"; _persistentValueDic[module] = persistentValue; UpdatePersistentValue(module); } } } catch (Exception ex) { LOG.WriteLog(eEvent.ERR_PREWET, "System", "Load PrewetPersistent xml exception"); } } /// /// 获取Prewet Persistent数值 /// /// public PrewetPersistentValue GetPrewetPersistentValue(string module) { if (_persistentValueDic.ContainsKey(module)) { return _persistentValueDic[module]; } else { return null; } } /// /// 更新PersistentValue /// /// public void UpdatePersistentValue(string module) { if (_persistentValueDic.ContainsKey(module)) { try { CustomXmlSerializer.Serialize(_persistentValueDic[module], _persistentValuePathDic[module]); } catch (Exception ex) { LOG.WriteLog(eEvent.ERR_PREWET, module, "Update PrewetPersistent xml file excepetion"); } } else { LOG.WriteLog(eEvent.ERR_PREWET, module, "Update PrewetPersistent xml file excepetion"); } } } }