DisplayManager.cs 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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.RT.SCCore;
  6. using Aitex.Core.Util;
  7. using Aitex.Core.WCF;
  8. using MECF.Framework.Common.Account;
  9. using MECF.Framework.Common.Equipment;
  10. using MECF.Framework.Common.Event;
  11. using MECF.Framework.Common.FAServices;
  12. using System;
  13. using System.Collections.Generic;
  14. using System.IO;
  15. using System.Linq;
  16. using System.ServiceModel;
  17. using System.Xml;
  18. namespace Aitex.Core.RT.Event
  19. {
  20. public class DisplayManager : Singleton<DisplayManager>
  21. {
  22. public Dictionary<string, string> DisplayDict { get; set; } = new Dictionary<string, string>();
  23. public Dictionary<string, string> ProcessDetailDisplayDict { get; set; } = new Dictionary<string, string>();
  24. private string _displayReplaceFile = PathManager.GetCfgDir() + "DisplayReplace.xml";
  25. private object _displayDicLocker = new object();
  26. public Dictionary<string, Dictionary<string, string>> ProcessDetailInfoDict { get; set; } = new Dictionary<string, Dictionary<string, string>>();
  27. public DisplayManager()
  28. {
  29. }
  30. public void Initialize()
  31. {
  32. Initialize(_displayReplaceFile);
  33. DATA.Subscribe($"System.Display", () => DisplayDict);
  34. DATA.Subscribe($"System.ProcessDetailDisplay", () => ProcessDetailDisplayDict);
  35. DATA.Subscribe($"System.ProcessDetailInfoDict", () => ProcessDetailInfoDict);
  36. }
  37. public void Initialize(string ListXmlFile)
  38. {
  39. try
  40. {
  41. if (!string.IsNullOrEmpty(ListXmlFile))
  42. {
  43. lock (_displayDicLocker)
  44. {
  45. BuildItems(ListXmlFile);
  46. }
  47. }
  48. }
  49. catch (Exception ex)
  50. {
  51. throw new ApplicationException("DisplayReplace," + ListXmlFile + ",\r\n" + ex.Message);
  52. }
  53. }
  54. private string GetGaslineHeaterIndex(string keyStr)
  55. {
  56. if (string.IsNullOrEmpty(keyStr))
  57. {
  58. return "";
  59. }
  60. var item = keyStr.Split('.').Where(a => !string.IsNullOrEmpty(a) && a.Contains(ModuleName.GaslineHeater.ToString())).FirstOrDefault();
  61. if (item == null)
  62. return "";
  63. return item.Replace(ModuleName.GaslineHeater.ToString(), "");
  64. }
  65. private void BuildItems(string xmlFile)
  66. {
  67. Dictionary<string, string> values = new Dictionary<string, string>();
  68. try
  69. {
  70. if (File.Exists(xmlFile))
  71. {
  72. XmlDocument xml = new XmlDocument();
  73. xml.Load(xmlFile);
  74. XmlNodeList node = xml.SelectNodes("Displays/HistoryGroup");
  75. foreach (XmlElement AlarmTable in node)
  76. {
  77. XmlNodeList nodeList = AlarmTable.SelectNodes("Display");
  78. foreach (XmlElement nodeCategory in nodeList)
  79. {
  80. string key = nodeCategory.GetAttribute("Name");
  81. string value = nodeCategory.GetAttribute("DisplayName");
  82. if (ModuleHelper.IsHeaterBand(value))
  83. {
  84. var auxIndex = GetGaslineHeaterIndex(key);
  85. if (!SC.ContainsItem($"PM1.RecipeEditParameter.AUX.{auxIndex}.Display"))
  86. continue;
  87. var scAuxName = SCCore.SC.GetStringValue($"PM1.RecipeEditParameter.AUX.{auxIndex}.Display");
  88. var valueArray = value.Split('.').ToList();
  89. value = $"{valueArray[0]}.{scAuxName}.{valueArray[1]}";
  90. }
  91. if (DisplayDict.ContainsKey(key))
  92. {
  93. DisplayDict[key] = value;
  94. }
  95. else
  96. {
  97. DisplayDict.Add(key, value);
  98. }
  99. }
  100. }
  101. node = xml.SelectNodes("Displays/DetailGroup");
  102. foreach (XmlElement AlarmTable in node)
  103. {
  104. XmlNodeList nodeList = AlarmTable.SelectNodes("Display");
  105. foreach (XmlElement nodeCategory in nodeList)
  106. {
  107. string key = nodeCategory.GetAttribute("Name");
  108. string value = nodeCategory.GetAttribute("DisplayName");
  109. if (ModuleHelper.IsHeaterBand(value))
  110. {
  111. var auxIndex = GetGaslineHeaterIndex(key);
  112. if (!SC.ContainsItem($"PM1.RecipeEditParameter.AUX.{auxIndex}.Display"))
  113. continue;
  114. var scAuxName = SCCore.SC.GetStringValue($"PM1.RecipeEditParameter.AUX.{auxIndex}.Display");
  115. var valueArray = value.Split('.').ToList();
  116. value = $"{valueArray[0]}.{scAuxName}.{valueArray[1]}";
  117. }
  118. #region 存储各个节点信息
  119. Dictionary<string, string> attributesDict = new Dictionary<string, string>();
  120. foreach (XmlAttribute attr in nodeCategory.Attributes)
  121. {
  122. if (ModuleHelper.IsHeaterBand(value) && attr.Name == "ColName" && string.IsNullOrEmpty(attr.Value))
  123. {
  124. attributesDict[attr.Name] = value;
  125. }
  126. else
  127. {
  128. attributesDict[attr.Name] = attr.Value;
  129. }
  130. }
  131. if (ProcessDetailInfoDict.ContainsKey(key))
  132. {
  133. ProcessDetailInfoDict[key] = attributesDict;
  134. }
  135. else
  136. {
  137. ProcessDetailInfoDict.Add(key, attributesDict);
  138. }
  139. #endregion
  140. if (ProcessDetailDisplayDict.ContainsKey(key))
  141. {
  142. ProcessDetailDisplayDict[key] = value;
  143. }
  144. else
  145. {
  146. ProcessDetailDisplayDict.Add(key, value);
  147. }
  148. }
  149. }
  150. }
  151. }
  152. catch (Exception ex)
  153. {
  154. LOG.Write(ex);
  155. }
  156. }
  157. }
  158. }