using System.Collections.Generic; using System.Collections.ObjectModel; using System.IO; using System.Linq; using System.Xml; using Aitex.Common.Util; using Aitex.Core.RT.Event; using MECF.Framework.Common.DataCenter; using MECF.Framework.Common.Equipment; using MECF.Framework.Common.Jobs; using MECF.Framework.Common.RecipeCenter; using OpenSEMI.ClientBase; using OpenSEMI.ClientBase.ServiceProvider; using RecipeEditorLib.DGExtension.CustomColumn; namespace CyberX8_MainPages.Sequence { public class SequenceDataProvider : IProvider { private IUiSequenceManager m_uiSequenceManager; public SequenceDataProvider(IUiSequenceManager uiSequenceManager) { m_uiSequenceManager = uiSequenceManager; } public void Create() { } public bool CreateSequenceFolder(string foldername) { return m_uiSequenceManager.CreateSequenceFolder(foldername); } public bool DeleteSequenceFolder(string foldername) { return m_uiSequenceManager.DeleteSequenceFolder(foldername); } public bool Save(SequenceData seq) { var path = GenerateSequenceFilePath("Sequence", seq.Name); if (CheckSequenceUsedInJob(seq.Name)) { DialogBox.ShowDialog(DialogButton.OK, 0, "Sequence is used in auto running jobs, can not be modified"); return false; } return m_uiSequenceManager.SaveSequence(seq.Name, seq.ToXml()); } public List GetSequences() { return m_uiSequenceManager.GetSequenceNameList(); } public List GetRecipes(ModuleName modulename) { return m_uiSequenceManager.GetRecipes(modulename, true).ToList(); } public SequenceData GetSequenceByName(ObservableCollection _columns, string name) { string content = m_uiSequenceManager.GetSequence(name); SequenceData seq = new SequenceData(); XmlDocument doc = new XmlDocument(); doc.LoadXml(content); seq.Name = name; seq.Load(_columns, doc); return seq; } public bool Rename(string beforename, string currentname) { var path = GenerateSequenceFilePath("Sequence", currentname); if (CheckSequenceUsedInJob(currentname)) { DialogBox.ShowDialog(DialogButton.OK, 0, "Sequence is used in auto running jobs, can not be modified"); return false; } return m_uiSequenceManager.RenameSequence(beforename, currentname); } public bool Delete(string name) { var path = GenerateSequenceFilePath("Sequence", name); if (CheckSequenceUsedInJob(name)) { DialogBox.ShowDialog(DialogButton.OK, 0, "Sequence is used in auto running jobs, can not be modified"); return false; } return m_uiSequenceManager.DeleteSequence(name); } public bool SaveAs(string name, SequenceData seq) { var path = GenerateSequenceFilePath("Sequence", name); if (CheckSequenceUsedInJob(name)) { DialogBox.ShowDialog(DialogButton.OK, 0, "Sequence is used in auto running jobs, can not be modified"); return false; } return m_uiSequenceManager.SaveAsSequence(name, seq.ToXml()); } public string GetSequenceFromXml() { string template = m_uiSequenceManager.GetSequenceFormatXml(); return template; } private string GenerateSequenceFilePath(string chamId, string recipeName) { return getRecipeDirPath(chamId) + recipeName + ".seq"; } private string getRecipeDirPath(string chamId) { var dir = string.Format("{0}{1}\\", PathManager.GetRecipeDir(), chamId); DirectoryInfo di = new DirectoryInfo(dir); if (!di.Exists) di.Create(); return dir; } public bool CheckSequenceUsedInJob(string sequenceName) { List ProcessList = (List)QueryDataClient.Instance.Service.GetData("Scheduler.CurrentRecipeList"); if (ProcessList != null) { foreach (var pj in ProcessList) { if (string.Equals(sequenceName, pj.Sequence.Name, System.StringComparison.OrdinalIgnoreCase)) return true; } } return false; } public List GetSequenceNameList() { return m_uiSequenceManager.GetSequenceNameList(); } public List GetRecipesByPath(string prefixPath) { return m_uiSequenceManager.GetRecipesByPath(prefixPath); } } }