Recipe.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Collections.ObjectModel;
  4. using System.ComponentModel;
  5. using System.Dynamic;
  6. using System.IO;
  7. using System.Linq;
  8. using System.Reflection;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. using Newtonsoft.Json;
  12. using Newtonsoft.Json.Converters;
  13. namespace Venus_Core
  14. {
  15. public enum RecipeType
  16. {
  17. Chuck,
  18. DeChuck,
  19. Process,
  20. Clean,
  21. }
  22. public enum StepType
  23. {
  24. Time,
  25. Stable,
  26. EndPoint,
  27. OverEtch,
  28. }
  29. public enum ProcessModule
  30. {
  31. Pressure,
  32. TCP, // Transformer Coupled Plasma (转换耦合等离子)
  33. Bias,
  34. Gas,
  35. ESC,
  36. Process,
  37. Compound,
  38. }
  39. public enum GeneratorMode
  40. {
  41. Pulsing,
  42. CW,
  43. }
  44. public enum PressureUnitMode
  45. {
  46. Pressure,
  47. Valve
  48. }
  49. public class RecipeHead: INotifyPropertyChanged
  50. {
  51. private string m_name;
  52. public string Name
  53. {
  54. get { return m_name; }
  55. set { m_name = value; InvokePropertyChanged("Name"); }
  56. }
  57. private string _Version = "Test";
  58. public string Version
  59. {
  60. get { return _Version; }
  61. set { _Version = value; InvokePropertyChanged("Version"); }
  62. }
  63. private RecipeType m_Type;
  64. [JsonConverter(typeof(StringEnumConverter))]
  65. public RecipeType Type
  66. {
  67. get { return m_Type; }
  68. set { m_Type = value; InvokePropertyChanged("Type"); }
  69. }
  70. private string m_ChunckRecipe;
  71. public string ChuckRecipe
  72. {
  73. get { return m_ChunckRecipe;}
  74. set { m_ChunckRecipe = value; InvokePropertyChanged("ChuckRecipe"); }
  75. }
  76. private string m_DechuckRecipe;
  77. public string DechuckRecipe
  78. {
  79. get { return m_DechuckRecipe;}
  80. set{ m_DechuckRecipe = value;InvokePropertyChanged("DechuckRecipe");}
  81. }
  82. private string m_CreateTime;
  83. public string CreateTime
  84. {
  85. get { return m_CreateTime;}
  86. set { m_CreateTime = value; InvokePropertyChanged("CreateTime"); }
  87. }
  88. private string m_LastModifiedBy;
  89. public string LastModifiedBy
  90. {
  91. get { return m_LastModifiedBy;}
  92. set { m_LastModifiedBy = value; InvokePropertyChanged("CreateTime"); }
  93. }
  94. private string m_Barcode;
  95. public string Barcode
  96. {
  97. get { return m_Barcode;}
  98. set { m_Barcode = value; InvokePropertyChanged("Barcode"); }
  99. }
  100. private string m_BasePressure;
  101. public string BasePressure
  102. {
  103. get { return m_BasePressure;}
  104. set { m_BasePressure = value; InvokePropertyChanged("BasePressure"); }
  105. }
  106. private string m_ChillerTemp;
  107. public string ChillerTemp
  108. {
  109. get { return m_ChillerTemp;}
  110. set { m_ChillerTemp = value; InvokePropertyChanged("ChillerTemp"); }
  111. }
  112. public event PropertyChangedEventHandler PropertyChanged;
  113. public void InvokePropertyChanged(string propertyName)
  114. {
  115. if (PropertyChanged != null)
  116. {
  117. PropertyChanged.Invoke(this, new PropertyChangedEventArgs(propertyName));
  118. }
  119. }
  120. }
  121. public class ProcessUnitBase
  122. {
  123. [JsonIgnore]
  124. public Func<RState> checker;
  125. [JsonIgnore]
  126. public Func<RState> starter;
  127. //[JsonIgnore]
  128. //public string Name { get; set; }
  129. //[JsonIgnore]
  130. //public ProcessModule Moudle { get; set; }
  131. public RState Start()
  132. {
  133. if (starter != null)
  134. return starter();
  135. return RState.Running;
  136. }
  137. public RState Run()
  138. {
  139. if (checker != null)
  140. return checker();
  141. return RState.Running;
  142. }
  143. }
  144. public class RecipeStep:INotifyPropertyChanged
  145. {
  146. private StepType m_StepType;
  147. [JsonConverter(typeof(StringEnumConverter))]
  148. public StepType Type
  149. {
  150. get { return m_StepType;}
  151. set { m_StepType = value; InvokePropertyChanged("Type"); }
  152. }
  153. private int m_Time;
  154. public int Time
  155. {
  156. get { return m_Time;}
  157. set { m_Time = value; InvokePropertyChanged("Time"); }
  158. }
  159. private int m_MinEndPointTime;
  160. public int MinEndPointTime
  161. {
  162. get { return m_MinEndPointTime;}
  163. set { m_MinEndPointTime = value; InvokePropertyChanged("MinEndPointTime"); }
  164. }
  165. private int m_MaxEndPointTime;
  166. public int MaxEndPointTime
  167. {
  168. get { return m_MaxEndPointTime; }
  169. set { m_MaxEndPointTime = value; InvokePropertyChanged("MaxEndPointTime"); }
  170. }
  171. private bool m_CycleStart;
  172. public bool CycleStart
  173. {
  174. get { return m_CycleStart;}
  175. set { m_CycleStart = value; InvokePropertyChanged("CycleStart"); }
  176. }
  177. private bool m_CycleEnd;
  178. public bool CycleEnd
  179. {
  180. get { return m_CycleEnd;}
  181. set { m_CycleEnd = value; InvokePropertyChanged("CycleEnd"); }
  182. }
  183. private int m_CycleNumber;
  184. public int CycleNumber
  185. {
  186. get { return m_CycleNumber;}
  187. set { m_CycleNumber = value; InvokePropertyChanged("CycleNumber"); }
  188. }
  189. public PressureUnitMode PressureUnitMode { get; set; }
  190. private ObservableCollection<Object> lstUnit = new ObservableCollection<Object>();
  191. public ObservableCollection<Object> LstUnit
  192. {
  193. get { return lstUnit; }
  194. set { lstUnit = value; InvokePropertyChanged("LstUnit"); }
  195. }
  196. public RState Start()
  197. {
  198. //foreach(var unit in lstUnit)
  199. //{
  200. // var state = unit.Start();
  201. // if (state != RState.Running)
  202. // return state;
  203. //}
  204. return RState.Running;
  205. }
  206. public RState Run()
  207. {
  208. //foreach (var unit in lstUnit)
  209. //{
  210. // var state = unit.Run();
  211. // if (state != RState.Running)
  212. // return state;
  213. //}
  214. return RState.Running;
  215. }
  216. public void AppendUnit(ProcessUnitBase unit)
  217. {
  218. lstUnit.Append(unit);
  219. }
  220. public event PropertyChangedEventHandler PropertyChanged;
  221. public void InvokePropertyChanged(string propertyName)
  222. {
  223. if (PropertyChanged != null)
  224. {
  225. PropertyChanged.Invoke(this, new PropertyChangedEventArgs(propertyName));
  226. }
  227. }
  228. }
  229. public class Recipe: INotifyPropertyChanged
  230. {
  231. private RecipeHead m_Header = new RecipeHead();
  232. public RecipeHead Header
  233. {
  234. get { return m_Header; }
  235. set { m_Header = value; InvokePropertyChanged("Header"); }
  236. }
  237. private ObservableCollection<RecipeStep> m_Steps;
  238. public ObservableCollection<RecipeStep> Steps
  239. {
  240. get { return m_Steps; }
  241. set { m_Steps = value; InvokePropertyChanged("Steps"); }
  242. }
  243. public static Recipe Load(string recipeFile)
  244. {
  245. var recipe= JsonConvert.DeserializeObject<Recipe>(recipeFile);
  246. foreach (var step in recipe.Steps)
  247. {
  248. ObservableCollection<ProcessUnitBase> unit = new ObservableCollection<ProcessUnitBase>();
  249. //int count = step.LstUnit.Count / 2;
  250. //for (int i = 0; i < count; i++)
  251. //{
  252. // Type t = Type.GetType(step.LstUnit[i].ToString());
  253. // //unit.Add(JsonConvert.DeserializeObject<t>(step.LstUnit[i+count].ToString()));
  254. // unit.Add(JsonConvert.DeserializeObject<ProcessUnitBase>(step.LstUnit[i + count].ToString()));
  255. //}
  256. for (int i=0;i< step.LstUnit.Count; i++)
  257. {
  258. //object item=step.LstUnit[i];
  259. string value = step.LstUnit[i].ToString();
  260. string[] striparr = value.Split(new string[] { "\r\n" }, StringSplitOptions.None);
  261. string item1= striparr[1].Remove(0, 15);
  262. string item2 = item1.Remove(item1.Length - 2, 2);
  263. //var item= value.Substring(value.IndexOf("UnitName"));
  264. //Type t = Type.GetType(value);
  265. switch (item2)
  266. {
  267. case "PressureUnitByPressureMode":
  268. unit.Add(JsonConvert.DeserializeObject<PressureUnitByPressureMode>(step.LstUnit[i].ToString()));
  269. break;
  270. case "PressureUnitByValveMode":
  271. unit.Add(JsonConvert.DeserializeObject<PressureUnitByValveMode>(step.LstUnit[i].ToString()));
  272. break;
  273. case "TCPUnit":
  274. unit.Add(JsonConvert.DeserializeObject<TCPUnit>(step.LstUnit[i].ToString()));
  275. break;
  276. case "BiasUnit":
  277. unit.Add(JsonConvert.DeserializeObject<BiasUnit>(step.LstUnit[i].ToString()));
  278. break;
  279. case "GasControlUnit":
  280. unit.Add(JsonConvert.DeserializeObject<GasControlUnit>(step.LstUnit[i].ToString()));
  281. break;
  282. case "ESCHVUnit":
  283. unit.Add(JsonConvert.DeserializeObject<ESCHVUnit>(step.LstUnit[i].ToString()));
  284. break;
  285. case "ProcessKitUnit":
  286. unit.Add(JsonConvert.DeserializeObject<ProcessKitUnit>(step.LstUnit[i].ToString()));
  287. break;
  288. }
  289. }
  290. step.LstUnit.Clear();
  291. unit.ToList().ForEach(x =>
  292. {
  293. step.LstUnit.Add(x);
  294. });
  295. }
  296. return recipe;
  297. }
  298. public bool Validate()
  299. {
  300. return true;
  301. }
  302. public bool Save(string recipeFile)
  303. {
  304. return true;
  305. }
  306. public event PropertyChangedEventHandler PropertyChanged;
  307. public void InvokePropertyChanged(string propertyName)
  308. {
  309. if (PropertyChanged != null)
  310. {
  311. PropertyChanged.Invoke(this, new PropertyChangedEventArgs(propertyName));
  312. }
  313. }
  314. }
  315. public class RecipeUnity
  316. {
  317. public static string ConvertJsonString(string str)
  318. {
  319. JsonSerializer serializer = new JsonSerializer();
  320. TextReader tr = new StringReader(str);
  321. JsonTextReader jtr = new JsonTextReader(tr);
  322. object obj = serializer.Deserialize(jtr);
  323. if (obj != null)
  324. {
  325. StringWriter textWriter = new StringWriter();
  326. JsonTextWriter jsonWriter = new JsonTextWriter(textWriter)
  327. {
  328. Formatting = Newtonsoft.Json.Formatting.Indented,
  329. Indentation = 4,
  330. IndentChar = ' '
  331. };
  332. serializer.Serialize(jsonWriter, obj);
  333. return textWriter.ToString();
  334. }
  335. else
  336. {
  337. return str;
  338. }
  339. }
  340. public static string RecipeToString(Recipe recipe)
  341. {
  342. return JsonConvert.SerializeObject(recipe);
  343. }
  344. public static String CreateRecipe(RecipeType recipeType)
  345. {
  346. Recipe recipe = new Recipe();
  347. recipe.Header = new RecipeHead();
  348. recipe.Header.CreateTime = DateTime.Now.ToString();
  349. recipe.Header.Type = recipeType;
  350. recipe.Steps = new ObservableCollection<RecipeStep>();
  351. recipe.Steps.Add(new RecipeStep()
  352. {
  353. LstUnit = new ObservableCollection<Object>()
  354. {
  355. new TCPUnit(){},
  356. new BiasUnit(),
  357. new GasControlUnit(),
  358. new ESCHVUnit(),
  359. new ProcessKitUnit()
  360. }
  361. });
  362. var recipeString = JsonConvert.SerializeObject(recipe);
  363. //var Recipe2=JsonConvert.DeserializeObject<Recipe>(recipeString);
  364. //string test = "";
  365. //test = Recipe2.Steps[0].LstUnit[0].ToString();
  366. //var tcpinit = JsonConvert.DeserializeObject<TCPUnit>(test);
  367. return recipeString;
  368. }
  369. }
  370. }