SequenceDataProvider.cs 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. using System.Collections.Generic;
  2. using System.Collections.ObjectModel;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Xml;
  6. using Aitex.Common.Util;
  7. using Aitex.Core.RT.Event;
  8. using MECF.Framework.Common.DataCenter;
  9. using MECF.Framework.Common.Equipment;
  10. using MECF.Framework.Common.Jobs;
  11. using MECF.Framework.Common.RecipeCenter;
  12. using MECF.Framework.UI.Client.ClientBase;
  13. using OpenSEMI.ClientBase;
  14. using OpenSEMI.ClientBase.ServiceProvider;
  15. using RecipeEditorLib.DGExtension.CustomColumn;
  16. namespace MECF.Framework.UI.Client.CenterViews.Editors.Sequence
  17. {
  18. public class SequenceDataProvider : IProvider
  19. {
  20. private static SequenceDataProvider _Instance = null;
  21. public static SequenceDataProvider Instance
  22. {
  23. get
  24. {
  25. if (_Instance == null)
  26. _Instance = new SequenceDataProvider();
  27. return _Instance;
  28. }
  29. }
  30. public void Create()
  31. {
  32. }
  33. public bool CreateSequenceFolder(string foldername)
  34. {
  35. return RecipeClient.Instance.Service.CreateSequenceFolder(foldername);
  36. }
  37. public bool DeleteSequenceFolder(string foldername)
  38. {
  39. return RecipeClient.Instance.Service.DeleteSequenceFolder(foldername);
  40. }
  41. public bool Save(SequenceData seq)
  42. {
  43. //if ((bool)QueryDataClient.Instance.Service.GetData("System.IsAutoMode"))
  44. //{
  45. // DialogBox.ShowDialog(DialogButton.OK, 0, "Auto状态下不能对recipe做出修改");
  46. // return false;
  47. //}
  48. var path = GenerateSequenceFilePath("Sequence", seq.Name);
  49. if (CheckSequenceUsedInJob(path))
  50. {
  51. DialogBox.ShowDialog(DialogButton.OK, 0, "Sequence is used in auto running jobs, can not be modified");
  52. return false;
  53. }
  54. return RecipeClient.Instance.Service.SaveSequence(seq.Name, seq.ToXml());
  55. }
  56. public List<string> GetSequences()
  57. {
  58. return RecipeClient.Instance.Service.GetSequenceNameList();
  59. }
  60. public List<string> GetRecipes(ModuleName modulename)
  61. {
  62. return RecipeClient.Instance.Service.GetRecipes(modulename, true).ToList();
  63. }
  64. public SequenceData GetSequenceByName(ObservableCollection<EditorDataGridTemplateColumnBase> _columns, string name)
  65. {
  66. string content = RecipeClient.Instance.Service.GetSequence(name);
  67. SequenceData seq = new SequenceData();
  68. XmlDocument doc = new XmlDocument();
  69. doc.LoadXml(content);
  70. seq.Name = name;
  71. seq.Load(_columns, doc);
  72. return seq;
  73. }
  74. public bool Rename(string beforename, string currentname)
  75. {
  76. //if ((bool)QueryDataClient.Instance.Service.GetData("System.IsAutoMode"))
  77. //{
  78. // DialogBox.ShowDialog(DialogButton.OK, 0, "Auto状态下不能对Sequence做出修改");
  79. // return false;
  80. //}
  81. var path = GenerateSequenceFilePath("Sequence", currentname);
  82. if (CheckSequenceUsedInJob(path))
  83. {
  84. DialogBox.ShowDialog(DialogButton.OK, 0, "Sequence is used in auto running jobs, can not be modified");
  85. return false;
  86. }
  87. return RecipeClient.Instance.Service.RenameSequence(beforename, currentname);
  88. }
  89. public bool Delete(string name)
  90. {
  91. //if ((bool)QueryDataClient.Instance.Service.GetData("System.IsAutoMode"))
  92. //{
  93. // DialogBox.ShowDialog(DialogButton.OK, 0, "Auto状态下不能对Sequence做出修改");
  94. // return false;
  95. //}
  96. var path = GenerateSequenceFilePath("Sequence", name);
  97. if (CheckSequenceUsedInJob(path))
  98. {
  99. DialogBox.ShowDialog(DialogButton.OK, 0, "Sequence is used in auto running jobs, can not be modified");
  100. return false;
  101. }
  102. return RecipeClient.Instance.Service.DeleteSequence(name);
  103. }
  104. public bool SaveAs(string name, SequenceData seq)
  105. {
  106. //if ((bool)QueryDataClient.Instance.Service.GetData("System.IsAutoMode"))
  107. //{
  108. // DialogBox.ShowDialog(DialogButton.OK, 0, "Auto状态下不能对Sequence做出修改");
  109. // return false;
  110. //}
  111. var path = GenerateSequenceFilePath("Sequence", name);
  112. if (CheckSequenceUsedInJob(path))
  113. {
  114. DialogBox.ShowDialog(DialogButton.OK, 0, "Sequence is used in auto running jobs, can not be modified");
  115. return false;
  116. }
  117. return RecipeClient.Instance.Service.SaveAsSequence(name, seq.ToXml());
  118. }
  119. public string GetSequenceFromXml()
  120. {
  121. string template = RecipeClient.Instance.Service.GetSequenceFormatXml();
  122. return template;
  123. }
  124. private string GenerateSequenceFilePath(string chamId, string recipeName)
  125. {
  126. return getRecipeDirPath(chamId) + recipeName + ".seq";
  127. }
  128. private string getRecipeDirPath(string chamId)
  129. {
  130. var dir = string.Format("{0}{1}\\", PathManager.GetRecipeDir(), chamId);
  131. DirectoryInfo di = new DirectoryInfo(dir);
  132. if (!di.Exists) di.Create();
  133. return dir;
  134. }
  135. public bool CheckSequenceUsedInJob(string pathName)
  136. {
  137. List<ProcessJobInfo> ProcessList = (List<ProcessJobInfo>)QueryDataClient.Instance.Service.GetData("Scheduler.CurrentRecipeList");
  138. if (ProcessList != null)
  139. {
  140. foreach (var pj in ProcessList)
  141. {
  142. if (pathName.EndsWith(@"\" + pj.Sequence.Name + ".seq", System.StringComparison.OrdinalIgnoreCase))
  143. return true;
  144. }
  145. }
  146. return false;
  147. }
  148. }
  149. }