// 因为是上下文路径,无需返回路径标识 public static void BuildCmdPath <TCmd>(LogEnum logType, Type location, Action <TCmd> path) where TCmd : ICmd { var messagePathId = VirtualRoot.BuildCmdPath(location, logType, path); _contextPathIds.Add(messagePathId); }
private void BuildCommonPaths() { // 之所以提前到这里是因为升级之前可能需要下载升级器,下载升级器时需要下载器 VirtualRoot.BuildCmdPath <ShowFileDownloaderCommand>(path: message => { FileDownloader.ShowWindow(message.DownloadFileUrl, message.FileTitle, message.DownloadComplete); }, location: this.GetType()); VirtualRoot.BuildCmdPath <UpgradeCommand>(path: message => { AppRoot.Upgrade(NTMinerAppType.MinerClient, message.FileName, message.Callback); }, location: this.GetType()); }
private void BuildCommonPaths() { // 之所以提前到这里是因为升级之前可能需要下载升级器,下载升级器时需要下载器 VirtualRoot.BuildCmdPath <ShowFileDownloaderCommand>(location: this.GetType(), LogEnum.DevConsole, path: message => { FileDownloader.ShowWindow(message.DownloadFileUrl, message.FileTitle, message.DownloadComplete); }); VirtualRoot.BuildCmdPath <UpgradeCommand>(location: this.GetType(), LogEnum.DevConsole, path: message => { AppRoot.Upgrade(message.FileName, message.Callback); }); }
private MqRedis(ConnectionMultiplexer redisConn, IModel channel) { this._redisConn = redisConn; this._mqChannel = channel; this._mqCountSender = new MqCountSender(this); VirtualRoot.BuildEventPath <Per20SecondEvent>("周期将本节点的MqCountData广播到Mq上去", LogEnum.None, message => { this._mqCountSender.SendMqCounts(MqCountRoot.GetMqCount()); }, typeof(MqCountRoot)); VirtualRoot.BuildCmdPath <RefreshMinerTestIdMqCommand>(message => { RefreshClientTestId(); }, this.GetType()); RefreshClientTestId(); }
private void Init() { NTMinerRoot.Instance.Init(() => { _appViewFactory.Link(); UIThread.Execute(() => { VirtualRoot.Execute(new ShowMinerClientsWindowCommand()); AppContext.NotifyIcon = ExtendedNotifyIcon.Create("群控客户端", isMinerStudio: true); }); #region 处理显示主界面命令 VirtualRoot.BuildCmdPath <ShowMainWindowCommand>(action: message => { VirtualRoot.Execute(new ShowMinerClientsWindowCommand()); }); #endregion HttpServer.Start($"http://localhost:{VirtualRoot.MinerStudioPort}"); AppContext.RemoteDesktop = MsRdpRemoteDesktop.OpenRemoteDesktop; }); }
public static void BuildCmdPath <TCmd>(this Window window, LogEnum logType, Type location, Action <TCmd> path) where TCmd : ICmd { if (WpfUtil.IsInDesignMode) { return; } if (window.Resources == null) { window.Resources = new ResourceDictionary(); } List <IMessagePathId> messagePathIds = (List <IMessagePathId>)window.Resources[messagePathIdsResourceKey]; if (messagePathIds == null) { messagePathIds = new List <IMessagePathId>(); window.Resources.Add(messagePathIdsResourceKey, messagePathIds); window.Closed += UiElement_Closed; } MessageTypeAttribute messageTypeDescription = MessageTypeAttribute.GetMessageTypeAttribute(typeof(TCmd)); var messagePathId = VirtualRoot.BuildCmdPath(location, logType, path); messagePathIds.Add(messagePathId); }
private void Link() { VirtualRoot.BuildEventPath <StartingMineFailedEvent>("开始挖矿失败", LogEnum.DevConsole, action: message => { AppContext.Instance.MinerProfileVm.IsMining = false; VirtualRoot.Out.ShowError(message.Message); }); #region 处理显示主界面命令 VirtualRoot.BuildCmdPath <ShowMainWindowCommand>(action: message => { ShowMainWindow(message.IsToggle); }); #endregion VirtualRoot.BuildCmdPath <CloseNTMinerCommand>(action: message => { // 不能推迟这个日志记录的时机,因为推迟会有windows异常日志 VirtualRoot.ThisLocalWarn(nameof(NTMinerRoot), $"退出{VirtualRoot.AppName}。原因:{message.Reason}"); UIThread.Execute(() => { try { Shutdown(); } catch (Exception e) { Logger.ErrorDebugLine(e); Environment.Exit(0); } }); }); #region 周期确保守护进程在运行 VirtualRoot.BuildEventPath <Per1MinuteEvent>("周期确保守护进程在运行", LogEnum.DevConsole, action: message => { Daemon.DaemonUtil.RunNTMinerDaemon(); }); #endregion #region 开始和停止挖矿后 VirtualRoot.BuildEventPath <MineStartedEvent>("启动1080ti小药丸、启动DevConsole? 更新挖矿按钮状态", LogEnum.DevConsole, action: message => { AppContext.Instance.MinerProfileVm.IsMining = true; StartStopMineButtonViewModel.Instance.BtnStopText = "正在挖矿"; // 启动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.BuildEventPath <MineStopedEvent>("停止挖矿后停止1080ti小药丸 挖矿停止后更新界面挖矿状态", LogEnum.DevConsole, action: message => { AppContext.Instance.MinerProfileVm.IsMining = false; StartStopMineButtonViewModel.Instance.BtnStopText = "尚未开始"; OhGodAnETHlargementPill.OhGodAnETHlargementPillUtil.Stop(); }); #endregion #region 处理禁用win10系统更新 VirtualRoot.BuildCmdPath <BlockWAUCommand>(action: message => { NTMiner.Windows.WindowsUtil.BlockWAU(); }); #endregion #region 优化windows VirtualRoot.BuildCmdPath <Win10OptimizeCommand>(action: message => { NTMiner.Windows.WindowsUtil.Win10Optimize(); }); #endregion #region 处理开启A卡计算模式 VirtualRoot.BuildCmdPath <SwitchRadeonGpuCommand>(action: message => { if (NTMinerRoot.Instance.GpuSet.GpuType == GpuType.AMD) { SwitchRadeonGpuMode(message.On); } }); #endregion #region 处理A卡驱动签名 VirtualRoot.BuildCmdPath <AtikmdagPatcherCommand>(action: message => { if (NTMinerRoot.Instance.GpuSet.GpuType == GpuType.AMD) { AtikmdagPatcher.AtikmdagPatcherUtil.Run(); } }); #endregion #region 启用或禁用windows远程桌面 VirtualRoot.BuildCmdPath <EnableWindowsRemoteDesktopCommand>(action: message => { if (NTMinerRegistry.GetIsRemoteDesktopEnabled()) { return; } string msg = "确定启用Windows远程桌面吗?"; DialogWindow.ShowSoftDialog(new DialogWindowViewModel( message: msg, title: "确认", onYes: () => { Rdp.SetRdpEnabled(true); Firewall.AddRdpRule(); })); }); #endregion #region 启用或禁用windows开机自动登录 VirtualRoot.BuildCmdPath <EnableOrDisableWindowsAutoLoginCommand>(action: message => { if (NTMiner.Windows.OS.Instance.IsAutoAdminLogon) { return; } NTMiner.Windows.Cmd.RunClose("control", "userpasswords2"); }); #endregion }
private void Link() { VirtualRoot.BuildCmdPath <RegCmdHereCommand>(action: message => { try { Windows.Cmd.RegCmdHere(); VirtualRoot.ThisLocalInfo(nameof(NTMinerRoot), "windows右键命令行添加成功", OutEnum.Success); } catch (Exception e) { Logger.ErrorDebugLine(e); VirtualRoot.ThisLocalError(nameof(NTMinerRoot), "windows右键命令行添加失败", OutEnum.Warn); } }); VirtualRoot.BuildEventPath <Per1MinuteEvent>("每1分钟阻止系统休眠", LogEnum.None, action: message => { Windows.Power.PreventSleep(); }); #region 挖矿开始时将无份额内核重启份额计数置0 int shareCount = 0; DateTime shareOn = DateTime.Now; VirtualRoot.BuildEventPath <MineStartedEvent>("挖矿开始后将无份额内核重启份额计数置0", LogEnum.DevConsole, action: message => { // 将无份额内核重启份额计数置0 shareCount = 0; if (!message.MineContext.IsRestart) { shareOn = DateTime.Now; } }); #endregion #region 每20秒钟检查是否需要重启 VirtualRoot.BuildEventPath <Per20SecondEvent>("每20秒钟检查是否需要重启", LogEnum.None, action: message => { #region 重启电脑 try { if (MinerProfile.IsPeriodicRestartComputer) { if ((DateTime.Now - this.CreatedOn).TotalMinutes > 60 * MinerProfile.PeriodicRestartComputerHours + MinerProfile.PeriodicRestartComputerMinutes) { string content = $"每运行{MinerProfile.PeriodicRestartKernelHours.ToString()}小时{MinerProfile.PeriodicRestartComputerMinutes.ToString()}分钟重启电脑"; VirtualRoot.ThisLocalWarn(nameof(NTMinerRoot), content, toConsole: true); Windows.Power.Restart(60); VirtualRoot.Execute(new CloseNTMinerCommand(content)); return; // 退出 } } } catch (Exception e) { Logger.ErrorDebugLine(e); } #endregion #region 周期重启内核 try { if (IsMining && MinerProfile.IsPeriodicRestartKernel) { if ((DateTime.Now - LockedMineContext.CreatedOn).TotalMinutes > 60 * MinerProfile.PeriodicRestartKernelHours + MinerProfile.PeriodicRestartKernelMinutes) { VirtualRoot.ThisLocalWarn(nameof(NTMinerRoot), $"每运行{MinerProfile.PeriodicRestartKernelHours.ToString()}小时{MinerProfile.PeriodicRestartKernelMinutes.ToString()}分钟重启内核", toConsole: true); RestartMine(); return; // 退出 } } } catch (Exception e) { Logger.ErrorDebugLine(e); } #endregion #region 无份额重启内核 try { if (IsMining && this.LockedMineContext.MainCoin != null) { int totalShare = 0; bool restartComputer = MinerProfile.IsNoShareRestartComputer && (DateTime.Now - shareOn).TotalMinutes > MinerProfile.NoShareRestartComputerMinutes; bool restartKernel = MinerProfile.IsNoShareRestartKernel && (DateTime.Now - shareOn).TotalMinutes > MinerProfile.NoShareRestartKernelMinutes; if (restartComputer || restartKernel) { ICoinShare mainCoinShare = this.CoinShareSet.GetOrCreate(this.LockedMineContext.MainCoin.GetId()); totalShare = mainCoinShare.TotalShareCount; if ((this.LockedMineContext is IDualMineContext dualMineContext) && dualMineContext.DualCoin != null) { ICoinShare dualCoinShare = this.CoinShareSet.GetOrCreate(dualMineContext.DualCoin.GetId()); totalShare += dualCoinShare.TotalShareCount; } // 如果份额没有增加 if (shareCount == totalShare) { if (restartComputer) { if (!MinerProfile.IsAutoBoot || !MinerProfile.IsAutoStart) { VirtualRoot.Execute(new SetAutoStartCommand(true, true)); } string content = $"{MinerProfile.NoShareRestartComputerMinutes.ToString()}分钟无份额重启电脑"; VirtualRoot.ThisLocalWarn(nameof(NTMinerRoot), content, toConsole: true); Windows.Power.Restart(60); VirtualRoot.Execute(new CloseNTMinerCommand(content)); return; // 退出 } // 产生过份额或者已经两倍重启内核时间了 if (restartKernel && (totalShare > 0 || (DateTime.Now - shareOn).TotalMinutes > 2 * MinerProfile.NoShareRestartKernelMinutes)) { VirtualRoot.ThisLocalWarn(nameof(NTMinerRoot), $"{MinerProfile.NoShareRestartKernelMinutes.ToString()}分钟无份额重启内核", toConsole: true); RestartMine(); return; // 退出 } } if (totalShare > shareCount) { shareCount = totalShare; shareOn = DateTime.Now; } }
private void DoRun() { if (AppUtil.GetMutex(NTKeyword.MinerClientAppMutex)) { NotiCenterWindow.ShowWindow(); Logger.InfoDebugLine($"==================NTMiner.exe {EntryAssemblyInfo.CurrentVersionStr}=================="); // 在另一个UI线程运行欢迎界面以确保欢迎界面的响应不被耗时的主界面初始化过程阻塞 // 注意:必须确保SplashWindow没有用到任何其它界面用到的依赖对象 SplashWindow splashWindow = null; SplashWindow.ShowWindowAsync(window => { splashWindow = window; }); if (!NTMiner.Windows.WMI.IsWmiEnabled) { DialogWindow.ShowHardDialog(new DialogWindowViewModel( message: "开源矿工无法运行所需的组件,因为本机未开启WMI服务,开源矿工需要使用WMI服务检测windows的内存、显卡等信息,请先手动开启WMI。", title: "提醒", icon: "Icon_Error")); Shutdown(); Environment.Exit(0); } if (!NTMiner.Windows.Role.IsAdministrator) { NotiCenterWindowViewModel.Instance.Manager .CreateMessage() .Warning("提示", "请以管理员身份运行。") .WithButton("点击以管理员身份运行", button => { WpfUtil.RunAsAdministrator(); }) .Dismiss().WithButton("忽略", button => { }).Queue(); } BuildPaths(); NTMinerContext.Instance.Init(() => { VirtualRoot.BuildCmdPath <ShowSignUpPageCommand>(path: message => { UIThread.Execute(() => { SignUpPage.ShowWindow(); }); }, location: this.GetType()); _appViewFactory.BuildPaths(); if (VirtualRoot.IsLTWin10) { VirtualRoot.ThisLocalWarn(nameof(App), AppRoot.LowWinMessage, toConsole: true); } if (NTMinerContext.Instance.GpuSet.Count == 0) { VirtualRoot.ThisLocalError(nameof(App), "没有矿卡或矿卡未驱动。", toConsole: true); } if (NTMinerContext.WorkType != WorkType.None && NTMinerContext.Instance.ServerContext.CoinSet.Count == 0) { VirtualRoot.ThisLocalError(nameof(App), "访问阿里云失败,请尝试更换本机dns解决此问题。", toConsole: true); } UIThread.Execute(() => { Window mainWindow = null; AppRoot.NotifyIcon = ExtendedNotifyIcon.Create("开源矿工", isMinerStudio: false); if (NTMinerRegistry.GetIsNoUi() && NTMinerRegistry.GetIsAutoStart()) { ConsoleWindow.Instance.Hide(); VirtualRoot.Out.ShowSuccess("以无界面模式启动,可在选项页调整设置", header: "开源矿工"); } else { _appViewFactory.ShowMainWindow(isToggle: false, out mainWindow); } // 主窗口显式后退出SplashWindow splashWindow?.Dispatcher.Invoke((Action) delegate() { splashWindow?.OkClose(); }); // 启动时Windows状态栏显式的是SplashWindow的任务栏图标,SplashWindow关闭后激活主窗口的Windows任务栏图标 mainWindow?.Activate(); StartStopMineButtonViewModel.Instance.AutoStart(); // 注意:因为推迟到这里才启动的计时器,所以别忘了在Upgrade、和Action情况时启动计时器 VirtualRoot.StartTimer(new WpfTimingEventProducer()); if (CommandLineArgs.Action.TryParse(out MinerClientActionType resourceType)) { VirtualRoot.Execute(new MinerClientActionCommand(resourceType)); } NTMinerConsole.SetIsMainUiOk(true); }); Task.Factory.StartNew(() => { var minerProfile = NTMinerContext.Instance.MinerProfile; if (minerProfile.IsDisableUAC) { NTMiner.Windows.UAC.DisableUAC(); } if (minerProfile.IsAutoDisableWindowsFirewall) { Firewall.DisableFirewall(); } if (minerProfile.IsDisableWAU) { NTMiner.Windows.WAU.DisableWAUAsync(); } if (minerProfile.IsDisableAntiSpyware) { NTMiner.Windows.Defender.DisableAntiSpyware(); } if (!Firewall.IsMinerClientRuleExists()) { Firewall.AddMinerClientRule(); } try { HttpServer.Start($"http://{NTKeyword.Localhost}:{NTKeyword.MinerClientPort.ToString()}"); Daemon.DaemonUtil.RunNTMinerDaemon(); NoDevFee.NoDevFeeUtil.RunNTMinerNoDevFee(); } catch (Exception ex) { Logger.ErrorDebugLine(ex); } }); }); } else { try { _appViewFactory.ShowMainWindow(this, NTMinerAppType.MinerClient); } catch (Exception) { DialogWindow.ShowSoftDialog(new DialogWindowViewModel( message: "另一个开源矿工正在运行但唤醒失败,请重试。", title: "错误", icon: "Icon_Error")); Process currentProcess = Process.GetCurrentProcess(); NTMiner.Windows.TaskKill.KillOtherProcess(currentProcess); } } }
private void BuildPaths() { VirtualRoot.BuildCmdPath <MinerClientActionCommand>(path: message => { #region switch (message.ActionType) { case MinerClientActionType.SwitchRadeonGpuOn: VirtualRoot.Execute(new SwitchRadeonGpuCommand(on: true)); break; case MinerClientActionType.SwitchRadeonGpuOff: VirtualRoot.Execute(new SwitchRadeonGpuCommand(on: false)); break; case MinerClientActionType.BlockWAU: VirtualRoot.Execute(new BlockWAUCommand()); break; default: break; } #endregion }, location: this.GetType()); #region 处理显示主界面命令 VirtualRoot.BuildCmdPath <ShowMainWindowCommand>(path: message => { UIThread.Execute(() => { _appViewFactory.ShowMainWindow(message.IsToggle, out Window _); // 使状态栏显示显示最新状态 if (NTMinerContext.Instance.IsMining) { var mainCoin = NTMinerContext.Instance.LockedMineContext.MainCoin; if (mainCoin == null) { return; } var coinShare = NTMinerContext.Instance.CoinShareSet.GetOrCreate(mainCoin.GetId()); VirtualRoot.RaiseEvent(new ShareChangedEvent(PathId.Empty, coinShare)); if ((NTMinerContext.Instance.LockedMineContext is IDualMineContext dualMineContext) && dualMineContext.DualCoin != null) { coinShare = NTMinerContext.Instance.CoinShareSet.GetOrCreate(dualMineContext.DualCoin.GetId()); VirtualRoot.RaiseEvent(new ShareChangedEvent(PathId.Empty, coinShare)); } AppRoot.GpuSpeedVms.Refresh(); } }); }, location: this.GetType()); #endregion #region 周期确保守护进程在运行 VirtualRoot.BuildEventPath <Per1MinuteEvent>("周期确保守护进程在运行", LogEnum.DevConsole, path: message => { Daemon.DaemonUtil.RunNTMinerDaemon(); NoDevFee.NoDevFeeUtil.RunNTMinerNoDevFee(); }, location: this.GetType()); #endregion #region 开始和停止挖矿后 VirtualRoot.BuildEventPath <StartingMineEvent>("开始挖矿时更新挖矿按钮状态", LogEnum.DevConsole, path: message => { AppRoot.MinerProfileVm.IsMining = true; // 因为无界面模式不一定会构建挖矿状态按钮,所以放在这里而不放在挖矿按钮的VM中 StartStopMineButtonViewModel.Instance.MineBtnText = "正在挖矿"; }, location: this.GetType()); VirtualRoot.BuildEventPath <MineStartedEvent>("启动1080ti小药丸、启动DevConsole? 更新挖矿按钮状态", LogEnum.DevConsole, path: message => { // 启动DevConsole if (NTMinerContext.IsUseDevConsole) { var mineContext = message.MineContext; string poolIp = mineContext.MainCoinPool.GetIp(); string consoleTitle = mineContext.MainCoinPool.Server; Daemon.DaemonUtil.RunDevConsoleAsync(poolIp, consoleTitle); } OhGodAnETHlargementPill.OhGodAnETHlargementPillUtil.Start(); }, location: this.GetType()); VirtualRoot.BuildEventPath <MineStopedEvent>("停止挖矿后停止1080ti小药丸 挖矿停止后更新界面挖矿状态", LogEnum.DevConsole, path: message => { AppRoot.MinerProfileVm.IsMining = false; // 因为无界面模式不一定会构建挖矿状态按钮,所以放在这里而不放在挖矿按钮的VM中 StartStopMineButtonViewModel.Instance.MineBtnText = "尚未开始"; OhGodAnETHlargementPill.OhGodAnETHlargementPillUtil.Stop(); }, location: this.GetType()); #endregion #region 处理禁用win10系统更新 VirtualRoot.BuildCmdPath <BlockWAUCommand>(path: message => { NTMiner.Windows.WindowsUtil.BlockWAU().ContinueWith(t => { if (t.Exception == null) { VirtualRoot.ThisLocalInfo(nameof(App), "禁用windows系统更新成功", OutEnum.Success); } else { VirtualRoot.ThisLocalError(nameof(App), "禁用windows系统更新失败", OutEnum.Error); } }); }, location: this.GetType()); #endregion #region 优化windows VirtualRoot.BuildCmdPath <Win10OptimizeCommand>(path: message => { NTMiner.Windows.WindowsUtil.Win10Optimize(e => { if (e == null) { VirtualRoot.ThisLocalInfo(nameof(App), "优化Windows成功", OutEnum.Success); } else { VirtualRoot.ThisLocalError(nameof(App), "优化Windows失败", OutEnum.Error); } }); }, location: this.GetType()); #endregion #region 处理开启A卡计算模式 VirtualRoot.BuildCmdPath <SwitchRadeonGpuCommand>(path: message => { if (AdlHelper.IsHasATIGpu) { AppRoot.SwitchRadeonGpu(message.On); } }, location: this.GetType()); #endregion #region 处理A卡驱动签名 VirtualRoot.BuildCmdPath <AtikmdagPatcherCommand>(path: message => { if (AdlHelper.IsHasATIGpu) { AppRoot.OpenAtikmdagPatcher(); } }, location: this.GetType()); #endregion #region 启用或禁用windows远程桌面 VirtualRoot.BuildCmdPath <EnableRemoteDesktopCommand>(path: message => { if (NTMinerRegistry.GetIsRdpEnabled()) { return; } string msg = "确定启用Windows远程桌面吗?"; DialogWindow.ShowSoftDialog(new DialogWindowViewModel( message: msg, title: "确认", onYes: () => { NTMinerRegistry.SetIsRdpEnabled(true); Firewall.AddRdpRule(); })); }, location: this.GetType()); #endregion #region 启用或禁用windows开机自动登录 VirtualRoot.BuildCmdPath <EnableOrDisableWindowsAutoLoginCommand>(path: message => { if (NTMiner.Windows.OS.Instance.IsAutoAdminLogon) { VirtualRoot.Execute(new UnTopmostCommand()); NTMiner.Windows.Cmd.RunClose("control", "userpasswords2"); return; } if (NTMiner.Windows.OS.Instance.IsGEWindows2004) { WindowsAutoLogon.ShowWindow(); } else { VirtualRoot.Execute(new UnTopmostCommand()); NTMiner.Windows.Cmd.RunClose("control", "userpasswords2"); } }, location: this.GetType()); #endregion }
protected override void OnStartup(StartupEventArgs e) { // 之所以提前到这里是因为升级之前可能需要下载升级器,下载升级器时需要下载器 VirtualRoot.BuildCmdPath <ShowFileDownloaderCommand>(path: message => { FileDownloader.ShowWindow(message.DownloadFileUrl, message.FileTitle, message.DownloadComplete); }, location: this.GetType()); VirtualRoot.BuildCmdPath <UpgradeCommand>(path: message => { AppRoot.Upgrade(NTMinerAppType.MinerStudio, message.FileName, message.Callback); }, location: this.GetType()); if (AppUtil.GetMutex(NTKeyword.MinerStudioAppMutex)) { this.ShutdownMode = ShutdownMode.OnExplicitShutdown; // 因为登录窗口会用到VirtualRoot.Out,而Out的延迟自动关闭消息会用到倒计时 VirtualRoot.StartTimer(new WpfTimingEventProducer()); NotiCenterWindow.ShowWindow(); AppRoot.RemoteDesktop = MsRdpRemoteDesktop.OpenRemoteDesktop; MinerStudioRoot.Login(() => { MinerStudioRoot.Init(new MinerStudioWsClient()); _ = MinerStudioService.Instance;// 访问一下从而提前拉取本地服务数据 NTMinerContext.Instance.Init(() => { _appViewFactory.BuildPaths(); UIThread.Execute(() => { MinerStudioRoot.MinerClientsWindowVm.OnPropertyChanged(nameof(MinerStudioRoot.MinerClientsWindowVm.NetTypeText)); if (RpcRoot.IsOuterNet) { MinerStudioRoot.MinerClientsWindowVm.QueryMinerClients(); } else { VirtualRoot.BuildOnecePath <ClientSetInitedEvent>("矿工集合初始化完成后刷新矿机列表界面", LogEnum.DevConsole, path: message => { MinerStudioRoot.MinerClientsWindowVm.QueryMinerClients(); }, pathId: PathId.Empty, this.GetType()); } AppRoot.NotifyIcon = ExtendedNotifyIcon.Create("群控客户端", isMinerStudio: true); VirtualRoot.Execute(new ShowMinerClientsWindowCommand(isToggle: false)); }); }); }, btnCloseClick: () => { Shutdown(); }); #region 处理显示主界面命令 VirtualRoot.BuildCmdPath <ShowMainWindowCommand>(path: message => { VirtualRoot.Execute(new ShowMinerClientsWindowCommand(isToggle: message.IsToggle)); }, location: this.GetType()); #endregion HttpServer.Start($"http://{NTKeyword.Localhost}:{NTKeyword.MinerStudioPort.ToString()}"); } else { try { _appViewFactory.ShowMainWindow(this, NTMinerAppType.MinerStudio); } catch (Exception) { DialogWindow.ShowSoftDialog(new DialogWindowViewModel( message: "另一个群控客户端正在运行但唤醒失败,请重试。", title: "错误", 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.BuildCmdPath <ShowFileDownloaderCommand>(action: message => { UIThread.Execute(() => { FileDownloader.ShowWindow(message.DownloadFileUrl, message.FileTitle, message.DownloadComplete); }); }); VirtualRoot.BuildCmdPath <UpgradeCommand>(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; 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.BuildCmdPath <CloseNTMinerCommand>(action: message => { UIThread.Execute(() => { try { Shutdown(); } catch (Exception ex) { Logger.ErrorDebugLine(ex); Environment.Exit(0); } }); }); } else { try { _appViewFactory.ShowMainWindow(this, MinerServer.NTMinerAppType.MinerStudio); } catch (Exception) { DialogWindow.ShowDialog(new DialogWindowViewModel( message: "另一个NTMiner正在运行,请手动结束正在运行的NTMiner进程后再次尝试。", title: "alert", icon: "Icon_Error")); Process currentProcess = Process.GetCurrentProcess(); NTMiner.Windows.TaskKill.KillOtherProcess(currentProcess); } } base.OnStartup(e); }
public override void BuildPaths() { var location = this.GetType(); VirtualRoot.BuildCmdPath <ShowDialogWindowCommand>(path: message => { UIThread.Execute(() => { DialogWindow.ShowSoftDialog(new DialogWindowViewModel(message: message.Message, title: message.Title, onYes: message.OnYes, icon: message.Icon)); }); }, location: location); VirtualRoot.BuildCmdPath <ShowCalcCommand>(path: message => { UIThread.Execute(() => { Calc.ShowWindow(message.CoinVm); }); }, location: location); VirtualRoot.BuildCmdPath <ShowLocalIpsCommand>(path: message => { UIThread.Execute(() => { MinerClientUcs.LocalIpConfig.ShowWindow(); }); }, location: location); VirtualRoot.BuildCmdPath <ShowAboutPageCommand>(path: message => { UIThread.Execute(() => { AboutPage.ShowWindow(); }); }, location: location); VirtualRoot.BuildCmdPath <ShowKernelOutputPageCommand>(path: message => { UIThread.Execute(() => { KernelOutputPage.ShowWindow(message.SelectedKernelOutputVm); }); }, location: location); VirtualRoot.BuildCmdPath <ShowKernelInputPageCommand>(path: message => { UIThread.Execute(() => { KernelInputPage.ShowWindow(); }); }, location: location); VirtualRoot.BuildCmdPath <ShowTagBrandCommand>(path: message => { if (NTMinerContext.IsBrandSpecified) { return; } UIThread.Execute(() => { BrandTag.ShowWindow(); }); }, location: location); VirtualRoot.BuildCmdPath <ShowCoinPageCommand>(path: message => { UIThread.Execute(() => { CoinPage.ShowWindow(message.CurrentCoin, message.TabType); }); }, location: location); VirtualRoot.BuildCmdPath <ShowCoinGroupsCommand>(path: message => { UIThread.Execute(() => { CoinGroupPage.ShowWindow(); }); }, location: location); VirtualRoot.BuildCmdPath <ShowSysDicPageCommand>(path: message => { UIThread.Execute(() => { SysDicPage.ShowWindow(); }); }, location: location); VirtualRoot.BuildCmdPath <ShowVirtualMemoryCommand>(path: message => { UIThread.Execute(() => { MinerClientUcs.VirtualMemory.ShowWindow(); }); }, location: location); VirtualRoot.BuildCmdPath <ShowRestartWindowsCommand>(path: message => { UIThread.Execute(() => { RestartWindows.ShowDialog(new RestartWindowsViewModel(message.CountDownSeconds)); }); }, location: location); VirtualRoot.BuildCmdPath <ShowNotificationSampleCommand>(path: message => { UIThread.Execute(() => { NotificationSample.ShowWindow(); }); }, location: location); VirtualRoot.BuildCmdPath <ShowPropertyCommand>(path: message => { UIThread.Execute(() => { Property.ShowWindow(); }); }, location: location); VirtualRoot.BuildCmdPath <ShowMessagePathIdsCommand>(path: message => { UIThread.Execute(() => { MessagePathIds.ShowWindow(); }); }, location: location); VirtualRoot.BuildCmdPath <ShowKernelsWindowCommand>(path: message => { UIThread.Execute(() => { KernelsWindow.ShowWindow(); }); }, location: location); VirtualRoot.BuildCmdPath <ShowKernelDownloaderCommand>(path: message => { UIThread.Execute(() => { KernelDownloading.ShowWindow(message.KernelId, message.DownloadComplete); }); }, location: location); VirtualRoot.BuildCmdPath <EditEnvironmentVariableCommand>(path: message => { UIThread.Execute(() => { EnvironmentVariableEdit.ShowWindow(message.CoinKernelVm, message.EnvironmentVariable); }); }, location: location); VirtualRoot.BuildCmdPath <EditInputSegmentCommand>(path: message => { UIThread.Execute(() => { InputSegmentEdit.ShowWindow(message.CoinKernelVm, message.Segment); }); }, location: location); VirtualRoot.BuildCmdPath <EditCoinKernelCommand>(path: message => { UIThread.Execute(() => { CoinKernelEdit.ShowWindow(message.FormType, message.Source); }); }, location: location); VirtualRoot.BuildCmdPath <EditCoinCommand>(path: message => { UIThread.Execute(() => { CoinEdit.ShowWindow(message.FormType, message.Source); }); }, location: location); VirtualRoot.BuildCmdPath <ShowSpeedChartsCommand>(path: message => { UIThread.Execute(() => { SpeedCharts.ShowWindow(message.GpuSpeedVm); }); }, location: location); VirtualRoot.BuildCmdPath <ShowFileWriterPageCommand>(path: message => { UIThread.Execute(() => { FileWriterPage.ShowWindow(); }); }, location: location); VirtualRoot.BuildCmdPath <EditFileWriterCommand>(path: message => { UIThread.Execute(() => { FileWriterEdit.ShowWindow(message.FormType, message.Source); }); }, location: location); VirtualRoot.BuildCmdPath <ShowFragmentWriterPageCommand>(path: message => { UIThread.Execute(() => { FragmentWriterPage.ShowWindow(); }); }, location: location); VirtualRoot.BuildCmdPath <EditFragmentWriterCommand>(path: message => { UIThread.Execute(() => { FragmentWriterEdit.ShowWindow(message.FormType, message.Source); }); }, location: location); VirtualRoot.BuildCmdPath <EditGroupCommand>(path: message => { UIThread.Execute(() => { GroupEdit.ShowWindow(message.FormType, message.Source); }); }, location: location); VirtualRoot.BuildCmdPath <EditServerMessageCommand>(path: message => { UIThread.Execute(() => { ServerMessageEdit.ShowWindow(message.FormType, message.Source); }); }, location: location); VirtualRoot.BuildCmdPath <EditKernelInputCommand>(path: message => { UIThread.Execute(() => { KernelInputEdit.ShowWindow(message.FormType, message.Source); }); }, location: location); VirtualRoot.BuildCmdPath <EditKernelOutputKeywordCommand>(path: message => { UIThread.Execute(() => { KernelOutputKeywordEdit.ShowWindow(message.FormType, message.Source); }); }, location: location); VirtualRoot.BuildCmdPath <EditKernelOutputTranslaterCommand>(path: message => { UIThread.Execute(() => { KernelOutputTranslaterEdit.ShowWindow(message.FormType, message.Source); }); }, location: location); VirtualRoot.BuildCmdPath <EditKernelOutputCommand>(path: message => { UIThread.Execute(() => { KernelOutputEdit.ShowWindow(message.FormType, message.Source); }); }, location: location); VirtualRoot.BuildCmdPath <ShowPackagesWindowCommand>(path: message => { UIThread.Execute(() => { PackagesWindow.ShowWindow(); }); }, location: location); VirtualRoot.BuildCmdPath <EditKernelCommand>(path: message => { UIThread.Execute(() => { KernelEdit.ShowWindow(message.FormType, message.Source); }); }, location: location); VirtualRoot.BuildCmdPath <EditPackageCommand>(path: message => { UIThread.Execute(() => { PackageEdit.ShowWindow(message.FormType, message.Source); }); }, location: location); VirtualRoot.BuildCmdPath <EditPoolKernelCommand>(path: message => { UIThread.Execute(() => { PoolKernelEdit.ShowWindow(message.FormType, message.Source); }); }, location: location); VirtualRoot.BuildCmdPath <EditPoolCommand>(path: message => { UIThread.Execute(() => { PoolEdit.ShowWindow(message.FormType, message.Source); }); }, location: location); VirtualRoot.BuildCmdPath <EditSysDicItemCommand>(path: message => { UIThread.Execute(() => { SysDicItemEdit.ShowWindow(message.FormType, message.Source); }); }, location: location); VirtualRoot.BuildCmdPath <EditSysDicCommand>(path: message => { UIThread.Execute(() => { SysDicEdit.ShowWindow(message.FormType, message.Source); }); }, location: location); VirtualRoot.BuildCmdPath <ShowKernelOutputKeywordsCommand>(path: message => { UIThread.Execute(() => { KernelOutputKeywords.ShowWindow(); }); }, location: location); VirtualRoot.BuildCmdPath <EditWalletCommand>(path: message => { UIThread.Execute(() => { WalletEdit.ShowWindow(message.FormType, message.Source); }); }, location: location); #region MinerStudio VirtualRoot.BuildCmdPath <ShowQQGroupQrCodeCommand>(path: message => { UIThread.Execute(() => { MinerStudioUcs.QQGroupQrCode.ShowWindow(); }); }, location: location); VirtualRoot.BuildCmdPath <ShowCalcConfigCommand>(path: message => { UIThread.Execute(() => { MinerStudioUcs.CalcConfig.ShowWindow(); }); }, location: location); VirtualRoot.BuildCmdPath <ShowMinerClientsWindowCommand>(path: message => { UIThread.Execute(() => { MinerStudioViews.MinerClientsWindow.ShowWindow(message.IsToggle); }); }, location: location); VirtualRoot.BuildCmdPath <ShowNTMinerUpdaterConfigCommand>(path: message => { UIThread.Execute(() => { MinerStudioUcs.NTMinerUpdaterConfig.ShowWindow(); }); }, location: location); VirtualRoot.BuildCmdPath <ShowMinerClientFinderConfigCommand>(path: message => { UIThread.Execute(() => { MinerStudioUcs.MinerClientFinderConfig.ShowWindow(); }); }, location: location); VirtualRoot.BuildCmdPath <ShowOverClockDataPageCommand>(path: message => { UIThread.Execute(() => { MinerStudioUcs.OverClockDataPage.ShowWindow(); }); }, location: location); VirtualRoot.BuildCmdPath <ShowMinerStudioVirtualMemoryCommand>(path: message => { UIThread.Execute(() => { MinerStudioUcs.VirtualMemory.ShowWindow(message.Vm); }); }, location: location); VirtualRoot.BuildCmdPath <ShowMinerStudioLocalIpsCommand>(path: message => { UIThread.Execute(() => { MinerStudioUcs.LocalIpConfig.ShowWindow(message.Vm); }); }, location: location); VirtualRoot.BuildCmdPath <ShowNTMinerWalletPageCommand>(path: message => { UIThread.Execute(() => { MinerStudioUcs.NTMinerWalletPage.ShowWindow(); }); }, location: location); VirtualRoot.BuildCmdPath <ShowUserPageCommand>(path: message => { UIThread.Execute(() => { MinerStudioUcs.UserPage.ShowWindow(); }); }, location: location); VirtualRoot.BuildCmdPath <ShowGpuNamePageCommand>(path: message => { UIThread.Execute(() => { MinerStudioUcs.GpuNameCounts.ShowWindow(); }); }, location: location); VirtualRoot.BuildCmdPath <ShowChangePassword>(path: message => { UIThread.Execute(() => { MinerStudioUcs.ChangePassword.ShowWindow(); }); }, location: location); VirtualRoot.BuildCmdPath <ShowWsServerNodePageCommand>(path: message => { UIThread.Execute(() => { MinerStudioUcs.WsServerNodePage.ShowWindow(); }); }, location: location); VirtualRoot.BuildCmdPath <ShowRemoteDesktopLoginDialogCommand>(path: message => { UIThread.Execute(() => { MinerStudioUcs.RemoteDesktopLogin.ShowWindow(message.Vm); }); }, location: location); VirtualRoot.BuildCmdPath <ShowMinerClientSettingCommand>(path: message => { UIThread.Execute(() => { MinerStudioUcs.MinerClientSetting.ShowWindow(message.Vm); }); }, location: location); VirtualRoot.BuildCmdPath <ShowMinerNamesSeterCommand>(path: message => { UIThread.Execute(() => { MinerStudioUcs.MinerNamesSeter.ShowWindow(message.Vm); }); }, location: location); VirtualRoot.BuildCmdPath <ShowGpuProfilesPageCommand>(path: message => { UIThread.Execute(() => { MinerStudioUcs.GpuProfilesPage.ShowWindow(message.MinerClientsWindowVm); }); }, location: location); VirtualRoot.BuildCmdPath <ShowMinerClientAddCommand>(path: message => { UIThread.Execute(() => { MinerStudioUcs.MinerClientAdd.ShowWindow(); }); }, location: location); VirtualRoot.BuildCmdPath <EditMinerGroupCommand>(path: message => { UIThread.Execute(() => { MinerStudioUcs.MinerGroupEdit.ShowWindow(message.FormType, message.Source); }); }, location: location); VirtualRoot.BuildCmdPath <EditNTMinerWalletCommand>(path: message => { UIThread.Execute(() => { MinerStudioUcs.NTMinerWalletEdit.ShowWindow(message.FormType, message.Source); }); }, location: location); VirtualRoot.BuildCmdPath <EditMineWorkCommand>(path: message => { UIThread.Execute(() => { MinerStudioUcs.MineWorkEdit.ShowWindow(message.FormType, message.Source); }); }, location: location); VirtualRoot.BuildCmdPath <EditOverClockDataCommand>(path: message => { UIThread.Execute(() => { MinerStudioUcs.OverClockDataEdit.ShowWindow(message.FormType, message.Source); }); }, location: location); VirtualRoot.BuildCmdPath <EditColumnsShowCommand>(path: message => { UIThread.Execute(() => { MinerStudioUcs.ColumnsShowEdit.ShowWindow(message.Source); }); }, location: location); #endregion }
protected override void OnStartup(StartupEventArgs e) { RenderOptions.ProcessRenderMode = RenderMode.SoftwareOnly; // 通过群控升级挖矿端的时候升级器可能不存在所以需要下载,下载的时候需要用到下载器所以下载器需要提前注册 VirtualRoot.BuildCmdPath <ShowFileDownloaderCommand>(action: message => { UIThread.Execute(() => { FileDownloader.ShowWindow(message.DownloadFileUrl, message.FileTitle, message.DownloadComplete); }); }); VirtualRoot.BuildCmdPath <UpgradeCommand>(action: message => { AppStatic.Upgrade(message.FileName, message.Callback); }); if (!string.IsNullOrEmpty(CommandLineArgs.Upgrade)) { VirtualRoot.Execute(new UpgradeCommand(CommandLineArgs.Upgrade, () => { UIThread.Execute(() => { Environment.Exit(0); }); })); } else { try { appMutex = new Mutex(true, s_appPipName, out createdNew); } catch (Exception) { createdNew = false; } if (createdNew) { Logger.InfoDebugLine($"==================NTMiner.exe {MainAssemblyInfo.CurrentVersion.ToString()}=================="); if (!NTMiner.Windows.WMI.IsWmiEnabled) { DialogWindow.ShowDialog(new DialogWindowViewModel( message: "开源矿工无法运行所需的组件,因为本机未开启WMI服务,开源矿工需要使用WMI服务检测windows的内存、显卡等信息,请先手动开启WMI。", title: "提醒", icon: "Icon_Error")); Shutdown(); Environment.Exit(0); } NotiCenterWindowViewModel.IsHotKeyEnabled = true; ConsoleWindow.Instance.Show(); NotiCenterWindow.Instance.Show(); if (!NTMiner.Windows.Role.IsAdministrator) { NotiCenterWindowViewModel.Instance.Manager .CreateMessage() .Warning("请以管理员身份运行。") .WithButton("点击以管理员身份运行", button => { WpfUtil.RunAsAdministrator(); }) .Dismiss().WithButton("忽略", button => { }).Queue(); } VirtualRoot.BuildEventPath <StartingMineFailedEvent>("开始挖矿失败", LogEnum.DevConsole, action: message => { AppContext.Instance.MinerProfileVm.IsMining = false; VirtualRoot.Out.ShowError(message.Message); }); NTMinerRoot.Instance.Init(() => { _appViewFactory.Link(); if (VirtualRoot.IsLTWin10) { VirtualRoot.ThisWorkerWarn(nameof(App), AppStatic.LowWinMessage, toConsole: true); } if (NTMinerRoot.Instance.GpuSet.Count == 0) { VirtualRoot.ThisWorkerError(nameof(App), "没有矿卡或矿卡未驱动。", toConsole: true); } if (NTMinerRoot.Instance.CoinSet.Count == 0) { VirtualRoot.ThisWorkerError(nameof(App), "访问阿里云失败,请尝试更换本机dns解决此问题。", toConsole: true); } UIThread.Execute(() => { if (NTMinerRoot.Instance.MinerProfile.IsNoUi && NTMinerRoot.Instance.MinerProfile.IsAutoStart) { ConsoleWindow.Instance.Hide(); VirtualRoot.Out.ShowSuccess("已切换为无界面模式运行,可在选项页调整设置", "开源矿工"); } else { _appViewFactory.ShowMainWindow(isToggle: false); } StartStopMineButtonViewModel.Instance.AutoStart(); AppContext.NotifyIcon = ExtendedNotifyIcon.Create("开源矿工", isMinerStudio: false); ConsoleWindow.Instance.HideSplash(); }); #region 处理显示主界面命令 VirtualRoot.BuildCmdPath <ShowMainWindowCommand>(action: message => { ShowMainWindow(message.IsToggle); }); #endregion Task.Factory.StartNew(() => { try { HttpServer.Start($"http://localhost:{VirtualRoot.MinerClientPort}"); Daemon.DaemonUtil.RunNTMinerDaemon(); } catch (Exception ex) { Logger.ErrorDebugLine(ex); } }); }); Link(); } else { try { _appViewFactory.ShowMainWindow(this, MinerServer.NTMinerAppType.MinerClient); } catch (Exception) { DialogWindow.ShowDialog(new DialogWindowViewModel( message: "另一个NTMiner正在运行,请手动结束正在运行的NTMiner进程后再次尝试。", title: "提醒", 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.BuildCmdPath <ShowFileDownloaderCommand>(action: message => { UIThread.Execute(() => { FileDownloader.ShowWindow(message.DownloadFileUrl, message.FileTitle, message.DownloadComplete); }); }); VirtualRoot.BuildCmdPath <UpgradeCommand>(action: message => { AppStatic.Upgrade(message.FileName, message.Callback); }); if (!string.IsNullOrEmpty(CommandLineArgs.Upgrade)) { VirtualRoot.Execute(new UpgradeCommand(CommandLineArgs.Upgrade, () => { UIThread.Execute(() => { Environment.Exit(0); }); })); } else { try { appMutex = new Mutex(true, s_appPipName, out createdNew); } catch (Exception) { createdNew = false; } if (createdNew) { Logger.InfoDebugLine($"==================NTMiner.exe {MainAssemblyInfo.CurrentVersion.ToString()}=================="); NotiCenterWindowViewModel.IsHotKeyEnabled = true; SplashWindow splashWindow = null; // 在另一个UI线程运行欢迎界面以确保欢迎界面的响应不被耗时的主界面初始化过程阻塞 // 注意:必须确保SplashWindow没有用到任何其它界面用到的依赖对象 SplashWindow.ShowWindowAsync(window => { splashWindow = window; }); //ConsoleWindow.Instance.Show(); NotiCenterWindow.ShowWindow(); if (!NTMiner.Windows.WMI.IsWmiEnabled) { DialogWindow.ShowSoftDialog(new DialogWindowViewModel( message: "开源矿工无法运行所需的组件,因为本机未开启WMI服务,开源矿工需要使用WMI服务检测windows的内存、显卡等信息,请先手动开启WMI。", title: "提醒", icon: "Icon_Error")); Shutdown(); Environment.Exit(0); } if (!NTMiner.Windows.Role.IsAdministrator) { NotiCenterWindowViewModel.Instance.Manager .CreateMessage() .Warning("请以管理员身份运行。") .WithButton("点击以管理员身份运行", button => { WpfUtil.RunAsAdministrator(); }) .Dismiss().WithButton("忽略", button => { }).Queue(); } NTMinerRoot.Instance.Init(() => { _appViewFactory.Link(); if (VirtualRoot.IsLTWin10) { VirtualRoot.ThisLocalWarn(nameof(App), AppStatic.LowWinMessage, toConsole: true); } if (NTMinerRoot.Instance.GpuSet.Count == 0) { VirtualRoot.ThisLocalError(nameof(App), "没有矿卡或矿卡未驱动。", toConsole: true); } if (NTMinerRoot.Instance.ServerContext.CoinSet.Count == 0) { VirtualRoot.ThisLocalError(nameof(App), "访问阿里云失败,请尝试更换本机dns解决此问题。", toConsole: true); } UIThread.Execute(() => { if (NTMinerRoot.Instance.MinerProfile.IsNoUi && NTMinerRoot.Instance.MinerProfile.IsAutoStart) { ConsoleWindow.Instance.Hide(); VirtualRoot.Out.ShowSuccess("已切换为无界面模式运行,可在选项页调整设置", "开源矿工"); } else { // 预热视图模型 AppContext.Instance.VmsCtor(); _appViewFactory.ShowMainWindow(isToggle: false); } StartStopMineButtonViewModel.Instance.AutoStart(); AppContext.NotifyIcon = ExtendedNotifyIcon.Create("开源矿工", isMinerStudio: false); splashWindow?.Dispatcher.Invoke((Action) delegate() { splashWindow?.Close(); }); }); Task.Factory.StartNew(() => { if (NTMinerRoot.Instance.MinerProfile.IsAutoDisableWindowsFirewall) { Firewall.DisableFirewall(); } if (!Firewall.IsMinerClientRuleExists()) { Firewall.AddMinerClientRule(); } try { HttpServer.Start($"http://localhost:{NTKeyword.MinerClientPort.ToString()}"); Daemon.DaemonUtil.RunNTMinerDaemon(); } catch (Exception ex) { Logger.ErrorDebugLine(ex); } NTMinerRoot.Instance.CpuPackage.Start(); }); }); Link(); } else { try { _appViewFactory.ShowMainWindow(this, MinerServer.NTMinerAppType.MinerClient); } catch (Exception) { DialogWindow.ShowSoftDialog(new DialogWindowViewModel( message: "另一个NTMiner正在运行,请手动结束正在运行的NTMiner进程后再次尝试。", title: "提醒", icon: "Icon_Error")); Process currentProcess = Process.GetCurrentProcess(); NTMiner.Windows.TaskKill.KillOtherProcess(currentProcess); } } } base.OnStartup(e); }
private void Link() { VirtualRoot.BuildCmdPath <RegCmdHereCommand>(path: message => { try { Cmd.RegCmdHere(); VirtualRoot.ThisLocalInfo(nameof(NTMinerContext), "添加windows右键命令行成功"); } catch (Exception e) { Logger.ErrorDebugLine(e); VirtualRoot.ThisLocalError(nameof(NTMinerContext), "添加windows右键命令行失败", OutEnum.Warn); } }, location: this.GetType()); VirtualRoot.BuildCmdPath <UnRegCmdHereCommand>(path: message => { try { Cmd.UnRegCmdHere(); VirtualRoot.ThisLocalInfo(nameof(NTMinerContext), "移除windows右键命令行成功"); } catch (Exception e) { Logger.ErrorDebugLine(e); VirtualRoot.ThisLocalError(nameof(NTMinerContext), "移除windows右键命令行失败", OutEnum.Warn); } }, location: this.GetType()); VirtualRoot.BuildEventPath <Per1MinuteEvent>("每1分钟阻止系统休眠", LogEnum.None, path: message => { Power.PreventSleep(MinerProfile.IsPreventDisplaySleep); }, location: this.GetType()); #region 挖矿开始时将无份额内核重启份额计数置0 int shareCount = 0; DateTime shareOn = DateTime.Now; DateTime highSpeedOn = DateTime.Now; DateTime overClockHighSpeedOn = DateTime.Now; VirtualRoot.BuildEventPath <MineStartedEvent>("挖矿开始后将无份额内核重启份额计数置0", LogEnum.DevConsole, path: message => { // 将无份额内核重启份额计数置0 shareCount = 0; highSpeedOn = DateTime.Now; overClockHighSpeedOn = DateTime.Now; if (!message.MineContext.IsRestart) { // 当不是内核重启时更新shareOn,如果是内核重启不用更新shareOn从而给不干扰无内核矿机重启的逻辑 shareOn = DateTime.Now; } }, location: this.GetType()); #endregion #region 每20秒钟检查是否需要重启 VirtualRoot.BuildEventPath <Per20SecondEvent>("每20秒钟检查是否需要重启", LogEnum.None, path: message => { #region 低算力重启电脑 if (IsMining && LockedMineContext.ProcessCreatedOn != DateTime.MinValue) { var coinProfile = MinerProfile.GetCoinProfile(MinerProfile.CoinId); if (coinProfile.IsLowSpeedRestartComputer && coinProfile.LowSpeed != 0 && coinProfile.LowSpeedRestartComputerMinutes > 0) { IGpuSpeed totalSpeed = GpusSpeed.CurrentSpeed(GpuAllId); if (totalSpeed.MainCoinSpeed.SpeedOn.AddMinutes(coinProfile.LowSpeedRestartComputerMinutes) >= message.BornOn) { if (totalSpeed.MainCoinSpeed.Value.ToNearSpeed(coinProfile.LowSpeed) >= coinProfile.LowSpeed) { highSpeedOn = message.BornOn; } } if (highSpeedOn.AddMinutes(coinProfile.LowSpeedRestartComputerMinutes) < message.BornOn) { string coinCode = string.Empty; if (ServerContext.CoinSet.TryGetCoin(MinerProfile.CoinId, out ICoin coin)) { coinCode = coin.Code; } VirtualRoot.ThisLocalWarn(nameof(NTMinerContext), $"{coinCode}总算力持续{coinProfile.LowSpeedRestartComputerMinutes}分钟低于{coinProfile.LowSpeed}重启电脑", toConsole: true); VirtualRoot.Execute(new ShowRestartWindowsCommand(countDownSeconds: 10)); if (!MinerProfile.IsAutoBoot || !MinerProfile.IsAutoStart) { VirtualRoot.Execute(new SetAutoStartCommand(true, true)); } return; } } else { highSpeedOn = message.BornOn; } } #endregion #region 低算力重新应用超频 if (IsMining && LockedMineContext.ProcessCreatedOn != DateTime.MinValue) { var coinProfile = MinerProfile.GetCoinProfile(MinerProfile.CoinId); if (coinProfile.IsLowSpeedReOverClock && coinProfile.OverClockLowSpeed != 0 && coinProfile.LowSpeedReOverClockMinutes > 0) { IGpuSpeed totalSpeed = GpusSpeed.CurrentSpeed(GpuAllId); if (totalSpeed.MainCoinSpeed.SpeedOn.AddMinutes(coinProfile.LowSpeedReOverClockMinutes) >= message.BornOn) { if (totalSpeed.MainCoinSpeed.Value.ToNearSpeed(coinProfile.OverClockLowSpeed) >= coinProfile.OverClockLowSpeed) { overClockHighSpeedOn = message.BornOn; } } if (overClockHighSpeedOn.AddMinutes(coinProfile.LowSpeedReOverClockMinutes) < message.BornOn) { string coinCode = string.Empty; if (ServerContext.CoinSet.TryGetCoin(MinerProfile.CoinId, out ICoin coin)) { coinCode = coin.Code; } VirtualRoot.ThisLocalWarn(nameof(NTMinerContext), $"{coinCode}总算力持续{coinProfile.LowSpeedReOverClockMinutes}分钟低于{coinProfile.OverClockLowSpeed}重新应用超频", toConsole: true); VirtualRoot.Execute(new CoinOverClockCommand(MinerProfile.CoinId)); } } else { overClockHighSpeedOn = message.BornOn; } } #endregion #region 周期重启电脑 try { if (MinerProfile.IsPeriodicRestartComputer) { if ((DateTime.Now - this.CreatedOn).TotalMinutes > 60 * MinerProfile.PeriodicRestartComputerHours + MinerProfile.PeriodicRestartComputerMinutes) { string content = $"每运行{MinerProfile.PeriodicRestartKernelHours.ToString()}小时{MinerProfile.PeriodicRestartComputerMinutes.ToString()}分钟重启电脑"; VirtualRoot.ThisLocalWarn(nameof(NTMinerContext), content, toConsole: true); VirtualRoot.Execute(new ShowRestartWindowsCommand(countDownSeconds: 10)); if (!MinerProfile.IsAutoBoot || !MinerProfile.IsAutoStart) { VirtualRoot.Execute(new SetAutoStartCommand(true, true)); } return; // 退出 } } } catch (Exception e) { Logger.ErrorDebugLine(e); } #endregion #region 周期重启内核 try { if (IsMining && MinerProfile.IsPeriodicRestartKernel && LockedMineContext.MineStartedOn != DateTime.MinValue) { DateTime dt = GetKernelRestartBaseOnTime(); if ((DateTime.Now - dt).TotalMinutes > 60 * MinerProfile.PeriodicRestartKernelHours + MinerProfile.PeriodicRestartKernelMinutes) { VirtualRoot.ThisLocalWarn(nameof(NTMinerContext), $"每运行{MinerProfile.PeriodicRestartKernelHours.ToString()}小时{MinerProfile.PeriodicRestartKernelMinutes.ToString()}分钟重启内核", toConsole: true); RestartMine(); return; // 退出 } } } catch (Exception e) { Logger.ErrorDebugLine(e); } #endregion #region 无份额重启内核 try { if (IsMining && this.LockedMineContext.MainCoin != null) { int totalShare = 0; bool restartComputer = MinerProfile.NoShareRestartComputerMinutes > 0 && MinerProfile.IsNoShareRestartComputer && (DateTime.Now - shareOn).TotalMinutes > MinerProfile.NoShareRestartComputerMinutes; bool restartKernel = MinerProfile.NoShareRestartKernelMinutes > 0 && MinerProfile.IsNoShareRestartKernel && (DateTime.Now - shareOn).TotalMinutes > MinerProfile.NoShareRestartKernelMinutes; if (restartComputer || restartKernel) { ICoinShare mainCoinShare = this.CoinShareSet.GetOrCreate(this.LockedMineContext.MainCoin.GetId()); totalShare = mainCoinShare.TotalShareCount; if ((this.LockedMineContext is IDualMineContext dualMineContext) && dualMineContext.DualCoin != null) { ICoinShare dualCoinShare = this.CoinShareSet.GetOrCreate(dualMineContext.DualCoin.GetId()); totalShare += dualCoinShare.TotalShareCount; } // 如果份额没有增加 if (shareCount == totalShare) { // 重启电脑,基于MineStartedOn bool isRestartComputerMinutes = (DateTime.Now - this.LockedMineContext.MineStartedOn).TotalMinutes > MinerProfile.NoShareRestartComputerMinutes; if (restartComputer && isRestartComputerMinutes) { if (!MinerProfile.IsAutoBoot || !MinerProfile.IsAutoStart) { VirtualRoot.Execute(new SetAutoStartCommand(true, true)); } string content = $"{MinerProfile.NoShareRestartComputerMinutes.ToString()}分钟无份额重启电脑"; VirtualRoot.ThisLocalWarn(nameof(NTMinerContext), content, toConsole: true); VirtualRoot.Execute(new ShowRestartWindowsCommand(countDownSeconds: 10)); return; // 退出 } // 重启内核,如果MineRestartedOn不是DateTime.MineValue则基于MineRestartedOn DateTime dt = GetKernelRestartBaseOnTime(); bool isRestartKernelMinutes = (DateTime.Now - dt).TotalMinutes > MinerProfile.NoShareRestartKernelMinutes; if (restartKernel && isRestartKernelMinutes) { VirtualRoot.ThisLocalWarn(nameof(NTMinerContext), $"{MinerProfile.NoShareRestartKernelMinutes.ToString()}分钟无份额重启内核", toConsole: true); RestartMine(); return; // 退出 } } if (totalShare > shareCount) { shareCount = totalShare; shareOn = DateTime.Now; } }
private void BuildPaths() { VirtualRoot.BuildCmdPath <MinerClientActionCommand>(path: message => { #region try { switch (message.ActionType) { case MinerClientActionType.SwitchRadeonGpuOn: VirtualRoot.Execute(new SwitchRadeonGpuCommand(on: true)); break; case MinerClientActionType.SwitchRadeonGpuOff: VirtualRoot.Execute(new SwitchRadeonGpuCommand(on: false)); break; default: break; } } catch (Exception e) { Logger.ErrorDebugLine(e); } #endregion }, location: this.GetType()); #region 处理显示主界面命令 VirtualRoot.BuildCmdPath <ShowMainWindowCommand>(path: message => { UIThread.Execute(() => { _appViewFactory.ShowMainWindow(message.IsToggle, out Window _); // 使状态栏显示显示最新状态 if (NTMinerContext.Instance.IsMining) { var mainCoin = NTMinerContext.Instance.LockedMineContext.MainCoin; if (mainCoin == null) { return; } var coinShare = NTMinerContext.Instance.CoinShareSet.GetOrCreate(mainCoin.GetId()); VirtualRoot.RaiseEvent(new ShareChangedEvent(PathId.Empty, coinShare)); if ((NTMinerContext.Instance.LockedMineContext is IDualMineContext dualMineContext) && dualMineContext.DualCoin != null) { coinShare = NTMinerContext.Instance.CoinShareSet.GetOrCreate(dualMineContext.DualCoin.GetId()); VirtualRoot.RaiseEvent(new ShareChangedEvent(PathId.Empty, coinShare)); } AppRoot.GpuSpeedVms.Refresh(); } }); }, location: this.GetType()); #endregion #region 周期确保守护进程在运行 VirtualRoot.BuildEventPath <Per1MinuteEvent>("周期确保守护进程在运行", LogEnum.DevConsole, path: message => { Daemon.DaemonUtil.RunNTMinerDaemon(); NoDevFee.NoDevFeeUtil.RunNTMinerNoDevFee(); }, location: this.GetType()); #endregion #region 开始和停止挖矿后 VirtualRoot.BuildEventPath <StartingMineEvent>("开始挖矿时更新挖矿按钮状态", LogEnum.DevConsole, path: message => { AppRoot.MinerProfileVm.IsMining = true; // 因为无界面模式不一定会构建挖矿状态按钮,所以放在这里而不放在挖矿按钮的VM中 StartStopMineButtonViewModel.Instance.MineBtnText = "正在挖矿"; }, location: this.GetType()); VirtualRoot.BuildEventPath <MineStartedEvent>("启动1080ti小药丸、启动DevConsole? 更新挖矿按钮状态", LogEnum.DevConsole, path: message => { // 启动DevConsole if (NTMinerContext.IsUseDevConsole) { var mineContext = message.MineContext; string poolIp = mineContext.MainCoinPool.GetIp(); string consoleTitle = mineContext.MainCoinPool.Server; Daemon.DaemonUtil.RunDevConsoleAsync(poolIp, consoleTitle); } }, location: this.GetType()); VirtualRoot.BuildEventPath <MineStopedEvent>("停止挖矿后停止1080ti小药丸 挖矿停止后更新界面挖矿状态", LogEnum.DevConsole, path: message => { AppRoot.MinerProfileVm.IsMining = false; // 因为无界面模式不一定会构建挖矿状态按钮,所以放在这里而不放在挖矿按钮的VM中 StartStopMineButtonViewModel.Instance.MineBtnText = "尚未开始"; }, location: this.GetType()); #endregion #region 处理开启A卡计算模式 VirtualRoot.BuildCmdPath <SwitchRadeonGpuCommand>(path: message => { if (AdlHelper.IsHasATIGpu) { AppRoot.SwitchRadeonGpu(message.On); } }, location: this.GetType()); #endregion #region 处理A卡驱动签名 VirtualRoot.BuildCmdPath <AtikmdagPatcherCommand>(path: message => { if (AdlHelper.IsHasATIGpu) { AppRoot.OpenAtikmdagPatcher(); } }, location: this.GetType()); #endregion }