ShutDonwControlViewModel.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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. public bool AllControlVisibility
  39. {
  40. get => _allControlVisibility;
  41. set
  42. {
  43. _allControlVisibility = value;
  44. NotifyOfPropertyChange(nameof(AllControlVisibility));
  45. }
  46. }
  47. public void ReStartRTAndUI()
  48. {
  49. if (DialogBox.Confirm("Are you sure you want to Restart UI and RT?"))
  50. Process.Start($"{Path.GetDirectoryName(PathManager.GetAppDir())}\\FurnaceBat\\startFurnace.bat");
  51. }
  52. public void ShutDownUIAndRT()
  53. {
  54. if (DialogBox.Confirm("Are you sure you want to shut down UI and RT?"))
  55. Process.Start($"{Path.GetDirectoryName(PathManager.GetAppDir())}\\FurnaceBat\\stopFurnace.bat");
  56. }
  57. public void ReStartUI()
  58. {
  59. if (DialogBox.Confirm("Are you sure you want to ReStart UI?"))
  60. Process.Start($"{Path.GetDirectoryName(PathManager.GetAppDir())}\\FurnaceBat\\restartUI.bat");
  61. }
  62. public void ShutDownUI()
  63. {
  64. if (DialogBox.Confirm("Are you sure you want to shut down UI?"))
  65. Process.Start($"{Path.GetDirectoryName(PathManager.GetAppDir())}\\FurnaceBat\\shutDownUI.bat");
  66. }
  67. public void AllControlPowerOff()
  68. {
  69. if (DialogBox.Confirm("Are you sure you want to shut down your computer in 60 seconds?"))
  70. ExecuteCommand("shutdown", "/s /f /t 60");
  71. }
  72. public void RestartComputer()
  73. {
  74. if (DialogBox.Confirm("Are you sure you want to restart your computer in 60 seconds?"))
  75. ExecuteCommand("shutdown", "/r /f /t 60");
  76. }
  77. public void AllControlReStart()
  78. {
  79. if (DialogBox.Confirm("Are you sure you want to restart All Control ?"))
  80. {
  81. ReStartRTAndUI();
  82. }
  83. }
  84. public void AllControlShutDown()
  85. {
  86. if (DialogBox.Confirm("Are you sure you want to restart All ShutDown ?"))
  87. {
  88. ShutDownUIAndRT();
  89. }
  90. }
  91. private void ExecuteCommand(string fileName, string arguments)
  92. {
  93. LOG.Info($"{fileName} {arguments}");
  94. try
  95. {
  96. System.Diagnostics.Process.Start(new ProcessStartInfo(fileName, arguments)
  97. {
  98. UseShellExecute = false,
  99. RedirectStandardOutput = true,
  100. RedirectStandardError = true,
  101. CreateNoWindow = true,
  102. });
  103. }
  104. catch (Exception ex)
  105. {
  106. LOG.Info($"{fileName} {arguments},An error occurred: {ex.Message}");
  107. }
  108. }
  109. }
  110. }