using Aitex.Core.RT.Log; using Caliburn.Micro.Core; using MECF.Framework.Common.RecipeCenter; using MECF.Framework.UI.Client.CenterViews.Editors.Recipe; using RecipeEditorLib.RecipeModel.Params; using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Reflection; using System.Text; using System.Xml; namespace FurnaceUI.Views.Recipes { public class RecipeDataJob : PropertyChangedBase { private string _prefixPath; public string PrefixPath { get => _prefixPath; set { _prefixPath = value; NotifyOfPropertyChange(nameof(PrefixPath)); } } private string _name; public string Name { get => _name; set { _name = value; NotifyOfPropertyChange(nameof(Name)); } } private string _createBy; public string CreateBy { get => _createBy; set { _createBy = value; NotifyOfPropertyChange(nameof(CreateBy)); } } private string _createTime; public string CreateTime { get => _createTime; set { _createTime = value; NotifyOfPropertyChange(nameof(CreateTime)); } } private string _lastReviseBy; public string LastReviseBy { get => _lastReviseBy; set { _lastReviseBy = value; NotifyOfPropertyChange(nameof(LastReviseBy)); } } private string _lastRevisionTime; public string LastRevisionTime { get => _lastRevisionTime; set { _lastRevisionTime = value; NotifyOfPropertyChange(nameof(LastRevisionTime)); } } private string _description; public string Description { get => _description; set { _description = value; NotifyOfPropertyChange(nameof(Description)); } } private string _recipePermission; public string RecipePermission { get { return this._recipePermission; } set { this._recipePermission = value; this.NotifyOfPropertyChange("RecipePermisson"); } } private string _recipeLevel; public string RecipeLevel { get { return this._recipeLevel; } set { this._recipeLevel = value; this.NotifyOfPropertyChange("RecipeLevel"); } } private string _processRecipe; public string ProcessRecipe { get => _processRecipe; set { _processRecipe = value; NotifyOfPropertyChange(nameof(ProcessRecipe)); } } private string _layoutRecipe; public string LayoutRecipe { get => _layoutRecipe; set { _layoutRecipe = value; NotifyOfPropertyChange(nameof(LayoutRecipe)); } } private string _coolTime; public string CoolTime { get => _coolTime; set { _coolTime = value; NotifyOfPropertyChange(nameof(CoolTime)); } } private string _recipeChamberType; public string RecipeChamberType { get => _recipeChamberType; set { _recipeChamberType = value; NotifyOfPropertyChange(nameof(RecipeChamberType)); } } private string _recipeVersion; public string RecipeVersion { get => _recipeVersion; set { _recipeVersion = value; NotifyOfPropertyChange(nameof(RecipeVersion)); } } private XmlDocument _doc; private string _module; private RecipeProvider _recipeProvider = new RecipeProvider(); public RecipeDataJob() { _doc = new XmlDocument(); } public void Clear() { CreateBy = ""; CreateTime = ""; LastReviseBy = ""; LastRevisionTime = ""; Description = ""; RecipeChamberType = ""; RecipeVersion = ""; _module = ""; } public void InitData(string prefixPath, string recipeName, string recipeContent, string module) { PrefixPath = prefixPath; Name = recipeName; _module = module; try { _doc = new XmlDocument(); _doc.LoadXml(recipeContent); if (!LoadHeader(_doc.SelectSingleNode("Aitex/TableRecipeData"))) return; XmlNode nodeModule; nodeModule = _doc.SelectSingleNode("Aitex/TableRecipeData"); XmlElement stepNode = nodeModule as XmlElement; foreach (XmlAttribute att in stepNode.Attributes) { switch (att.Name) { case "CreatedBy": CreateBy = att.Value; break; case "CreationTime": CreateTime = att.Value; break; case "LastRevisedBy": LastReviseBy = att.Value; break; case "LastRevisionTime": LastRevisionTime = att.Value; break; case "Description": Description = att.Value; break; } } nodeModule = _doc.SelectSingleNode($"Aitex/TableRecipeData/Module[@Name='{module}']/Step"); if (nodeModule == null) return; stepNode = nodeModule as XmlElement; foreach (XmlAttribute att in stepNode.Attributes) { switch (att.Name) { case "ProcessRecipe": ProcessRecipe = att.Value; break; case "LayoutRecipe": LayoutRecipe = att.Value; break; case "CoolTime": CoolTime = att.Value; break; } } } catch (Exception ex) { LOG.Write(ex); } } public string GetXmlString() { try { XmlElement nodeData = _doc.SelectSingleNode($"Aitex/TableRecipeData") as XmlElement; nodeData.SetAttribute("LastRevisedBy", LastReviseBy); nodeData.SetAttribute("LastRevisionTime", LastRevisionTime); nodeData.SetAttribute("Description", Description); nodeData.SetAttribute("RecipeChamberType", RecipeChamberType); nodeData.SetAttribute("RecipePermission", RecipePermission); nodeData.SetAttribute("RecipeLevel", RecipeLevel); XmlNode nodeModule = _doc.SelectSingleNode($"Aitex/TableRecipeData/Module[@Name='{_module}']"); if (nodeModule == null) { nodeModule = _doc.CreateElement("Module"); nodeData.AppendChild(nodeModule); } nodeModule.RemoveAll(); (nodeModule as XmlElement).SetAttribute("Name", _module); XmlElement nodeStep = _doc.CreateElement("Step"); nodeStep.SetAttribute("ProcessRecipe", ProcessRecipe); nodeStep.SetAttribute("LayoutRecipe", LayoutRecipe); nodeStep.SetAttribute("CoolTime", CoolTime); nodeModule.AppendChild(nodeStep); } catch (Exception ex) { LOG.Write(ex); return _doc.OuterXml; } return _doc.OuterXml; } private bool LoadHeader(XmlNode nodeHeader) { if (nodeHeader == null) return false; if (nodeHeader.Attributes["CreatedBy"] != null) CreateBy = nodeHeader.Attributes["CreatedBy"].Value; if (nodeHeader.Attributes["CreationTime"] != null) CreateTime = nodeHeader.Attributes["CreationTime"].Value; if (nodeHeader.Attributes["LastRevisedBy"] != null) LastReviseBy = nodeHeader.Attributes["LastRevisedBy"].Value; if (nodeHeader.Attributes["LastRevisionTime"] != null) LastRevisionTime = nodeHeader.Attributes["LastRevisionTime"].Value; if (nodeHeader.Attributes["Description"] != null) Description = nodeHeader.Attributes["Description"].Value; if (nodeHeader.Attributes["RecipeLevel"] != null) RecipeLevel = nodeHeader.Attributes["RecipeLevel"].Value; string chamberType = string.Empty; if (nodeHeader.Attributes["RecipeChamberType"] != null) chamberType = nodeHeader.Attributes["RecipeChamberType"].Value; if (!string.IsNullOrEmpty(chamberType) && chamberType != RecipeChamberType) { LOG.Write($"{chamberType} is not accordance with {RecipeChamberType}"); return false; } return true; } } }