SystemConfigManager.cs 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Xml;
  7. using Aitex.Common.Util;
  8. using Aitex.Core.RT.Log;
  9. using Aitex.Core.Util;
  10. using MECF.Framework.Common.DataCenter;
  11. using MECF.Framework.Common.Equipment;
  12. using VirgoUI.Client;
  13. namespace Virgo_D.UI.Config
  14. {
  15. class SystemConfigManager : Singleton<SystemConfigManager>
  16. {
  17. private XmlDocument _domLocal = new XmlDocument();
  18. private XmlDocument _domDefaultA = new XmlDocument();
  19. private XmlDocument _domDefaultB = new XmlDocument();
  20. private XmlDocument _domDataViewConfig = new XmlDocument();
  21. public void Initialize()
  22. {
  23. try
  24. {
  25. string fileNameLocal = PathManager.GetCfgDir() + "\\SystemConfig.xml";
  26. if (File.Exists(fileNameLocal))
  27. {
  28. _domLocal.Load(fileNameLocal);
  29. }
  30. string fileNameDefaultA = "";
  31. string fileNameDefaultB = "";
  32. string moduleString = (string)QueryDataClient.Instance.Service.GetConfig("System.InstalledModules");
  33. fileNameDefaultB = PathManager.GetCfgDir() + "\\SystemConfigB.default.xml";
  34. if (!moduleString.Contains("PMB"))
  35. {
  36. fileNameDefaultB = PathManager.GetCfgDir() + "\\SystemConfigB_1PM.default.xml";
  37. }
  38. fileNameDefaultA = PathManager.GetCfgDir() + "\\SystemConfigA.default.xml";
  39. if (!moduleString.Contains("PMB"))
  40. {
  41. fileNameDefaultA = PathManager.GetCfgDir() + "\\SystemConfigA_1PM.default.xml";
  42. }
  43. if (File.Exists(fileNameDefaultA))
  44. {
  45. _domDefaultA.Load(fileNameDefaultA);
  46. }
  47. if (File.Exists(fileNameDefaultB))
  48. {
  49. _domDefaultB.Load(fileNameDefaultB);
  50. }
  51. var dataViewConfigFile = PathManager.GetCfgDir() + "\\DataViewConfig.xml";
  52. if (File.Exists(dataViewConfigFile))
  53. {
  54. _domDataViewConfig.Load(dataViewConfigFile);
  55. }
  56. if (!File.Exists(fileNameDefaultA) && !File.Exists(fileNameLocal))
  57. throw new ApplicationException(string.Format("did not find the system config file {0} ", fileNameLocal));
  58. }
  59. catch (Exception ex)
  60. {
  61. LOG.Write(ex);
  62. throw;
  63. }
  64. }
  65. public bool QueryDataViewConfigName(string dbName)
  66. {
  67. if(_domDataViewConfig != null)
  68. {
  69. var node = _domDataViewConfig.SelectSingleNode($"/SystemConfig/DataElements/DataElement[@dbName= '{dbName}']");
  70. return node != null;
  71. }
  72. return false;
  73. }
  74. public string GetUiLayoutXmlFile()
  75. {
  76. return GetValue("/SystemConfig/uiLayoutXmlFile");
  77. }
  78. public string GetTopviewLogoFile()
  79. {
  80. return GetValue("/SystemConfig/topViewLogoFile");
  81. }
  82. string GetValue(string path)
  83. {
  84. XmlElement node =
  85. _domLocal.SelectSingleNode(path) as XmlElement;
  86. if (node == null)
  87. {
  88. node =
  89. _domDefaultA.SelectSingleNode(path) as XmlElement;
  90. }
  91. if (node == null)
  92. return null;
  93. return node.GetAttribute("value");
  94. }
  95. //dbName, displayName, cnName, isPressureAxis
  96. // type = "A" or "B"
  97. public List<Tuple<string, string, string, bool>> GetMonitorDataList(string type)
  98. {
  99. List<Tuple<string, string, string, bool>> lstResult = new List<Tuple<string, string, string, bool>>();
  100. XmlNodeList nodeList = _domLocal.SelectNodes("/SystemConfig/DataElements/DataElement");
  101. if (nodeList == null || nodeList.Count == 0)
  102. {
  103. if (type == "A")
  104. nodeList = _domDefaultA.SelectNodes("/SystemConfig/DataElements/DataElement");
  105. else
  106. {
  107. nodeList = _domDefaultB.SelectNodes("/SystemConfig/DataElements/DataElement");
  108. }
  109. }
  110. if (nodeList != null)
  111. {
  112. foreach (XmlElement dataXmlElement in nodeList)
  113. {
  114. lstResult.Add(Tuple.Create(dataXmlElement.GetAttribute("dbName"),
  115. dataXmlElement.GetAttribute("displayName"),
  116. dataXmlElement.GetAttribute("cn"),
  117. !string.IsNullOrEmpty(dataXmlElement.GetAttribute("isPressureAxis")) && bool.Parse(dataXmlElement.GetAttribute("isPressureAxis"))));
  118. }
  119. }
  120. return lstResult;
  121. }
  122. }
  123. }