Esempio n. 1
0
 private void OnNTMinerRootInited()
 {
     NTMinerRoot.KernelDownloader = new KernelDownloader();
     Execute.OnUIThread(() => {
         BootLog.Log("new MainWindow");
         Window splashWindow    = MainWindow;
         MainWindow window      = new MainWindow();
         IMainWindow mainWindow = window;
         this.MainWindow        = window;
         this.MainWindow.Show();
         this.MainWindow.Activate();
         BootLog.Log("MainWindow showed");
         notifyIcon = new ExtendedNotifyIcon("pack://application:,,,/NTMiner;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
         #region 处理重启NTMiner命令
         Global.Access <RestartNTMinerCommand>(
             Guid.Parse("d1712c1f-507c-496f-9da2-870cbd9fc57f"),
             "处理重启NTMiner命令",
             LogEnum.None,
             action: message => {
             List <string> args = CommandLineArgs.Args;
             if (message.IsWorkEdit)
             {
                 if (CommandLineArgs.IsWorkEdit && CommandLineArgs.WorkId == message.MineWorkId)
                 {
                     Execute.OnUIThread(() => {
                         Dispatcher.Invoke((ThreadStart)mainWindow.ShowThisWindow);
                     });
                     return;
                 }
                 if (!CommandLineArgs.IsControlCenter)
                 {
                     args.Add("--controlCenter");
                 }
             }
             if (message.MineWorkId != Guid.Empty)
             {
                 if (!CommandLineArgs.IsWorker)
                 {
                     args.Add("--workid=" + message.MineWorkId.ToString());
                 }
                 else
                 {
                     for (int i = 0; i < args.Count; i++)
                     {
                         if (args[i].StartsWith("--workid=", StringComparison.OrdinalIgnoreCase))
                         {
                             args[i] = "--workid=" + message.MineWorkId.ToString();
                             break;
                         }
                     }
                 }
             }
             else
             {
                 if (CommandLineArgs.IsWorker)
                 {
                     int workIdIndex = -1;
                     for (int i = 0; i < args.Count; i++)
                     {
                         if (args[i].ToLower().Contains("--workid="))
                         {
                             workIdIndex = i;
                             break;
                         }
                     }
                     if (workIdIndex != -1)
                     {
                         args.RemoveAt(workIdIndex);
                     }
                 }
             }
             NTMiner.Windows.Cmd.RunClose(ClientId.AppFileFullName, string.Join(" ", args));
             Current.MainWindow.Close();
         });
         #endregion
         Task.Factory.StartNew(() => {
             AppHelper.RunPipeServer(this, _appPipName);
         });
         try {
             NTMinerRoot.Current.Start();
         }
         catch (Exception ex) {
             Global.Logger.Error(ex.Message, ex);
         }
         splashWindow?.Close();
         if (NTMinerRoot.Current.MinerProfile.IsAutoStart || CommandLineArgs.IsAutoStart)
         {
             Global.DebugLine("自动开始挖矿倒计时", ConsoleColor.Yellow);
             Views.Ucs.AutoStartCountdown.ShowDialog();
         }
         BootLog.SyncToDisk();
     });
 }