private ExtendedNotifyIcon(Icon icon, string text, bool isMinerStudio) { _isMinerStudio = isMinerStudio; _targetNotifyIcon = new NotifyIcon { Icon = icon, Visible = isMinerStudio || NTMinerRoot.GetIsShowNotifyIcon(), Text = text, ContextMenu = new ContextMenu() }; _targetNotifyIcon.ContextMenu.MenuItems.Add(new MenuItem("退出" + text, (sender, e) => { VirtualRoot.Execute(new CloseNTMinerCommand()); })); _targetNotifyIcon.MouseDown += (object sender, MouseEventArgs e) => { if (e.Button == MouseButtons.Left) { VirtualRoot.Execute(new ShowMainWindowCommand(isToggle: true)); } }; }
private ExtendedNotifyIcon(Icon icon, string text, bool isMinerStudio) { _isMinerStudio = isMinerStudio; _targetNotifyIcon = new NotifyIcon { Icon = icon, Visible = isMinerStudio || NTMinerRoot.GetIsShowNotifyIcon(), Text = text, ContextMenuStrip = new ContextMenuStrip { BackColor = Color.White, ShowImageMargin = false } }; _targetNotifyIcon.ContextMenuStrip.Items.Add("退出" + text, null, (sender, e) => { VirtualRoot.Execute(new CloseNTMinerCommand()); }); _targetNotifyIcon.MouseDown += (object sender, MouseEventArgs e) => { if (e.Button == MouseButtons.Left) { VirtualRoot.Execute(new ShowMainWindowCommand(isToggle: true)); } }; }
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); }); 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 {NTMinerRoot.CurrentVersion.ToString()}=================="); if (!NTMiner.Windows.WMI.IsWmiEnabled) { DialogWindow.ShowDialog(message: "开源矿工无法运行所需的组件,因为本机未开启WMI服务,开源矿工需要使用WMI服务检测windows的内存、显卡等信息,请先手动开启WMI。", title: "提醒", icon: "Icon_Error"); Shutdown(); Environment.Exit(0); } NTMinerOverClockUtil.ExtractResource(); VirtualRoot.SetIsMinerClient(true); NotiCenterWindowViewModel.IsHotKeyEnabled = true; Window splashWindow = _appViewFactory.CreateSplashWindow(); splashWindow.Show(); NotiCenterWindow.Instance.Show(); if (DevMode.IsDevMode) { HandlerIdsWindow window = new HandlerIdsWindow(); window.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 (NTMinerRoot.GetIsNoUi() && NTMinerRegistry.GetIsAutoStart()) { MainWindow = NotiCenterWindow.Instance; 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(); Daemon.DaemonUtil.RunNTMinerDaemon(); } 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); }
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(() => { if (NTMinerRoot.GetIsCloseMeanExit()) { VirtualRoot.Execute(new CloseNTMinerCommand()); return; } MainWindow = NotiCenterWindow.Instance; foreach (Window window in Windows) { if (window != MainWindow) { window.Close(); } } NotiCenterWindowViewModel.Instance.Manager.ShowSuccessMessage(message.Message, "开源矿工"); }); }); #region 周期确保守护进程在运行 VirtualRoot.On <Per1MinuteEvent>("周期确保守护进程在运行", LogEnum.DevConsole, action: message => { 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 <EnableWindowsRemoteDesktopCommand>("处理启用或禁用Windows远程桌面命令", LogEnum.DevConsole, action: message => { if (NTMinerRoot.GetIsRemoteDesktopEnabled()) { return; } string msg = "确定启用Windows远程桌面吗?"; DialogWindow.ShowDialog(message: msg, title: "确认", onYes: () => { Rdp.SetRdpEnabled(true, true); Firewall.AddRemoteDesktopRule(); }, 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 }
private MinerProfileViewModel() { #if DEBUG VirtualRoot.Stopwatch.Restart(); #endif if (Design.IsInDesignMode) { return; } this.AutoStartDelaySecondsUp = new DelegateCommand(() => { this.AutoStartDelaySeconds++; }); this.AutoStartDelaySecondsDown = new DelegateCommand(() => { if (this.AutoStartDelaySeconds > 0) { this.AutoStartDelaySeconds--; } }); this.AutoRestartKernelTimesUp = new DelegateCommand(() => { this.AutoRestartKernelTimes++; }); this.AutoRestartKernelTimesDown = new DelegateCommand(() => { if (this.AutoRestartKernelTimes > 0) { this.AutoRestartKernelTimes--; } }); this.NoShareRestartKernelMinutesUp = new DelegateCommand(() => { this.NoShareRestartKernelMinutes++; }); this.NoShareRestartKernelMinutesDown = new DelegateCommand(() => { if (this.NoShareRestartKernelMinutes > 0) { this.NoShareRestartKernelMinutes--; } }); this.PeriodicRestartKernelHoursUp = new DelegateCommand(() => { this.PeriodicRestartKernelHours++; }); this.PeriodicRestartKernelHoursDown = new DelegateCommand(() => { if (this.PeriodicRestartKernelHours > 0) { this.PeriodicRestartKernelHours--; } }); this.PeriodicRestartKernelMinutesUp = new DelegateCommand(() => { this.PeriodicRestartKernelMinutes++; }); this.PeriodicRestartKernelMinutesDown = new DelegateCommand(() => { if (this.PeriodicRestartKernelMinutes > 0) { this.PeriodicRestartKernelMinutes--; } }); this.PeriodicRestartComputerHoursUp = new DelegateCommand(() => { this.PeriodicRestartComputerHours++; }); this.PeriodicRestartComputerHoursDown = new DelegateCommand(() => { if (this.PeriodicRestartComputerHours > 0) { this.PeriodicRestartComputerHours--; } }); this.PeriodicRestartComputerMinutesUp = new DelegateCommand(() => { this.PeriodicRestartComputerMinutes++; }); this.PeriodicRestartComputerMinutesDown = new DelegateCommand(() => { if (this.PeriodicRestartComputerMinutes > 0) { this.PeriodicRestartComputerMinutes--; } }); this.EPriceUp = new DelegateCommand(() => { this.EPrice = Math.Round(this.EPrice + 0.1, 2); }); this.EPriceDown = new DelegateCommand(() => { if (this.EPrice > 0.1) { this.EPrice = Math.Round(this.EPrice - 0.1, 2); } }); this.PowerAppendUp = new DelegateCommand(() => { this.PowerAppend++; }); this.PowerAppendDown = new DelegateCommand(() => { if (this.PowerAppend > 0) { this.PowerAppend--; } }); this.MaxTempUp = new DelegateCommand(() => { this.MaxTemp++; }); this.MaxTempDown = new DelegateCommand(() => { if (this.MaxTemp > 0) { this.MaxTemp--; } }); this.AutoNoUiMinutesUp = new DelegateCommand(() => { this.AutoNoUiMinutes++; }); this.AutoNoUiMinutesDown = new DelegateCommand(() => { if (this.AutoNoUiMinutes > 0) { this.AutoNoUiMinutes--; } }); NTMinerRoot.SetRefreshArgsAssembly(() => { if (CoinVm != null && CoinVm.CoinKernel != null && CoinVm.CoinKernel.Kernel != null) { var coinKernelProfile = CoinVm.CoinKernel.CoinKernelProfile; var kernelInput = CoinVm.CoinKernel.Kernel.KernelInputVm; if (coinKernelProfile != null && kernelInput != null) { if (coinKernelProfile.IsDualCoinEnabled && !kernelInput.IsAutoDualWeight) { if (coinKernelProfile.DualCoinWeight > kernelInput.DualWeightMax) { coinKernelProfile.DualCoinWeight = kernelInput.DualWeightMax; } else if (coinKernelProfile.DualCoinWeight < kernelInput.DualWeightMin) { coinKernelProfile.DualCoinWeight = kernelInput.DualWeightMin; } NTMinerRoot.Instance.MinerProfile.SetCoinKernelProfileProperty(coinKernelProfile.CoinKernelId, nameof(coinKernelProfile.DualCoinWeight), coinKernelProfile.DualCoinWeight); } } } this.ArgsAssembly = NTMinerRoot.Instance.BuildAssembleArgs(out _, out _, out _); }); VirtualRoot.On <ServerContextVmsReInitedEvent>("ServerContext的VM集刷新后刷新视图界面", LogEnum.DevConsole, action: message => { OnPropertyChanged(nameof(CoinVm)); }); Window <RefreshAutoBootStartCommand>("刷新开机启动和自动挖矿的展示", LogEnum.UserConsole, action: message => { OnPropertyChanged(nameof(IsAutoBoot)); OnPropertyChanged(nameof(IsAutoStart)); }); On <MinerProfilePropertyChangedEvent>("MinerProfile设置变更后刷新VM内存", LogEnum.DevConsole, action: message => { OnPropertyChanged(message.PropertyName); }); On <MineWorkPropertyChangedEvent>("MineWork设置变更后刷新VM内存", LogEnum.DevConsole, action: message => { OnPropertyChanged(message.PropertyName); }); VirtualRoot.On <LocalContextVmsReInitedEvent>("本地上下文视图模型集刷新后刷新界面", LogEnum.DevConsole, action: message => { AllPropertyChanged(); }); #if DEBUG Write.DevWarn($"耗时{VirtualRoot.Stopwatch.ElapsedMilliseconds}毫秒 {this.GetType().Name}.ctor"); #endif }
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(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); }
public void RefreshIcon() { _targetNotifyIcon.Visible = _isMinerStudio || NTMinerRoot.GetIsShowNotifyIcon(); }