RecipeService.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ServiceModel;
  4. using Aitex.Core.RT.Event;
  5. using Aitex.Core.RT.Key;
  6. using Aitex.Core.RT.OperationCenter;
  7. using Aitex.Core.RT.RecipeCenter;
  8. using MECF.Framework.Common.Equipment;
  9. using Aitex.Core.RT.Log;
  10. namespace MECF.Framework.Common.RecipeCenter
  11. {
  12. public class RecipeService : IRecipeService
  13. {
  14. /// <summary>
  15. /// Load a recipe from server to client for editing.
  16. /// </summary>
  17. /// <param name="chamId"></param>
  18. /// <param name="recipeName"></param>
  19. /// <returns></returns>
  20. public string LoadRecipe(ModuleName chamId, string recipeName)
  21. {
  22. LOG.Write(eEvent.EV_SEQUENCE, ModuleName.System, string.Format("Read {0} Recipe: {1}", chamId, recipeName));
  23. return RecipeFileManager.Instance.LoadRecipe(chamId.ToString(), recipeName, false);
  24. }
  25. /// <summary>
  26. /// Delete a recipe by recipe name
  27. /// </summary>
  28. /// <param name="chamId"></param>
  29. /// <param name="recipeName"></param>
  30. /// <returns></returns>
  31. public bool DeleteRecipe(ModuleName chamId, string recipeName)
  32. {
  33. if (CheckSoftwareExpired())
  34. return false;
  35. //if (!ChamberOperationService.IsSuperEnter()) return false;
  36. LOG.Write(eEvent.EV_SEQUENCE, ModuleName.System, string.Format("Delete {0} Recipe: {1}", chamId, recipeName));
  37. return RecipeFileManager.Instance.DeleteRecipe(chamId.ToString(), recipeName);
  38. }
  39. /// <summary>
  40. /// Get recipe list in xml format
  41. /// </summary>
  42. /// <param name="chamId"></param>
  43. /// <param name="includingUsedRecipe"></param>
  44. /// <returns></returns>
  45. public string GetXmlRecipeList(ModuleName chamId, bool includingUsedRecipe)
  46. {
  47. return RecipeFileManager.Instance.GetXmlRecipeList(chamId.ToString(), includingUsedRecipe);
  48. }
  49. /// <summary>
  50. /// Get recipe data by recipe name
  51. /// </summary>
  52. /// <param name="chamId"></param>
  53. /// <param name="includingUsedRecipe"></param>
  54. /// <returns></returns>
  55. public IEnumerable<string> GetRecipes(ModuleName chamId, bool includingUsedRecipe)
  56. {
  57. return RecipeFileManager.Instance.GetRecipes(chamId.ToString(), includingUsedRecipe);
  58. }
  59. /// <summary>
  60. /// Rename recipe
  61. /// </summary>
  62. /// <param name="chamId"></param>
  63. /// <param name="oldName"></param>
  64. /// <param name="newName"></param>
  65. /// <returns></returns>
  66. public bool RenameRecipe(ModuleName chamId, string oldName, string newName)
  67. {
  68. if (CheckSoftwareExpired())
  69. return false;
  70. LOG.Write(eEvent.EV_SEQUENCE, ModuleName.System, string.Format("Rename {0} Recipe {1}为{2}", chamId, oldName, newName));
  71. //if (!ChamberOperationService.IsSuperEnter()) return false;
  72. return RecipeFileManager.Instance.RenameRecipe(chamId.ToString(), oldName, newName);
  73. }
  74. /// <summary>
  75. /// delete a recipe folder
  76. /// </summary>
  77. /// <param name="chamId"></param>
  78. /// <param name="folderName"></param>
  79. /// <returns></returns>
  80. public bool DeleteFolder(ModuleName chamId, string folderName)
  81. {
  82. if (CheckSoftwareExpired())
  83. return false;
  84. //if (!ChamberOperationService.IsSuperEnter()) return false;
  85. LOG.Write(eEvent.EV_SEQUENCE, ModuleName.System, string.Format("Delete {0} Recipe Folder: {1}", chamId, folderName));
  86. return RecipeFileManager.Instance.DeleteFolder(chamId.ToString(), folderName);
  87. }
  88. /// <summary>
  89. /// save recipe content
  90. /// </summary>
  91. /// <param name="chamId"></param>
  92. /// <param name="recipeName"></param>
  93. /// <param name="recipeContent"></param>
  94. /// <returns></returns>
  95. public bool SaveRecipe(ModuleName chamId, string recipeName, string recipeContent)
  96. {
  97. if (CheckSoftwareExpired())
  98. return false;
  99. LOG.Write(eEvent.EV_SEQUENCE, ModuleName.System, string.Format("Modify and save {0} Recipe: {1}", chamId, recipeName));
  100. return RecipeFileManager.Instance.SaveRecipe(chamId.ToString(), recipeName, recipeContent, false, false);
  101. }
  102. public bool SaveRecipeWithType(ModuleName chamId, string type, string recipeName, string recipeContent)
  103. {
  104. if (CheckSoftwareExpired())
  105. return false;
  106. LOG.Write(eEvent.EV_SEQUENCE, ModuleName.System, string.Format("Modify and save {0} Recipe: {1}", chamId, recipeName));
  107. return RecipeFileManager.Instance.SaveRecipe(chamId.ToString(),type, recipeName, recipeContent, false, false);
  108. }
  109. /// <summary>
  110. /// move recipe content
  111. /// </summary>
  112. /// <param name="chamId"></param>
  113. /// <param name="recipeName"></param>
  114. /// <returns></returns>
  115. public bool MoveRecipeFile(ModuleName chamId, string recipeName, string tragetFolderName)
  116. {
  117. if (CheckSoftwareExpired())
  118. return false;
  119. LOG.Write(eEvent.EV_SEQUENCE, ModuleName.System, string.Format("Move {0} recipe :{1}", chamId, recipeName));
  120. return RecipeFileManager.Instance.MoveRecipeFile(chamId.ToString(), recipeName, tragetFolderName, false, false);
  121. }
  122. /// <summary>
  123. /// save recipe content
  124. /// </summary>
  125. /// <param name="chamId"></param>
  126. /// <param name="recipeName"></param>
  127. /// <param name="recipeContent"></param>
  128. /// <returns></returns>
  129. public bool SaveAsRecipe(ModuleName chamId, string recipeName, string recipeContent)
  130. {
  131. if (CheckSoftwareExpired())
  132. return false;
  133. LOG.Write(eEvent.EV_SEQUENCE, ModuleName.System, string.Format("Modify and save as {0} recipe {1}", chamId, recipeName));
  134. return RecipeFileManager.Instance.SaveAsRecipe(chamId.ToString(), recipeName, recipeContent);
  135. }
  136. /// <summary>
  137. /// save recipe content
  138. /// </summary>
  139. /// <param name="chamId"></param>
  140. /// <param name="recipeName"></param>
  141. /// <param name="recipeContent"></param>
  142. /// <returns></returns>
  143. public bool SaveAsRecipeWithType(ModuleName chamId,string type, string recipeName, string recipeContent)
  144. {
  145. if (CheckSoftwareExpired())
  146. return false;
  147. LOG.Write(eEvent.EV_SEQUENCE, ModuleName.System, string.Format("Modify and save as {0} recipe {1}", chamId, recipeName));
  148. return RecipeFileManager.Instance.SaveAsRecipe(chamId.ToString(),type, recipeName, recipeContent);
  149. }
  150. /// <summary>
  151. /// create a new recipe folder
  152. /// </summary>
  153. /// <param name="chamId"></param>
  154. /// <param name="folderName"></param>
  155. /// <returns></returns>
  156. public bool CreateFolder(ModuleName chamId, string folderName)
  157. {
  158. if (CheckSoftwareExpired())
  159. return false;
  160. LOG.Write(eEvent.EV_SEQUENCE, ModuleName.System, string.Format("Create {0} recipe foler {1}", chamId, folderName));
  161. return RecipeFileManager.Instance.CreateFolder(chamId.ToString(), folderName);
  162. }
  163. /// <summary>
  164. /// Rename recipe folder name
  165. /// </summary>
  166. /// <param name="chamId"></param>
  167. /// <param name="oldName"></param>
  168. /// <param name="newName"></param>
  169. /// <returns></returns>
  170. public bool RenameFolder(ModuleName chamId, string oldName, string newName)
  171. {
  172. if (CheckSoftwareExpired())
  173. return false;
  174. LOG.Write(eEvent.EV_SEQUENCE, ModuleName.System, string.Format("Rename {0} recipe folder {1} to {2}", chamId, oldName, newName));
  175. return RecipeFileManager.Instance.RenameFolder(chamId.ToString(), oldName, newName);
  176. }
  177. private bool CheckSoftwareExpired()
  178. {
  179. bool isExpired = KeyManager.Instance.IsExpired;
  180. if (isExpired)
  181. LOG.Write(eEvent.WARN_SEQUENCE,ModuleName.System, "Software is expired. Can not do the operation");
  182. return isExpired;
  183. }
  184. /// <summary>
  185. /// get reactor's recipe format define file
  186. /// </summary>
  187. /// <param name="chamId"></param>
  188. /// <returns></returns>
  189. public string GetRecipeFormatXml(ModuleName chamId)
  190. {
  191. return RecipeFileManager.Instance.GetRecipeFormatXml(chamId.ToString());
  192. }
  193. /// <summary>
  194. /// get reactor's template recipe file
  195. /// </summary>
  196. /// <param name="chamId"></param>
  197. /// <returns></returns>
  198. public string GetRecipeTemplate(ModuleName chamId)
  199. {
  200. return RecipeFileManager.Instance.GetRecipeTemplate(chamId.ToString());
  201. }
  202. /// <summary>
  203. /// 获取当前反应腔正在运行的Recipe信息
  204. /// </summary>
  205. /// <param name="chamId"></param>
  206. /// <returns>recipeName + recipeContent</returns>
  207. public Tuple<string, string> LoadRunTimeRecipeInfo(ModuleName chamId)
  208. {
  209. return null;
  210. //var pm = PmManager.GetReactor(chamId);
  211. //if (pm != null) return pm.LoadRunTimeRecipeInfo();
  212. //return Singleton<PMEntity>.Instance.GetRecipeInfo();
  213. }
  214. public string GetRecipeByBarcode(ModuleName chamId, string barcode)
  215. {
  216. return "";
  217. //return RecipeFileManager.Instance.GetRecipeByBarcode(chamId.ToString(), barcode);
  218. }
  219. public string GetXmlSequenceList(ModuleName chamId )
  220. {
  221. return RecipeFileManager.Instance.GetXmlSequenceList(chamId.ToString() );
  222. }
  223. public string GetSequence(string sequenceName)
  224. {
  225. return RecipeFileManager.Instance.GetSequence(sequenceName, true);
  226. }
  227. public List<string> GetSequenceNameList()
  228. {
  229. return RecipeFileManager.Instance.GetSequenceNameList();
  230. }
  231. public bool DeleteSequence(string sequenceName)
  232. {
  233. return RecipeFileManager.Instance.DeleteSequence(sequenceName);
  234. }
  235. public bool SaveSequence(string sequenceName, string sequenceContent)
  236. {
  237. return RecipeFileManager.Instance.SaveSequence(sequenceName, sequenceContent, false);
  238. }
  239. public bool SaveAsSequence(string sequenceName, string sequenceContent)
  240. {
  241. return RecipeFileManager.Instance.SaveAsSequence(sequenceName, sequenceContent);
  242. }
  243. public bool RenameSequence(string oldName, string newName)
  244. {
  245. return RecipeFileManager.Instance.RenameSequence(oldName, newName);
  246. }
  247. public string GetSequenceFormatXml()
  248. {
  249. return RecipeFileManager.Instance.GetSequenceFormatXml();
  250. }
  251. public bool RenameSequenceFolder(string oldName, string newName)
  252. {
  253. return RecipeFileManager.Instance.RenameSequenceFolder(oldName, newName);
  254. }
  255. public bool CreateSequenceFolder(string folderName)
  256. {
  257. return RecipeFileManager.Instance.CreateSequenceFolder(folderName);
  258. }
  259. public bool DeleteSequenceFolder(string folderName)
  260. {
  261. return RecipeFileManager.Instance.DeleteSequenceFolder(folderName);
  262. }
  263. #region extended recipe interface
  264. public string LoadRecipeByPath(string path)
  265. {
  266. return RecipeFileManager.Instance.LoadRecipeByPath(path);
  267. }
  268. public bool DeleteRecipeByPath(string pathName, string recipeName)
  269. {
  270. return RecipeFileManager.Instance.DeleteRecipe(pathName, recipeName);
  271. }
  272. public string GetXmlRecipeListByPath(string pathName, bool includingUsedRecipe)
  273. {
  274. return RecipeFileManager.Instance.GetXmlRecipeList(pathName, includingUsedRecipe);
  275. }
  276. public IEnumerable<string> GetRecipesByPath(string pathName, bool includingUsedRecipe)
  277. {
  278. return RecipeFileManager.Instance.GetRecipes(pathName, includingUsedRecipe);
  279. }
  280. public bool RenameRecipeByPath(string pathName, string oldName, string newName)
  281. {
  282. return RecipeFileManager.Instance.RenameRecipe(pathName, oldName, newName);
  283. }
  284. public bool DeleteFolderByPath(string pathName, string folderName)
  285. {
  286. return RecipeFileManager.Instance.DeleteFolder(pathName, folderName);
  287. }
  288. public bool SaveRecipeByPath(string pathName, string recipeName, string recipeContent)
  289. {
  290. return RecipeFileManager.Instance.SaveRecipe(pathName, recipeName, recipeContent, false, false);
  291. }
  292. public bool SaveAsRecipeByPath(string pathName, string recipeName, string recipeContent)
  293. {
  294. return RecipeFileManager.Instance.SaveAsRecipe(pathName, recipeName, recipeContent);
  295. }
  296. public bool CreateFolderByPath(string pathName, string folderName)
  297. {
  298. return RecipeFileManager.Instance.CreateFolder(pathName, folderName);
  299. }
  300. public bool RenameFolderByPath(string pathName, string oldName, string newName)
  301. {
  302. return RecipeFileManager.Instance.RenameFolder(pathName, oldName, newName);
  303. }
  304. public string GetRecipeFormatXmlByPath(string pathName)
  305. {
  306. return RecipeFileManager.Instance.GetRecipeFormatXml(pathName);
  307. }
  308. public string GetRecipeTemplateByPath(string pathName)
  309. {
  310. return RecipeFileManager.Instance.GetRecipeTemplate(pathName);
  311. }
  312. public Tuple<string, string> LoadRunTimeRecipeInfoByPath(string pathName)
  313. {
  314. return null;
  315. }
  316. public string GetRecipeByBarcodeByPath(string pathName, string barcode)
  317. {
  318. return "";
  319. }
  320. #endregion
  321. }
  322. }