private void BuildCommonPaths() { // 之所以提前到这里是因为升级之前可能需要下载升级器,下载升级器时需要下载器 VirtualRoot.AddCmdPath <ShowFileDownloaderCommand>(action: message => { FileDownloader.ShowWindow(message.DownloadFileUrl, message.FileTitle, message.DownloadComplete); }, location: this.GetType()); VirtualRoot.AddCmdPath <UpgradeCommand>(action: 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); }); }
public override void OnActionExecuting(HttpActionContext actionContext) { base.OnActionExecuting(actionContext); string ip = actionContext.Request.GetRemoteIp(); if (IPAddress.TryParse(ip, out IPAddress remoteIp)) { VirtualRoot.RaiseEvent(new WebApiRequestEvent(remoteIp)); } string controllerName = actionContext.ActionDescriptor.ControllerDescriptor.ControllerName; string actionName = $"{controllerName}.{actionContext.ActionDescriptor.ActionName}"; AppRoot.Action(actionName); }
private void BuildPaths() { VirtualRoot.AddCmdPath <MinerClientActionCommand>(action: 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; case MinerClientActionType.BlockWAU: VirtualRoot.Execute(new BlockWAUCommand()); break; default: break; } } catch (Exception e) { Logger.ErrorDebugLine(e); } #endregion }, location: this.GetType()); #region 处理显示主界面命令 VirtualRoot.AddCmdPath <ShowMainWindowCommand>(action: 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.AddEventPath <Per1MinuteEvent>("周期确保守护进程在运行", LogEnum.DevConsole, action: message => { Daemon.DaemonUtil.RunNTMinerDaemon(); NoDevFee.NoDevFeeUtil.RunNTMinerNoDevFee(); }, location: this.GetType()); #endregion #region 开始和停止挖矿后 VirtualRoot.AddEventPath <StartingMineEvent>("开始挖矿时更新挖矿按钮状态", LogEnum.DevConsole, action: message => { AppRoot.MinerProfileVm.IsMining = true; // 因为无界面模式不一定会构建挖矿状态按钮,所以放在这里而不放在挖矿按钮的VM中 StartStopMineButtonViewModel.Instance.BtnStopText = "正在挖矿"; }, location: this.GetType()); VirtualRoot.AddEventPath <MineStartedEvent>("启动1080ti小药丸、启动DevConsole? 更新挖矿按钮状态", LogEnum.DevConsole, action: 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.AddEventPath <MineStopedEvent>("停止挖矿后停止1080ti小药丸 挖矿停止后更新界面挖矿状态", LogEnum.DevConsole, action: message => { AppRoot.MinerProfileVm.IsMining = false; // 因为无界面模式不一定会构建挖矿状态按钮,所以放在这里而不放在挖矿按钮的VM中 StartStopMineButtonViewModel.Instance.BtnStopText = "尚未开始"; OhGodAnETHlargementPill.OhGodAnETHlargementPillUtil.Stop(); }, location: this.GetType()); #endregion #region 处理禁用win10系统更新 VirtualRoot.AddCmdPath <BlockWAUCommand>(action: 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.AddCmdPath <Win10OptimizeCommand>(action: 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.AddCmdPath <SwitchRadeonGpuCommand>(action: message => { if (NTMinerContext.Instance.GpuSet.GpuType == GpuType.AMD) { AppRoot.SwitchRadeonGpu(message.On); } }, location: this.GetType()); #endregion #region 处理A卡驱动签名 VirtualRoot.AddCmdPath <AtikmdagPatcherCommand>(action: message => { if (NTMinerContext.Instance.GpuSet.GpuType == GpuType.AMD) { AppRoot.OpenAtikmdagPatcher(); } }, location: this.GetType()); #endregion #region 启用或禁用windows远程桌面 VirtualRoot.AddCmdPath <EnableRemoteDesktopCommand>(action: 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.AddCmdPath <EnableOrDisableWindowsAutoLoginCommand>(action: message => { if (NTMiner.Windows.OS.Instance.IsAutoAdminLogon) { 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); }
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 }
protected override void OnStartup(StartupEventArgs e) { // 之所以提前到这里是因为升级之前可能需要下载升级器,下载升级器时需要下载器 VirtualRoot.AddCmdPath <ShowFileDownloaderCommand>(action: message => { FileDownloader.ShowWindow(message.DownloadFileUrl, message.FileTitle, message.DownloadComplete); }, location: this.GetType()); VirtualRoot.AddCmdPath <UpgradeCommand>(action: message => { AppRoot.Upgrade(NTMinerAppType.MinerClient, message.FileName, message.Callback); }, location: this.GetType()); VirtualRoot.AddCmdPath <MinerClientActionCommand>(action: message => { Task task = TaskEx.CompletedTask; try { // 注意不要提前return,因为最后需要执行Environment.Exit(0) switch (message.ActionType) { case MinerClientActionType.AtikmdagPatcher: { AdlHelper adlHelper = new AdlHelper(); if (adlHelper.GpuCount != 0) { task = AtikmdagPatcher.AtikmdagPatcherUtil.Run(); } } break; case MinerClientActionType.SwitchRadeonGpuOn: { AdlHelper adlHelper = new AdlHelper(); if (adlHelper.GpuCount != 0) { task = SwitchRadeonGpu.SwitchRadeonGpu.Run(on: true); } } break; case MinerClientActionType.SwitchRadeonGpuOff: { AdlHelper adlHelper = new AdlHelper(); task = SwitchRadeonGpu.SwitchRadeonGpu.Run(on: false); } break; case MinerClientActionType.BlockWAU: task = NTMiner.Windows.WindowsUtil.BlockWAU(); break; default: break; } } catch { } task.ContinueWith(t => { Environment.Exit(0); }); }, location: this.GetType()); if (!string.IsNullOrEmpty(CommandLineArgs.Upgrade)) { VirtualRoot.Execute(new UpgradeCommand(CommandLineArgs.Upgrade, () => { UIThread.Execute(() => () => { Environment.Exit(0); }); })); } else if (!string.IsNullOrEmpty(CommandLineArgs.Action)) { if (CommandLineArgs.Action.TryParse(out MinerClientActionType resourceType)) { VirtualRoot.Execute(new MinerClientActionCommand(resourceType)); } } else { if (AppUtil.GetMutex(NTKeyword.MinerClientAppMutex)) { Logger.InfoDebugLine($"==================NTMiner.exe {EntryAssemblyInfo.CurrentVersionStr}=================="); // 在另一个UI线程运行欢迎界面以确保欢迎界面的响应不被耗时的主界面初始化过程阻塞 // 注意:必须确保SplashWindow没有用到任何其它界面用到的依赖对象 SplashWindow splashWindow = null; SplashWindow.ShowWindowAsync(window => { splashWindow = window; }); NotiCenterWindow.ShowWindow(); 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(); } NTMinerContext.Instance.Init(() => { _appViewFactory.Link(); 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.Instance.ServerContext.CoinSet.Count == 0) { VirtualRoot.ThisLocalError(nameof(App), "访问阿里云失败,请尝试更换本机dns解决此问题。", toConsole: true); } UIThread.Execute(() => () => { Window mainWindow = null; AppRoot.NotifyIcon = ExtendedNotifyIcon.Create("开源矿工", isMinerStudio: false); if (NTMinerContext.Instance.MinerProfile.IsNoUi && NTMinerContext.Instance.MinerProfile.IsAutoStart) { 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(); VirtualRoot.StartTimer(new WpfTimingEventProducer()); }); 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); } }); }); Link(); } 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); } } } base.OnStartup(e); }