private StartStopMineButtonViewModel() { if (WpfUtil.IsInDesignMode) { return; } #if DEBUG Write.Stopwatch.Restart(); #endif this.StartMine = new DelegateCommand(() => { VirtualRoot.ThisLocalInfo(nameof(StartStopMineButtonViewModel), $"手动开始挖矿", toConsole: true); this.MinerProfile.IsMining = true; NTMinerRoot.Instance.StartMine(); BtnStopText = "正在挖矿"; }); this.StopMine = new DelegateCommand(() => { VirtualRoot.ThisLocalInfo(nameof(StartStopMineButtonViewModel), $"手动停止挖矿", toConsole: true); if (!NTMinerRoot.Instance.IsMining) { this.MinerProfile.IsMining = false; } NTMinerRoot.IsAutoStartCanceled = true; NTMinerRoot.Instance.StopMineAsync(StopMineReason.LocalUserAction, () => { if (!NTMinerRoot.Instance.IsMining) { this.MinerProfile.IsMining = false; } }); }); #if DEBUG Write.DevTimeSpan($"耗时{Write.Stopwatch.ElapsedMilliseconds}毫秒 {this.GetType().Name}.ctor"); #endif }
public void AutoStart() { bool IsAutoStart = (MinerProfile.IsAutoStart || CommandLineArgs.IsAutoStart); if (IsAutoStart && !this.MinerProfile.IsMining) { this.MinerProfile.IsMining = true; IMessagePathId handler = null; handler = VirtualRoot.BuildViaLimitPath <Per1SecondEvent>("挖矿倒计时", LogEnum.None, action: message => { if (NTMinerRoot.IsAutoStartCanceled) { BtnStopText = $"尚未开始"; } else { BtnStopText = $"倒计时{handler.ViaLimit.ToString()}"; } if (handler.ViaLimit == 0) { if (!NTMinerRoot.IsAutoStartCanceled) { BtnStopText = "正在挖矿"; MinerProfile.IsMining = true; VirtualRoot.ThisLocalInfo(nameof(StartStopMineButtonViewModel), $"自动开始挖矿", toConsole: true); NTMinerRoot.Instance.StartMine(); } } }, viaLimit: MinerProfile.AutoStartDelaySeconds); } }
public LocalIpSet() { NetworkChange.NetworkAddressChanged += (object sender, EventArgs e) => { var old = _localIps; Refresh(); var localIps = _localIps; if (old.Count != localIps.Count) { VirtualRoot.ThisLocalWarn(nameof(LocalIpSet), "网络接口的 IP 地址发生了更改", toConsole: true); } else { for (int i = 0; i < old.Count; i++) { if (old[i] != localIps[i]) { VirtualRoot.ThisLocalWarn(nameof(LocalIpSet), "网络接口的 IP 地址发生了更改", toConsole: true); break; } } } }; NetworkChange.NetworkAvailabilityChanged += (object sender, NetworkAvailabilityEventArgs e) => { if (e.IsAvailable) { VirtualRoot.ThisLocalInfo(nameof(LocalIpSet), $"网络可用", toConsole: true); } else { VirtualRoot.ThisLocalWarn(nameof(LocalIpSet), $"网络不可用", toConsole: true); } }; }
private StartStopMineButtonViewModel() { if (WpfUtil.IsInDesignMode) { return; } VirtualRoot.BuildCmdPath <StopMineCommand>(this.GetType(), LogEnum.DevConsole, path: message => { if (!NTMinerContext.Instance.IsMining) { this.MinerProfile.IsMining = false; } NTMinerContext.IsAutoStartCanceled = true; NTMinerContext.Instance.StopMineAsync(StopMineReason.LocalUserAction, () => { if (!NTMinerContext.Instance.IsMining) { this.MinerProfile.IsMining = false; } }); }); this.StartMine = new DelegateCommand(() => { VirtualRoot.ThisLocalInfo(nameof(StartStopMineButtonViewModel), $"手动开始挖矿", toConsole: true); NTMinerContext.Instance.StartMine(); }); this.StopMine = new DelegateCommand(() => { VirtualRoot.ThisLocalInfo(nameof(StartStopMineButtonViewModel), $"手动停止挖矿", toConsole: true); VirtualRoot.Execute(new StopMineCommand()); }); }
public void AutoStart() { bool isAutoStart = (MinerProfile.IsAutoStart || CommandLineArgs.IsAutoStart); if (isAutoStart && !this.MinerProfile.IsMining) { NTMinerConsole.UserInfo($"{MinerProfile.AutoStartDelaySeconds.ToString()}秒后开始挖矿"); this.MinerProfile.IsMining = true; IMessagePathId pathId = null; pathId = VirtualRoot.BuildViaTimesLimitPath <Per1SecondEvent>("自动开始挖矿倒计时", LogEnum.None, viaTimesLimit: MinerProfile.AutoStartDelaySeconds, location: this.GetType(), PathPriority.Normal, path: message => { if (!NTMinerContext.IsAutoStartCanceled) { MineBtnText = $"倒计时{pathId.ViaTimesLimit.ToString()}"; } if (pathId.ViaTimesLimit == 0) { if (!NTMinerContext.IsAutoStartCanceled) { VirtualRoot.ThisLocalInfo(nameof(StartStopMineButtonViewModel), $"自动开始挖矿", toConsole: true); NTMinerContext.Instance.StartMine(); } } }); } }
public void BenchmarkTest() { VirtualRoot.LocalMessages.Clear(); int times = 2000; Assert.IsTrue(times > NTKeyword.LocalMessageSetCapacity); string content = "this is a test"; for (int i = 0; i < times; i++) { VirtualRoot.ThisLocalInfo(nameof(LocalMessageTests), content); } Assert.IsTrue(VirtualRoot.LocalMessages.Count == NTKeyword.LocalMessageSetCapacity); }
public void BenchmarkTest() { VirtualRoot.Execute(new ClearLocalMessageSetCommand()); int times = 2000; Assert.IsTrue(times > NTKeyword.LocalMessageSetCapacity); string content = "this is a test"; for (int i = 0; i < times; i++) { VirtualRoot.ThisLocalInfo(nameof(LocalMessageTests), content); } Assert.IsTrue(VirtualRoot.LocalMessages.AsEnumerable().Count() == NTKeyword.LocalMessageSetCapacity); }
public AbstractAppViewFactory() { VirtualRoot.AddCmdPath <CloseNTMinerCommand>(action: message => { // 不能推迟这个日志记录的时机,因为推迟会有windows异常日志 VirtualRoot.ThisLocalInfo(nameof(AbstractAppViewFactory), $"退出{VirtualRoot.AppName}。原因:{message.Reason}"); UIThread.Execute(() => { try { Application.Current.Shutdown(); } catch (Exception ex) { Logger.ErrorDebugLine(ex); Environment.Exit(0); } }); }, location: typeof(AbstractAppViewFactory)); }
public static void Win10Optimize() { try { Task.Factory.StartNew(() => { Type type = typeof(WindowsUtil); Assembly assembly = type.Assembly; string name = "Win10Optimize.reg"; string fileFullName = Path.Combine(MainAssemblyInfo.TempDirFullName, name); assembly.ExtractManifestResource(type, name, fileFullName); Cmd.RunClose("regedit", $"/s \"{fileFullName}\"", waitForExit: true); VirtualRoot.ThisLocalInfo(nameof(WindowsUtil), "优化Windows成功", OutEnum.Success); }); } catch (Exception e) { Logger.ErrorDebugLine(e); VirtualRoot.ThisLocalError(nameof(WindowsUtil), "优化Windows失败", OutEnum.Warn); } }
public static void BlockWAU() { try { Task.Factory.StartNew(() => { Type type = typeof(WindowsUtil); Assembly assembly = type.Assembly; string name = "BlockWAU.bat"; string fileFullName = Path.Combine(MainAssemblyInfo.TempDirFullName, name); assembly.ExtractManifestResource(type, name, fileFullName); Cmd.RunClose(fileFullName, string.Empty, waitForExit: true); VirtualRoot.ThisLocalInfo(nameof(WindowsUtil), "禁用windows系统更新成功", OutEnum.Success); }); } catch (Exception e) { VirtualRoot.ThisLocalError(nameof(WindowsUtil), "禁用windows系统更新失败", OutEnum.Warn); Logger.ErrorDebugLine(e); } }
private NotiCenterWindow() { this.DataContext = Vm; InitializeComponent(); if (NotiCenterWindowViewModel.IsHotKeyEnabled) { HotKeyUtil.RegHotKey = (key) => { if (!RegHotKey(key, out string message)) { VirtualRoot.Out.ShowError(message, autoHideSeconds: 4); return(false); } else { VirtualRoot.ThisLocalInfo(nameof(NotiCenterWindow), $"热键Ctrl + Alt + {key.ToString()} 设置成功", OutEnum.Success); return(true); } }; } }
private StartStopMineButtonViewModel() { if (WpfUtil.IsInDesignMode) { return; } #if DEBUG NTStopwatch.Start(); #endif VirtualRoot.AddCmdPath <StopMineCommand>(action: message => { if (!NTMinerContext.Instance.IsMining) { this.MinerProfile.IsMining = false; } NTMinerContext.IsAutoStartCanceled = true; NTMinerContext.Instance.StopMineAsync(StopMineReason.LocalUserAction, () => { if (!NTMinerContext.Instance.IsMining) { this.MinerProfile.IsMining = false; } }); }, this.GetType(), LogEnum.DevConsole); this.StartMine = new DelegateCommand(() => { VirtualRoot.ThisLocalInfo(nameof(StartStopMineButtonViewModel), $"手动开始挖矿", toConsole: true); NTMinerContext.Instance.StartMine(); }); this.StopMine = new DelegateCommand(() => { VirtualRoot.ThisLocalInfo(nameof(StartStopMineButtonViewModel), $"手动停止挖矿", toConsole: true); VirtualRoot.Execute(new StopMineCommand()); }); #if DEBUG var elapsedMilliseconds = NTStopwatch.Stop(); if (elapsedMilliseconds.ElapsedMilliseconds > NTStopwatch.ElapsedMilliseconds) { Write.DevTimeSpan($"耗时{elapsedMilliseconds} {this.GetType().Name}.ctor"); } #endif }
private void KernelProcessDaemon() { if (this.IsRestart) { return; } string processName = this.Kernel.GetProcessName(); this.AddEventPath <Per1MinuteEvent>("周期性检查挖矿内核是否消失,如果消失尝试重启", LogEnum.DevConsole, action: message => { if (this == NTMinerContext.Instance.LockedMineContext) { if (!string.IsNullOrEmpty(processName)) { Process[] processes = Process.GetProcessesByName(processName); if (processes.Length == 0) { this.AutoRestartKernelCount += 1; VirtualRoot.ThisLocalWarn(nameof(NTMinerContext), processName + $"挖矿内核进程消失", toConsole: true); if (NTMinerContext.Instance.MinerProfile.IsAutoRestartKernel && this.AutoRestartKernelCount <= NTMinerContext.Instance.MinerProfile.AutoRestartKernelTimes) { VirtualRoot.ThisLocalInfo(nameof(NTMinerContext), $"尝试第{this.AutoRestartKernelCount.ToString()}次重启,共{NTMinerContext.Instance.MinerProfile.AutoRestartKernelTimes.ToString()}次", toConsole: true); NTMinerContext.Instance.RestartMine(); } else { NTMinerContext.Instance.StopMineAsync(StopMineReason.KernelProcessLost); } } } } else { this.Close(); } }, location: this.GetType()); }
public MainWindow() { if (WpfUtil.IsInDesignMode) { return; } if (!NTMinerConsole.IsEnabled) { NTMinerConsole.Enable(); } this.Vm = new MainWindowViewModel(); this.DataContext = Vm; this.MinHeight = 430; this.MinWidth = 640; this.Width = AppRoot.MainWindowWidth; this.Height = AppRoot.MainWindowHeight; #if DEBUG NTStopwatch.Start(); #endif ConsoleWindow.Instance.MouseDown += (sender, e) => { MoveConsoleWindow(); }; SystemEvents.SessionSwitch += SystemEvents_SessionSwitch; this.Loaded += (sender, e) => { ConsoleTabItemTopBorder.Margin = new Thickness(0, ConsoleTabItem.ActualHeight - 1, 0, 0); MoveConsoleWindow(); hwndSource = PresentationSource.FromVisual((Visual)sender) as HwndSource; hwndSource.AddHook(new HwndSourceHook(Win32Proc.WindowProc)); }; InitializeComponent(); _leftDrawerGripWidth = LeftDrawerGrip.Width; _btnOverClockBackground = BtnOverClock.Background; // 下面几行是为了看见设计视图 this.ResizeCursors.Visibility = Visibility.Visible; this.HideLeftDrawerGrid(); // 上面几行是为了看见设计视图 DateTime lastGetServerMessageOn = DateTime.MinValue; // 切换了主界面上的Tab时 this.MainTabControl.SelectionChanged += (sender, e) => { // 延迟创建,以加快主界面的启动 #region var selectedItem = MainTabControl.SelectedItem; if (selectedItem == TabItemSpeedTable) { if (SpeedTableContainer.Child == null) { SpeedTableContainer.Child = GetSpeedTable(); } } else if (selectedItem == TabItemMessage) { if (MessagesContainer.Child == null) { MessagesContainer.Child = new Messages(); } } else if (selectedItem == TabItemToolbox) { if (ToolboxContainer.Child == null) { ToolboxContainer.Child = new Toolbox(); } } else if (selectedItem == TabItemMinerProfileOption) { if (MinerProfileOptionContainer.Child == null) { MinerProfileOptionContainer.Child = new MinerProfileOption(); } } RpcRoot.SetIsServerMessagesVisible(selectedItem == TabItemMessage); if (selectedItem == TabItemMessage) { if (lastGetServerMessageOn.AddSeconds(10) < DateTime.Now) { lastGetServerMessageOn = DateTime.Now; VirtualRoot.Execute(new LoadNewServerMessageCommand()); } } if (selectedItem == ConsoleTabItem) { ConsoleTabItemTopBorder.Visibility = Visibility.Visible; } else { ConsoleTabItemTopBorder.Visibility = Visibility.Collapsed; } #endregion }; this.IsVisibleChanged += (sender, e) => { #region if (this.IsVisible) { NTMinerContext.IsUiVisible = true; } else { NTMinerContext.IsUiVisible = false; } MoveConsoleWindow(); #endregion }; this.StateChanged += (s, e) => { #region if (Vm.MinerProfile.IsShowInTaskbar) { ShowInTaskbar = true; } else { if (WindowState == WindowState.Minimized) { ShowInTaskbar = false; } else { ShowInTaskbar = true; } } if (WindowState == WindowState.Maximized) { ResizeCursors.Visibility = Visibility.Collapsed; } else { ResizeCursors.Visibility = Visibility.Visible; } MoveConsoleWindow(); #endregion }; bool isLeftClosed = false; this.ConsoleRectangle.IsVisibleChanged += (sender, e) => { if (this.ConsoleRectangle.IsVisible) { if (isLeftClosed != (LeftDrawerGrip.Width == _leftDrawerGripWidth)) { ConsoleWindowFit(); } } else { isLeftClosed = LeftDrawerGrip.Width == _leftDrawerGripWidth; } }; this.ConsoleRectangle.SizeChanged += (s, e) => { MoveConsoleWindow(); }; if (this.Width < 860) { NTMinerConsole.UserWarn("左侧面板已折叠,可点击侧边的'开始挖矿'按钮展开。"); } this.SizeChanged += (s, e) => { #region if (this.Width < 860) { this.CloseLeftDrawer(); this.BtnAboutNTMiner.Visibility = Visibility.Collapsed; } else { this.OpenLeftDrawer(isSizeChanged: true); this.BtnAboutNTMiner.Visibility = Visibility.Visible; } if (!this.ConsoleRectangle.IsVisible) { if (e.WidthChanged) { ConsoleWindow.Instance.Width = e.NewSize.Width; } if (e.HeightChanged) { ConsoleWindow.Instance.Height = e.NewSize.Height; } } #endregion }; NotiCenterWindow.Bind(this, ownerIsTopmost: true); this.LocationChanged += (sender, e) => { MoveConsoleWindow(); }; VirtualRoot.BuildCmdPath <TopmostCommand>(path: message => { UIThread.Execute(() => { if (!this.Topmost) { this.Topmost = true; } }); }, this.GetType()); VirtualRoot.BuildCmdPath <UnTopmostCommand>(path: message => { UIThread.Execute(() => { if (this.Topmost) { this.Topmost = false; } }); }, this.GetType()); VirtualRoot.BuildCmdPath <CloseMainWindowCommand>(path: message => { UIThread.Execute(() => { if (message.IsAutoNoUi) { SwitchToNoUi(); } else { this.Close(); } }); }, location: this.GetType()); this.BuildEventPath <Per1MinuteEvent>("挖矿中时自动切换为无界面模式", LogEnum.DevConsole, path: message => { if (NTMinerContext.IsUiVisible && NTMinerContext.Instance.MinerProfile.IsAutoNoUi && NTMinerContext.Instance.IsMining) { if (NTMinerContext.MainWindowRendedOn.AddMinutes(NTMinerContext.Instance.MinerProfile.AutoNoUiMinutes) < message.BornOn) { VirtualRoot.ThisLocalInfo(nameof(MainWindow), $"挖矿中界面展示{NTMinerContext.Instance.MinerProfile.AutoNoUiMinutes}分钟后自动切换为无界面模式,可在选项页调整配置"); VirtualRoot.Execute(new CloseMainWindowCommand(isAutoNoUi: true)); } } }, location: this.GetType()); #if DEBUG var elapsedMilliseconds = NTStopwatch.Stop(); if (elapsedMilliseconds.ElapsedMilliseconds > NTStopwatch.ElapsedMilliseconds) { NTMinerConsole.DevTimeSpan($"耗时{elapsedMilliseconds} {this.GetType().Name}.ctor"); } #endif }
private void RefreshCpu() { if (_isFirstRefreshCpu) { _isFirstRefreshCpu = false; Task.Factory.StartNew(() => { #if DEBUG Write.Stopwatch.Restart(); #endif int performance = (int)Windows.Cpu.Instance.GetPerformance(); // 因为初始化费时间 int temperature = (int)Windows.Cpu.Instance.GetTemperature(); #if DEBUG Write.DevTimeSpan($"耗时{Write.Stopwatch.ElapsedMilliseconds}毫秒 {this.GetType().Name}.RefreshCpu"); #endif UIThread.Execute(() => { UpdateCpuView(performance, temperature); }); this.WindowContextEventPath <Per1SecondEvent>("每秒钟更新CPU使用率和温度", LogEnum.None, action: message => { RefreshCpu(); }); }); } else { int performance = (int)Windows.Cpu.Instance.GetPerformance(); int temperature = (int)Windows.Cpu.Instance.GetTemperature(); UpdateCpuView(performance, temperature); if (Vm.MinerProfile.IsAutoStopByCpu) { if (NTMinerRoot.Instance.IsMining) { Vm.MinerProfile.LowTemperatureCount = 0; if (temperature >= Vm.MinerProfile.CpuStopTemperature) { Vm.MinerProfile.HighTemperatureCount++; } else { Vm.MinerProfile.HighTemperatureCount = 0; } if (Vm.MinerProfile.HighTemperatureCount >= Vm.MinerProfile.CpuGETemperatureSeconds) { Vm.MinerProfile.HighTemperatureCount = 0; NTMinerRoot.Instance.StopMineAsync(StopMineReason.HighCpuTemperature); VirtualRoot.ThisLocalInfo(nameof(MainWindow), $"自动停止挖矿,因为 CPU 温度连续{Vm.MinerProfile.CpuGETemperatureSeconds}秒不低于{Vm.MinerProfile.CpuStopTemperature}℃", toConsole: true); } } else { Vm.MinerProfile.HighTemperatureCount = 0; if (Vm.MinerProfile.IsAutoStartByCpu && NTMinerRoot.Instance.StopReason == StopMineReason.HighCpuTemperature) { if (temperature <= Vm.MinerProfile.CpuStartTemperature) { Vm.MinerProfile.LowTemperatureCount++; } else { Vm.MinerProfile.LowTemperatureCount = 0; } if (Vm.MinerProfile.LowTemperatureCount >= Vm.MinerProfile.CpuLETemperatureSeconds) { Vm.MinerProfile.LowTemperatureCount = 0; VirtualRoot.ThisLocalInfo(nameof(MainWindow), $"自动开始挖矿,因为 CPU 温度连续{Vm.MinerProfile.CpuLETemperatureSeconds}秒不高于{Vm.MinerProfile.CpuStartTemperature}℃", toConsole: true); NTMinerRoot.Instance.StartMine(); } } } } } }
private void KbCancelButton_Click(object sender, System.Windows.RoutedEventArgs e) { _isCanceled = true; VirtualRoot.Execute(new CloseWindowCommand(this.Vm.Id)); VirtualRoot.ThisLocalInfo(nameof(RestartWindows), "取消重启电脑"); }
public LocalIpSet() { NetworkChange.NetworkAddressChanged += (object sender, EventArgs e) => { // 延迟获取网络信息以防止立即获取时获取不到 TimeSpan.FromSeconds(1).Delay().ContinueWith(t => { var old = _localIps; _isInited = false; InitOnece(); var localIps = _localIps; if (localIps.Length == 0) { VirtualRoot.ThisLocalWarn(nameof(LocalIpSet), "网络连接已断开", toConsole: true); } else { if (old.Length == 0) { VirtualRoot.ThisLocalInfo(nameof(LocalIpSet), "网络连接已连接", toConsole: true); } else { bool isIpChanged = false; if (old.Length != localIps.Length) { isIpChanged = true; } else { foreach (var item in localIps) { var oldItem = old.FirstOrDefault(a => a.SettingID == item.SettingID); if (item != oldItem) { isIpChanged = true; break; } } } VirtualRoot.ThisLocalWarn(nameof(LocalIpSet), $"网络接口的 IP 地址发生了 {(isIpChanged ? "变更" : "刷新")}", toConsole: true); } } }); }; NetworkChange.NetworkAvailabilityChanged += (object sender, NetworkAvailabilityEventArgs e) => { if (e.IsAvailable) { VirtualRoot.ThisLocalInfo(nameof(LocalIpSet), $"网络可用", toConsole: true); } else { VirtualRoot.ThisLocalWarn(nameof(LocalIpSet), $"网络不可用", toConsole: true); } }; VirtualRoot.BuildCmdPath <SetLocalIpCommand>(action: message => { ManagementObject mo = null; using (ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration")) { ManagementObjectCollection moc = mc.GetInstances(); foreach (ManagementObject item in moc) { if ((string)item["SettingID"] == message.Input.SettingID) { mo = item; break; } } } if (mo != null) { if (message.Input.DHCPEnabled) { mo.InvokeMethod("EnableStatic", null); mo.InvokeMethod("SetGateways", null); mo.InvokeMethod("EnableDHCP", null); } else { ManagementBaseObject inPar = mo.GetMethodParameters("EnableStatic"); inPar["IPAddress"] = new string[] { message.Input.IPAddress }; inPar["SubnetMask"] = new string[] { message.Input.IPSubnet }; mo.InvokeMethod("EnableStatic", inPar, null); inPar = mo.GetMethodParameters("SetGateways"); inPar["DefaultIPGateway"] = new string[] { message.Input.DefaultIPGateway }; mo.InvokeMethod("SetGateways", inPar, null); } if (message.IsAutoDNSServer) { mo.InvokeMethod("SetDNSServerSearchOrder", null); } else { ManagementBaseObject inPar = mo.GetMethodParameters("SetDNSServerSearchOrder"); inPar["DNSServerSearchOrder"] = new string[] { message.Input.DNSServer0, message.Input.DNSServer1 }; mo.InvokeMethod("SetDNSServerSearchOrder", inPar, null); } } }); }
public MainWindow() { if (WpfUtil.IsInDesignMode) { return; } this.MinHeight = 430; this.MinWidth = 640; this.Width = AppStatic.MainWindowWidth; this.Height = AppStatic.MainWindowHeight; #if DEBUG NTStopwatch.Start(); #endif ConsoleWindow.Instance.Show(); ConsoleWindow.Instance.MouseDown += (sender, e) => { MoveConsoleWindow(); }; ConsoleWindow.Instance.Hide(); this.Owner = ConsoleWindow.Instance; SystemEvents.SessionSwitch += SystemEvents_SessionSwitch; this.Loaded += (sender, e) => { MoveConsoleWindow(); hwndSource = PresentationSource.FromVisual((Visual)sender) as HwndSource; hwndSource.AddHook(new HwndSourceHook(Win32Proc.WindowProc)); }; InitializeComponent(); _leftDrawerGripWidth = LeftDrawerGrip.Width; _btnLeftDrawerGripBrush = BtnLeftDrawerGrip.Background; NTMinerRoot.RefreshArgsAssembly.Invoke(); // 下面几行是为了看见设计视图 this.ResizeCursors.Visibility = Visibility.Visible; this.HideLeftDrawerGrid(); // 上面几行是为了看见设计视图 DateTime lastGetServerMessageOn = DateTime.MinValue; // 切换了主界面上的Tab时 this.MainArea.SelectionChanged += (sender, e) => { // 延迟创建,以加快主界面的启动 #region var selectedItem = MainArea.SelectedItem; if (selectedItem == TabItemSpeedTable) { if (SpeedTableContainer.Child == null) { SpeedTableContainer.Child = GetSpeedTable(); } } else if (selectedItem == TabItemMessage) { if (MessagesContainer.Child == null) { MessagesContainer.Child = new Messages(); } } else if (selectedItem == TabItemToolbox) { if (ToolboxContainer.Child == null) { ToolboxContainer.Child = new Toolbox(); } } else if (selectedItem == TabItemMinerProfileOption) { if (MinerProfileOptionContainer.Child == null) { MinerProfileOptionContainer.Child = new MinerProfileOption(); } } VirtualRoot.SetIsServerMessagesVisible(selectedItem == TabItemMessage); if (selectedItem == TabItemMessage) { if (lastGetServerMessageOn.AddSeconds(10) < DateTime.Now) { lastGetServerMessageOn = DateTime.Now; VirtualRoot.Execute(new LoadNewServerMessageCommand()); } } #endregion }; this.IsVisibleChanged += (sender, e) => { #region if (this.IsVisible) { NTMinerRoot.IsUiVisible = true; } else { NTMinerRoot.IsUiVisible = false; } MoveConsoleWindow(); #endregion }; this.ConsoleRectangle.IsVisibleChanged += (sender, e) => { MoveConsoleWindow(); }; this.StateChanged += (s, e) => { #region if (Vm.MinerProfile.IsShowInTaskbar) { ShowInTaskbar = true; } else { if (WindowState == WindowState.Minimized) { ShowInTaskbar = false; } else { ShowInTaskbar = true; } } if (WindowState == WindowState.Maximized) { ResizeCursors.Visibility = Visibility.Collapsed; } else { ResizeCursors.Visibility = Visibility.Visible; } MoveConsoleWindow(); #endregion }; this.ConsoleRectangle.SizeChanged += (s, e) => { MoveConsoleWindow(); }; this.SizeChanged += (s, e) => { #region if (this.Width < 860) { this.CloseLeftDrawer(); } else { this.OpenLeftDrawer(); } if (!this.ConsoleRectangle.IsVisible) { if (e.WidthChanged) { ConsoleWindow.Instance.Width = e.NewSize.Width; } if (e.HeightChanged) { ConsoleWindow.Instance.Height = e.NewSize.Height; } } #endregion }; NotiCenterWindow.Instance.Bind(this, ownerIsTopMost: true); this.LocationChanged += (sender, e) => { MoveConsoleWindow(); }; VirtualRoot.AddCmdPath <CloseMainWindowCommand>(action: message => { UIThread.Execute(() => () => { if (message.IsAutoNoUi) { SwitchToNoUi(); } else { this.Close(); } }); }, location: this.GetType()); this.AddEventPath <PoolDelayPickedEvent>("从内核输出中提取了矿池延时时展示到界面", LogEnum.DevConsole, action: message => { UIThread.Execute(() => () => { if (message.IsDual) { Vm.StateBarVm.DualPoolDelayText = message.PoolDelayText; } else { Vm.StateBarVm.PoolDelayText = message.PoolDelayText; } }); }, location: this.GetType()); this.AddEventPath <MineStartedEvent>("开始挖矿后将清空矿池延时", LogEnum.DevConsole, action: message => { UIThread.Execute(() => () => { Vm.StateBarVm.PoolDelayText = string.Empty; Vm.StateBarVm.DualPoolDelayText = string.Empty; }); }, location: this.GetType()); this.AddEventPath <MineStopedEvent>("停止挖矿后将清空矿池延时", LogEnum.DevConsole, action: message => { UIThread.Execute(() => () => { Vm.StateBarVm.PoolDelayText = string.Empty; Vm.StateBarVm.DualPoolDelayText = string.Empty; }); }, location: this.GetType()); this.AddEventPath <Per1MinuteEvent>("挖矿中时自动切换为无界面模式", LogEnum.DevConsole, action: message => { if (NTMinerRoot.IsUiVisible && NTMinerRoot.Instance.MinerProfile.IsAutoNoUi && NTMinerRoot.Instance.IsMining) { if (NTMinerRoot.MainWindowRendedOn.AddMinutes(NTMinerRoot.Instance.MinerProfile.AutoNoUiMinutes) < message.BornOn) { VirtualRoot.ThisLocalInfo(nameof(MainWindow), $"挖矿中界面展示{NTMinerRoot.Instance.MinerProfile.AutoNoUiMinutes}分钟后自动切换为无界面模式,可在选项页调整配置"); VirtualRoot.Execute(new CloseMainWindowCommand(isAutoNoUi: true)); } } }, location: this.GetType()); this.AddEventPath <CpuPackageStateChangedEvent>("CPU包状态变更后刷新Vm内存", LogEnum.None, action: message => { UpdateCpuView(); }, location: this.GetType()); #if DEBUG var elapsedMilliseconds = NTStopwatch.Stop(); if (elapsedMilliseconds.ElapsedMilliseconds > NTStopwatch.ElapsedMilliseconds) { Write.DevTimeSpan($"耗时{elapsedMilliseconds} {this.GetType().Name}.ctor"); } #endif }