SystemConfigProvider.cs 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. using Aitex.Core.RT.Log;
  2. using Caliburn.Micro;
  3. using MECF.Framework.Common.DataCenter;
  4. using MECF.Framework.Common.Equipment;
  5. using OpenSEMI.ClientBase.ServiceProvider;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. using System.Windows;
  12. using System.Xml;
  13. using CyberX8_Core;
  14. using MECF.Framework.Common.Utilities;
  15. namespace CyberX8_MainPages.Unity
  16. {
  17. public class SystemConfigProvider : IProvider
  18. {
  19. private static SystemConfigProvider _Instance = null;
  20. private int _currentChamberNumber = 0;
  21. //private int? _systemtype = null;
  22. private List<string> _InstalledModules=null;
  23. private List<string> _modulelist = new List<string>() { "EFEM", "TM", "LLA", "LLB", "SETM", "VCE1", "PMA", "PMB", "PMC", "PMD", "PME", "PMF" };
  24. public static SystemConfigProvider Instance
  25. {
  26. get
  27. {
  28. if (_Instance == null)
  29. _Instance = new SystemConfigProvider();
  30. return _Instance;
  31. }
  32. }
  33. public void Create()
  34. {
  35. }
  36. private Dictionary<string, DataType> typeDic = new Dictionary<string, DataType>() {
  37. { "String", DataType.String },
  38. { "Bool", DataType.Bool },
  39. { "Integer", DataType.Int },
  40. { "Double", DataType.Double }
  41. };
  42. public ConfigNode GetConfig()
  43. {
  44. string config = QueryDataClient.Instance.Service.GetConfigFileContent();
  45. _currentChamberNumber = Convert.ToInt32(QueryDataClient.Instance.Service.GetConfig("System.ChamberSelect"));
  46. Dictionary<string, object> allModulesDictionary = QueryDataClient.Instance.Service.PollData(new List<string>() { "System.InstalledModules" });
  47. if (allModulesDictionary != null)
  48. {
  49. _InstalledModules = CommonFunction.GetValue<List<string>>(allModulesDictionary, "System.InstalledModules");
  50. }
  51. if (string.IsNullOrEmpty(config))
  52. return null;
  53. ConfigNode result = new ConfigNode() { Path = string.Empty };
  54. try
  55. {
  56. XmlDocument xml = new XmlDocument();
  57. xml.LoadXml(config);
  58. XmlElement element = xml.SelectSingleNode("root") as XmlElement;
  59. BuildTree(element, result);
  60. }
  61. catch (Exception ex)
  62. {
  63. //LOG.Write(ex);
  64. LOG.WriteExeption(ex);
  65. }
  66. return result;
  67. }
  68. public void BuildTree(XmlElement root, ConfigNode item,int chambertype = -1)
  69. {
  70. item.Name = root.GetAttribute("name");
  71. item.SubNodes = new List<ConfigNode>();
  72. item.Items = new List<ConfigItem>();
  73. if (_modulelist.Contains(item.Name))
  74. {
  75. if (!_InstalledModules.Contains(item.Name))
  76. item.IsShow = false;
  77. else
  78. {
  79. if (Enum.TryParse(item.Name, out ModuleName currentChamber))
  80. chambertype = Convert.ToInt32(QueryDataClient.Instance.Service.GetConfig($"{currentChamber}.ChamberType"));
  81. else
  82. chambertype = -1;
  83. }
  84. }
  85. XmlNodeList group = root.SelectNodes("configs");
  86. XmlNodeList single = root.SelectNodes("config");
  87. if (group != null)
  88. {
  89. foreach (var groupItem in group)
  90. {
  91. XmlElement element = groupItem as XmlElement;
  92. ConfigNode sc = new ConfigNode() { Path = item.Name };
  93. BuildTree(element, sc, chambertype);
  94. item.SubNodes.Add(sc);
  95. }
  96. }
  97. if (single != null)
  98. {
  99. foreach (var singleItem in single)
  100. {
  101. XmlElement element = singleItem as XmlElement;
  102. string strVisible = element.GetAttribute("visible");
  103. bool bVisible;
  104. if (!bool.TryParse(strVisible, out bVisible))
  105. bVisible = true;
  106. if (!bVisible) //do not show the item if visible field is false
  107. continue;
  108. string typeflag = element.GetAttribute("typeflag");
  109. if (!string.IsNullOrEmpty(typeflag) && chambertype != -1)
  110. {
  111. int support = Convert.ToInt32(typeflag);
  112. int currentchambertype = -1;
  113. for (int i = 0; i < Enum.GetValues(typeof(ChamberType)).Length; i++)
  114. {
  115. if (i == chambertype)
  116. {
  117. currentchambertype = (int)Enum.GetValues(typeof(ChamberType)).GetValue(i);
  118. break;
  119. }
  120. }
  121. if ((support & currentchambertype) != currentchambertype)
  122. continue;
  123. }
  124. ConfigItem config = new ConfigItem()
  125. {
  126. Name = element.GetAttribute("name"),
  127. DefaultValue = element.GetAttribute("default"),
  128. Description = element.GetAttribute("description"),
  129. Max = ConvertStringToDouble(element.GetAttribute("max")),
  130. Min = ConvertStringToDouble(element.GetAttribute("min")),
  131. Parameter = element.GetAttribute("paramter"),
  132. Unit = element.GetAttribute("unit"),
  133. Tag = element.GetAttribute("tag")
  134. };
  135. string strType = element.GetAttribute("type");
  136. config.Type = typeDic.ContainsKey(strType) ? typeDic[strType] : DataType.Unknown;
  137. config.Visible = bVisible;
  138. item.Items.Add(config);
  139. }
  140. }
  141. }
  142. private double ConvertStringToDouble(string value)
  143. {
  144. double result;
  145. if (!double.TryParse(value, out result))
  146. result = double.NaN;
  147. return result;
  148. }
  149. public ConfigNode GetConfigTree()
  150. {
  151. return GetConfig();
  152. }
  153. public List<string> GetValuesByNode(string node)
  154. {
  155. List<string> values = new List<string>();
  156. //interface to get values
  157. return values;
  158. }
  159. public string GetValueByName(string name)
  160. {
  161. object result = QueryDataClient.Instance.Service.GetConfig(name);
  162. if (result != null)
  163. return result.ToString();
  164. else
  165. return string.Empty;
  166. }
  167. }
  168. }