RecipeDataJob.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  1. using Aitex.Core.RT.Log;
  2. using Caliburn.Micro.Core;
  3. using MECF.Framework.Common.RecipeCenter;
  4. using MECF.Framework.UI.Client.CenterViews.Editors.Recipe;
  5. using RecipeEditorLib.RecipeModel.Params;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Collections.ObjectModel;
  9. using System.Reflection;
  10. using System.Text;
  11. using System.Xml;
  12. namespace FurnaceUI.Views.Recipes
  13. {
  14. public class RecipeDataJob : PropertyChangedBase
  15. {
  16. private string _prefixPath;
  17. public string PrefixPath
  18. {
  19. get => _prefixPath;
  20. set
  21. {
  22. _prefixPath = value;
  23. NotifyOfPropertyChange(nameof(PrefixPath));
  24. }
  25. }
  26. private string _name;
  27. public string Name
  28. {
  29. get => _name;
  30. set
  31. {
  32. _name = value;
  33. NotifyOfPropertyChange(nameof(Name));
  34. }
  35. }
  36. private string _createBy;
  37. public string CreateBy
  38. {
  39. get => _createBy;
  40. set
  41. {
  42. _createBy = value;
  43. NotifyOfPropertyChange(nameof(CreateBy));
  44. }
  45. }
  46. private string _createTime;
  47. public string CreateTime
  48. {
  49. get => _createTime;
  50. set
  51. {
  52. _createTime = value;
  53. NotifyOfPropertyChange(nameof(CreateTime));
  54. }
  55. }
  56. private string _lastReviseBy;
  57. public string LastReviseBy
  58. {
  59. get => _lastReviseBy;
  60. set
  61. {
  62. _lastReviseBy = value;
  63. NotifyOfPropertyChange(nameof(LastReviseBy));
  64. }
  65. }
  66. private string _lastRevisionTime;
  67. public string LastRevisionTime
  68. {
  69. get => _lastRevisionTime;
  70. set
  71. {
  72. _lastRevisionTime = value;
  73. NotifyOfPropertyChange(nameof(LastRevisionTime));
  74. }
  75. }
  76. private string _description;
  77. public string Description
  78. {
  79. get => _description;
  80. set
  81. {
  82. _description = value;
  83. NotifyOfPropertyChange(nameof(Description));
  84. }
  85. }
  86. private string _recipePermission;
  87. public string RecipePermission
  88. {
  89. get { return this._recipePermission; }
  90. set
  91. {
  92. this._recipePermission = value;
  93. this.NotifyOfPropertyChange("RecipePermisson");
  94. }
  95. }
  96. private string _recipeLevel;
  97. public string RecipeLevel
  98. {
  99. get { return this._recipeLevel; }
  100. set
  101. {
  102. this._recipeLevel = value;
  103. this.NotifyOfPropertyChange("RecipeLevel");
  104. }
  105. }
  106. private string _processRecipe;
  107. public string ProcessRecipe
  108. {
  109. get => _processRecipe;
  110. set
  111. {
  112. _processRecipe = value;
  113. NotifyOfPropertyChange(nameof(ProcessRecipe));
  114. }
  115. }
  116. private string _layoutRecipe;
  117. public string LayoutRecipe
  118. {
  119. get => _layoutRecipe;
  120. set
  121. {
  122. _layoutRecipe = value;
  123. NotifyOfPropertyChange(nameof(LayoutRecipe));
  124. }
  125. }
  126. private string _coolTime;
  127. public string CoolTime
  128. {
  129. get => _coolTime;
  130. set
  131. {
  132. _coolTime = value;
  133. NotifyOfPropertyChange(nameof(CoolTime));
  134. }
  135. }
  136. private string _recipeChamberType;
  137. public string RecipeChamberType
  138. {
  139. get => _recipeChamberType;
  140. set
  141. {
  142. _recipeChamberType = value;
  143. NotifyOfPropertyChange(nameof(RecipeChamberType));
  144. }
  145. }
  146. private string _recipeVersion;
  147. public string RecipeVersion
  148. {
  149. get => _recipeVersion;
  150. set
  151. {
  152. _recipeVersion = value;
  153. NotifyOfPropertyChange(nameof(RecipeVersion));
  154. }
  155. }
  156. private XmlDocument _doc;
  157. private string _module;
  158. private RecipeProvider _recipeProvider = new RecipeProvider();
  159. public RecipeDataJob()
  160. {
  161. _doc = new XmlDocument();
  162. }
  163. public void Clear()
  164. {
  165. CreateBy = "";
  166. CreateTime = "";
  167. LastReviseBy = "";
  168. LastRevisionTime = "";
  169. Description = "";
  170. RecipeChamberType = "";
  171. RecipeVersion = "";
  172. _module = "";
  173. }
  174. public void InitData(string prefixPath, string recipeName, string recipeContent, string module)
  175. {
  176. PrefixPath = prefixPath;
  177. Name = recipeName;
  178. _module = module;
  179. try
  180. {
  181. _doc = new XmlDocument();
  182. _doc.LoadXml(recipeContent);
  183. if (!LoadHeader(_doc.SelectSingleNode("Aitex/TableRecipeData")))
  184. return;
  185. XmlNode nodeModule;
  186. nodeModule = _doc.SelectSingleNode("Aitex/TableRecipeData");
  187. XmlElement stepNode = nodeModule as XmlElement;
  188. foreach (XmlAttribute att in stepNode.Attributes)
  189. {
  190. switch (att.Name)
  191. {
  192. case "CreatedBy":
  193. CreateBy = att.Value;
  194. break;
  195. case "CreationTime":
  196. CreateTime = att.Value;
  197. break;
  198. case "LastRevisedBy":
  199. LastReviseBy = att.Value;
  200. break;
  201. case "LastRevisionTime":
  202. LastRevisionTime = att.Value;
  203. break;
  204. case "Description":
  205. Description = att.Value;
  206. break;
  207. }
  208. }
  209. nodeModule = _doc.SelectSingleNode($"Aitex/TableRecipeData/Module[@Name='{module}']/Step");
  210. if (nodeModule == null)
  211. return;
  212. stepNode = nodeModule as XmlElement;
  213. foreach (XmlAttribute att in stepNode.Attributes)
  214. {
  215. switch (att.Name)
  216. {
  217. case "ProcessRecipe":
  218. ProcessRecipe = att.Value;
  219. break;
  220. case "LayoutRecipe":
  221. LayoutRecipe = att.Value;
  222. break;
  223. case "CoolTime":
  224. CoolTime = att.Value;
  225. break;
  226. }
  227. }
  228. }
  229. catch (Exception ex)
  230. {
  231. LOG.Write(ex);
  232. }
  233. }
  234. public string GetXmlString()
  235. {
  236. try
  237. {
  238. XmlElement nodeData = _doc.SelectSingleNode($"Aitex/TableRecipeData") as XmlElement;
  239. nodeData.SetAttribute("LastRevisedBy", LastReviseBy);
  240. nodeData.SetAttribute("LastRevisionTime", LastRevisionTime);
  241. nodeData.SetAttribute("Description", Description);
  242. nodeData.SetAttribute("RecipeChamberType", RecipeChamberType);
  243. nodeData.SetAttribute("RecipePermission", RecipePermission);
  244. nodeData.SetAttribute("RecipeLevel", RecipeLevel);
  245. XmlNode nodeModule = _doc.SelectSingleNode($"Aitex/TableRecipeData/Module[@Name='{_module}']");
  246. if (nodeModule == null)
  247. {
  248. nodeModule = _doc.CreateElement("Module");
  249. nodeData.AppendChild(nodeModule);
  250. }
  251. nodeModule.RemoveAll();
  252. (nodeModule as XmlElement).SetAttribute("Name", _module);
  253. XmlElement nodeStep = _doc.CreateElement("Step");
  254. nodeStep.SetAttribute("ProcessRecipe", ProcessRecipe);
  255. nodeStep.SetAttribute("LayoutRecipe", LayoutRecipe);
  256. nodeStep.SetAttribute("CoolTime", CoolTime);
  257. nodeModule.AppendChild(nodeStep);
  258. }
  259. catch (Exception ex)
  260. {
  261. LOG.Write(ex);
  262. return _doc.OuterXml;
  263. }
  264. return _doc.OuterXml;
  265. }
  266. private bool LoadHeader(XmlNode nodeHeader)
  267. {
  268. if (nodeHeader == null)
  269. return false;
  270. if (nodeHeader.Attributes["CreatedBy"] != null)
  271. CreateBy = nodeHeader.Attributes["CreatedBy"].Value;
  272. if (nodeHeader.Attributes["CreationTime"] != null)
  273. CreateTime = nodeHeader.Attributes["CreationTime"].Value;
  274. if (nodeHeader.Attributes["LastRevisedBy"] != null)
  275. LastReviseBy = nodeHeader.Attributes["LastRevisedBy"].Value;
  276. if (nodeHeader.Attributes["LastRevisionTime"] != null)
  277. LastRevisionTime = nodeHeader.Attributes["LastRevisionTime"].Value;
  278. if (nodeHeader.Attributes["Description"] != null)
  279. Description = nodeHeader.Attributes["Description"].Value;
  280. if (nodeHeader.Attributes["RecipeLevel"] != null)
  281. RecipeLevel = nodeHeader.Attributes["RecipeLevel"].Value;
  282. string chamberType = string.Empty;
  283. if (nodeHeader.Attributes["RecipeChamberType"] != null)
  284. chamberType = nodeHeader.Attributes["RecipeChamberType"].Value;
  285. if (!string.IsNullOrEmpty(chamberType) && chamberType != RecipeChamberType)
  286. {
  287. LOG.Write($"{chamberType} is not accordance with {RecipeChamberType}");
  288. return false;
  289. }
  290. return true;
  291. }
  292. }
  293. }