using Aitex.Common.Util; using Aitex.Core.RT.DataCenter; using Aitex.Core.RT.Log; using Aitex.Core.Util; using MECF.Framework.Common.ToolLayout; using CyberX8_Core; using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Markup; namespace MECF.Framework.Common.Layout { public class ProcessLayoutManager : Singleton { #region 常量 private const int MARGIN_LEFT = 10; #endregion #region 内部变量 /// /// Process Layout cell名称字典(key-cell Id,value-layout item对象) /// private Dictionary _idProcessLayoutCellItemDic = new Dictionary(); /// /// 名称与Cell字典(key-Cell Id,value-cell 名称) /// private Dictionary _nameProcessLayoutCellItemDic = new Dictionary(); /// /// 模块名称与cell字典(key-模块名称,value-cell对象) /// private Dictionary _moduleNameProcessLayoutCellItemDic = new Dictionary(); /// /// xml地址 /// private string _xmlPath = ""; /// /// process layout对象 /// private ProcessLayout _processLayout; #endregion /// /// 初始化 /// /// public void Initialize() { try { _xmlPath = PathManager.GetCfgDir() + "Layout\\Layout.xml"; _processLayout = CustomXmlSerializer.Deserialize(new FileInfo(_xmlPath)); if (_processLayout != null) { DATA.Subscribe("System.Layout", () => _processLayout, SubscriptionAttribute.FLAG.IgnoreSaveDB); foreach (ProcessLayoutCellItem item in _processLayout.Items) { if (item.Name != "Loader") { item.ModuleName = CellItemManager.Instance.GetModuleNameByCellId($"Cell{item.CellId}"); } else { item.ModuleName = item.Name; } if (!string.IsNullOrEmpty(item.ModuleName)) { _moduleNameProcessLayoutCellItemDic[item.ModuleName] = item; } _idProcessLayoutCellItemDic[item.CellId] = item; _nameProcessLayoutCellItemDic[item.Name] = item; } } } catch(Exception ex) { LOG.WriteLog(eEvent.ERR_EXCEPTION, "System", ex.Message); } } /// /// 获取ProcessLayout cell项 /// /// /// public ProcessLayoutCellItem GetProcessLayoutCellItemByName(string cellName) { return _nameProcessLayoutCellItemDic.ContainsKey(cellName) ? _nameProcessLayoutCellItemDic[cellName] : null; } /// /// 获取ProcessLayout cell项 /// /// /// public ProcessLayoutCellItem GetProcessLayoutCellItemByModuleName(string moduleName) { return _moduleNameProcessLayoutCellItemDic.ContainsKey(moduleName) ? _moduleNameProcessLayoutCellItemDic[moduleName] : null; } /// /// 保存Process Layout /// /// public void SaveProcessLayout() { CustomXmlSerializer.Serialize(_processLayout, _xmlPath); } } }