private void ShowMainWindow(bool isToggle) { UIThread.Execute(() => { AppViewFactory.ShowMainWindow(isToggle); // 使状态栏显示显示最新状态 if (NTMinerRoot.Instance.IsMining) { var mainCoin = NTMinerRoot.Instance.CurrentMineContext.MainCoin; if (mainCoin == null) { return; } var coinShare = NTMinerRoot.Instance.CoinShareSet.GetOrCreate(mainCoin.GetId()); VirtualRoot.Happened(new ShareChangedEvent(coinShare)); if ((NTMinerRoot.Instance.CurrentMineContext is IDualMineContext dualMineContext) && dualMineContext.DualCoin != null) { coinShare = NTMinerRoot.Instance.CoinShareSet.GetOrCreate(dualMineContext.DualCoin.GetId()); VirtualRoot.Happened(new ShareChangedEvent(coinShare)); } AppContext.Instance.GpuSpeedVms.Refresh(); } }); }
protected override void OnStartup(StartupEventArgs e) { RenderOptions.ProcessRenderMode = RenderMode.SoftwareOnly; 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) { if (!NTMiner.Windows.WMI.IsWmiEnabled) { DialogWindow.ShowDialog(message: "开源矿工无法运行所需的组件,因为本机未开启WMI服务,开源矿工需要使用WMI服务检测windows的内存、显卡等信息,请先手动开启WMI。", title: "提醒", icon: "Icon_Error"); Shutdown(); Environment.Exit(0); } NTMinerOverClockUtil.ExtractResource(); NTMinerRoot.SetIsMinerClient(true); NotiCenterWindowViewModel.IsHotKeyEnabled = true; Window splashWindow = AppViewFactory.CreateSplashWindow(); splashWindow.Show(); NotiCenterWindow.Instance.Show(); if (!NTMiner.Windows.Role.IsAdministrator) { NotiCenterWindowViewModel.Instance.Manager .CreateMessage() .Warning("请以管理员身份运行。") .WithButton("点击以管理员身份运行", button => { Wpf.Util.RunAsAdministrator(); }) .Dismiss().WithButton("忽略", button => { }).Queue(); } VirtualRoot.On <StartingMineFailedEvent>("开始挖矿失败", LogEnum.DevConsole, action: message => { AppContext.Instance.MinerProfileVm.IsMining = false; Write.UserFail(message.Message); }); NTMinerRoot.Instance.Init(() => { AppViewFactory.Link(); if (NTMinerRoot.Instance.GpuSet.Count == 0) { NotiCenterWindowViewModel.Instance.Manager.ShowErrorMessage("没有矿卡或矿卡未驱动。"); } UIThread.Execute(() => { if (NTMinerRegistry.GetIsNoUi() && NTMinerRegistry.GetIsAutoStart()) { NotiCenterWindowViewModel.Instance.Manager.ShowSuccessMessage("已切换为无界面模式运行", "开源矿工"); } else { AppViewFactory.ShowMainWindow(isToggle: false); } AppContext.NotifyIcon = ExtendedNotifyIcon.Create("开源矿工", isMinerStudio: false); splashWindow?.Close(); }); #region 处理显示主界面命令 VirtualRoot.Window <ShowMainWindowCommand>("处理显示主界面命令", LogEnum.DevConsole, action: message => { ShowMainWindow(message.IsToggle); }); #endregion Task.Factory.StartNew(() => { try { HttpServer.Start($"http://localhost:{Consts.MinerClientPort}"); NTMinerRoot.Instance.Start(); } catch (Exception ex) { Logger.ErrorDebugLine(ex); } }); }); Link(); } else { try { AppViewFactory.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); }
protected override void OnStartup(StartupEventArgs e) { RenderOptions.ProcessRenderMode = RenderMode.SoftwareOnly; 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; NTMinerRoot.SetIsMinerClient(false); NotiCenterWindow.Instance.Show(); LoginWindow loginWindow = new LoginWindow(); var result = loginWindow.ShowDialog(); if (result.HasValue && result.Value) { bool isInnerIp = Ip.Util.IsInnerIp(Registry.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); }