DisplayManager.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. using Aitex.Common.Util;
  2. using Aitex.Core.RT.DataCenter;
  3. using Aitex.Core.RT.Log;
  4. using Aitex.Core.RT.OperationCenter;
  5. using Aitex.Core.Util;
  6. using Aitex.Core.WCF;
  7. using MECF.Framework.Common.Account;
  8. using MECF.Framework.Common.Event;
  9. using MECF.Framework.Common.FAServices;
  10. using System;
  11. using System.Collections.Generic;
  12. using System.IO;
  13. using System.Linq;
  14. using System.ServiceModel;
  15. using System.Xml;
  16. namespace Aitex.Core.RT.Event
  17. {
  18. public class DisplayManager : Singleton<DisplayManager>
  19. {
  20. public Dictionary<string, string> DisplayDict { get; set; } = new Dictionary<string, string>();
  21. public Dictionary<string, string> ProcessDetailDisplayDict { get; set; } = new Dictionary<string, string>();
  22. private string _displayReplaceFile = PathManager.GetCfgDir() + "DisplayReplace.xml";
  23. private object _displayDicLocker = new object();
  24. public DisplayManager()
  25. {
  26. }
  27. public void Initialize()
  28. {
  29. Initialize(_displayReplaceFile);
  30. DATA.Subscribe($"System.Display", () => DisplayDict);
  31. DATA.Subscribe($"System.ProcessDetailDisplay", () => ProcessDetailDisplayDict);
  32. }
  33. public void Initialize(string ListXmlFile)
  34. {
  35. try
  36. {
  37. if (!string.IsNullOrEmpty(ListXmlFile))
  38. {
  39. lock (_displayDicLocker)
  40. {
  41. BuildItems(ListXmlFile);
  42. }
  43. }
  44. }
  45. catch (Exception ex)
  46. {
  47. throw new ApplicationException("DisplayReplace," + ListXmlFile + ",\r\n" + ex.Message);
  48. }
  49. }
  50. private void BuildItems(string xmlFile)
  51. {
  52. Dictionary<string, string> values = new Dictionary<string, string>();
  53. try
  54. {
  55. if (File.Exists(xmlFile))
  56. {
  57. XmlDocument xml = new XmlDocument();
  58. xml.Load(xmlFile);
  59. XmlNodeList node = xml.SelectNodes("Displays/HistoryGroup");
  60. foreach (XmlElement AlarmTable in node)
  61. {
  62. XmlNodeList nodeList = AlarmTable.SelectNodes("Display");
  63. foreach (XmlElement nodeCategory in nodeList)
  64. {
  65. string name = nodeCategory.GetAttribute("Name");
  66. if (DisplayDict.ContainsKey(name))
  67. {
  68. DisplayDict[name] = nodeCategory.GetAttribute("DisplayName");
  69. }
  70. else
  71. {
  72. DisplayDict.Add(name, nodeCategory.GetAttribute("DisplayName"));
  73. }
  74. }
  75. }
  76. node = xml.SelectNodes("Displays/DetailGroup");
  77. foreach (XmlElement AlarmTable in node)
  78. {
  79. XmlNodeList nodeList = AlarmTable.SelectNodes("Display");
  80. foreach (XmlElement nodeCategory in nodeList)
  81. {
  82. string name = nodeCategory.GetAttribute("Name");
  83. if (ProcessDetailDisplayDict.ContainsKey(name))
  84. {
  85. ProcessDetailDisplayDict[name] = nodeCategory.GetAttribute("DisplayName");
  86. }
  87. else
  88. {
  89. ProcessDetailDisplayDict.Add(name, nodeCategory.GetAttribute("DisplayName"));
  90. }
  91. }
  92. }
  93. }
  94. }
  95. catch (Exception ex)
  96. {
  97. LOG.Write(ex);
  98. }
  99. }
  100. }
  101. }