SystemConfigProvider.cs 7.0 KB

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