SystemConfigManager.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. namespace Virgo_D.UI.Config
  12. {
  13. class SystemConfigManager : Singleton<SystemConfigManager>
  14. {
  15. private XmlDocument _domLocal = new XmlDocument();
  16. private XmlDocument _domDefault = new XmlDocument();
  17. public void Initialize()
  18. {
  19. try
  20. {
  21. string fileNameLocal = PathManager.GetCfgDir() + "\\SystemConfig.xml";
  22. if (File.Exists(fileNameLocal))
  23. {
  24. _domLocal.Load(fileNameLocal);
  25. }
  26. string fileNameDefault = "";
  27. if ((bool)QueryDataClient.Instance.Service.GetConfig($"PMA.BiasRf.EnableBiasRF"))
  28. {
  29. fileNameDefault = PathManager.GetCfgDir() + "\\SystemConfigB.default.xml";
  30. if (!(bool)QueryDataClient.Instance.Service.GetConfig($"System.PMBIsInstalled"))
  31. {
  32. fileNameDefault = PathManager.GetCfgDir() + "\\SystemConfigB_1PM.default.xml";
  33. }
  34. }
  35. else
  36. {
  37. fileNameDefault = PathManager.GetCfgDir() + "\\SystemConfigA.default.xml";
  38. if (!(bool)QueryDataClient.Instance.Service.GetConfig($"System.PMBIsInstalled"))
  39. {
  40. fileNameDefault = PathManager.GetCfgDir() + "\\SystemConfigA_1PM.default.xml";
  41. }
  42. }
  43. if (File.Exists(fileNameDefault))
  44. {
  45. _domDefault.Load(fileNameDefault);
  46. }
  47. if (!File.Exists(fileNameDefault) && !File.Exists(fileNameLocal))
  48. throw new ApplicationException(string.Format("did not find the system config file {0} ", fileNameLocal));
  49. }
  50. catch (Exception ex)
  51. {
  52. LOG.Write(ex);
  53. throw;
  54. }
  55. }
  56. public string GetUiLayoutXmlFile()
  57. {
  58. return GetValue("/SystemConfig/uiLayoutXmlFile");
  59. }
  60. public string GetTopviewLogoFile()
  61. {
  62. return GetValue("/SystemConfig/topViewLogoFile");
  63. }
  64. string GetValue(string path)
  65. {
  66. XmlElement node =
  67. _domLocal.SelectSingleNode(path) as XmlElement;
  68. if (node == null)
  69. {
  70. node =
  71. _domDefault.SelectSingleNode(path) as XmlElement;
  72. }
  73. if (node == null)
  74. return null;
  75. return node.GetAttribute("value");
  76. }
  77. //dbName, displayName, cnName, isPressureAxis
  78. public List<Tuple<string, string, string, bool>> GetMonitorDataList()
  79. {
  80. List<Tuple<string, string, string, bool>> lstResult = new List<Tuple<string, string, string, bool>>();
  81. XmlNodeList nodeList = _domLocal.SelectNodes("/SystemConfig/DataElements/DataElement");
  82. if (nodeList == null || nodeList.Count==0)
  83. {
  84. nodeList = _domDefault.SelectNodes("/SystemConfig/DataElements/DataElement");
  85. }
  86. if (nodeList != null)
  87. {
  88. foreach (XmlElement dataXmlElement in nodeList)
  89. {
  90. lstResult.Add(Tuple.Create(dataXmlElement.GetAttribute("dbName"),
  91. dataXmlElement.GetAttribute("displayName"),
  92. dataXmlElement.GetAttribute("cn"),
  93. !string.IsNullOrEmpty(dataXmlElement.GetAttribute("isPressureAxis")) && bool.Parse(dataXmlElement.GetAttribute("isPressureAxis"))));
  94. }
  95. }
  96. return lstResult;
  97. }
  98. }
  99. }