using Aitex.Common.Util; using Aitex.Core.RT.DataCenter; using Aitex.Core.RT.Log; using Aitex.Core.RT.OperationCenter; using Aitex.Core.Util; using Aitex.Core.WCF; using MECF.Framework.Common.Account; using MECF.Framework.Common.Event; using MECF.Framework.Common.FAServices; using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.ServiceModel; using System.Xml; namespace Aitex.Core.RT.Event { public class DisplayManager : Singleton { public Dictionary DisplayDict { get; set; } = new Dictionary(); public Dictionary ProcessDetailDisplayDict { get; set; } = new Dictionary(); private string _displayReplaceFile = PathManager.GetCfgDir() + "DisplayReplace.xml"; private object _displayDicLocker = new object(); public DisplayManager() { } public void Initialize() { Initialize(_displayReplaceFile); DATA.Subscribe($"System.Display", () => DisplayDict); DATA.Subscribe($"System.ProcessDetailDisplay", () => ProcessDetailDisplayDict); } public void Initialize(string ListXmlFile) { try { if (!string.IsNullOrEmpty(ListXmlFile)) { lock (_displayDicLocker) { BuildItems(ListXmlFile); } } } catch (Exception ex) { throw new ApplicationException("DisplayReplace," + ListXmlFile + ",\r\n" + ex.Message); } } private void BuildItems(string xmlFile) { Dictionary values = new Dictionary(); try { if (File.Exists(xmlFile)) { XmlDocument xml = new XmlDocument(); xml.Load(xmlFile); XmlNodeList node = xml.SelectNodes("Displays/HistoryGroup"); foreach (XmlElement AlarmTable in node) { XmlNodeList nodeList = AlarmTable.SelectNodes("Display"); foreach (XmlElement nodeCategory in nodeList) { string name = nodeCategory.GetAttribute("Name"); if (DisplayDict.ContainsKey(name)) { DisplayDict[name] = nodeCategory.GetAttribute("DisplayName"); } else { DisplayDict.Add(name, nodeCategory.GetAttribute("DisplayName")); } } } node = xml.SelectNodes("Displays/DetailGroup"); foreach (XmlElement AlarmTable in node) { XmlNodeList nodeList = AlarmTable.SelectNodes("Display"); foreach (XmlElement nodeCategory in nodeList) { string name = nodeCategory.GetAttribute("Name"); if (ProcessDetailDisplayDict.ContainsKey(name)) { ProcessDetailDisplayDict[name] = nodeCategory.GetAttribute("DisplayName"); } else { ProcessDetailDisplayDict.Add(name, nodeCategory.GetAttribute("DisplayName")); } } } } } catch (Exception ex) { LOG.Write(ex); } } } }