using Aitex.Common.Util; using Aitex.Core.RT.Log; using Aitex.Core.Util; using MECF.Framework.Common.DataCenter; using System; using System.Collections.Generic; using System.IO; using System.Xml; namespace Virgo_D.UI.Config { class SystemConfigManager : Singleton { private XmlDocument _domLocal = new XmlDocument(); private XmlDocument _domDefaultA = new XmlDocument(); private XmlDocument _domDefaultB = new XmlDocument(); public void Initialize() { try { string fileNameLocal = PathManager.GetCfgDir() + "\\SystemConfig.xml"; if (File.Exists(fileNameLocal)) { _domLocal.Load(fileNameLocal); } string fileNameDefaultA = ""; string fileNameDefaultB = ""; fileNameDefaultB = PathManager.GetCfgDir() + "\\SystemConfigB.default.xml"; if (!(bool)QueryDataClient.Instance.Service.GetConfig($"System.PMBIsInstalled")) { fileNameDefaultB = PathManager.GetCfgDir() + "\\SystemConfigB_1PM.default.xml"; } fileNameDefaultA = PathManager.GetCfgDir() + "\\SystemConfigA.default.xml"; if (!(bool)QueryDataClient.Instance.Service.GetConfig($"System.PMBIsInstalled")) { fileNameDefaultA = PathManager.GetCfgDir() + "\\SystemConfigA_1PM.default.xml"; } if (File.Exists(fileNameDefaultA)) { _domDefaultA.Load(fileNameDefaultA); } if (File.Exists(fileNameDefaultB)) { _domDefaultB.Load(fileNameDefaultB); } if (!File.Exists(fileNameDefaultA) && !File.Exists(fileNameLocal)) throw new ApplicationException(string.Format("did not find the system config file {0} ", fileNameLocal)); } catch (Exception ex) { LOG.Write(ex); throw; } } public string GetUiLayoutXmlFile() { return GetValue("/SystemConfig/uiLayoutXmlFile"); } public string GetTopviewLogoFile() { return GetValue("/SystemConfig/topViewLogoFile"); } string GetValue(string path) { XmlElement node = _domLocal.SelectSingleNode(path) as XmlElement; if (node == null) { node = _domDefaultA.SelectSingleNode(path) as XmlElement; } if (node == null) return null; return node.GetAttribute("value"); } //dbName, displayName, cnName, isPressureAxis // type = "A" or "B" public List> GetMonitorDataList(string type) { List> lstResult = new List>(); XmlNodeList nodeList = _domLocal.SelectNodes("/SystemConfig/DataElements/DataElement"); if (nodeList == null || nodeList.Count == 0) { if (type == "A") nodeList = _domDefaultA.SelectNodes("/SystemConfig/DataElements/DataElement"); else { nodeList = _domDefaultB.SelectNodes("/SystemConfig/DataElements/DataElement"); } } if (nodeList != null) { foreach (XmlElement dataXmlElement in nodeList) { lstResult.Add(Tuple.Create(dataXmlElement.GetAttribute("dbName"), dataXmlElement.GetAttribute("displayName"), dataXmlElement.GetAttribute("cn"), !string.IsNullOrEmpty(dataXmlElement.GetAttribute("isPressureAxis")) && bool.Parse(dataXmlElement.GetAttribute("isPressureAxis")))); } } return lstResult; } } }