SystemConfigManager.cs 3.1 KB

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