using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Xml; using Aitex.Common.Util; using Aitex.Core.RT.Event; using Aitex.Core.RT.Log; using Aitex.Core.RT.RecipeCenter; using Aitex.Core.RT.SCCore; namespace MECF.Framework.Common.RecipeCenter { public class DefaultRecipeFileContext : IRecipeFileContext { public string GetRecipeDefiniton(string chamberId) { try { string recipeSchema = PathManager.GetCfgDir() + @"\RecipeFormat.xml"; XmlDocument xmlDom = new XmlDocument(); xmlDom.Load(recipeSchema); int count = (int)SC.GetValue($"PMA.GasCount"); string gas1Name = SC.GetStringValue($"PMA.MfcGas1.GasName"); int gas1N2Scale = SC.GetValue($"PMA.MfcGas1.MfcN2Scale"); double gas1ScaleFactor = SC.GetValue($"PMA.MfcGas1.MfcScaleFactor"); var nodeGas1 = xmlDom.SelectSingleNode(string.Format("/Aitex/TableRecipeFormat/Catalog/Group/Step[@ControlName='MfcGas1']")) as XmlElement; if (nodeGas1 != null) { if (count < 1) { nodeGas1.ParentNode.RemoveChild(nodeGas1); } else { nodeGas1.SetAttribute("DisplayName", gas1Name + " " + gas1N2Scale * gas1ScaleFactor + " " + "sccm"); nodeGas1.SetAttribute("Max", (int)(gas1N2Scale * gas1ScaleFactor) + ""); } } string gas2Name = SC.GetStringValue($"PMA.MfcGas2.GasName"); int gas2N2Scale = SC.GetValue($"PMA.MfcGas2.MfcN2Scale"); double gas2ScaleFactor = SC.GetValue($"PMA.MfcGas2.MfcScaleFactor"); var nodeGas2 = xmlDom.SelectSingleNode(string.Format("/Aitex/TableRecipeFormat/Catalog/Group/Step[@ControlName='MfcGas2']")) as XmlElement; if (nodeGas2 != null) { if (count < 2) { nodeGas2.ParentNode.RemoveChild(nodeGas2); } else { nodeGas2.SetAttribute("DisplayName",gas2Name + " " + gas2N2Scale * gas2ScaleFactor + " " + "sccm"); nodeGas2.SetAttribute("Max", (int)(gas2N2Scale * gas2ScaleFactor) + ""); } } string gas3Name = SC.GetStringValue($"PMA.MfcGas3.GasName"); int gas3N2Scale = SC.GetValue($"PMA.MfcGas3.MfcN2Scale"); double gas3ScaleFactor = SC.GetValue($"PMA.MfcGas3.MfcScaleFactor"); var nodeGas3 = xmlDom.SelectSingleNode(string.Format("/Aitex/TableRecipeFormat/Catalog/Group/Step[@ControlName='MfcGas3']")) as XmlElement; if (nodeGas3 != null) { if (count < 3) { nodeGas3.ParentNode.RemoveChild(nodeGas3); } else { nodeGas3.SetAttribute("DisplayName",gas3Name + " " + gas3N2Scale * gas3ScaleFactor + " " + "sccm"); nodeGas3.SetAttribute("Max", (int)(gas3N2Scale * gas3ScaleFactor) + ""); } } string gas4Name = SC.GetStringValue($"PMA.MfcGas4.GasName"); int gas4N2Scale = SC.GetValue($"PMA.MfcGas4.MfcN2Scale"); double gas4ScaleFactor = SC.GetValue($"PMA.MfcGas4.MfcScaleFactor"); var nodeGas4 = xmlDom.SelectSingleNode(string.Format("/Aitex/TableRecipeFormat/Catalog/Group/Step[@ControlName='MfcGas4']")) as XmlElement; if (nodeGas4 != null) { if (count < 4) { nodeGas4.ParentNode.RemoveChild(nodeGas4); } else { nodeGas4.SetAttribute("DisplayName",gas4Name + " " + gas4N2Scale * gas4ScaleFactor + " " + "sccm"); nodeGas4.SetAttribute("Max", (int)(gas4N2Scale * gas4ScaleFactor) + ""); } } return xmlDom.OuterXml; } catch (Exception ex) { LOG.Write(ex); return ""; } } public IEnumerable GetRecipes(string chamberId, bool includingUsedRecipe) { try { string recipePath = PathManager.GetRecipeDir() + chamberId + "\\"; var di = new DirectoryInfo(recipePath); var fis = di.GetFiles("*.rcp", SearchOption.AllDirectories); var recipes = new List(); foreach (var fi in fis) { string str = fi.FullName.Substring(recipePath.Length); str = str.Substring(0, str.LastIndexOf('.')); if (includingUsedRecipe || (!includingUsedRecipe && !str.Contains("HistoryRecipe\\"))) { recipes.Add(str); } } return recipes; } catch (Exception ex) { LOG.Write(ex); return new List(); } } public void PostInfoEvent(string message) { EV.PostMessage("System", EventEnum.GeneralInfo, message); } public void PostWarningEvent(string message) { EV.PostMessage("System", EventEnum.DefaultWarning, message); } public void PostAlarmEvent(string message) { EV.PostMessage("System", EventEnum.DefaultAlarm, message); } public void PostDialogEvent(string message) { EV.PostNotificationMessage(message); } public void PostInfoDialogMessage(string message) { EV.PostMessage("System", EventEnum.GeneralInfo, message); EV.PostPopDialogMessage(EventLevel.Information, "System Information", message); } public void PostWarningDialogMessage(string message) { EV.PostMessage("System", EventEnum.GeneralInfo, message); EV.PostPopDialogMessage(EventLevel.Warning, "System Warning", message); } public void PostAlarmDialogMessage(string message) { EV.PostMessage("System", EventEnum.GeneralInfo, message); EV.PostPopDialogMessage(EventLevel.Alarm, "System Alarm", message); } public string GetRecipeTemplate(string chamberId) { string schema = GetRecipeDefiniton(chamberId); XmlDocument dom = new XmlDocument(); dom.LoadXml(schema); XmlNode nodeTemplate = dom.SelectSingleNode("/Aitex/TableRecipeData"); return nodeTemplate.OuterXml; } } }