private void Link() { VirtualRoot.Window <CloseNTMinerCommand>("处理关闭NTMiner客户端命令", LogEnum.UserConsole, action: message => { UIThread.Execute(() => { try { if (MainWindow != null) { MainWindow.Close(); } Shutdown(); } catch (Exception e) { Logger.ErrorDebugLine(e); Environment.Exit(0); } }); }); VirtualRoot.Window <CloseMainWindowCommand>("处理关闭主界面命令", LogEnum.DevConsole, action: message => { UIThread.Execute(() => { MainWindow = NotiCenterWindow.Instance; foreach (Window window in Windows) { if (window != MainWindow) { window.Close(); } } NotiCenterWindowViewModel.Instance.Manager.ShowSuccessMessage("已切换为无界面模式运行", "开源矿工"); }); }); #region 周期确保守护进程在运行 Daemon.DaemonUtil.RunNTMinerDaemon(); VirtualRoot.On <Per20SecondEvent>("周期确保守护进程在运行", LogEnum.DevConsole, action: message => { if (NTMinerRegistry.GetDaemonActiveOn().AddSeconds(20) < DateTime.Now) { Daemon.DaemonUtil.RunNTMinerDaemon(); } }); #endregion #region 1080小药丸 VirtualRoot.On <MineStartedEvent>("开始挖矿后启动1080ti小药丸、挖矿开始后如果需要启动DevConsole则启动DevConsole", LogEnum.DevConsole, action: message => { // 启动DevConsole if (NTMinerRoot.IsUseDevConsole) { var mineContext = message.MineContext; string poolIp = mineContext.MainCoinPool.GetIp(); string consoleTitle = mineContext.MainCoinPool.Server; Daemon.DaemonUtil.RunDevConsoleAsync(poolIp, consoleTitle); } OhGodAnETHlargementPill.OhGodAnETHlargementPillUtil.Start(); }); VirtualRoot.On <MineStopedEvent>("停止挖矿后停止1080ti小药丸", LogEnum.DevConsole, action: message => { OhGodAnETHlargementPill.OhGodAnETHlargementPillUtil.Stop(); }); #endregion #region 处理禁用win10系统更新 VirtualRoot.Window <BlockWAUCommand>("处理禁用win10系统更新命令", LogEnum.DevConsole, action: message => { NTMiner.Windows.WindowsUtil.BlockWAU(); }); #endregion #region 处理开启A卡计算模式 VirtualRoot.Window <SwitchRadeonGpuCommand>("处理开启A卡计算模式命令", LogEnum.DevConsole, action: message => { if (NTMinerRoot.Instance.GpuSet.GpuType == GpuType.AMD) { if (NTMinerRoot.Instance.IsMining) { NTMinerRoot.Instance.StopMineAsync(() => { SwitchRadeonGpuMode(); NTMinerRoot.Instance.StartMine(); }); } else { SwitchRadeonGpuMode(); } } }); #endregion #region 处理A卡驱动签名 VirtualRoot.Window <AtikmdagPatcherCommand>("处理A卡驱动签名命令", LogEnum.DevConsole, action: message => { if (NTMinerRoot.Instance.GpuSet.GpuType == GpuType.AMD) { if (NTMinerRoot.Instance.IsMining) { NTMinerRoot.Instance.StopMineAsync(() => { AtikmdagPatcher.AtikmdagPatcherUtil.Run(); NTMinerRoot.Instance.StartMine(); }); } else { AtikmdagPatcher.AtikmdagPatcherUtil.Run(); } } }); #endregion }
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) { AppStatic.SetIsMinerClient(false); SplashWindow splashWindow = new SplashWindow(); splashWindow.Show(); NotiCenterWindow.Instance.Show(); bool isInnerIp = Ip.Util.IsInnerIp(NTMinerRegistry.GetControlCenterHost()); if (isInnerIp) { NTMinerServices.NTMinerServicesUtil.RunNTMinerServices(); } NTMinerRoot.Instance.Init(() => { NTMinerRoot.KernelDownloader = new KernelDownloader(); UIThread.Execute(() => { splashWindow?.Close(); bool?result = true; if (isInnerIp) { 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(() => { try { if (MainWindow != null) { MainWindow.Close(); } Shutdown(); } catch (Exception ex) { Logger.ErrorDebugLine(ex.Message, ex); 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(); NTMiner.Windows.TaskKill.KillOtherProcess(currentProcess); } } base.OnStartup(e); }
protected override void OnStartup(StartupEventArgs e) { RenderOptions.ProcessRenderMode = RenderMode.SoftwareOnly; VirtualRoot.Window <ShowFileDownloaderCommand>(LogEnum.DevConsole, action: message => { UIThread.Execute(() => { FileDownloader.ShowWindow(message.DownloadFileUrl, message.FileTitle, message.DownloadComplete); }); }); VirtualRoot.Window <UpgradeCommand>(LogEnum.DevConsole, action: message => { AppStatic.Upgrade(message.FileName, message.Callback); }); try { appMutex = new Mutex(true, s_appPipName, out createdNew); } catch (Exception) { createdNew = false; } if (createdNew) { this.ShutdownMode = ShutdownMode.OnExplicitShutdown; VirtualRoot.SetIsMinerClient(false); NotiCenterWindow.Instance.Show(); LoginWindow loginWindow = new LoginWindow(); var result = loginWindow.ShowDialog(); if (result.HasValue && result.Value) { bool isInnerIp = Ip.Util.IsInnerIp(NTMinerRegistry.GetControlCenterHost()); if (isInnerIp) { NTMinerServices.NTMinerServicesUtil.RunNTMinerServices(() => { Init(); }); } else { Init(); } } VirtualRoot.Window <CloseNTMinerCommand>("处理关闭群控客户端命令", LogEnum.UserConsole, action: message => { UIThread.Execute(() => { try { if (MainWindow != null) { MainWindow.Close(); } Shutdown(); } catch (Exception ex) { Logger.ErrorDebugLine(ex); Environment.Exit(0); } }); }); } else { try { _appViewFactory.ShowMainWindow(this, MinerServer.NTMinerAppType.MinerStudio); } catch (Exception) { DialogWindow.ShowDialog(message: "另一个NTMiner正在运行,请手动结束正在运行的NTMiner进程后再次尝试。", title: "alert", icon: "Icon_Error"); Process currentProcess = Process.GetCurrentProcess(); NTMiner.Windows.TaskKill.KillOtherProcess(currentProcess); } } 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); }
private void Link() { VirtualRoot.Window <CloseNTMinerCommand>("处理关闭NTMiner客户端命令", LogEnum.UserConsole, action: message => { UIThread.Execute(() => { try { if (MainWindow != null) { MainWindow.Close(); } Shutdown(); } catch (Exception e) { Logger.ErrorDebugLine(e); Environment.Exit(0); } }); }); VirtualRoot.Window <CloseMainWindowCommand>("处理关闭主界面命令", LogEnum.DevConsole, action: message => { UIThread.Execute(() => { MainWindow = NotiCenterWindow.Instance; foreach (Window window in Windows) { if (window != MainWindow) { window.Close(); } } NotiCenterWindowViewModel.Instance.Manager.ShowSuccessMessage(message.Message, "开源矿工"); }); }); #region 周期确保守护进程在运行 Daemon.DaemonUtil.RunNTMinerDaemon(); VirtualRoot.On <Per20SecondEvent>("周期确保守护进程在运行", LogEnum.DevConsole, action: message => { if (NTMinerRegistry.GetDaemonActiveOn().AddSeconds(20) < DateTime.Now) { Daemon.DaemonUtil.RunNTMinerDaemon(); } }); #endregion #region 1080小药丸 VirtualRoot.On <MineStartedEvent>("开始挖矿后启动1080ti小药丸、挖矿开始后如果需要启动DevConsole则启动DevConsole", LogEnum.DevConsole, action: message => { // 启动DevConsole if (NTMinerRoot.IsUseDevConsole) { var mineContext = message.MineContext; string poolIp = mineContext.MainCoinPool.GetIp(); string consoleTitle = mineContext.MainCoinPool.Server; Daemon.DaemonUtil.RunDevConsoleAsync(poolIp, consoleTitle); } OhGodAnETHlargementPill.OhGodAnETHlargementPillUtil.Start(); }); VirtualRoot.On <MineStopedEvent>("停止挖矿后停止1080ti小药丸", LogEnum.DevConsole, action: message => { OhGodAnETHlargementPill.OhGodAnETHlargementPillUtil.Stop(); }); #endregion #region 处理禁用win10系统更新 VirtualRoot.Window <BlockWAUCommand>("处理禁用win10系统更新命令", LogEnum.DevConsole, action: message => { NTMiner.Windows.WindowsUtil.BlockWAU(); }); #endregion #region 优化windows VirtualRoot.Window <Win10OptimizeCommand>("处理优化windows命令", LogEnum.DevConsole, action: message => { NTMiner.Windows.WindowsUtil.Win10Optimize(); }); #endregion #region 处理开启A卡计算模式 VirtualRoot.Window <SwitchRadeonGpuCommand>("处理开启A卡计算模式命令", LogEnum.DevConsole, action: message => { if (NTMinerRoot.Instance.GpuSet.GpuType == GpuType.AMD) { SwitchRadeonGpuMode(); } }); #endregion #region 处理A卡驱动签名 VirtualRoot.Window <AtikmdagPatcherCommand>("处理A卡驱动签名命令", LogEnum.DevConsole, action: message => { if (NTMinerRoot.Instance.GpuSet.GpuType == GpuType.AMD) { AtikmdagPatcher.AtikmdagPatcherUtil.Run(); } }); #endregion #region 启用或禁用windows远程桌面 VirtualRoot.Window <EnableOrDisableWindowsRemoteDesktopCommand>("处理启用或禁用Windows远程桌面命令", LogEnum.DevConsole, action: message => { string msg = "确定启用Windows远程桌面吗?"; if (!message.IsEnable) { msg = "确定禁用Windows远程桌面吗?"; return; } DialogWindow.ShowDialog(message: msg, title: "确认", onYes: () => { if (message.IsEnable) { Rdp.SetRdpEnabled(true, true); Firewall.AddRemoteDesktopRule(); } else { Rdp.SetRdpEnabled(false, true); Firewall.RemoveRemoteDesktopRule(); } }, icon: IconConst.IconConfirm); }); #endregion #region 启用或禁用windows开机自动登录 VirtualRoot.Window <EnableOrDisableWindowsAutoLoginCommand>("处理启用或禁用Windows开机自动登录命令", LogEnum.DevConsole, action: message => { if (NTMiner.Windows.OS.Instance.IsAutoAdminLogon) { return; } NTMiner.Windows.Cmd.RunClose("control", "userpasswords2"); }); #endregion }