using Aitex.Core.RT.Log; using Caliburn.Micro; using MECF.Framework.Common.DataCenter; using MECF.Framework.Common.Equipment; using OpenSEMI.ClientBase.ServiceProvider; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Xml; using CyberX8_Core; using MECF.Framework.Common.Utilities; namespace CyberX8_MainPages.Unity { public class SystemConfigProvider : IProvider { private static SystemConfigProvider _Instance = null; private int _currentChamberNumber = 0; //private int? _systemtype = null; private List _InstalledModules=null; private List _modulelist = new List() { "EFEM", "TM", "LLA", "LLB", "SETM", "VCE1", "PMA", "PMB", "PMC", "PMD", "PME", "PMF" }; public static SystemConfigProvider Instance { get { if (_Instance == null) _Instance = new SystemConfigProvider(); return _Instance; } } public void Create() { } private Dictionary typeDic = new Dictionary() { { "String", DataType.String }, { "Bool", DataType.Bool }, { "Integer", DataType.Int }, { "Double", DataType.Double } }; public ConfigNode GetConfig() { string config = QueryDataClient.Instance.Service.GetConfigFileContent(); _currentChamberNumber = Convert.ToInt32(QueryDataClient.Instance.Service.GetConfig("System.ChamberSelect")); Dictionary allModulesDictionary = QueryDataClient.Instance.Service.PollData(new List() { "System.InstalledModules" }); if (allModulesDictionary != null) { _InstalledModules = CommonFunction.GetValue>(allModulesDictionary, "System.InstalledModules"); } if (string.IsNullOrEmpty(config)) return null; ConfigNode result = new ConfigNode() { Path = string.Empty }; try { XmlDocument xml = new XmlDocument(); xml.LoadXml(config); XmlElement element = xml.SelectSingleNode("root") as XmlElement; BuildTree(element, result); } catch (Exception ex) { //LOG.Write(ex); LOG.WriteExeption(ex); } return result; } public void BuildTree(XmlElement root, ConfigNode item,int chambertype = -1) { item.Name = root.GetAttribute("name"); item.SubNodes = new List(); item.Items = new List(); if (_modulelist.Contains(item.Name)) { if (!_InstalledModules.Contains(item.Name)) item.IsShow = false; else { if (Enum.TryParse(item.Name, out ModuleName currentChamber)) chambertype = Convert.ToInt32(QueryDataClient.Instance.Service.GetConfig($"{currentChamber}.ChamberType")); else chambertype = -1; } } XmlNodeList group = root.SelectNodes("configs"); XmlNodeList single = root.SelectNodes("config"); if (group != null) { foreach (var groupItem in group) { XmlElement element = groupItem as XmlElement; ConfigNode sc = new ConfigNode() { Path = item.Name }; BuildTree(element, sc, chambertype); item.SubNodes.Add(sc); } } if (single != null) { foreach (var singleItem in single) { XmlElement element = singleItem as XmlElement; string strVisible = element.GetAttribute("visible"); bool bVisible; if (!bool.TryParse(strVisible, out bVisible)) bVisible = true; if (!bVisible) //do not show the item if visible field is false continue; string typeflag = element.GetAttribute("typeflag"); if (!string.IsNullOrEmpty(typeflag) && chambertype != -1) { int support = Convert.ToInt32(typeflag); int currentchambertype = -1; for (int i = 0; i < Enum.GetValues(typeof(ChamberType)).Length; i++) { if (i == chambertype) { currentchambertype = (int)Enum.GetValues(typeof(ChamberType)).GetValue(i); break; } } if ((support & currentchambertype) != currentchambertype) continue; } ConfigItem config = new ConfigItem() { Name = element.GetAttribute("name"), DefaultValue = element.GetAttribute("default"), Description = element.GetAttribute("description"), Max = ConvertStringToDouble(element.GetAttribute("max")), Min = ConvertStringToDouble(element.GetAttribute("min")), Parameter = element.GetAttribute("paramter"), Unit = element.GetAttribute("unit"), Tag = element.GetAttribute("tag") }; string strType = element.GetAttribute("type"); config.Type = typeDic.ContainsKey(strType) ? typeDic[strType] : DataType.Unknown; config.Visible = bVisible; item.Items.Add(config); } } } private double ConvertStringToDouble(string value) { double result; if (!double.TryParse(value, out result)) result = double.NaN; return result; } public ConfigNode GetConfigTree() { return GetConfig(); } public List GetValuesByNode(string node) { List values = new List(); //interface to get values return values; } public string GetValueByName(string name) { object result = QueryDataClient.Instance.Service.GetConfig(name); if (result != null) return result.ToString(); else return string.Empty; } } }