SystemConfigProvider.cs 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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", "SETM", "VCE1", "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. BuildTree(element, sc, chambertype);
  89. item.SubNodes.Add(sc);
  90. }
  91. }
  92. if (single != null)
  93. {
  94. foreach (var singleItem in single)
  95. {
  96. XmlElement element = singleItem as XmlElement;
  97. string strVisible = element.GetAttribute("visible");
  98. bool bVisible;
  99. if (!bool.TryParse(strVisible, out bVisible))
  100. bVisible = true;
  101. if (!bVisible) //do not show the item if visible field is false
  102. continue;
  103. string typeflag = element.GetAttribute("typeflag");
  104. if (!string.IsNullOrEmpty(typeflag) && chambertype != -1)
  105. {
  106. int support = Convert.ToInt32(typeflag);
  107. int currentchambertype = -1;
  108. for (int i = 0; i < Enum.GetValues(typeof(ChamberType)).Length; i++)
  109. {
  110. if (i == chambertype)
  111. {
  112. currentchambertype = (int)Enum.GetValues(typeof(ChamberType)).GetValue(i);
  113. break;
  114. }
  115. }
  116. if ((support & currentchambertype) != currentchambertype)
  117. continue;
  118. }
  119. ConfigItem config = new ConfigItem()
  120. {
  121. Name = element.GetAttribute("name"),
  122. DefaultValue = element.GetAttribute("default"),
  123. Description = element.GetAttribute("description"),
  124. Max = ConvertStringToFloat(element.GetAttribute("max")),
  125. Min = ConvertStringToFloat(element.GetAttribute("min")),
  126. Parameter = element.GetAttribute("paramter"),
  127. Unit = element.GetAttribute("unit"),
  128. Tag = element.GetAttribute("tag")
  129. };
  130. string strType = element.GetAttribute("type");
  131. config.Type = typeDic.ContainsKey(strType) ? typeDic[strType] : DataType.Unknown;
  132. config.Visible = bVisible;
  133. item.Items.Add(config);
  134. }
  135. }
  136. }
  137. private float ConvertStringToFloat(string value)
  138. {
  139. float result;
  140. if (!float.TryParse(value, out result))
  141. result = float.NaN;
  142. return result;
  143. }
  144. public ConfigNode GetConfigTree()
  145. {
  146. return GetConfig();
  147. }
  148. public List<string> GetValuesByNode(string node)
  149. {
  150. List<string> values = new List<string>();
  151. //interface to get values
  152. return values;
  153. }
  154. public string GetValueByName(string name)
  155. {
  156. object result = QueryDataClient.Instance.Service.GetConfig(name);
  157. if (result != null)
  158. return result.ToString();
  159. else
  160. return string.Empty;
  161. }
  162. }
  163. }