Recipe.cs 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Collections.ObjectModel;
  4. using System.ComponentModel;
  5. using System.Diagnostics;
  6. using System.IO;
  7. using System.Linq;
  8. using Newtonsoft.Json;
  9. using Newtonsoft.Json.Converters;
  10. using Newtonsoft.Json.Linq;
  11. using Venus_Core.Attributes;
  12. namespace Venus_Core
  13. {
  14. public enum RecipeType
  15. {
  16. Chuck,
  17. DeChuck,
  18. Process,
  19. Clean,
  20. }
  21. public enum StepType
  22. {
  23. Time,
  24. Stable,
  25. EndPoint,
  26. OverEtch,
  27. }
  28. public enum ProcessModule
  29. {
  30. Pressure,
  31. TCP, // Transformer Coupled Plasma (转换耦合等离子)
  32. Bias,
  33. Gas,
  34. ESC,
  35. Process,
  36. Compound,
  37. }
  38. public enum GeneratorMode
  39. {
  40. CW,
  41. Pulsing,
  42. }
  43. public enum PressureUnitMode
  44. {
  45. Pressure,
  46. Valve
  47. }
  48. public enum Suspect
  49. {
  50. Origin,
  51. Position1,
  52. Position2,
  53. Position3,
  54. Position4,
  55. Position5
  56. }
  57. public enum TargetMode
  58. {
  59. Step,
  60. Cycle
  61. }
  62. public enum ToleranceMode
  63. {
  64. None,
  65. Value,
  66. Percent
  67. }
  68. public enum MatchWorkMode
  69. {
  70. Auto,
  71. Manual
  72. }
  73. public class RecipeHead : INotifyPropertyChanged
  74. {
  75. private string m_name;
  76. [IsOnlyRead]
  77. public string Name
  78. {
  79. get { return m_name; }
  80. set { m_name = value; InvokePropertyChanged("Name"); }
  81. }
  82. private string _Version = "TestVersion";
  83. public string Version
  84. {
  85. get { return _Version; }
  86. set { _Version = value; InvokePropertyChanged("Version"); }
  87. }
  88. private JetChamber _ChamberType = JetChamber.None;
  89. [JsonConverter(typeof(StringEnumConverter))]
  90. [IsOnlyRead]
  91. public JetChamber ChamberType
  92. {
  93. get { return _ChamberType; }
  94. set { _ChamberType = value; InvokePropertyChanged("ChamberType"); }
  95. }
  96. private RecipeType m_Type;
  97. [JsonConverter(typeof(StringEnumConverter))]
  98. [IsOnlyRead]
  99. public RecipeType Type
  100. {
  101. get { return m_Type; }
  102. set { m_Type = value; InvokePropertyChanged("Type"); }
  103. }
  104. private string m_ChunckRecipe;
  105. [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)]
  106. public string ChuckRecipe
  107. {
  108. get { return m_ChunckRecipe; }
  109. set { m_ChunckRecipe = value; InvokePropertyChanged("ChuckRecipe"); }
  110. }
  111. private string m_DechuckRecipe;
  112. [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)]
  113. public string DechuckRecipe
  114. {
  115. get { return m_DechuckRecipe; }
  116. set { m_DechuckRecipe = value; InvokePropertyChanged("DechuckRecipe"); }
  117. }
  118. private bool m_IsShowTolerance;
  119. public bool IsShowTolerance
  120. {
  121. get { return m_IsShowTolerance; }
  122. set { m_IsShowTolerance = value; InvokePropertyChanged("IsShowTolerance"); }
  123. }
  124. private string m_CreateTime;
  125. [IsOnlyRead]
  126. public string CreateTime
  127. {
  128. get { return m_CreateTime; }
  129. set { m_CreateTime = value; InvokePropertyChanged("CreateTime"); }
  130. }
  131. private string m_EditTime;
  132. [IsOnlyRead]
  133. public string EditTime
  134. {
  135. get { return m_EditTime; }
  136. set { m_EditTime = value; InvokePropertyChanged("EditTime"); }
  137. }
  138. private string m_LastModifiedBy;
  139. [IsOnlyRead]
  140. public string LastModifiedBy
  141. {
  142. get { return m_LastModifiedBy; }
  143. set { m_LastModifiedBy = value; InvokePropertyChanged("LastModifiedBy"); }
  144. }
  145. private string m_Barcode;
  146. public string Barcode
  147. {
  148. get { return m_Barcode; }
  149. set { m_Barcode = value; InvokePropertyChanged("Barcode"); }
  150. }
  151. private string m_BasePressure;
  152. public string BasePressure
  153. {
  154. get { return m_BasePressure; }
  155. set { m_BasePressure = value; InvokePropertyChanged("BasePressure"); }
  156. }
  157. private string m_WallTemperature;
  158. [DefaultValue(null)]
  159. [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)]
  160. public string WallTemperature
  161. {
  162. get { return m_WallTemperature; }
  163. set { m_WallTemperature = value; InvokePropertyChanged("WallTemperature"); }
  164. }
  165. private string m_Temperature;
  166. public string Temperature
  167. {
  168. get { return m_Temperature; }
  169. set { m_Temperature = value; InvokePropertyChanged("Temperature"); }
  170. }
  171. private int m_RFHoldTime = 1000;
  172. [CustomName("RF HoldTime(s)")]
  173. public int RFHoldTime
  174. {
  175. get { return m_RFHoldTime; }
  176. set { m_RFHoldTime = value; InvokePropertyChanged("RFHoldTime"); }
  177. }
  178. private int? m_BiasRFHoldTime;
  179. [CustomName("BiasRF HoldTime(s)")]
  180. [DefaultValue(null)]
  181. [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)]
  182. public int? BiasRFHoldTime
  183. {
  184. get { return m_BiasRFHoldTime; }
  185. set { m_BiasRFHoldTime = value; InvokePropertyChanged("BiasRFHoldTime"); }
  186. }
  187. private string m_Comment;
  188. public string Comment
  189. {
  190. get { return m_Comment; }
  191. set { m_Comment = value; InvokePropertyChanged("Comment"); }
  192. }
  193. public event PropertyChangedEventHandler PropertyChanged;
  194. public void InvokePropertyChanged(string propertyName)
  195. {
  196. if (PropertyChanged != null)
  197. {
  198. PropertyChanged.Invoke(this, new PropertyChangedEventArgs(propertyName));
  199. }
  200. }
  201. public RecipeHead()
  202. {
  203. //WallTemperature = null;
  204. }
  205. }
  206. public abstract class ProcessUnitBase
  207. {
  208. [JsonIgnore]
  209. public Func<ProcessUnitBase, RecipeStep, RState> checker;
  210. [JsonIgnore]
  211. public Func<ProcessUnitBase, RecipeStep, RState> starter;
  212. [JsonIgnore]
  213. public Action<ProcessUnitBase, RecipeStep> end;
  214. //[JsonIgnore]
  215. //public string Name { get; set; }
  216. //[JsonIgnore]
  217. //public ProcessModule Moudle { get; set; }
  218. public RState Start(RecipeStep step)
  219. {
  220. if (starter != null)
  221. return starter(this, step);
  222. return RState.Running;
  223. }
  224. public RState Run(RecipeStep step)
  225. {
  226. if (checker != null)
  227. return checker(this, step);
  228. return RState.Running;
  229. }
  230. public void End(RecipeStep step)
  231. {
  232. if (end != null)
  233. end(this, step);
  234. }
  235. //public virtual Dictionary<string,float> GetFDCItems()
  236. //{
  237. // return null;
  238. //}
  239. }
  240. [Serializable]
  241. public class RecipeStep : INotifyPropertyChanged
  242. {
  243. [JsonIgnore]
  244. public Func<RecipeStep, RState> checker;
  245. [JsonIgnore]
  246. public Func<RecipeStep, RState> starter;
  247. [JsonIgnore]
  248. public Func<RecipeStep, RState> ender;
  249. private int m_StepNo = 1;
  250. [IsOnlyRead]
  251. public int StepNo
  252. {
  253. get { return m_StepNo; }
  254. set { m_StepNo = value; InvokePropertyChanged("StepNo"); }
  255. }
  256. private StepType m_StepType;
  257. [JsonConverter(typeof(StringEnumConverter))]
  258. public StepType Type
  259. {
  260. get { return m_StepType; }
  261. set { m_StepType = value; InvokePropertyChanged("Type"); }
  262. }
  263. private int m_Time;
  264. [CustomName("Time(s)")]
  265. public int Time
  266. {
  267. get { return m_Time; }
  268. set { m_Time = value; InvokePropertyChanged("Time"); }
  269. }
  270. private string m_Description;
  271. public string Description
  272. {
  273. get { return m_Description; }
  274. set { m_Description = value; InvokePropertyChanged("Description"); }
  275. }
  276. private string m_EPDConfigName;
  277. [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)]
  278. public string EPDConfig
  279. {
  280. get { return m_EPDConfigName; }
  281. set { m_EPDConfigName = value; InvokePropertyChanged("EPDConfig"); }
  282. }
  283. private int? m_MinEndPointTime;
  284. [CustomName("MinEndPointTime(s)")]
  285. [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)]
  286. public int? MinEndPointTime
  287. {
  288. get { return m_MinEndPointTime; }
  289. set { m_MinEndPointTime = value; InvokePropertyChanged("MinEndPointTime"); }
  290. }
  291. private int? m_MaxEndPointTime;
  292. [CustomName("MaxEndPointTime(s)")]
  293. [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)]
  294. public int? MaxEndPointTime
  295. {
  296. get { return m_MaxEndPointTime; }
  297. set { m_MaxEndPointTime = value; InvokePropertyChanged("MaxEndPointTime"); }
  298. }
  299. private int? m_OverEtchPercent;
  300. [CustomName("OverEtchPercent(%)")]
  301. [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)]
  302. public int? OverEtchPercent
  303. {
  304. get { return m_OverEtchPercent; }
  305. set { m_OverEtchPercent = value; InvokePropertyChanged("OverEtchPercent"); }
  306. }
  307. private bool m_CycleStart;
  308. public bool CycleStart
  309. {
  310. get { return m_CycleStart; }
  311. set { m_CycleStart = value; InvokePropertyChanged("CycleStart"); }
  312. }
  313. private bool m_CycleEnd;
  314. public bool CycleEnd
  315. {
  316. get { return m_CycleEnd; }
  317. set { m_CycleEnd = value; InvokePropertyChanged("CycleEnd"); }
  318. }
  319. private int m_CycleNumber;
  320. public int CycleNumber
  321. {
  322. get { return m_CycleNumber; }
  323. set { m_CycleNumber = value; InvokePropertyChanged("CycleNumber"); }
  324. }
  325. private ObservableCollection<object> lstUnit = new ObservableCollection<object>();
  326. public ObservableCollection<object> LstUnit
  327. {
  328. get { return lstUnit; }
  329. set { lstUnit = value; InvokePropertyChanged("LstUnit"); }
  330. }
  331. private Stopwatch _stepTimer = new Stopwatch();
  332. public long ElapsedTime()
  333. {
  334. return _stepTimer.ElapsedMilliseconds;
  335. }
  336. public void StartStepTimer()
  337. {
  338. _stepTimer.Restart();
  339. }
  340. //private long _lastEPDStepTime = 0;
  341. //public void RecordEPDStepTime()
  342. //{
  343. // _lastEPDStepTime = _stepTimer.ElapsedMilliseconds;
  344. //}
  345. //public long GetLastEPDStepTime()
  346. //{
  347. // return _lastEPDStepTime;
  348. //}
  349. public RState Start()
  350. {
  351. starter(this);
  352. foreach (var unit in lstUnit)
  353. {
  354. var processUnit = unit as ProcessUnitBase;
  355. if (processUnit != null)
  356. {
  357. var state = processUnit.Start(this);
  358. if (state != RState.Running)
  359. return state;
  360. }
  361. else
  362. return RState.Failed;
  363. }
  364. return RState.Running;
  365. }
  366. public RState Start(int steps, int currentstep)
  367. {
  368. starter(this);
  369. foreach (var unit in lstUnit)
  370. {
  371. var processUnit = unit as ProcessUnitBase;
  372. if (processUnit != null)
  373. {
  374. var state = processUnit.Start(this);
  375. if (state != RState.Running)
  376. return state;
  377. }
  378. else
  379. return RState.Failed;
  380. }
  381. return RState.Running;
  382. }
  383. public RState Run()
  384. {
  385. var checkerState= checker(this);
  386. if (checkerState == RState.End)
  387. {
  388. return RState.End;
  389. }
  390. else if (checkerState == RState.Failed)
  391. {
  392. return RState.Failed;
  393. }
  394. bool bStable = true;
  395. foreach (var unit in lstUnit)
  396. {
  397. var processUnit = unit as ProcessUnitBase;
  398. if (processUnit != null)
  399. {
  400. var state = processUnit.Run(this);
  401. if (Type == StepType.Stable)
  402. {
  403. if (state != RState.Running && state != RState.End)
  404. return state;
  405. if (state == RState.Running)
  406. bStable = false;
  407. }
  408. else
  409. {
  410. if (state != RState.Running)
  411. return state;
  412. }
  413. }
  414. else
  415. return RState.Failed;
  416. }
  417. return (Type == StepType.Stable && bStable) ? RState.End : RState.Running;
  418. }
  419. public void End()
  420. {
  421. foreach (var unit in lstUnit)
  422. {
  423. var processUnit = unit as ProcessUnitBase;
  424. if (processUnit != null)
  425. {
  426. processUnit.End(this);
  427. }
  428. }
  429. ender(this);
  430. }
  431. public double RampFactor()
  432. {
  433. return _stepTimer.ElapsedMilliseconds / (Time * 1000.0);
  434. }
  435. public void AppendUnit(ProcessUnitBase unit)
  436. {
  437. lstUnit.Append(unit);
  438. }
  439. public event PropertyChangedEventHandler PropertyChanged;
  440. public void InvokePropertyChanged(string propertyName)
  441. {
  442. if (PropertyChanged != null)
  443. {
  444. PropertyChanged.Invoke(this, new PropertyChangedEventArgs(propertyName));
  445. }
  446. }
  447. }
  448. public class Recipe : INotifyPropertyChanged
  449. {
  450. private RecipeHead m_Header = new RecipeHead();
  451. public RecipeHead Header
  452. {
  453. get { return m_Header; }
  454. set { m_Header = value; InvokePropertyChanged("Header"); }
  455. }
  456. private ObservableCollection<RecipeStep> m_Steps;
  457. public ObservableCollection<RecipeStep> Steps
  458. {
  459. get { return m_Steps; }
  460. set { m_Steps = value; InvokePropertyChanged("Steps"); }
  461. }
  462. public static Recipe Load(string recipeFile)
  463. {
  464. var recipe = JsonConvert.DeserializeObject<Recipe>(recipeFile);
  465. if (recipe == null)
  466. {
  467. return null;
  468. }
  469. foreach (var step in recipe.Steps)
  470. {
  471. ObservableCollection<object> unit = new ObservableCollection<object>();
  472. for (int i = 0; i < step.LstUnit.Count; i++)
  473. {
  474. string value = step.LstUnit[i].ToString();
  475. string[] striparr = value.Split(new string[] { "\r\n" }, StringSplitOptions.None);
  476. string item1 = striparr[1].Remove(0, 15);
  477. string item2 = item1.Remove(item1.Length - 2, 2);
  478. if (recipe.Header.ChamberType == JetChamber.VenusSE || recipe.Header.ChamberType == JetChamber.VenusDE || recipe.Header.ChamberType == JetChamber.Kepler2300)
  479. {
  480. switch (item2)
  481. {
  482. case "PressureModeUnit":
  483. unit.Add(JsonConvert.DeserializeObject<PressureByPressureModeUnit>(step.LstUnit[i].ToString()));
  484. break;
  485. case "ControlPressureUnit":
  486. unit.Add(JsonConvert.DeserializeObject<Kepler2200PressureByPressureModeUnit>(step.LstUnit[i].ToString()));
  487. break;
  488. //case "PressureByValveModeUnit":
  489. // unit.Add(JsonConvert.DeserializeObject<PressureByValveModeUnit>(step.LstUnit[i].ToString()));
  490. // break;
  491. case "TCPUnit":
  492. unit.Add(JsonConvert.DeserializeObject<TCPUnit>(step.LstUnit[i].ToString()));
  493. break;
  494. case "RFUnit":
  495. unit.Add(JsonConvert.DeserializeObject<RFUnit>(step.LstUnit[i].ToString()));
  496. break;
  497. case "BiasUnit":
  498. unit.Add(JsonConvert.DeserializeObject<BiasUnit>(step.LstUnit[i].ToString()));
  499. break;
  500. case "GasControlUnit":
  501. unit.Add(JsonConvert.DeserializeObject<GasControlUnit>(step.LstUnit[i].ToString()));
  502. break;
  503. case "ESCHVUnit":
  504. unit.Add(JsonConvert.DeserializeObject<ESCHVUnit>(step.LstUnit[i].ToString()));
  505. break;
  506. case "ProcessKitUnit":
  507. unit.Add(JsonConvert.DeserializeObject<ProcessKitUnit>(step.LstUnit[i].ToString()));
  508. break;
  509. case "HeaterUnit":
  510. unit.Add(JsonConvert.DeserializeObject<HeaterUnit>(step.LstUnit[i].ToString()));
  511. break;
  512. case "RFBoxUnit":
  513. unit.Add(JsonConvert.DeserializeObject<RFBoxUnit>(step.LstUnit[i].ToString()));
  514. break;
  515. case "GasUnit":
  516. unit.Add(JsonConvert.DeserializeObject<Kepler2200GasControlUnit>(step.LstUnit[i].ToString()));
  517. break;
  518. case "SEGasControlUnit":
  519. unit.Add(JsonConvert.DeserializeObject<VenusSEGasControlUnit>(step.LstUnit[i].ToString()));
  520. break;
  521. case "DEGasControlUnit":
  522. unit.Add(JsonConvert.DeserializeObject<VenusDEGasControlUnit>(step.LstUnit[i].ToString()));
  523. break;
  524. case "Magnet":
  525. unit.Add(JsonConvert.DeserializeObject<MagnetUnit>(step.LstUnit[i].ToString()));
  526. break;
  527. }
  528. }
  529. else
  530. {
  531. switch (item2)
  532. {
  533. //case "PressureModeUnit":
  534. // unit.Add(JsonConvert.DeserializeObject<PressureByPressureModeUnit>(step.LstUnit[i].ToString()));
  535. // break;
  536. case "ControlPressureUnit":
  537. case "PressureModeUnit":
  538. unit.Add(JsonConvert.DeserializeObject<Kepler2200PressureByPressureModeUnit>(step.LstUnit[i].ToString()));
  539. break;
  540. case "RFUnit":
  541. case "TCPUnit":
  542. unit.Add(JsonConvert.DeserializeObject<RFUnit>(step.LstUnit[i].ToString()));
  543. break;
  544. case "HeaterUnit":
  545. unit.Add(JsonConvert.DeserializeObject<HeaterUnit>(step.LstUnit[i].ToString()));
  546. break;
  547. case "RFBoxUnit":
  548. unit.Add(JsonConvert.DeserializeObject<RFBoxUnit>(step.LstUnit[i].ToString()));
  549. break;
  550. case "GasUnit":
  551. unit.Add(JsonConvert.DeserializeObject<Kepler2200GasControlUnit>(step.LstUnit[i].ToString()));
  552. break;
  553. }
  554. }
  555. }
  556. step.LstUnit.Clear();
  557. unit.ToList().ForEach(x =>
  558. {
  559. step.LstUnit.Add(x);
  560. });
  561. }
  562. return recipe;
  563. }
  564. public static string ShowEAPRecipe(string recipeContent, ObservableCollection<RecipeStep> Steps)
  565. {
  566. JObject jobject = JObject.Parse(recipeContent);
  567. JArray Firsttokenselect = jobject.SelectToken("Steps") as JArray;
  568. if (Firsttokenselect != null)
  569. {
  570. foreach (JObject firstItem in Firsttokenselect)
  571. {
  572. JArray Secondtokenselect = firstItem.SelectToken("LstUnit") as JArray;
  573. foreach (JObject secondItem in Secondtokenselect)
  574. {
  575. for (int i = 0; i < Steps.Count; i++)
  576. {
  577. for (int j = 0; j < Steps[i].LstUnit.Count; j++)
  578. {
  579. Type type = Steps[i].LstUnit[j].GetType();
  580. foreach (var propertyInfo in type.GetProperties())
  581. {
  582. object[] toleranceAttrs = propertyInfo.GetCustomAttributes(typeof(IsTolerance), true);
  583. if (toleranceAttrs.Length > 0)
  584. {
  585. secondItem.Remove(propertyInfo.Name);
  586. }
  587. }
  588. }
  589. }
  590. }
  591. }
  592. }
  593. return jobject.ToString();
  594. }
  595. public static string ShowToleranceRecipe(string recipeContent, ObservableCollection<RecipeStep> Steps)
  596. {
  597. JObject jobject = JObject.Parse(recipeContent);
  598. JArray Firsttokenselect = jobject.SelectToken("Steps") as JArray;
  599. if (Firsttokenselect != null)
  600. {
  601. foreach (JObject firstItem in Firsttokenselect)
  602. {
  603. JArray Secondtokenselect = firstItem.SelectToken("LstUnit") as JArray;
  604. foreach (JObject secondItem in Secondtokenselect)
  605. {
  606. for (int i = 0; i < Steps.Count; i++)
  607. {
  608. for (int j = 0; j < Steps[i].LstUnit.Count; j++)
  609. {
  610. Type type = Steps[i].LstUnit[j].GetType();
  611. foreach (var propertyInfo in type.GetProperties())
  612. {
  613. object[] toleranceAttrs = propertyInfo.GetCustomAttributes(typeof(IsTolerance), true);
  614. if (toleranceAttrs.Length == 0)
  615. {
  616. secondItem.Remove(propertyInfo.Name);
  617. }
  618. }
  619. }
  620. }
  621. }
  622. }
  623. }
  624. return jobject.ToString();
  625. }
  626. public bool Validate()
  627. {
  628. return true;
  629. }
  630. public bool Save(string recipeFile)
  631. {
  632. return true;
  633. }
  634. public event PropertyChangedEventHandler PropertyChanged;
  635. public void InvokePropertyChanged(string propertyName)
  636. {
  637. if (PropertyChanged != null)
  638. {
  639. PropertyChanged.Invoke(this, new PropertyChangedEventArgs(propertyName));
  640. }
  641. }
  642. }
  643. public class RecipeUnity
  644. {
  645. public static string ConvertJsonString(string str)
  646. {
  647. JsonSerializer serializer = new JsonSerializer();
  648. TextReader tr = new StringReader(str);
  649. JsonTextReader jtr = new JsonTextReader(tr);
  650. object obj = serializer.Deserialize(jtr);
  651. if (obj != null)
  652. {
  653. StringWriter textWriter = new StringWriter();
  654. JsonTextWriter jsonWriter = new JsonTextWriter(textWriter)
  655. {
  656. Formatting = Newtonsoft.Json.Formatting.Indented,
  657. Indentation = 4,
  658. IndentChar = ' '
  659. };
  660. serializer.Serialize(jsonWriter, obj);
  661. return textWriter.ToString();
  662. }
  663. else
  664. {
  665. return str;
  666. }
  667. }
  668. public static string RecipeToString(Recipe recipe)
  669. {
  670. return JsonConvert.SerializeObject(recipe);
  671. }
  672. public static String CreateRecipe(JetChamber currentChamber, RecipeType recipeType, string recipeName,string userName)
  673. {
  674. Recipe recipe = new Recipe();
  675. recipe.Header = new RecipeHead();
  676. recipe.Header.CreateTime = DateTime.Now.ToString();
  677. recipe.Header.EditTime = DateTime.Now.ToString();
  678. recipe.Header.Type = recipeType;
  679. recipe.Header.ChamberType = currentChamber;
  680. recipe.Header.Name = recipeName;
  681. recipe.Header.LastModifiedBy =userName;
  682. recipe.Steps = new ObservableCollection<RecipeStep>();
  683. RecipeStep recipeStep = new RecipeStep();
  684. recipeStep.LstUnit = GetAllUnits(currentChamber, recipeType);
  685. recipe.Steps.Add(recipeStep);
  686. var recipeString = JsonConvert.SerializeObject(recipe);
  687. return recipeString;
  688. }
  689. public static ObservableCollection<object> GetAllUnits(JetChamber jetChamber, RecipeType recipeType)
  690. {
  691. ObservableCollection<object> LstUnit = new ObservableCollection<object>();
  692. switch (jetChamber)
  693. {
  694. //case JetChamber.Venus:
  695. // if (recipeType == RecipeType.Clean)
  696. // {
  697. // foreach (var item in Enum.GetValues(typeof(VenusCleanRecipeUnits)))
  698. // {
  699. // Type t = Type.GetType($"Venus_Core.{item.ToString()}");
  700. // var obj = System.Activator.CreateInstance(t);
  701. // LstUnit.Add(obj);
  702. // }
  703. // }
  704. // else
  705. // {
  706. // foreach (var item in Enum.GetValues(typeof(VenusUnits)))
  707. // {
  708. // Type t = Type.GetType($"Venus_Core.{item.ToString()}");
  709. // var obj = System.Activator.CreateInstance(t);
  710. // LstUnit.Add(obj);
  711. // }
  712. // }
  713. // break;
  714. case JetChamber.Kepler2300:
  715. if (recipeType == RecipeType.Clean)
  716. {
  717. foreach (var item in Enum.GetValues(typeof(Kepler2300CleanRecipeUints)))
  718. {
  719. Type t = Type.GetType($"Venus_Core.{item.ToString()}");
  720. var obj = System.Activator.CreateInstance(t);
  721. LstUnit.Add(obj as ProcessUnitBase);
  722. }
  723. }
  724. else
  725. {
  726. foreach (var item in Enum.GetValues(typeof(Kepler2300Uints)))
  727. {
  728. Type t = Type.GetType($"Venus_Core.{item.ToString()}");
  729. var obj = System.Activator.CreateInstance(t);
  730. LstUnit.Add(obj as ProcessUnitBase);
  731. }
  732. }
  733. break;
  734. case JetChamber.Kepler2200A:
  735. foreach (var item in Enum.GetValues(typeof(Kepler2200AUnits)))
  736. {
  737. Type t = Type.GetType($"Venus_Core.{item.ToString()}");
  738. var obj = System.Activator.CreateInstance(t);
  739. LstUnit.Add(obj as ProcessUnitBase);
  740. }
  741. break;
  742. case JetChamber.Kepler2200B:
  743. foreach (var item in Enum.GetValues(typeof(Kepler2200BUnits)))
  744. {
  745. Type t = Type.GetType($"Venus_Core.{item.ToString()}");
  746. var obj = System.Activator.CreateInstance(t);
  747. LstUnit.Add(obj as ProcessUnitBase);
  748. }
  749. break;
  750. case JetChamber.VenusSE:
  751. foreach (var item in Enum.GetValues(typeof(VenusSEUnits)))
  752. {
  753. Type t = Type.GetType($"Venus_Core.{item.ToString()}");
  754. var obj = System.Activator.CreateInstance(t);
  755. LstUnit.Add(obj as ProcessUnitBase);
  756. }
  757. break;
  758. case JetChamber.VenusDE:
  759. foreach (var item in Enum.GetValues(typeof(VenusDEUnits)))
  760. {
  761. Type t = Type.GetType($"Venus_Core.{item.ToString()}");
  762. var obj = System.Activator.CreateInstance(t);
  763. LstUnit.Add(obj as ProcessUnitBase);
  764. }
  765. break;
  766. }
  767. return LstUnit;
  768. }
  769. }
  770. }