| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 | 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<SRDPersistentManager>    {        #region 内部变量        private Dictionary<string, SRDPersistentValue> _persistentValueDic = new Dictionary<string, SRDPersistentValue>();        private Dictionary<string, string> _persistentValuePathDic = new Dictionary<string, string>();        #endregion        /// <summary>        /// 初始化        /// </summary>        public void Initialize()        {            try            {                List<string> 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<SRDPersistentValue>(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");            }        }        /// <summary>        /// 获取PersistentValue值        /// </summary>        /// <param name="module"></param>        /// <returns></returns>        public SRDPersistentValue GetModulePersistentValue(string module)        {            return _persistentValueDic.ContainsKey(module)?_persistentValueDic[module]:null;        }        /// <summary>        /// 更新数值        /// </summary>        /// <param name="module"></param>        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");            }                        }        /// <summary>        /// 更新操作模式状态        /// </summary>        /// <param name="module" operstionMode="currentOperationMode"></param>        /// <returns></returns>        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");            }        }        /// <summary>        /// 更新Recipe操作模式状态        /// </summary>        /// <returns></returns>        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");            }        }    }}
 |