public void AutoStart() { bool IsAutoStart = (MinerProfile.IsAutoStart || CommandLineArgs.IsAutoStart); if (IsAutoStart && !this.MinerProfile.IsMining) { this.MinerProfile.IsMining = true; int n = MinerProfile.AutoStartDelaySeconds; IMessagePathId handler = null; handler = VirtualRoot.BuildEventPath <Per1SecondEvent>("挖矿倒计时", LogEnum.None, action: message => { if (NTMinerRoot.IsAutoStartCanceled) { BtnStopText = $"尚未开始"; n = 0; } else { BtnStopText = $"倒计时{--n}"; } if (n <= 0) { VirtualRoot.DeletePath(handler); if (!NTMinerRoot.IsAutoStartCanceled) { BtnStopText = "正在挖矿"; MinerProfile.IsMining = true; VirtualRoot.ThisWorkerInfo(nameof(StartStopMineButtonViewModel), $"自动开始挖矿", toConsole: true); NTMinerRoot.Instance.StartMine(); } } }); } }
private StartStopMineButtonViewModel() { if (Design.IsInDesignMode) { return; } #if DEBUG Write.Stopwatch.Restart(); #endif this.StartMine = new DelegateCommand(() => { VirtualRoot.ThisWorkerInfo(nameof(StartStopMineButtonViewModel), $"手动开始挖矿", toConsole: true); this.MinerProfile.IsMining = true; NTMinerRoot.Instance.StartMine(); BtnStopText = "正在挖矿"; }); this.StopMine = new DelegateCommand(() => { VirtualRoot.ThisWorkerInfo(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 TestMethod1() { File.Delete(VirtualRoot.WorkerMessageDbFileFullName); Assert.IsTrue(VirtualRoot.WorkerMessages.Count == 0); string content = "this is a test"; VirtualRoot.ThisWorkerInfo(nameof(WorkerMessageTests), content); Assert.IsTrue(VirtualRoot.WorkerMessages.Count == 1); Assert.IsTrue(VirtualRoot.WorkerMessages.Count == 1); }
public void BenchmarkTest() { File.Delete(VirtualRoot.WorkerMessageDbFileFullName); int times = 2000; Assert.IsTrue(times > VirtualRoot.WorkerMessageSetCapacity); string content = "this is a test"; for (int i = 0; i < times; i++) { VirtualRoot.ThisWorkerInfo(nameof(WorkerMessageTests), content); } Assert.IsTrue(VirtualRoot.WorkerMessages.Count == VirtualRoot.WorkerMessageSetCapacity); }
public LocalIpSet() { NetworkChange.NetworkAddressChanged += (object sender, EventArgs e) => { Refresh(); VirtualRoot.ThisWorkerWarn(nameof(LocalIpSet), "网络接口的 IP 地址发生了更改", toConsole: true); }; NetworkChange.NetworkAvailabilityChanged += (object sender, NetworkAvailabilityEventArgs e) => { if (e.IsAvailable) { VirtualRoot.ThisWorkerInfo(nameof(LocalIpSet), $"网络可用", toConsole: true); } else { VirtualRoot.ThisWorkerWarn(nameof(LocalIpSet), $"网络不可用", toConsole: true); } }; }
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.ThisWorkerInfo(nameof(WindowsUtil), "优化Windows成功", OutEnum.Success); }); } catch (Exception e) { Logger.ErrorDebugLine(e); VirtualRoot.ThisWorkerError(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.ThisWorkerInfo(nameof(WindowsUtil), "禁用windows系统更新成功", OutEnum.Success); }); } catch (Exception e) { VirtualRoot.ThisWorkerError(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, 4); return(false); } else { VirtualRoot.ThisWorkerInfo(nameof(NotiCenterWindow), $"热键Ctrl + Alt + {key.ToString()} 设置成功", OutEnum.Success); return(true); } }; } }
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.ThisWorkerInfo(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.ThisWorkerInfo(nameof(MainWindow), $"自动开始挖矿,因为 CPU 温度连续{Vm.MinerProfile.CpuLETemperatureSeconds}秒不高于{Vm.MinerProfile.CpuStartTemperature}℃", toConsole: true); NTMinerRoot.Instance.StartMine(); } } } } } }