ShutDonwControlViewModel.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. using Aitex.Common.Util;
  2. using Aitex.Core.RT.Log;
  3. using Aitex.Core.Util;
  4. using MECF.Framework.Common.OperationCenter;
  5. using MECF.Framework.UI.Client.ClientBase;
  6. using OpenSEMI.ClientBase;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Diagnostics;
  10. using System.IO;
  11. using System.Linq;
  12. using System.Windows;
  13. namespace MECF.Framework.UI.Client.CenterViews.Configs.SystemConfig
  14. {
  15. public class ShutDonwControlViewModel : UiViewModelBase
  16. {
  17. private bool _uIAndRTControlVisibility = false;
  18. public bool UIAndRTControlVisibility
  19. {
  20. get => _uIAndRTControlVisibility;
  21. set
  22. {
  23. _uIAndRTControlVisibility = value;
  24. NotifyOfPropertyChange(nameof(UIAndRTControlVisibility));
  25. }
  26. }
  27. private bool _uIControlVisibility = false;
  28. public bool UIControlVisibility
  29. {
  30. get => _uIControlVisibility;
  31. set
  32. {
  33. _uIControlVisibility = value;
  34. NotifyOfPropertyChange(nameof(UIControlVisibility));
  35. }
  36. }
  37. private bool _allControlVisibility = false;
  38. private string _path = "";
  39. public ShutDonwControlViewModel()
  40. {
  41. _path = Path.GetDirectoryName(PathManager.GetAppDir());
  42. if (_path.Contains("FurnaceUI"))
  43. {
  44. _path = _path.Replace("FurnaceUI", "FurnaceRT");
  45. }
  46. }
  47. public bool AllControlVisibility
  48. {
  49. get => _allControlVisibility;
  50. set
  51. {
  52. _allControlVisibility = value;
  53. NotifyOfPropertyChange(nameof(AllControlVisibility));
  54. }
  55. }
  56. public void ReStartRTAndUI()
  57. {
  58. if (DialogBox.Confirm("Are you sure you want to Restart UI and RT?"))
  59. Process.Start($"{_path}\\FurnaceBat\\startFurnace.bat");
  60. }
  61. public void ShutDownUIAndRT()
  62. {
  63. if (DialogBox.Confirm("Are you sure you want to shut down UI and RT?"))
  64. Process.Start($"{_path}\\FurnaceBat\\stopFurnace.bat");
  65. }
  66. public void ReStartUI()
  67. {
  68. if (DialogBox.Confirm("Are you sure you want to ReStart UI?"))
  69. Process.Start($"{_path}\\FurnaceBat\\restartUI.bat");
  70. }
  71. public void ShutDownUI()
  72. {
  73. if (DialogBox.Confirm("Are you sure you want to shut down UI?"))
  74. Process.Start($"{_path}\\FurnaceBat\\shutDownUI.bat");
  75. }
  76. public void AllControlPowerOff()
  77. {
  78. if (DialogBox.Confirm("Are you sure you want to shut down your computer in 60 seconds?"))
  79. ExecuteCommand("shutdown", "/s /f /t 60");
  80. }
  81. public void RestartComputer()
  82. {
  83. if (DialogBox.Confirm("Are you sure you want to restart your computer in 60 seconds?"))
  84. ExecuteCommand("shutdown", "/r /f /t 60");
  85. }
  86. public void AllControlReStart()
  87. {
  88. if (DialogBox.Confirm("Are you sure you want to restart All Control ?"))
  89. {
  90. Process.Start($"{_path}\\FurnaceBat\\startFurnace.bat");
  91. }
  92. }
  93. public void AllControlShutDown()
  94. {
  95. if (DialogBox.Confirm("Are you sure you want to restart All ShutDown ?"))
  96. {
  97. Process.Start($"{_path}\\FurnaceBat\\stopFurnace.bat");
  98. }
  99. }
  100. private void ExecuteCommand(string fileName, string arguments)
  101. {
  102. LOG.Info($"{fileName} {arguments}");
  103. try
  104. {
  105. System.Diagnostics.Process.Start(new ProcessStartInfo(fileName, arguments)
  106. {
  107. UseShellExecute = false,
  108. RedirectStandardOutput = true,
  109. RedirectStandardError = true,
  110. CreateNoWindow = true,
  111. });
  112. }
  113. catch (Exception ex)
  114. {
  115. LOG.Info($"{fileName} {arguments},An error occurred: {ex.Message}");
  116. }
  117. }
  118. }
  119. }