protected override void OnStartup(StartupEventArgs e) { RenderOptions.ProcessRenderMode = RenderMode.SoftwareOnly; try { appMutex = new Mutex(true, s_appPipName, out createdNew); } catch (Exception) { createdNew = false; } if (createdNew) { Vms.AppStatic.IsMinerClient = false; SplashWindow splashWindow = new SplashWindow(); splashWindow.Show(); NotiCenterWindow.Instance.Show(); NTMinerRoot.AppName = "开源矿工群控客户端"; NTMinerServices.NTMinerServicesUtil.RunNTMinerServices(); NTMinerRoot.Current.Init(() => { NTMinerRoot.KernelDownloader = new KernelDownloader(); UIThread.Execute(() => { splashWindow?.Close(); bool?result = true; if (Ip.Util.IsInnerIp(NTMinerRegistry.GetControlCenterHost())) { SingleUser.LoginName = "innerip"; SingleUser.SetPasswordSha1("123"); result = true; } else if (string.IsNullOrEmpty(SingleUser.LoginName) || string.IsNullOrEmpty(SingleUser.PasswordSha1)) { LoginWindow loginWindow = new LoginWindow(); result = loginWindow.ShowDialog(); } if (result.HasValue && result.Value) { ChartsWindow.ShowWindow(); System.Drawing.Icon icon = new System.Drawing.Icon(GetResourceStream(new Uri("pack://application:,,,/MinerStudio;component/logo.ico")).Stream); AppHelper.NotifyIcon = ExtendedNotifyIcon.Create(icon, "群控客户端", isMinerStudio: true); #region 处理显示主界面命令 VirtualRoot.Window <ShowMainWindowCommand>("处理显示主界面命令", LogEnum.None, action: message => { Dispatcher.Invoke((ThreadStart)ChartsWindow.ShowWindow); }); #endregion HttpServer.Start($"http://localhost:{WebApiConst.MinerStudioPort}"); AppHelper.RemoteDesktop = MsRdpRemoteDesktop.OpenRemoteDesktop; } }); }); VirtualRoot.Window <CloseNTMinerCommand>("处理关闭群控客户端命令", LogEnum.UserConsole, action: message => { UIThread.Execute(() => { if (MainWindow != null) { MainWindow.Close(); } Shutdown(); Environment.Exit(0); }); }); } else { try { AppHelper.ShowMainWindow(this, MinerServer.NTMinerAppType.MinerStudio); } 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); }
protected override void OnStartup(StartupEventArgs e) { RenderOptions.ProcessRenderMode = RenderMode.SoftwareOnly; if (!string.IsNullOrEmpty(CommandLineArgs.Upgrade)) { Vms.AppStatic.Upgrade(CommandLineArgs.Upgrade, () => { Environment.Exit(0); }); } else { try { appMutex = new Mutex(true, s_appPipName, out createdNew); } catch (Exception) { createdNew = false; } if (createdNew) { Vms.AppStatic.IsMinerClient = true; SplashWindow splashWindow = new SplashWindow(); splashWindow.Show(); NTMinerRoot.KernelBrandId = Brand.BrandUtil.KernelBrandId; NotiCenterWindow.Instance.Show(); NTMinerRoot.AppName = "开源矿工挖矿客户端"; NTMinerRoot.Current.Init(() => { NTMinerRoot.KernelDownloader = new KernelDownloader(); UIThread.Execute(() => { MainWindow window = new MainWindow(); IMainWindow mainWindow = window; this.MainWindow = window; this.MainWindow.Show(); this.MainWindow.Activate(); System.Drawing.Icon icon = new System.Drawing.Icon(GetResourceStream(new Uri("pack://application:,,,/NTMiner;component/logo.ico")).Stream); AppHelper.NotifyIcon = ExtendedNotifyIcon.Create(icon, "挖矿端", isMinerStudio: false); #region 处理显示主界面命令 VirtualRoot.Window <ShowMainWindowCommand>("处理显示主界面命令", LogEnum.None, action: message => { Dispatcher.Invoke((ThreadStart)mainWindow.ShowThisWindow); }); #endregion splashWindow?.Close(); Task.Factory.StartNew(() => { try { HttpServer.Start($"http://localhost:{WebApiConst.MinerClientPort}"); NTMinerRoot.Current.Start(); } catch (Exception ex) { Logger.ErrorDebugLine(ex.Message, ex); } }); }); }); VirtualRoot.Window <CloseNTMinerCommand>("处理关闭NTMiner客户端命令", LogEnum.UserConsole, action: message => { UIThread.Execute(() => { if (MainWindow != null) { MainWindow.Close(); } Shutdown(); Environment.Exit(0); }); }); VirtualRoot.On <MineStartedEvent>("开始挖矿后启动1080ti小药丸", LogEnum.DevConsole, action: message => { OhGodAnETHlargementPill.OhGodAnETHlargementPillUtil.Start(); }); VirtualRoot.On <MineStopedEvent>("停止挖矿后停止1080ti小药丸", LogEnum.DevConsole, action: message => { OhGodAnETHlargementPill.OhGodAnETHlargementPillUtil.Stop(); }); NTMinerOverClockUtil.ExtractResource(); } else { try { AppHelper.ShowMainWindow(this, MinerServer.NTMinerAppType.MinerClient); } 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); }
public App() { Logging.LogDir.SetDir(System.IO.Path.Combine(VirtualRoot.GlobalDirFullName, "Logs")); AppHelper.Init(this); InitializeComponent(); }
protected override void OnStartup(StartupEventArgs e) { Global.Logger.InfoDebugLine("App.OnStartup start"); RenderOptions.ProcessRenderMode = RenderMode.SoftwareOnly; try { appMutex = new Mutex(true, _appPipName, out createdNew); } catch (Exception) { createdNew = false; } if (createdNew) { Vms.AppStatic.IsMinerClient = false; Global.Logger.InfoDebugLine("new SplashWindow"); SplashWindow splashWindow = new SplashWindow(); splashWindow.Show(); NTMinerRoot.Current.Init(() => { 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) { Global.Logger.InfoDebugLine("new MainWindow"); ControlCenterWindow window = new ControlCenterWindow(); IMainWindow mainWindow = window; this.MainWindow = window; this.MainWindow.Show(); this.MainWindow.Activate(); Global.Logger.InfoDebugLine("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); }); }); #endregion } splashWindow?.Close(); }); }); } 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); Global.Logger.InfoDebugLine("App.OnStartup end"); }
protected override void OnStartup(StartupEventArgs e) { RenderOptions.ProcessRenderMode = RenderMode.SoftwareOnly; if (!string.IsNullOrEmpty(CommandLineArgs.Upgrade)) { AppStatic.Upgrade(CommandLineArgs.Upgrade, () => { Environment.Exit(0); }); } else { try { appMutex = new Mutex(true, s_appPipName, out createdNew); } catch (Exception) { createdNew = false; } if (createdNew) { if (!NTMiner.Windows.WMI.IsWmiEnabled) { DialogWindow.ShowDialog(message: "开源矿工无法运行所需的组件,因为本机未开机WMI服务,开源矿工需要使用WMI服务检测windows的内存、显卡等信息,请先手动开启WMI。", title: "提醒", icon: "Icon_Error"); Shutdown(); Environment.Exit(0); } NTMinerOverClockUtil.ExtractResource(); AppStatic.SetIsMinerClient(true); NotiCenterWindowViewModel.IsHotKeyEnabled = true; SplashWindow splashWindow = new SplashWindow(); splashWindow.Show(); NotiCenterWindow.Instance.Show(); NTMinerRoot.Instance.Init(() => { NTMinerRoot.KernelDownloader = new KernelDownloader(); UIThread.Execute(() => { if (!NTMinerRegistry.GetIsNoUi() || !NTMinerRegistry.GetIsAutoStart()) { Views.MainWindow.ShowMainWindow(); } else { NotiCenterWindowViewModel.Instance.Manager.ShowSuccessMessage("已切换为无界面模式运行", "开源矿工"); } System.Drawing.Icon icon = new System.Drawing.Icon(GetResourceStream(new Uri("pack://application:,,,/NTMiner;component/logo.ico")).Stream); AppHelper.NotifyIcon = ExtendedNotifyIcon.Create(icon, "开源矿工", isMinerStudio: false); #region 处理显示主界面命令 VirtualRoot.Window <ShowMainWindowCommand>("处理显示主界面命令", LogEnum.None, action: message => { UIThread.Execute(() => { MainWindow mainWindow = this.MainWindow as MainWindow; if (mainWindow == null) { AppContext.Enable(); Views.MainWindow.ShowMainWindow(); // 使状态栏显示显示最新状态 if (NTMinerRoot.Instance.IsMining) { var coinShare = NTMinerRoot.Instance.CoinShareSet.GetOrCreate(NTMinerRoot.Instance.CurrentMineContext.MainCoin.GetId()); VirtualRoot.Happened(new ShareChangedEvent(coinShare)); if (NTMinerRoot.Instance.CurrentMineContext is IDualMineContext dualMineContext) { coinShare = NTMinerRoot.Instance.CoinShareSet.GetOrCreate(dualMineContext.DualCoin.GetId()); VirtualRoot.Happened(new ShareChangedEvent(coinShare)); } AppContext.Instance.GpuSpeedVms.Refresh(); } } else { mainWindow.ShowThisWindow(message.IsToggle); } }); }); #endregion splashWindow?.Close(); Task.Factory.StartNew(() => { try { HttpServer.Start($"http://localhost:{WebApiConst.MinerClientPort}"); NTMinerRoot.Instance.Start(); } catch (Exception ex) { Logger.ErrorDebugLine(ex.Message, ex); } }); }); }); Link(); } else { try { AppHelper.ShowMainWindow(this, MinerServer.NTMinerAppType.MinerClient); } catch (Exception) { DialogWindow.ShowDialog(message: "另一个NTMiner正在运行,请手动结束正在运行的NTMiner进程后再次尝试。", title: "提醒", icon: "Icon_Error"); Process currentProcess = Process.GetCurrentProcess(); NTMiner.Windows.TaskKill.KillOtherProcess(currentProcess); } } } base.OnStartup(e); }
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(); }); }