BackUpViewModel.cs 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. using Aitex.Core.Util;
  2. using Caliburn.Micro;
  3. using Caliburn.Micro.Core;
  4. using FurnaceUI.Controls.Common;
  5. using FurnaceUI.DataModule;
  6. using FurnaceUI.Models;
  7. using MECF.Framework.Common.OperationCenter;
  8. using MECF.Framework.UI.Client.ClientBase;
  9. using OpenSEMI.ClientBase;
  10. using System.Collections.Generic;
  11. using System.Collections.ObjectModel;
  12. using System.Linq;
  13. using System.Threading.Tasks;
  14. using System.Windows;
  15. using System.Windows.Input;
  16. namespace FurnaceUI.Views.Parameter
  17. {
  18. public class BackUpViewModel : FurnaceUIViewModelBase
  19. {
  20. [Subscription("Rt.Status")]
  21. public string RtStatus { get; set; }
  22. [Subscription("PM1.Status")]
  23. public string PM1EntityStatus { get; set; }
  24. private Visibility _gridHistoryVisibility = Visibility.Visible;
  25. public Visibility GridHistoryVisibility
  26. {
  27. get { return _gridHistoryVisibility; }
  28. set { _gridHistoryVisibility = value; this.NotifyOfPropertyChange(nameof(GridHistoryVisibility)); }
  29. }
  30. [Subscription("System.BackUpFileData")]
  31. public Dictionary<string, List<string>> AllFilesDatas { get; set; }
  32. private ObservableCollection<PageDataView> _historyTableDatas = new ObservableCollection<PageDataView>();
  33. public ObservableCollection<PageDataView> HistoryTableDatas
  34. {
  35. get { return _historyTableDatas; }
  36. set { _historyTableDatas = value; this.NotifyOfPropertyChange(nameof(HistoryTableDatas)); }
  37. }
  38. public PageDataView SelectedItemHistory
  39. {
  40. get { return _selectedItemHistory; }
  41. set
  42. {
  43. _selectedItemHistory = value;
  44. this.NotifyOfPropertyChange(nameof(SelectedItemHistory));
  45. }
  46. }
  47. private PageDataView _selectedItemHistory;
  48. private bool _busyIndicatorVisibility = false;
  49. public bool BusyIndicatorVisibility
  50. {
  51. get { return _busyIndicatorVisibility; }
  52. set { _busyIndicatorVisibility = value; this.NotifyOfPropertyChange(nameof(BusyIndicatorVisibility)); }
  53. }
  54. private bool _isAllEnable = true;
  55. public bool IsAllEnable
  56. {
  57. get { return _isAllEnable; }
  58. set { _isAllEnable = value; this.NotifyOfPropertyChange(nameof(IsAllEnable)); }
  59. }
  60. RelayCommand _compareCommand;
  61. public ICommand CompareCommand
  62. {
  63. get
  64. {
  65. if (_compareCommand == null)
  66. {
  67. _compareCommand = new RelayCommand(param => this.CompareClick(), param => this.CanCompareClick());
  68. }
  69. return _compareCommand;
  70. }
  71. }
  72. RelayCommand _rollBackCommand;
  73. public ICommand RollBackCommand
  74. {
  75. get
  76. {
  77. if (_rollBackCommand == null)
  78. {
  79. _rollBackCommand = new RelayCommand(param => this.RollBackClick(), param => this.CanRollBackClick());
  80. }
  81. return _rollBackCommand;
  82. }
  83. }
  84. protected override void OnActivate()
  85. {
  86. base.OnActivate();
  87. DelayData();
  88. }
  89. protected override void OnViewLoaded(object view)
  90. {
  91. base.OnViewLoaded(view);
  92. }
  93. protected override void OnDeactivate(bool close)
  94. {
  95. base.OnDeactivate(close);
  96. }
  97. public void CreateZIP()
  98. {
  99. var selection = DialogBox.ShowDialog(DialogButton.Yes | DialogButton.No, DialogType.CONFIRM,
  100. $"Are you sure you want to CreateZIP?");
  101. if (selection == DialogButton.No)
  102. return;
  103. BusyIndicatorVisibility = true;
  104. InvokeClient.Instance.Service.DoOperation($"System.CreateZIP");
  105. DelayData();
  106. }
  107. public void BackUpClick()
  108. {
  109. var selection = DialogBox.ShowDialog(DialogButton.Yes | DialogButton.No, DialogType.CONFIRM,
  110. $"Are you sure you want to BackUp?");
  111. if (selection == DialogButton.No)
  112. return;
  113. BusyIndicatorVisibility = true;
  114. InvokeClient.Instance.Service.DoOperation($"System.BackUpFileData");
  115. DelayData(1500);
  116. }
  117. async void DelayData(int delayTime = 1000)
  118. {
  119. await WaitForResultsAsync(delayTime);
  120. GetDataOfConfigItems();
  121. BusyIndicatorVisibility = false;
  122. }
  123. private async Task WaitForResultsAsync(int delayTime)
  124. {
  125. // Simulate waiting for results using a delay
  126. // In a real-world scenario, you might wait for an event or a specific condition
  127. await Task.Delay(delayTime);
  128. // Here you can add logic to check if the results are ready
  129. // For example, polling or using a completion source
  130. }
  131. private void RollBackClick()
  132. {
  133. var selection = DialogBox.ShowDialog(DialogButton.Yes | DialogButton.No, DialogType.WARNING,
  134. $"If you want to RollBack, you must restart after RollBack!");
  135. if (selection == DialogButton.No)
  136. return;
  137. var selectItem = HistoryTableDatas.Where(a => a.IsSelect == true).Select(a => $"{a.ValueStr}@{a.Name}").FirstOrDefault();
  138. if (selectItem == null)
  139. {
  140. DialogBox.ShowWarning("Please select at least one");
  141. return;
  142. }
  143. InvokeClient.Instance.Service.DoOperation($"System.RollBackFileData", selectItem);
  144. DelayData();
  145. }
  146. private void CompareClick()
  147. {
  148. var selection = DialogBox.ShowDialog(DialogButton.Yes | DialogButton.No, DialogType.CONFIRM,
  149. $"Are you sure you want to Compare?");
  150. if (selection == DialogButton.No)
  151. return;
  152. var selectItems = HistoryTableDatas.Where(a => a.IsSelect == true).Select(a => $"{a.ValueStr}@{a.Name}").ToList();
  153. InvokeClient.Instance.Service.DoOperation($"System.CompareFileData", string.Join(",", selectItems.ToArray()));
  154. var windowManager = IoC.Get<IWindowManager>();
  155. BackUpCompareViewModel backUpCompareViewModel = new BackUpCompareViewModel();
  156. backUpCompareViewModel.SelectItemNames = HistoryTableDatas.Where(a => a.IsSelect == true).Select(a => $"{a.ValueStr}").ToList();
  157. var rtn = (windowManager as WindowManager)?.ShowDialogWithTitle(backUpCompareViewModel, null, $"Compare View");
  158. }
  159. protected override void InvokeAfterUpdateProperty(Dictionary<string, object> data)
  160. {
  161. base.InvokeAfterUpdateProperty(data);
  162. //System位于AutoIdle/Idle/Init/ PM位于
  163. IsAllEnable = (RtStatus == "Idle" || RtStatus == "AutoIdle" || RtStatus == "Init" || RtStatus == "Error") && (PM1EntityStatus == "Idle");
  164. }
  165. private bool CanRollBackClick()
  166. {
  167. bool isEnable = false;
  168. if (HistoryTableDatas != null)
  169. {
  170. int count = HistoryTableDatas.Count(p => p.IsSelect == true);
  171. if (count == 1)
  172. {
  173. isEnable = true;
  174. }
  175. }
  176. return isEnable;
  177. }
  178. private bool CanCompareClick()
  179. {
  180. bool isEnable = false;
  181. if (HistoryTableDatas != null)
  182. {
  183. int count = HistoryTableDatas.Count(p => p.IsSelect == true);
  184. if (0 < count && count <= 2)
  185. {
  186. isEnable = true;
  187. }
  188. }
  189. return isEnable;
  190. }
  191. private void GetDataOfConfigItems()
  192. {
  193. HistoryTableDatas.Clear();
  194. if (AllFilesDatas == null || AllFilesDatas.Count == 0)
  195. {
  196. return;
  197. }
  198. foreach (var item in AllFilesDatas["SC"])
  199. {
  200. var nameStr = item.Split('@');
  201. var time = nameStr[0];
  202. var name = nameStr[1];
  203. HistoryTableDatas.Add(new PageDataView() { Name = name, ValueStr = time });
  204. }
  205. }
  206. }
  207. }