RTApplication.cs 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. using Aitex.Core.Util;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading;
  7. using System.Threading.Tasks;
  8. using System.Windows;
  9. using System.Windows.Controls;
  10. using System.Windows.Forms;
  11. using Aitex.Core.Backend;
  12. using Aitex.Core.RT.Log;
  13. using MECF.Framework.Common.NotifyTrayIcons;
  14. using MECF.Framework.RT.Core.Backend;
  15. using MECF.Framework.RT.Core.Applications;
  16. namespace athosRT
  17. {
  18. class RTApplication
  19. {
  20. public class RtApplication
  21. {
  22. //static ThreadExceptionEventHandler ThreadHandler = new ThreadExceptionEventHandler(Application_ThreadException);
  23. //private ShowWindowNotifyIcon _trayIcon;
  24. //private IRtInstance _instance;
  25. //private static bool _ignoreError;
  26. //public static BackendMainView MainView { get; set; }
  27. //private PassWordView _loginWindow = new PassWordView();
  28. //private static Mutex _mutex;
  29. //public void Initialize(IRtInstance instance)
  30. //{
  31. // AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
  32. // AppDomain.CurrentDomain.ProcessExit += new EventHandler(CurrentDomain_ProcessExit);
  33. // //Because this is a static event, you must detach your event handlers when your application is disposed, or memory leaks will result.
  34. // System.Windows.Forms.Application.ThreadException += ThreadHandler;
  35. // System.Windows.Forms.Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
  36. // _instance = instance;
  37. // CheckAnotherInstanceRunning(instance.SystemName);
  38. // MainView = new BackendMainView();
  39. // MainView.Icon = _instance.TrayIcon;
  40. // MainView.Title = _instance.SystemName + " Console";
  41. // _loginWindow.Title = _instance.SystemName + " RT Backend Login";
  42. // _ignoreError = _instance.KeepRunningAfterUnknownException;
  43. // if (_instance.EnableNotifyIcon)
  44. // {
  45. // _trayIcon = new ShowWindowNotifyIcon(_instance.SystemName, _instance.TrayIcon);
  46. // _trayIcon.ExitWindow += TrayIconExitWindow;
  47. // _trayIcon.ShowMainWindow += TrayIconShowMainWindow;
  48. // _trayIcon.ShowBallon(_instance.SystemName, "Start running");
  49. // }
  50. // InitSystem();
  51. // if (_instance.DefaultShowBackendWindow)
  52. // {
  53. // MainView.Show();
  54. // }
  55. //}
  56. //void CheckAnotherInstanceRunning(string appName)
  57. //{
  58. // _mutex = new Mutex(true, appName, out bool createNew);
  59. // if (!createNew)
  60. // {
  61. // if (!_mutex.WaitOne(1000))
  62. // {
  63. // string msg = $"{appName} is already running,can not start again";
  64. // System.Windows.MessageBox.Show(msg, $"{appName} Launch Failed", System.Windows.MessageBoxButton.OK, MessageBoxImage.Warning, System.Windows.MessageBoxResult.No,
  65. // System.Windows.MessageBoxOptions.DefaultDesktopOnly);
  66. // Environment.Exit(0);
  67. // }
  68. // }
  69. //}
  70. //static void CurrentDomain_ProcessExit(object sender, EventArgs e)
  71. //{
  72. // System.Windows.Forms.Application.ThreadException -= ThreadHandler;
  73. //}
  74. //static void Application_ThreadException(object sender, ThreadExceptionEventArgs e)
  75. //{
  76. // ShowMessageDialog(e.Exception);
  77. //}
  78. //static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
  79. //{
  80. // ShowMessageDialog((Exception)e.ExceptionObject);
  81. //}
  82. //static void ShowMessageDialog(Exception ex)
  83. //{
  84. // //LOG.WriteExeption(ex);
  85. // if (!_ignoreError)
  86. // {
  87. // string message = string.Format(" RT unknown exception:{0},\n", DateTime.Now);
  88. // System.Windows.MessageBox.Show(message + ex.Message, "Unexpected exception", System.Windows.MessageBoxButton.YesNo,
  89. // System.Windows.MessageBoxImage.Exclamation,
  90. // System.Windows.MessageBoxResult.No,
  91. // System.Windows.MessageBoxOptions.DefaultDesktopOnly);
  92. // //Environment.Exit(0);
  93. // }
  94. //}
  95. //private void TrayIconExitWindow()
  96. //{
  97. // if (System.Windows.MessageBox.Show("Are you sure you want to exit system?", _instance.SystemName, System.Windows.MessageBoxButton.YesNo,
  98. // System.Windows.MessageBoxImage.Exclamation,
  99. // System.Windows.MessageBoxResult.No,
  100. // System.Windows.MessageBoxOptions.DefaultDesktopOnly) == System.Windows.MessageBoxResult.Yes)
  101. // {
  102. // if (_trayIcon != null)
  103. // {
  104. // _trayIcon.ShowBallon(_instance.SystemName, "Stop running");
  105. // }
  106. // Terminate();
  107. // }
  108. //}
  109. //private void TrayIconShowMainWindow(bool show)
  110. //{
  111. // if (MainView == null)
  112. // return;
  113. // if (show)
  114. // {
  115. // if (!MainView.IsVisible)
  116. // {
  117. // if (!_loginWindow.IsVisible)
  118. // {
  119. // _loginWindow.Reset();
  120. // _loginWindow.ShowDialog();
  121. // if (_loginWindow.VerificationResult)
  122. // MainView.Show();
  123. // }
  124. // }
  125. // else
  126. // {
  127. // MainView.Show();
  128. // }
  129. // }
  130. // else
  131. // {
  132. // MainView.Hide();
  133. // }
  134. //}
  135. //private void InitSystem()
  136. //{
  137. // if (_instance.Loader != null)
  138. // {
  139. // _instance.Loader.Initialize();
  140. // }
  141. //}
  142. //public void Terminate()
  143. //{
  144. // if (_instance.Loader != null)
  145. // {
  146. // _instance.Loader.Terminate();
  147. // }
  148. // if (_trayIcon != null)
  149. // {
  150. // _trayIcon.Dispose();
  151. // }
  152. // if (MainView != null)
  153. // {
  154. // MainView.Close();
  155. // }
  156. // System.Windows.Application.Current.Shutdown(0);
  157. // Environment.Exit(0);
  158. //}
  159. }
  160. }
  161. }