ControlJobStatusViewModel.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  1. using Aitex.Core.UI.MVVM;
  2. using Aitex.Core.Util;
  3. using MECF.Framework.Common.CommonData;
  4. using MECF.Framework.Common.Jobs;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Collections.ObjectModel;
  8. using System.Linq;
  9. using System.Runtime.Serialization;
  10. using System.Text;
  11. using System.Threading.Tasks;
  12. using System.Windows;
  13. using System.Windows.Input;
  14. using FurnaceUI.Models;
  15. using MECF.Framework.Common.OperationCenter;
  16. using OpenSEMI.ClientBase;
  17. namespace FurnaceUI.Views.Status
  18. {
  19. class ControlJobStatusViewModel : FurnaceUIViewModelBase
  20. {
  21. public bool IsPermission { get => this.Permission == 3; }
  22. public class ControlJobData : NotifiableItem
  23. {
  24. [DataMember]
  25. public int Num { get; set; }
  26. [DataMember]
  27. public string Name { get; set; }
  28. [DataMember]
  29. public string State { get; set; }
  30. [DataMember]
  31. public bool Auto { get; set; }
  32. }
  33. public ObservableCollection<ControlJobData> ControlJobsData { get; set; }
  34. public ICommand ControlJobsCommand { get; set; }
  35. [Subscription("Scheduler.ControlJobList")]
  36. public List<ControlJobInfo> ControlJobs
  37. {
  38. get;
  39. set;
  40. }
  41. [Subscription("Scheduler.CurrentProcessJob")]
  42. public ProcessJobInfo CurrentProcessJob
  43. {
  44. get;
  45. set;
  46. }
  47. public ControlJobStatusViewModel()/* : base("MonitorJobViewModel")*/
  48. {
  49. ControlJobsData = new ObservableCollection<ControlJobData>();
  50. }
  51. public ControlJobData SelectedControlJob { get; set; }
  52. public string SelectedControlJobsObjtID
  53. {
  54. get
  55. {
  56. return SelectedControlJob != null ? SelectedControlJob.Name : "";
  57. }
  58. }
  59. public string SelectedControlJobsState
  60. {
  61. get
  62. {
  63. if(SelectedControlJob == null)
  64. {
  65. return " ";
  66. }
  67. return SelectedControlJob.State.ToString();
  68. }
  69. }
  70. public bool IsEnablePause
  71. {
  72. get
  73. {
  74. if (SelectedControlJob == null)
  75. return false;
  76. return SelectedControlJob.State.ToString() == "Executing";
  77. }
  78. }
  79. public bool IsEnableCoolingSkip
  80. {
  81. get
  82. {
  83. if (CurrentProcessJob == null)
  84. return false;
  85. return CurrentProcessJob.ProcessingState.ToString() == "CoolingBeforeDischarge";
  86. }
  87. }
  88. public bool IsEnableResume
  89. {
  90. get
  91. {
  92. if (SelectedControlJob == null)
  93. return false;
  94. return SelectedControlJob.State.ToString() == "Paused";
  95. }
  96. }
  97. public bool IsEnableStop
  98. {
  99. get
  100. {
  101. if (SelectedControlJob == null)
  102. return false;
  103. return SelectedControlJob.State.ToString() == "Executing" ||
  104. SelectedControlJob.State.ToString() == "Paused" ||
  105. SelectedControlJob.State.ToString() == "WaitingForStart" ||
  106. SelectedControlJob.State.ToString() == "Queued" ;
  107. }
  108. }
  109. public string CurrentStartMode
  110. {
  111. get
  112. {
  113. if(SelectedControlJob == null)
  114. {
  115. return "Waiting For Start";
  116. }
  117. return ((SelectedControlJob.State.ToString() == "Queued") || (SelectedControlJob.State.ToString() == "Completed")) ? "Waiting For Start" : "Active";
  118. }
  119. }
  120. public string CurrentStateIsActive
  121. {
  122. get
  123. {
  124. if (SelectedControlJob == null)
  125. {
  126. return "Transparent";
  127. }
  128. return ((SelectedControlJob.State.ToString() == "Queued") || (SelectedControlJob.State.ToString() == "Completed")) ? "Transparent" : "Green";
  129. }
  130. }
  131. public string CurrentStateIsActiveForeground
  132. {
  133. get
  134. {
  135. if (CurrentStateIsActive == "Green")
  136. {
  137. return "White";
  138. }
  139. return "Black";
  140. }
  141. }
  142. public string CurrentStateIsQueued
  143. {
  144. get
  145. {
  146. if (SelectedControlJob == null)
  147. {
  148. return "Transparent";
  149. }
  150. return SelectedControlJob.State.ToString() == "Queued" ? "Green": "Transparent" ;
  151. }
  152. }
  153. public string CurrentStateIsSelected
  154. {
  155. get
  156. {
  157. if (SelectedControlJob == null)
  158. {
  159. return "Transparent";
  160. }
  161. return SelectedControlJob.State.ToString() == "Selected" ? "Green" : "Transparent";
  162. }
  163. }
  164. public string CurrentStateIsWaitingForStart
  165. {
  166. get
  167. {
  168. if (SelectedControlJob == null)
  169. {
  170. return "Transparent";
  171. }
  172. return SelectedControlJob.State.ToString() == "WaitingForStart" ? "Green" : "Transparent";
  173. }
  174. }
  175. public string CurrentStateIsExecuting
  176. {
  177. get
  178. {
  179. if (SelectedControlJob == null)
  180. {
  181. return "Transparent";
  182. }
  183. return SelectedControlJob.State.ToString() == "Executing" ? "Green" : "Transparent";
  184. }
  185. }
  186. public string CurrentStateIsPaused
  187. {
  188. get
  189. {
  190. if (SelectedControlJob == null)
  191. {
  192. return "Transparent";
  193. }
  194. return SelectedControlJob.State.ToString() == "Paused" ? "Green" : "Transparent";
  195. }
  196. }
  197. public string CurrentStateIsCompleted
  198. {
  199. get
  200. {
  201. if (SelectedControlJob == null)
  202. {
  203. return "Transparent";
  204. }
  205. return SelectedControlJob.State.ToString() == "Completed" ? "Green" : "Transparent";
  206. }
  207. }
  208. protected override void InvokeAfterUpdateProperty(Dictionary<string, object> data)
  209. {
  210. base.InvokeAfterUpdateProperty(data);
  211. if (ControlJobs == null || ControlJobs.Count == 0)
  212. {
  213. ControlJobsData.Clear();
  214. }
  215. else
  216. {
  217. int _Numcount = 1;
  218. foreach (var item in ControlJobs)
  219. {
  220. var match = ControlJobsData.ToList().Find(x => x.Name == item.Name);
  221. if (match == null)
  222. {
  223. ControlJobData cj = new ControlJobData();
  224. cj.Name = item.Name;
  225. cj.State = item.State.ToString();
  226. cj.Num = _Numcount;
  227. _Numcount++;
  228. ControlJobsData.Add(cj);
  229. }
  230. else
  231. {
  232. match.State = item.State.ToString();
  233. match.InvokePropertyChanged();
  234. }
  235. }
  236. List<ControlJobData> tobeRemove = new List<ControlJobData>();
  237. foreach (var cj in ControlJobsData)
  238. {
  239. if (ControlJobs.FirstOrDefault(x => x.Name == cj.Name) == null)
  240. tobeRemove.Add(cj);
  241. }
  242. foreach (var cj in tobeRemove)
  243. {
  244. ControlJobsData.Remove(cj);
  245. }
  246. _Numcount = 1;
  247. foreach (var item in ControlJobsData)
  248. {
  249. item.Num = _Numcount;
  250. _Numcount++;
  251. }
  252. }
  253. }
  254. public void ClosedCmd()
  255. {
  256. (GetView() as Window).Close();
  257. }
  258. public void CoolingSkip()
  259. {
  260. if (!DialogBox.Confirm("Are you sure to cooling skip"))
  261. {
  262. return;
  263. }
  264. InvokeClient.Instance.Service.DoOperation("System.CoolingSkip");
  265. }
  266. public void AbortJob()
  267. {
  268. if(string.IsNullOrEmpty(SelectedControlJobsObjtID))
  269. {
  270. DialogBox.ShowWarning("Control job is not selected");
  271. return;
  272. }
  273. if(!DialogBox.Confirm("Are you sure to abort the control job"))
  274. {
  275. return;
  276. }
  277. var param = new object[] { SelectedControlJobsObjtID };
  278. InvokeClient.Instance.Service.DoOperation("System.AbortJob", param);
  279. }
  280. public void Start()
  281. {
  282. if (string.IsNullOrEmpty(SelectedControlJobsObjtID))
  283. {
  284. DialogBox.ShowWarning("Control job is not selected");
  285. return;
  286. }
  287. var param = new object[] { SelectedControlJobsObjtID };
  288. InvokeClient.Instance.Service.DoOperation("System.StartJob", param);
  289. }
  290. public void Pause()
  291. {
  292. if (string.IsNullOrEmpty(SelectedControlJobsObjtID))
  293. {
  294. DialogBox.ShowWarning("Control job is not selected");
  295. return;
  296. }
  297. var param = new object[] { SelectedControlJobsObjtID };
  298. InvokeClient.Instance.Service.DoOperation("System.PauseJob", param);
  299. }
  300. public void Resume()
  301. {
  302. if (string.IsNullOrEmpty(SelectedControlJobsObjtID))
  303. {
  304. DialogBox.ShowWarning("Control job is not selected");
  305. return;
  306. }
  307. var param = new object[] { SelectedControlJobsObjtID };
  308. InvokeClient.Instance.Service.DoOperation("System.ResumeJob", param);
  309. }
  310. public void Stop()
  311. {
  312. if (string.IsNullOrEmpty(SelectedControlJobsObjtID))
  313. {
  314. DialogBox.ShowWarning("Control job is not selected");
  315. return;
  316. }
  317. var param = new object[] { SelectedControlJobsObjtID };
  318. InvokeClient.Instance.Service.DoOperation("System.StopJob", param);
  319. }
  320. }
  321. }