ProcessConfigViewModel.cs 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.IO;
  6. using System.Linq;
  7. using System.Reflection;
  8. using System.Reflection.Emit;
  9. using System.Text;
  10. using System.Windows;
  11. using System.Windows.Forms;
  12. using System.Windows.Input;
  13. using System.Xml;
  14. using Aitex.Core.Common.DeviceData;
  15. using Aitex.Core.RT.Device.Common;
  16. using Aitex.Core.RT.Log;
  17. using Aitex.Core.RT.SCCore;
  18. using Aitex.Core.UI.MVVM;
  19. using Aitex.Core.Utilities;
  20. using Aitex.Triton160.Common;
  21. using MessageBox = System.Windows.MessageBox;
  22. namespace Aitex.Triton160.UI.ViewModel
  23. {
  24. public class ProcessConfigData : INotifyPropertyChanged
  25. {
  26. public event PropertyChangedEventHandler PropertyChanged;
  27. public void InvokePropertyChanged(string propertyName)
  28. {
  29. if (PropertyChanged != null)
  30. {
  31. PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
  32. }
  33. }
  34. public void InvokePropertyChanged()
  35. {
  36. PropertyInfo[] ps = this.GetType().GetProperties();
  37. foreach (PropertyInfo p in ps)
  38. {
  39. InvokePropertyChanged(p.Name);
  40. if (p.PropertyType == typeof(ICommand))
  41. {
  42. DelegateCommand<string> cmd = p.GetValue(this, null) as DelegateCommand<string>;
  43. if (cmd != null)
  44. cmd.RaiseCanExecuteChanged();
  45. }
  46. }
  47. FieldInfo[] fi = this.GetType().GetFields();
  48. foreach (FieldInfo p in fi)
  49. {
  50. InvokePropertyChanged(p.Name);
  51. if (p.FieldType == typeof(ICommand))
  52. {
  53. DelegateCommand<string> cmd = p.GetValue(this) as DelegateCommand<string>;
  54. if (cmd != null)
  55. cmd.RaiseCanExecuteChanged();
  56. }
  57. }
  58. }
  59. public string VentTimeLimit
  60. {
  61. get;
  62. set;
  63. }
  64. public string VentTime
  65. {
  66. get;
  67. set;
  68. }
  69. public string PurgePumpTimeLimit
  70. {
  71. get;
  72. set;
  73. }
  74. public string PurgePumpStableTime
  75. {
  76. get;
  77. set;
  78. }
  79. public string PurgePumpPressure
  80. {
  81. get;
  82. set;
  83. }
  84. public string PurgeVentTimeLimit
  85. {
  86. get;
  87. set;
  88. }
  89. public string PurgeVentStableTime
  90. {
  91. get;
  92. set;
  93. }
  94. public string PurgeVentPressure
  95. {
  96. get;
  97. set;
  98. }
  99. public string PurgeCycleCount
  100. {
  101. get;
  102. set;
  103. }
  104. public string GasFlowPressureAlarmTime
  105. {
  106. get;
  107. set;
  108. }
  109. public string GasFlowPressureAlarmRange
  110. {
  111. get;
  112. set;
  113. }
  114. public string RfPowerAlarmRange
  115. {
  116. get;
  117. set;
  118. }
  119. public string RfPowerAlarmTime
  120. {
  121. get;
  122. set;
  123. }
  124. public string RfReflectPowerAlarmRange
  125. {
  126. get;
  127. set;
  128. }
  129. public string RfReflectPowerAlarmTime
  130. {
  131. get;
  132. set;
  133. }
  134. public string RfMatchModeDuringProcess
  135. {
  136. get;
  137. set;
  138. }
  139. }
  140. class ProcessConfigViewModel : UIViewModelBase
  141. {
  142. private List<string> _keys = new List<string>()
  143. {
  144. SCName.System_VentTimeLimit,
  145. SCName.ProcessConfig_PurgePumpTimeLimit,
  146. SCName.ProcessConfig_PurgePumpStableTime,
  147. SCName.ProcessConfig_PurgePumpPressure,
  148. SCName.ProcessConfig_PurgeVentTimeLimit,
  149. SCName.ProcessConfig_PurgeVentStableTime,
  150. SCName.ProcessConfig_PurgeVentPressure,
  151. SCName.ProcessConfig_PurgeCycleCount,
  152. SCName.System_GasFlowPressureAlarmTime,
  153. SCName.System_GasFlowPressureAlarmRange,
  154. SCName.System_RfPowerAlarmRange,
  155. SCName.System_RfPowerAlarmTime,
  156. SCName.System_RfReflectPowerAlarmRange,
  157. SCName.System_RfReflectPowerAlarmTime,
  158. SCName.System_VentTime,
  159. SCName.System_RfMatchModeDuringProcess,
  160. };
  161. public ProcessConfigData Feedback
  162. {
  163. get;
  164. set;
  165. }
  166. [IgnorePropertyChange]
  167. public ProcessConfigData SetPoint
  168. {
  169. get;
  170. set;
  171. }
  172. public ICommand SetConfigCommand
  173. {
  174. get;
  175. private set;
  176. }
  177. public ICommand SaveAsConfigCommand
  178. {
  179. get;
  180. private set;
  181. }
  182. public ICommand LoadConfigCommand
  183. {
  184. get;
  185. private set;
  186. }
  187. public ICommand SetAllConfigCommand
  188. {
  189. get;
  190. private set;
  191. }
  192. public ProcessConfigViewModel()
  193. : base("ProcessConfigViewModel")
  194. {
  195. SetConfigCommand = new DelegateCommand<object>(SetConfig);
  196. SaveAsConfigCommand = new DelegateCommand<object>(SaveAsConfig);
  197. LoadConfigCommand = new DelegateCommand<object>(LoadConfig);
  198. SetAllConfigCommand = new DelegateCommand<object>(SetAllConfig);
  199. Feedback = new ProcessConfigData();
  200. SetPoint = new ProcessConfigData();
  201. }
  202. private void SaveAsConfig(object param)
  203. {
  204. SaveFileDialog sfd = new SaveFileDialog();
  205. sfd.DefaultExt = ".cfg";
  206. sfd.Filter = ".cfg|*.*";
  207. sfd.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
  208. sfd.FileName = string.Format("process_config_{0}.cfg", DateTime.Now.ToString("yyyyMMdd_HHmmssfff"));
  209. if (sfd.ShowDialog() == DialogResult.OK)
  210. {
  211. XmlDocument xml = new XmlDocument();
  212. xml.LoadXml(@"<?xml version='1.0' encoding='utf-8'?><Aitex><ProcessConfigs></ProcessConfigs></Aitex>");
  213. CreateNode(xml, "GasFlowPressureAlarmRange", Feedback.GasFlowPressureAlarmRange);
  214. CreateNode(xml, "GasFlowPressureAlarmTime", Feedback.GasFlowPressureAlarmTime);
  215. CreateNode(xml, "RfMatchModeDuringProcess", Feedback.RfMatchModeDuringProcess);
  216. CreateNode(xml, "PurgeCycleCount", Feedback.PurgeCycleCount);
  217. CreateNode(xml, "PurgePumpPressure", Feedback.PurgePumpPressure);
  218. CreateNode(xml, "PurgePumpStableTime", Feedback.PurgePumpStableTime);
  219. CreateNode(xml, "PurgePumpTimeLimit", Feedback.PurgePumpTimeLimit);
  220. CreateNode(xml, "PurgeVentPressure", Feedback.PurgeVentPressure);
  221. CreateNode(xml, "PurgeVentStableTime", Feedback.PurgeVentStableTime);
  222. CreateNode(xml, "PurgeVentTimeLimit", Feedback.PurgeVentTimeLimit);
  223. CreateNode(xml, "RfPowerAlarmRange", Feedback.RfPowerAlarmRange);
  224. CreateNode(xml, "RfPowerAlarmTime", Feedback.RfPowerAlarmTime);
  225. CreateNode(xml, "RfReflectPowerAlarmRange", Feedback.RfReflectPowerAlarmRange);
  226. CreateNode(xml, "RfReflectPowerAlarmTime", Feedback.RfReflectPowerAlarmTime);
  227. CreateNode(xml, "VentTime", Feedback.VentTime);
  228. CreateNode(xml, "VentTimeLimit", Feedback.VentTimeLimit);
  229. try
  230. {
  231. xml.Save(sfd.FileName);
  232. }
  233. catch (Exception ex)
  234. {
  235. MessageBox.Show(ex.Message, "Save Error", MessageBoxButton.OK, MessageBoxImage.Warning);
  236. }
  237. }
  238. }
  239. void CreateNode(XmlDocument xmlDoc, string name, string value)
  240. {
  241. XmlNode node = xmlDoc.CreateElement("ProcessConfig");
  242. XmlAttribute attrName = xmlDoc.CreateAttribute("Name");
  243. attrName.Value = name;
  244. node.Attributes.Append(attrName);
  245. XmlAttribute attrValue = xmlDoc.CreateAttribute("Value");
  246. attrValue.Value = value;
  247. node.Attributes.Append(attrValue);
  248. xmlDoc.SelectSingleNode("Aitex/ProcessConfigs").AppendChild(node);
  249. }
  250. private void LoadConfig(object param)
  251. {
  252. OpenFileDialog ofd = new OpenFileDialog();
  253. ofd.DefaultExt = ".cfg";
  254. ofd.Filter = ".cfg|*.*";
  255. ofd.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
  256. if (ofd.ShowDialog() == DialogResult.OK)
  257. {
  258. XmlDocument xml = new XmlDocument();
  259. try
  260. {
  261. xml.Load(ofd.FileName);
  262. }
  263. catch (Exception ex)
  264. {
  265. MessageBox.Show(ex.Message, "Open Failed", MessageBoxButton.OK, MessageBoxImage.Warning);
  266. return;
  267. }
  268. SetPoint.GasFlowPressureAlarmRange = GetNodeValue(xml, "GasFlowPressureAlarmRange", SetPoint.GasFlowPressureAlarmRange);
  269. SetPoint.InvokePropertyChanged("GasFlowPressureAlarmRange");
  270. SetPoint.GasFlowPressureAlarmTime = GetNodeValue(xml, "GasFlowPressureAlarmTime", SetPoint.GasFlowPressureAlarmTime);
  271. SetPoint.InvokePropertyChanged("GasFlowPressureAlarmTime");
  272. SetPoint.RfMatchModeDuringProcess = GetNodeValue(xml, "RfMatchModeDuringProcess", SetPoint.RfMatchModeDuringProcess);
  273. SetPoint.InvokePropertyChanged("RfMatchModeDuringProcess");
  274. SetPoint.PurgeCycleCount = GetNodeValue(xml, "PurgeCycleCount", SetPoint.PurgeCycleCount);
  275. SetPoint.InvokePropertyChanged("PurgeCycleCount");
  276. SetPoint.PurgePumpPressure = GetNodeValue(xml, "PurgePumpPressure", SetPoint.PurgePumpPressure);
  277. SetPoint.InvokePropertyChanged("PurgePumpPressure");
  278. SetPoint.PurgePumpStableTime = GetNodeValue(xml, "PurgePumpStableTime", SetPoint.PurgePumpStableTime);
  279. SetPoint.InvokePropertyChanged("PurgePumpStableTime");
  280. SetPoint.PurgePumpTimeLimit = GetNodeValue(xml, "PurgePumpTimeLimit", SetPoint.PurgePumpTimeLimit);
  281. SetPoint.InvokePropertyChanged("PurgePumpTimeLimit");
  282. SetPoint.PurgeVentPressure = GetNodeValue(xml, "PurgeVentPressure", SetPoint.PurgeVentPressure);
  283. SetPoint.InvokePropertyChanged("PurgeVentPressure");
  284. SetPoint.PurgeVentStableTime = GetNodeValue(xml, "PurgeVentStableTime", SetPoint.PurgeVentStableTime);
  285. SetPoint.InvokePropertyChanged("PurgeVentStableTime");
  286. SetPoint.PurgeVentTimeLimit = GetNodeValue(xml, "PurgeVentTimeLimit", SetPoint.PurgeVentTimeLimit);
  287. SetPoint.InvokePropertyChanged("PurgeVentTimeLimit");
  288. SetPoint.RfPowerAlarmRange = GetNodeValue(xml, "RfPowerAlarmRange", SetPoint.RfPowerAlarmRange);
  289. SetPoint.InvokePropertyChanged("RfPowerAlarmRange");
  290. SetPoint.RfPowerAlarmTime = GetNodeValue(xml, "RfPowerAlarmTime", SetPoint.RfPowerAlarmTime);
  291. SetPoint.InvokePropertyChanged("RfPowerAlarmTime");
  292. SetPoint.RfReflectPowerAlarmRange = GetNodeValue(xml, "RfReflectPowerAlarmRange", SetPoint.RfReflectPowerAlarmRange);
  293. SetPoint.InvokePropertyChanged("RfReflectPowerAlarmRange");
  294. SetPoint.RfReflectPowerAlarmTime = GetNodeValue(xml, "RfReflectPowerAlarmTime", SetPoint.RfReflectPowerAlarmTime);
  295. SetPoint.InvokePropertyChanged("RfReflectPowerAlarmTime");
  296. SetPoint.VentTime = GetNodeValue(xml, "VentTime", SetPoint.VentTime);
  297. SetPoint.InvokePropertyChanged("VentTime");
  298. SetPoint.VentTimeLimit = GetNodeValue(xml, "VentTimeLimit", SetPoint.VentTimeLimit);
  299. SetPoint.InvokePropertyChanged("VentTimeLimit");
  300. }
  301. }
  302. string GetNodeValue(XmlDocument xmlDoc, string configItem, string defaultValue)
  303. {
  304. try
  305. {
  306. XmlNode node = xmlDoc.SelectSingleNode(string.Format("Aitex/ProcessConfigs/ProcessConfig[@Name='{0}']", configItem));
  307. if (node != null)
  308. {
  309. return node.Attributes["Value"].InnerText;
  310. }
  311. }
  312. catch (Exception ex)
  313. {
  314. LOG.Write(ex);
  315. }
  316. return defaultValue;
  317. }
  318. private void SetAllConfig(object param)
  319. {
  320. if (SetPoint.GasFlowPressureAlarmRange != Feedback.GasFlowPressureAlarmRange)
  321. SetConfig("GasFlowPressureAlarmRange");
  322. if (SetPoint.GasFlowPressureAlarmTime != Feedback.GasFlowPressureAlarmTime)
  323. SetConfig("GasFlowPressureAlarmTime");
  324. if (SetPoint.RfMatchModeDuringProcess != Feedback.RfMatchModeDuringProcess)
  325. SetConfig("RfMatchModeDuringProcess");
  326. if (SetPoint.PurgeCycleCount != Feedback.PurgeCycleCount)
  327. SetConfig("PurgeCycleCount");
  328. if (SetPoint.PurgePumpPressure != Feedback.PurgePumpPressure)
  329. SetConfig("PurgePumpPressure");
  330. if (SetPoint.PurgePumpStableTime != Feedback.PurgePumpStableTime)
  331. SetConfig("PurgePumpStableTime");
  332. if (SetPoint.PurgePumpTimeLimit != Feedback.PurgePumpTimeLimit)
  333. SetConfig("PurgePumpTimeLimit");
  334. if (SetPoint.PurgeVentPressure != Feedback.PurgeVentPressure)
  335. SetConfig("PurgeVentPressure");
  336. if (SetPoint.PurgeVentStableTime != Feedback.PurgeVentStableTime)
  337. SetConfig("PurgeVentStableTime");
  338. if (SetPoint.PurgeVentTimeLimit != Feedback.PurgeVentTimeLimit)
  339. SetConfig("PurgeVentTimeLimit");
  340. if (SetPoint.RfPowerAlarmRange != Feedback.RfPowerAlarmRange)
  341. SetConfig("RfPowerAlarmRange");
  342. if (SetPoint.RfPowerAlarmTime != Feedback.RfPowerAlarmTime)
  343. SetConfig("RfPowerAlarmTime");
  344. if (SetPoint.RfReflectPowerAlarmRange != Feedback.RfReflectPowerAlarmRange)
  345. SetConfig("RfReflectPowerAlarmRange");
  346. if (SetPoint.RfReflectPowerAlarmTime != Feedback.RfReflectPowerAlarmTime)
  347. SetConfig("RfReflectPowerAlarmTime");
  348. if (SetPoint.VentTime != Feedback.VentTime)
  349. SetConfig("VentTime");
  350. if (SetPoint.VentTimeLimit != Feedback.VentTimeLimit)
  351. SetConfig("VentTimeLimit");
  352. }
  353. void SetConfig(object param)
  354. {
  355. string config = param.ToString();
  356. string value = "";
  357. string scName = "";
  358. switch (config)
  359. {
  360. case "VentTimeLimit":
  361. value = SetPoint.VentTimeLimit;
  362. scName = SCName.System_VentTimeLimit;
  363. break;
  364. case "VentTime":
  365. value = SetPoint.VentTime;
  366. scName = SCName.System_VentTime;
  367. break;
  368. case "PurgePumpTimeLimit":
  369. value = SetPoint.PurgePumpTimeLimit;
  370. scName = SCName.ProcessConfig_PurgePumpTimeLimit;
  371. break;
  372. case "PurgePumpStableTime":
  373. value = SetPoint.PurgePumpStableTime;
  374. scName = SCName.ProcessConfig_PurgePumpStableTime;
  375. break;
  376. case "PurgePumpPressure":
  377. value = SetPoint.PurgePumpPressure;
  378. scName = SCName.ProcessConfig_PurgePumpPressure;
  379. break;
  380. case "PurgeVentTimeLimit":
  381. value = SetPoint.PurgeVentTimeLimit;
  382. scName = SCName.ProcessConfig_PurgeVentTimeLimit;
  383. break;
  384. case "PurgeVentStableTime":
  385. value = SetPoint.PurgeVentStableTime;
  386. scName = SCName.ProcessConfig_PurgeVentStableTime;
  387. break;
  388. case "PurgeVentPressure":
  389. value = SetPoint.PurgeVentPressure;
  390. scName = SCName.ProcessConfig_PurgeVentPressure;
  391. break;
  392. case "PurgeCycleCount":
  393. value = SetPoint.PurgeCycleCount;
  394. scName = SCName.ProcessConfig_PurgeCycleCount;
  395. break;
  396. case "GasFlowPressureAlarmTime":
  397. value = SetPoint.GasFlowPressureAlarmTime;
  398. scName = SCName.System_GasFlowPressureAlarmTime;
  399. break;
  400. case "GasFlowPressureAlarmRange":
  401. value = SetPoint.GasFlowPressureAlarmRange;
  402. scName = SCName.System_GasFlowPressureAlarmRange;
  403. break;
  404. case "RfPowerAlarmRange":
  405. value = SetPoint.RfPowerAlarmRange;
  406. scName = SCName.System_RfPowerAlarmRange;
  407. break;
  408. case "RfPowerAlarmTime":
  409. value = SetPoint.RfPowerAlarmTime;
  410. scName = SCName.System_RfPowerAlarmTime;
  411. break;
  412. case "RfReflectPowerAlarmRange":
  413. value = SetPoint.RfReflectPowerAlarmRange;
  414. scName = SCName.System_RfReflectPowerAlarmRange;
  415. break;
  416. case "RfReflectPowerAlarmTime":
  417. value = SetPoint.RfReflectPowerAlarmTime;
  418. scName = SCName.System_RfReflectPowerAlarmTime;
  419. break;
  420. case "RfMatchModeDuringProcess":
  421. value = SetPoint.RfMatchModeDuringProcess == "Manual" ? "0" : "1";
  422. scName = SCName.System_RfMatchModeDuringProcess;
  423. break;
  424. }
  425. if (string.IsNullOrEmpty(value))
  426. {
  427. MessageBox.Show(string.Format(Aitex.Triton160.UI.Properties.Resources.ProcessConfigViewModel_SetConfig_SetPoint0IsNotValid, value));
  428. return;
  429. }
  430. Triton160UiSystem.Instance.WCF.Invoker.DoOperation(TritonOperation.SetConfig.ToString(), scName, value);
  431. }
  432. protected override void Poll()
  433. //protected override void InvokeBeforeUpdateProperty(Dictionary<string, object> data)
  434. {
  435. Dictionary<string, object> configs = Triton160UiSystem.Instance.WCF.Query.PollConfig(_keys);
  436. foreach (KeyValuePair<string, object> config in configs)
  437. {
  438. switch (config.Key)
  439. {
  440. case SCName.System_VentTime:
  441. Feedback.VentTime = config.Value.ToString();
  442. break;
  443. case SCName.System_VentTimeLimit:
  444. Feedback.VentTimeLimit = config.Value.ToString();
  445. break;
  446. case SCName.ProcessConfig_PurgePumpTimeLimit:
  447. Feedback.PurgePumpTimeLimit = config.Value.ToString();
  448. break;
  449. case SCName.ProcessConfig_PurgePumpStableTime:
  450. Feedback.PurgePumpStableTime = config.Value.ToString();
  451. break;
  452. case SCName.ProcessConfig_PurgePumpPressure:
  453. Feedback.PurgePumpPressure = config.Value.ToString();
  454. break;
  455. case SCName.ProcessConfig_PurgeVentTimeLimit:
  456. Feedback.PurgeVentTimeLimit = config.Value.ToString();
  457. break;
  458. case SCName.ProcessConfig_PurgeVentStableTime:
  459. Feedback.PurgeVentStableTime = config.Value.ToString();
  460. break;
  461. case SCName.ProcessConfig_PurgeVentPressure:
  462. Feedback.PurgeVentPressure = config.Value.ToString();
  463. break;
  464. case SCName.ProcessConfig_PurgeCycleCount:
  465. Feedback.PurgeCycleCount = config.Value.ToString();
  466. break;
  467. case SCName.System_GasFlowPressureAlarmTime:
  468. Feedback.GasFlowPressureAlarmTime = config.Value.ToString();
  469. break;
  470. case SCName.System_GasFlowPressureAlarmRange:
  471. Feedback.GasFlowPressureAlarmRange = config.Value.ToString();
  472. break;
  473. case SCName.System_RfPowerAlarmRange:
  474. Feedback.RfPowerAlarmRange = config.Value.ToString();
  475. break;
  476. case SCName.System_RfPowerAlarmTime:
  477. Feedback.RfPowerAlarmTime = config.Value.ToString();
  478. break;
  479. case SCName.System_RfReflectPowerAlarmRange:
  480. Feedback.RfReflectPowerAlarmRange = config.Value.ToString();
  481. break;
  482. case SCName.System_RfReflectPowerAlarmTime:
  483. Feedback.RfReflectPowerAlarmTime = config.Value.ToString();
  484. break;
  485. case SCName.System_RfMatchModeDuringProcess:
  486. Feedback.RfMatchModeDuringProcess = config.Value.ToString() == "0" ? "Manual" : "Auto";
  487. break;
  488. }
  489. }
  490. }
  491. }
  492. }