示例#1
0
 protected override void OnStartup(StartupEventArgs e)
 {
     BootLog.Log("App.OnStartup start");
     RenderOptions.ProcessRenderMode = RenderMode.SoftwareOnly;
     try {
         appMutex = new Mutex(true, _appPipName, out createdNew);
     }
     catch (Exception) {
         createdNew = false;
     }
     if (createdNew)
     {
         if (!NTMiner.Windows.Role.IsAdministrator)
         {
             AppHelper.RunAsAdministrator();
             return;
         }
         BootLog.Log("new SplashWindow");
         SplashWindow splashWindow = new SplashWindow();
         splashWindow.Show();
         NTMinerRoot.Inited = OnNTMinerRootInited;
     }
     else
     {
         try {
             if (CommandLineArgs.IsWorkEdit)
             {
                 object argumentsValue = NTMiner.Windows.Registry.GetValue(Registry.Users, ClientId.NTMinerRegistrySubKey, "Arguments");
                 if (argumentsValue != null && (string)argumentsValue == $"--controlcenter --workid={CommandLineArgs.WorkId}")
                 {
                     AppHelper.ShowMainWindow(this, _appPipName);
                 }
                 else
                 {
                     NTMinerClientDaemon.Instance.RestartNTMiner(NTMinerRoot.MinerClientHost, 3336, CommandLineArgs.WorkId, null);
                     this.Shutdown();
                 }
             }
             else
             {
                 AppHelper.ShowMainWindow(this, _appPipName);
             }
         }
         catch (Exception) {
             DialogWindow.ShowDialog(message: "另一个NTMiner正在运行,请手动结束正在运行的NTMiner进程后再次尝试。", title: "alert", icon: "Icon_Error");
             Process   currentProcess = Process.GetCurrentProcess();
             Process[] processes      = Process.GetProcessesByName(currentProcess.ProcessName);
             foreach (var process in processes)
             {
                 if (process.Id != currentProcess.Id)
                 {
                     NTMiner.Windows.TaskKill.Kill(process.Id);
                 }
             }
         }
     }
     base.OnStartup(e);
     BootLog.Log("App.OnStartup end");
     BootLog.SyncToDisk();
 }
示例#2
0
 protected override void OnStartup(StartupEventArgs e)
 {
     BootLog.Log("App.OnStartup start");
     RenderOptions.ProcessRenderMode = RenderMode.SoftwareOnly;
     try {
         appMutex = new Mutex(true, _appPipName, out createdNew);
     }
     catch (Exception) {
         createdNew = false;
     }
     if (createdNew)
     {
         if (!NTMiner.Windows.Role.IsAdministrator)
         {
             AppHelper.RunAsAdministrator();
             return;
         }
         BootLog.Log("new SplashWindow");
         SplashWindow splashWindow = new SplashWindow();
         splashWindow.Show();
         NTMinerRoot.Inited = () => {
             NTMinerRoot.KernelDownloader = new KernelDownloader();
             Execute.OnUIThread(() => {
                 bool?result = true;
                 if (string.IsNullOrEmpty(Server.LoginName) || string.IsNullOrEmpty(Server.Password))
                 {
                     LoginWindow loginWindow = new LoginWindow();
                     splashWindow.Hide();
                     result = loginWindow.ShowDialog();
                 }
                 if (result.HasValue && result.Value)
                 {
                     BootLog.Log("new MainWindow");
                     ControlCenterWindow window = new ControlCenterWindow();
                     IMainWindow mainWindow     = window;
                     this.MainWindow            = window;
                     this.MainWindow.Show();
                     this.MainWindow.Activate();
                     BootLog.Log("MainWindow showed");
                     notifyIcon = new ExtendedNotifyIcon("pack://application:,,,/ControlCenterApp;component/logo.ico");
                     notifyIcon.Init();
                     #region 处理显示主界面命令
                     Global.Access <ShowMainWindowCommand>(
                         Guid.Parse("01f3c467-f494-42b8-bcb5-848050df59f3"),
                         "处理显示主界面命令",
                         LogEnum.None,
                         action: message => {
                         Execute.OnUIThread(() => {
                             Dispatcher.Invoke((ThreadStart)mainWindow.ShowThisWindow);
                             AppHelper.MainWindowShowed();
                         });
                     });
                     #endregion
                     Task.Factory.StartNew(() => {
                         AppHelper.RunPipeServer(this, _appPipName);
                     });
                 }
                 splashWindow?.Close();
                 BootLog.SyncToDisk();
             });
         };
     }
     else
     {
         try {
             AppHelper.ShowMainWindow(this, _appPipName);
         }
         catch (Exception) {
             DialogWindow.ShowDialog(message: "另一个NTMiner正在运行,请手动结束正在运行的NTMiner进程后再次尝试。", title: "alert", icon: "Icon_Error");
             Process   currentProcess = Process.GetCurrentProcess();
             Process[] processes      = Process.GetProcessesByName(currentProcess.ProcessName);
             foreach (var process in processes)
             {
                 if (process.Id != currentProcess.Id)
                 {
                     NTMiner.Windows.TaskKill.Kill(process.Id);
                 }
             }
         }
     }
     base.OnStartup(e);
     BootLog.Log("App.OnStartup end");
     BootLog.SyncToDisk();
 }