public MinerProfileIndex() { #if DEBUG NTStopwatch.Start(); #endif InitializeComponent(); this.PopupKernel.Closed += Popup_Closed; this.PopupMainCoinPool.Closed += Popup_Closed; this.PopupMainCoin.Closed += Popup_Closed; this.PopupMainCoinWallet.Closed += Popup_Closed; this.RunOneceOnLoaded((window) => { window.AddEventPath <ServerContextVmsReInitedEvent>("上下文视图模型集刷新后刷新界面上的popup", LogEnum.DevConsole, action: message => { UIThread.Execute(() => { if (Vm.MinerProfile.MineWork != null) { return; } if (this.PopupKernel.Child != null && this.PopupKernel.IsOpen) { this.PopupKernel.IsOpen = false; OpenKernelPopup(); } if (this.PopupMainCoinPool.Child != null && this.PopupMainCoinPool.IsOpen) { this.PopupMainCoinPool.IsOpen = false; OpenMainCoinPoolPopup(); } if (this.PopupMainCoinPool1.Child != null && this.PopupMainCoinPool1.IsOpen) { this.PopupMainCoinPool1.IsOpen = false; OpenMainCoinPool1Popup(); } if (this.PopupMainCoin != null && this.PopupMainCoin.IsOpen) { this.PopupMainCoin.IsOpen = false; OpenMainCoinPopup(); } if (this.PopupMainCoinWallet != null && this.PopupMainCoinWallet.IsOpen) { this.PopupMainCoinWallet.IsOpen = false; OpenMainCoinWalletPopup(); } }); }, location: this.GetType()); }); #if DEBUG var elapsedMilliseconds = NTStopwatch.Stop(); if (elapsedMilliseconds.ElapsedMilliseconds > NTStopwatch.ElapsedMilliseconds) { Write.DevTimeSpan($"耗时{elapsedMilliseconds} {this.GetType().Name}.ctor"); } #endif }
public void LoadGpuState() { #if DEBUG Write.Stopwatch.Restart(); #endif for (int i = 0; i < Count; i++) { LoadGpuState(i); } #if DEBUG Write.DevTimeSpan($"耗时{Write.Stopwatch.ElapsedMilliseconds}毫秒 {this.GetType().Name}.{nameof(LoadGpuState)}"); #endif }
private NTMinerWalletViewModels() { #if DEBUG NTStopwatch.Start(); #endif if (WpfUtil.IsInDesignMode) { return; } Init(refresh: false); AppRoot.AddEventPath <NTMinerWalletSetInitedEvent>("NTMiner钱包集初始化后", LogEnum.DevConsole, action: message => { Init(refresh: true); }, location: this.GetType()); this.Add = new DelegateCommand(() => { new NTMinerWalletViewModel(Guid.NewGuid()).Edit.Execute(FormType.Add); }); AppRoot.AddEventPath <NTMinerWalletAddedEvent>("添加NTMiner钱包后刷新VM内存", LogEnum.DevConsole, action: message => { if (!_dicById.ContainsKey(message.Source.GetId())) { _dicById.Add(message.Source.GetId(), new NTMinerWalletViewModel(message.Source)); if (AppRoot.CoinVms.TryGetCoinVm(message.Source.CoinCode, out CoinViewModel coinVm)) { coinVm.OnPropertyChanged(nameof(coinVm.NTMinerWallets)); } } }, location: this.GetType()); AppRoot.AddEventPath <NTMinerWalletUpdatedEvent>("更新NTMiner钱包后刷新VM内存", LogEnum.DevConsole, action: message => { if (_dicById.TryGetValue(message.Source.GetId(), out NTMinerWalletViewModel vm)) { vm.Update(message.Source); } }, location: this.GetType()); AppRoot.AddEventPath <NTMinerWalletRemovedEvent>("删除NTMiner钱包后刷新VM内存", LogEnum.DevConsole, action: message => { _dicById.Remove(message.Source.GetId()); if (AppRoot.CoinVms.TryGetCoinVm(message.Source.CoinCode, out CoinViewModel coinVm)) { coinVm.OnPropertyChanged(nameof(coinVm.NTMinerWallets)); } }, location: this.GetType()); #if DEBUG var elapsedMilliseconds = NTStopwatch.Stop(); if (elapsedMilliseconds.ElapsedMilliseconds > NTStopwatch.ElapsedMilliseconds) { Write.DevTimeSpan($"耗时{elapsedMilliseconds} {this.GetType().Name}.ctor"); } #endif }
private static bool NvmlInit() { if (_isNvmlInited) { return(_isNvmlInited); } lock (_locker) { if (_isNvmlInited) { return(_isNvmlInited); } try { #if DEBUG NTStopwatch.Start(); #endif if (!Directory.Exists(_nvsmiDir)) { Directory.CreateDirectory(_nvsmiDir); } if (!File.Exists(_nvmlDllFileFullName) && File.Exists(_nvmlDllFileFullName2)) { File.Copy(_nvmlDllFileFullName2, _nvmlDllFileFullName); } NvmlNativeMethods.SetDllDirectory(_nvsmiDir); var nvmlReturn = NvmlNativeMethods.nvmlInit(); NvmlNativeMethods.SetDllDirectory(null); _isNvmlInited = nvmlReturn == nvmlReturn.Success; // 没什么用,做个防御 if (!_isNvmlInited) { _nvmlInitFailCount++; if (_nvmlInitFailCount >= 10) { _isNvmlInited = true; } } #if DEBUG var elapsedMilliseconds = NTStopwatch.Stop(); if (elapsedMilliseconds.ElapsedMilliseconds > NTStopwatch.ElapsedMilliseconds) { Write.DevTimeSpan($"耗时{elapsedMilliseconds} {nameof(NvmlHelper)}.{nameof(NvmlInit)}()"); } #endif return(_isNvmlInited); } catch (Exception e) { Logger.ErrorDebugLine(e); } return(false); } }
private GpuStatusBarViewModel() { #if DEBUG NTStopwatch.Start(); #endif this.GpuAllVm = AppContext.Instance.GpuVms.Items.FirstOrDefault(a => a.Index == NTMinerRoot.GpuAllId); #if DEBUG var elapsedMilliseconds = NTStopwatch.Stop(); if (elapsedMilliseconds.ElapsedMilliseconds > NTStopwatch.ElapsedMilliseconds) { Write.DevTimeSpan($"耗时{elapsedMilliseconds} {this.GetType().Name}.ctor"); } #endif }
/// <summary> /// 获取NTMiner所支持的所有内核的近处名 /// </summary> /// <param name="kernelSet"></param> /// <returns></returns> public static HashSet <string> GetAllKernelProcessNames(this IKernelSet kernelSet) { #if DEBUG Write.Stopwatch.Restart(); #endif HashSet <string> hashSet = new HashSet <string>(StringComparer.OrdinalIgnoreCase); foreach (var kernel in kernelSet) { hashSet.Add(kernel.GetProcessName()); } #if DEBUG Write.DevTimeSpan($"耗时{Write.Stopwatch.ElapsedMilliseconds}毫秒 {nameof(KernelSetExtension)}.{nameof(GetAllKernelProcessNames)}()"); #endif return(hashSet); }
private OverClockDataViewModels() { #if DEBUG NTStopwatch.Start(); #endif if (WpfUtil.IsInDesignMode) { return; } Init(refresh: false); AppRoot.AddEventPath <OverClockDataSetInitedEvent>("超频菜谱集初始化后", LogEnum.DevConsole, action: message => { Init(refresh: true); }, location: this.GetType()); AppRoot.AddEventPath <OverClockDataAddedEvent>("添加超频菜谱后刷新VM内存", LogEnum.DevConsole, action: message => { if (!_dicById.ContainsKey(message.Source.GetId())) { _dicById.Add(message.Source.GetId(), new OverClockDataViewModel(message.Source)); if (AppRoot.CoinVms.TryGetCoinVm(message.Source.CoinId, out CoinViewModel coinVm)) { coinVm.OnPropertyChanged(nameof(coinVm.OverClockDatas)); } } }, location: this.GetType()); AppRoot.AddEventPath <OverClockDataUpdatedEvent>("更新超频菜谱后刷新VM内存", LogEnum.DevConsole, action: message => { if (_dicById.TryGetValue(message.Source.GetId(), out OverClockDataViewModel vm)) { vm.Update(message.Source); } }, location: this.GetType()); AppRoot.AddEventPath <OverClockDataRemovedEvent>("删除超频菜谱后刷新VM内存", LogEnum.DevConsole, action: message => { _dicById.Remove(message.Source.GetId()); if (AppRoot.CoinVms.TryGetCoinVm(message.Source.CoinId, out CoinViewModel coinVm)) { coinVm.OnPropertyChanged(nameof(coinVm.OverClockDatas)); } }, location: this.GetType()); #if DEBUG var elapsedMilliseconds = NTStopwatch.Stop(); if (elapsedMilliseconds.ElapsedMilliseconds > NTStopwatch.ElapsedMilliseconds) { Write.DevTimeSpan($"耗时{elapsedMilliseconds} {this.GetType().Name}.ctor"); } #endif }
public void LoadGpuState() { #if DEBUG NTStopwatch.Start(); #endif for (int i = 0; i < Count; i++) { LoadGpuState(i); } #if DEBUG var elapsedMilliseconds = NTStopwatch.Stop(); if (elapsedMilliseconds.ElapsedMilliseconds > NTStopwatch.ElapsedMilliseconds) { Write.DevTimeSpan($"耗时{elapsedMilliseconds} {this.GetType().Name}.{nameof(LoadGpuState)}"); } #endif }
private void CreateProcessAsync() { Task.Factory.StartNew(() => { lock (_locker) { try { #if DEBUG NTStopwatch.Start(); #endif // 清理除当前外的Temp/Kernel Cleaner.Instance.Clear(); #if DEBUG var elapsedMilliseconds = NTStopwatch.Stop(); if (elapsedMilliseconds.ElapsedMilliseconds > NTStopwatch.ElapsedMilliseconds) { Write.DevTimeSpan($"耗时{elapsedMilliseconds} {this.GetType().Name}.{nameof(CreateProcessAsync)}[{nameof(Cleaner)}.{nameof(Cleaner.Clear)}]"); } #endif Write.UserOk("场地打扫完毕"); // 应用超频 if (NTMinerContext.Instance.GpuProfileSet.IsOverClockEnabled(MainCoin.GetId())) { Write.UserWarn("应用超频,如果CPU性能较差耗时可能超过1分钟,请耐心等待"); var cmd = new CoinOverClockCommand(coinId: MainCoin.GetId()); AddOnecePath <CoinOverClockDoneEvent>("超频完成后继续流程", LogEnum.DevConsole, message => { // pathId是唯一的,从而可以断定该消息一定是因为该命令而引发的 ContinueCreateProcess(); }, location: this.GetType(), pathId: cmd.MessageId); // 超频是在另一个线程执行的,因为N卡超频当cpu性能非常差时较耗时 VirtualRoot.Execute(cmd); } else { ContinueCreateProcess(); } } catch (Exception e) { Logger.ErrorDebugLine(e); Write.UserFail("挖矿内核启动失败,请联系开发人员解决"); } } }); }
private CoinSnapshotDataViewModels() { if (WpfUtil.IsInDesignMode) { return; } #if DEBUG NTStopwatch.Start(); #endif foreach (var coinVm in AppRoot.CoinVms.AllCoins) { _dicByCoinCode.Add(coinVm.Code, new CoinSnapshotDataViewModel(CoinSnapshotData.CreateEmpty(coinVm.Code))); } #if DEBUG var elapsedMilliseconds = NTStopwatch.Stop(); if (elapsedMilliseconds.ElapsedMilliseconds > NTStopwatch.ElapsedMilliseconds) { Write.DevTimeSpan($"耗时{elapsedMilliseconds} {this.GetType().Name}.ctor"); } #endif }
private void Init() { #if DEBUG Write.Stopwatch.Start(); #endif lock (_locker) { if (!_isInited) { _isInited = true; _localIps = GetLocalIps(); VirtualRoot.RaiseEvent(new LocalIpSetInitedEvent()); } } #if DEBUG // 将近300毫秒 var elapsedMilliseconds = Write.Stopwatch.Stop(); if (elapsedMilliseconds.ElapsedMilliseconds > NTStopwatch.ElapsedMilliseconds) { Write.DevTimeSpan($"耗时{elapsedMilliseconds} {this.GetType().Name}.{nameof(Init)}"); } #endif }
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 static bool NvmlInit() { if (_isNvmlInited) { return(_isNvmlInited); } lock (_nvmlInitLocker) { if (_isNvmlInited) { return(_isNvmlInited); } try { #if DEBUG Write.Stopwatch.Restart(); #endif if (!Directory.Exists(_nvsmiDir)) { Directory.CreateDirectory(_nvsmiDir); } if (!File.Exists(_nvmlDllFileFullName) && File.Exists(_nvmlDllFileFullName2)) { File.Copy(_nvmlDllFileFullName2, _nvmlDllFileFullName); } NvmlNativeMethods.SetDllDirectory(_nvsmiDir); var nvmlReturn = NvmlNativeMethods.nvmlInit(); NvmlNativeMethods.SetDllDirectory(null); _isNvmlInited = nvmlReturn == nvmlReturn.Success; #if DEBUG Write.DevTimeSpan($"耗时{Write.Stopwatch.ElapsedMilliseconds}毫秒 {nameof(NvmlHelper)}.{nameof(NvmlInit)}()"); #endif return(_isNvmlInited); } catch (Exception e) { Logger.ErrorDebugLine(e); } return(false); } }
private StartStopMineButtonViewModel() { if (WpfUtil.IsInDesignMode) { return; } #if DEBUG Write.Stopwatch.Start(); #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 var elapsedMilliseconds = Write.Stopwatch.Stop(); if (elapsedMilliseconds.ElapsedMilliseconds > NTStopwatch.ElapsedMilliseconds) { Write.DevTimeSpan($"耗时{elapsedMilliseconds} {this.GetType().Name}.ctor"); } #endif }
private void OverClock(INTMinerContext root, IGpuProfile data) { #if DEBUG NTStopwatch.Start(); #endif if (root.GpuSet.TryGetGpu(data.Index, out IGpu gpu)) { IOverClock overClock = root.GpuSet.OverClock; if (!data.IsAutoFanSpeed) { overClock.SetFanSpeed(data.Index, data.Cool); } overClock.SetCoreClock(data.Index, data.CoreClockDelta, data.CoreVoltage); overClock.SetMemoryClock(data.Index, data.MemoryClockDelta, data.MemoryVoltage); overClock.SetPowerLimit(data.Index, data.PowerCapacity); overClock.SetTempLimit(data.Index, data.TempLimit); if (data.Index == NTMinerContext.GpuAllId) { Write.UserOk($"统一超频:{data.ToOverClockString()}"); } else { Write.UserOk($"GPU{gpu.Index}超频:{data.ToOverClockString()}"); } 1.SecondsDelay().ContinueWith(t => { overClock.RefreshGpuState(data.Index); }); } #if DEBUG var elapsedMilliseconds = NTStopwatch.Stop(); if (elapsedMilliseconds.ElapsedMilliseconds > NTStopwatch.ElapsedMilliseconds) { Write.DevTimeSpan($"耗时{elapsedMilliseconds} {this.GetType().Name}.OverClock"); } #endif }
private MinerGroupViewModels() { #if DEBUG NTStopwatch.Start(); #endif if (WpfUtil.IsInDesignMode) { return; } foreach (var item in NTMinerContext.Instance.MinerStudioContext.MinerGroupSet.AsEnumerable()) { if (!_dicById.ContainsKey(item.Id)) { _dicById.Add(item.Id, new MinerGroupViewModel(item)); } } AppRoot.AddEventPath <MinerGroupSetInitedEvent>("矿工组集初始化后初始化Vm内存", LogEnum.DevConsole, action: message => { foreach (var item in NTMinerContext.Instance.MinerStudioContext.MinerGroupSet.AsEnumerable()) { if (!_dicById.ContainsKey(item.Id)) { _dicById.Add(item.Id, new MinerGroupViewModel(item)); } } this.OnPropertyChangeds(); MinerClientsWindowViewModel.Instance.RefreshMinerClientsSelectedMinerGroup(MinerClientsWindowViewModel.Instance.MinerClients.ToArray()); }, this.GetType()); this.Add = new DelegateCommand(() => { new MinerGroupViewModel(Guid.NewGuid()).Edit.Execute(FormType.Add); }); AppRoot.AddEventPath <MinerGroupAddedEvent>("添加矿机分组后刷新VM内存", LogEnum.DevConsole, action: message => { if (!_dicById.TryGetValue(message.Source.GetId(), out MinerGroupViewModel vm)) { vm = new MinerGroupViewModel(message.Source); _dicById.Add(message.Source.GetId(), vm); OnPropertyChangeds(); MinerClientsWindowVm.OnPropertyChanged(nameof(MinerClientsWindowViewModel.SelectedMinerGroup)); } }, location: this.GetType()); AppRoot.AddEventPath <MinerGroupUpdatedEvent>("添加矿机分组后刷新VM内存", LogEnum.DevConsole, action: message => { if (_dicById.TryGetValue(message.Source.GetId(), out MinerGroupViewModel vm)) { vm.Update(message.Source); } }, location: this.GetType()); AppRoot.AddEventPath <MinerGroupRemovedEvent>("移除了矿机组后刷新Vm内容", LogEnum.DevConsole, action: message => { if (_dicById.TryGetValue(message.Source.Id, out MinerGroupViewModel vm)) { _dicById.Remove(vm.Id); OnPropertyChangeds(); MinerClientsWindowVm.OnPropertyChanged(nameof(MinerClientsWindowViewModel.SelectedMinerGroup)); } }, this.GetType()); #if DEBUG var elapsedMilliseconds = NTStopwatch.Stop(); if (elapsedMilliseconds.ElapsedMilliseconds > NTStopwatch.ElapsedMilliseconds) { Write.DevTimeSpan($"耗时{elapsedMilliseconds} {this.GetType().Name}.ctor"); } #endif }
public MinerProfileViewModel() { #if DEBUG NTStopwatch.Start(); #endif if (WpfUtil.IsInDesignMode) { return; } if (Instance != null) { throw new InvalidProgramException(); } if (this.IsCreateShortcut) { CreateShortcut(); } this.Up = new DelegateCommand <string>(propertyName => { PropertyInfo propertyInfo = this.GetType().GetProperty(propertyName); if (propertyInfo != null) { if (propertyInfo.PropertyType == typeof(int)) { propertyInfo.SetValue(this, (int)propertyInfo.GetValue(this, null) + 1, null); } else if (propertyInfo.PropertyType == typeof(double)) { propertyInfo.SetValue(this, Math.Round((double)propertyInfo.GetValue(this, null) + 0.1, 2), null); } } else { Write.DevError($"类型{this.GetType().FullName}不具有名称为{propertyName}的属性"); } }); this.Down = new DelegateCommand <string>(propertyName => { PropertyInfo propertyInfo = this.GetType().GetProperty(propertyName); if (propertyInfo != null) { if (propertyInfo.PropertyType == typeof(int)) { int value = (int)propertyInfo.GetValue(this, null); if (value > 0) { propertyInfo.SetValue(this, value - 1, null); } } else if (propertyInfo.PropertyType == typeof(double)) { double value = (double)propertyInfo.GetValue(this, null); if (value > 0.1) { propertyInfo.SetValue(this, Math.Round(value - 0.1, 2), null); } } } else { Write.DevError($"类型{this.GetType().FullName}不具有名称为{propertyName}的属性"); } }); NTMinerRoot.SetRefreshArgsAssembly(() => { #if DEBUG NTStopwatch.Start(); #endif 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); } } } NTMinerRoot.Instance.CurrentMineContext = NTMinerRoot.Instance.CreateMineContext(); if (NTMinerRoot.Instance.CurrentMineContext != null) { this.ArgsAssembly = NTMinerRoot.Instance.CurrentMineContext.CommandLine; } else { this.ArgsAssembly = string.Empty; } #if DEBUG var milliseconds = NTStopwatch.Stop(); if (milliseconds.ElapsedMilliseconds > NTStopwatch.ElapsedMilliseconds) { Write.DevTimeSpan($"耗时{milliseconds} {this.GetType().Name}.SetRefreshArgsAssembly"); } #endif }); VirtualRoot.AddEventPath <ServerContextVmsReInitedEvent>("ServerContext的VM集刷新后刷新视图界面", LogEnum.DevConsole, action: message => { OnPropertyChanged(nameof(CoinVm)); }, location: this.GetType()); AppContext.AddCmdPath <RefreshAutoBootStartCommand>("刷新开机启动和自动挖矿的展示", LogEnum.DevConsole, action: message => { MinerProfileData data = NTMinerRoot.CreateLocalRepository <MinerProfileData>().GetByKey(this.Id); if (data != null) { this.IsAutoBoot = data.IsAutoBoot; this.IsAutoStart = data.IsAutoStart; } }, location: this.GetType()); AppContext.AddEventPath <MinerProfilePropertyChangedEvent>("MinerProfile设置变更后刷新VM内存", LogEnum.DevConsole, action: message => { OnPropertyChanged(message.PropertyName); }, location: this.GetType()); VirtualRoot.AddEventPath <LocalContextVmsReInitedEvent>("本地上下文视图模型集刷新后刷新界面", LogEnum.DevConsole, action: message => { AllPropertyChanged(); if (CoinVm != null) { CoinVm.OnPropertyChanged(nameof(CoinVm.Wallets)); CoinVm.CoinKernel?.CoinKernelProfile.SelectedDualCoin?.OnPropertyChanged(nameof(CoinVm.Wallets)); CoinVm.CoinProfile.OnPropertyChanged(nameof(CoinVm.CoinProfile.SelectedWallet)); CoinVm.CoinKernel?.CoinKernelProfile.SelectedDualCoin?.CoinProfile.OnPropertyChanged(nameof(CoinVm.CoinProfile.SelectedDualCoinWallet)); } }, location: this.GetType()); #if DEBUG var elapsedMilliseconds = NTStopwatch.Stop(); if (elapsedMilliseconds.ElapsedMilliseconds > NTStopwatch.ElapsedMilliseconds) { Write.DevTimeSpan($"耗时{elapsedMilliseconds} {this.GetType().Name}.ctor"); } #endif }
public MainWindow() { this.MinHeight = 430; this.MinWidth = 640; this.Width = AppStatic.MainWindowWidth; this.Height = AppStatic.MainWindowHeight; #if DEBUG Write.Stopwatch.Restart(); #endif UIThread.StartTimer(); InitializeComponent(); NTMinerRoot.RefreshArgsAssembly.Invoke(); if (Design.IsInDesignMode) { return; } this.StateChanged += (s, e) => { if (Vm.MinerProfile.IsShowInTaskbar) { ShowInTaskbar = true; } else { if (WindowState == WindowState.Minimized) { ShowInTaskbar = false; } else { ShowInTaskbar = true; } } }; this.SizeChanged += (object sender, SizeChangedEventArgs e) => { if (e.WidthChanged) { const double width = 800; if (e.NewSize.Width < width) { Collapse(); } else if (e.NewSize.Width >= width) { Expand(); } } }; this.ConsoleRectangle.SizeChanged += (object sender, SizeChangedEventArgs e) => { ReSizeConsoleWindow(); }; EventHandler changeNotiCenterWindowLocation = NotiCenterWindow.CreateNotiCenterWindowLocationManager(this); this.Activated += changeNotiCenterWindowLocation; this.LocationChanged += changeNotiCenterWindowLocation; if (DevMode.IsDevMode) { this.On <ServerJsonVersionChangedEvent>("开发者模式展示ServerJsonVersion", LogEnum.DevConsole, action: message => { UIThread.Execute(() => { Vm.ServerJsonVersion = Vm.GetServerJsonVersion(); }); }); } this.On <PoolDelayPickedEvent>("从内核输出中提取了矿池延时时展示到界面", LogEnum.DevConsole, action: message => { UIThread.Execute(() => { if (message.IsDual) { Vm.StateBarVm.DualPoolDelayText = message.PoolDelayText; } else { Vm.StateBarVm.PoolDelayText = message.PoolDelayText; } }); }); this.On <MineStartedEvent>("开始挖矿后将清空矿池延时", LogEnum.DevConsole, action: message => { UIThread.Execute(() => { Vm.StateBarVm.PoolDelayText = string.Empty; Vm.StateBarVm.DualPoolDelayText = string.Empty; }); }); this.On <MineStopedEvent>("停止挖矿后将清空矿池延时", LogEnum.DevConsole, action: message => { UIThread.Execute(() => { Vm.StateBarVm.PoolDelayText = string.Empty; Vm.StateBarVm.DualPoolDelayText = string.Empty; }); }); this.On <Per1MinuteEvent>("挖矿中时自动切换为无界面模式 和 守护进程状态显示", LogEnum.DevConsole, action: message => { if (NTMinerRoot.IsUiVisible && NTMinerRoot.GetIsAutoNoUi() && NTMinerRoot.Instance.IsMining) { if (NTMinerRoot.MainWindowRendedOn.AddMinutes(NTMinerRoot.GetAutoNoUiMinutes()) < message.Timestamp) { VirtualRoot.Execute(new CloseMainWindowCommand($"界面展示{NTMinerRoot.GetAutoNoUiMinutes()}分钟后自动切换为无界面模式,可在选项页调整配置")); } } Vm.RefreshDaemonStateBrush(); }); #if DEBUG Write.DevTimeSpan($"耗时{Write.Stopwatch.ElapsedMilliseconds}毫秒 {this.GetType().Name}.ctor"); #endif }
public StateBar() { #if DEBUG NTStopwatch.Start(); #endif InitializeComponent(); if (WpfUtil.IsInDesignMode) { return; } this.RunOneceOnLoaded((window) => { window.Activated += (object sender, EventArgs e) => { Vm.OnPropertyChanged(nameof(Vm.IsAutoAdminLogon)); Vm.OnPropertyChanged(nameof(Vm.AutoAdminLogonToolTip)); Vm.OnPropertyChanged(nameof(Vm.IsRemoteDesktopEnabled)); Vm.OnPropertyChanged(nameof(Vm.RemoteDesktopToolTip)); }; window.AddEventPath <LocalIpSetInitedEvent>("本机IP集刷新后刷新状态栏", LogEnum.DevConsole, action: message => { UIThread.Execute(() => Vm.RefreshLocalIps()); }, location: this.GetType()); window.AddEventPath <MinutePartChangedEvent>("时间的分钟部分变更过更新计时器显示", LogEnum.None, action: message => { UIThread.Execute(() => { Vm.UpdateDateTime(); }); }, location: this.GetType()); window.AddEventPath <Per1SecondEvent>("挖矿计时秒表", LogEnum.None, action: message => { UIThread.Execute(() => { DateTime now = DateTime.Now; Vm.UpdateBootTimeSpan(now - NTMinerRoot.Instance.CreatedOn); var mineContext = NTMinerRoot.Instance.LockedMineContext; if (mineContext != null) { Vm.UpdateMineTimeSpan(now - mineContext.CreatedOn); } }); }, location: this.GetType()); window.AddEventPath <AppVersionChangedEvent>("发现了服务端新版本", LogEnum.DevConsole, action: message => { UIThread.Execute(() => { Vm.SetCheckUpdateForeground(isLatest: EntryAssemblyInfo.CurrentVersion >= NTMinerRoot.ServerVersion); }); }, location: this.GetType()); window.AddEventPath <KernelSelfRestartedEvent>("内核自我重启时刷新计数器", LogEnum.DevConsole, action: message => { UIThread.Execute(() => { Vm.OnPropertyChanged(nameof(Vm.KernelSelfRestartCountText)); }); }, location: this.GetType()); window.AddEventPath <MineStartedEvent>("挖矿开始后将内核自我重启计数清零", LogEnum.DevConsole, action: message => { UIThread.Execute(() => { Vm.OnPropertyChanged(nameof(Vm.KernelSelfRestartCountText)); }); }, location: this.GetType()); }); var gpuSet = NTMinerRoot.Instance.GpuSet; // 建议每张显卡至少对应4G虚拟内存,否则标红 if (NTMinerRoot.OSVirtualMemoryMb < gpuSet.Count * 4) { BtnShowVirtualMemory.Foreground = WpfUtil.RedBrush; } #if DEBUG var elapsedMilliseconds = NTStopwatch.Stop(); if (elapsedMilliseconds.ElapsedMilliseconds > NTStopwatch.ElapsedMilliseconds) { Write.DevTimeSpan($"耗时{elapsedMilliseconds} {this.GetType().Name}.ctor"); } #endif }
public AMDGpuSet(INTMinerRoot root) : this() { #if DEBUG Write.Stopwatch.Restart(); #endif _root = root; adlHelper.Init(); this.OverClock = new GpuOverClock(adlHelper); int deviceCount = 0; deviceCount = adlHelper.GpuCount; for (int i = 0; i < deviceCount; i++) { var atiGpu = adlHelper.GetGpuName(i); string name = atiGpu.AdapterName; // short gpu name if (!string.IsNullOrEmpty(name)) { name = name.Replace("Radeon (TM) RX ", string.Empty); name = name.Replace("Radeon RX ", string.Empty); } var gpu = Gpu.Create(i, atiGpu.BusNumber.ToString(), name); gpu.TotalMemory = adlHelper.GetTotalMemory(i); _gpus.Add(i, gpu); } if (deviceCount > 0) { this.DriverVersion = adlHelper.GetDriverVersion(); this.Properties.Add(new GpuSetProperty(GpuSetProperty.DRIVER_VERSION, "驱动版本", DriverVersion)); const ulong minG = (ulong)5 * 1024 * 1024 * 1024; bool has470 = _gpus.Any(a => a.Key != NTMinerRoot.GpuAllId && a.Value.TotalMemory < minG); if (has470) { Dictionary <string, string> kvs = new Dictionary <string, string> { { "GPU_MAX_ALLOC_PERCENT", "100" }, { "GPU_MAX_HEAP_SIZE", "100" }, { "GPU_SINGLE_ALLOC_PERCENT", "100" } }; foreach (var kv in kvs) { var property = new GpuSetProperty(kv.Key, kv.Key, kv.Value); this.Properties.Add(property); } Task.Factory.StartNew(() => { OverClock.RefreshGpuState(NTMinerRoot.GpuAllId); foreach (var kv in kvs) { Environment.SetEnvironmentVariable(kv.Key, kv.Value); } }); } else { Task.Factory.StartNew(() => { OverClock.RefreshGpuState(NTMinerRoot.GpuAllId); }); } } #if DEBUG Write.DevTimeSpan($"耗时{Write.Stopwatch.ElapsedMilliseconds}毫秒 {this.GetType().Name}.ctor"); #endif }
public MinerProfileViewModel() { #if DEBUG Write.Stopwatch.Restart(); #endif if (WpfUtil.IsInDesignMode) { return; } if (Instance != null) { throw new InvalidProgramException(); } if (this.IsCreateShortcut) { CreateShortcut(); } 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.NoShareRestartComputerMinutesUp = new DelegateCommand(() => { this.NoShareRestartComputerMinutes++; }); this.NoShareRestartComputerMinutesDown = new DelegateCommand(() => { if (this.NoShareRestartComputerMinutes > 0) { this.NoShareRestartComputerMinutes--; } }); 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.CpuGETemperatureSecondsUp = new DelegateCommand(() => { this.CpuGETemperatureSeconds++; }); this.CpuGETemperatureSecondsDown = new DelegateCommand(() => { this.CpuGETemperatureSeconds--; }); this.CpuStopTemperatureUp = new DelegateCommand(() => { this.CpuStopTemperature++; }); this.CpuStopTemperatureDown = new DelegateCommand(() => { this.CpuStopTemperature--; }); this.CpuLETemperatureSecondsUp = new DelegateCommand(() => { this.CpuLETemperatureSeconds++; }); this.CpuLETemperatureSecondsDown = new DelegateCommand(() => { this.CpuLETemperatureSeconds--; }); this.CpuStartTemperatureUp = new DelegateCommand(() => { this.CpuStartTemperature++; }); this.CpuStartTemperatureDown = new DelegateCommand(() => { this.CpuStartTemperature--; }); 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.BuildEventPath <ServerContextVmsReInitedEvent>("ServerContext的VM集刷新后刷新视图界面", LogEnum.DevConsole, action: message => { OnPropertyChanged(nameof(CoinVm)); }); AppContext.AppContextCmdPath <RefreshAutoBootStartCommand>("刷新开机启动和自动挖矿的展示", LogEnum.DevConsole, action: message => { MinerProfileData data = NTMinerRoot.CreateLocalRepository <MinerProfileData>().GetByKey(this.Id); if (data != null) { this.IsAutoBoot = data.IsAutoBoot; this.IsAutoStart = data.IsAutoStart; } }); AppContext.AppContextEventPath <MinerProfilePropertyChangedEvent>("MinerProfile设置变更后刷新VM内存", LogEnum.DevConsole, action: message => { OnPropertyChanged(message.PropertyName); }); VirtualRoot.BuildEventPath <LocalContextVmsReInitedEvent>("本地上下文视图模型集刷新后刷新界面", LogEnum.DevConsole, action: message => { AllPropertyChanged(); if (CoinVm != null) { CoinVm.OnPropertyChanged(nameof(CoinVm.Wallets)); CoinVm.CoinKernel?.CoinKernelProfile.SelectedDualCoin?.OnPropertyChanged(nameof(CoinVm.Wallets)); CoinVm.CoinProfile.OnPropertyChanged(nameof(CoinVm.CoinProfile.SelectedWallet)); CoinVm.CoinKernel?.CoinKernelProfile.SelectedDualCoin?.CoinProfile.OnPropertyChanged(nameof(CoinVm.CoinProfile.SelectedDualCoinWallet)); } }); #if DEBUG Write.DevTimeSpan($"耗时{Write.Stopwatch.ElapsedMilliseconds}毫秒 {this.GetType().Name}.ctor"); #endif }
public MainWindow() { this.MinHeight = 430; this.MinWidth = 640; this.Width = AppStatic.MainWindowWidth; this.Height = AppStatic.MainWindowHeight; #if DEBUG Write.Stopwatch.Start(); #endif this.Loaded += (sender, e) => { ConsoleWindow.Instance.Show(); ConsoleWindow.Instance.MouseDown += (ss, ee) => { MoveConsoleWindow(); }; this.Owner = ConsoleWindow.Instance; hwndSource = PresentationSource.FromVisual((Visual)sender) as HwndSource; hwndSource.AddHook(new HwndSourceHook(Win32MessageProc.WindowProc)); MoveConsoleWindow(); }; InitializeComponent(); BtnMinerProfileGrip.Visibility = Visibility.Collapsed; if (WpfUtil.IsInDesignMode) { return; } UIThread.StartTimer(); _borderBrush = this.BorderBrush; DateTime lastGetServerMessageOn = DateTime.MinValue; NTMinerRoot.RefreshArgsAssembly.Invoke(); // 切换了主界面上的Tab时 this.MainArea.SelectionChanged += (sender, e) => { // 延迟创建,以加快主界面的启动 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()); } } }; this.IsVisibleChanged += (sender, e) => { if (this.IsVisible) { NTMinerRoot.IsUiVisible = true; NTMinerRoot.MainWindowRendedOn = DateTime.Now; } else { NTMinerRoot.IsUiVisible = false; } MoveConsoleWindow(); }; this.ConsoleRectangle.IsVisibleChanged += (sender, e) => { MoveConsoleWindow(); }; this.StateChanged += (s, e) => { if (Vm.MinerProfile.IsShowInTaskbar) { ShowInTaskbar = true; } else { if (WindowState == WindowState.Minimized) { ShowInTaskbar = false; } else { ShowInTaskbar = true; } } if (WindowState == WindowState.Maximized) { ResizeCursors.Visibility = Visibility.Collapsed; this.BorderBrush = WpfUtil.BlackBrush; } else { ResizeCursors.Visibility = Visibility.Visible; this.BorderBrush = _borderBrush; } MoveConsoleWindow(); }; this.ConsoleRectangle.SizeChanged += (s, e) => { MoveConsoleWindow(); }; NotiCenterWindow.Bind(this, ownerIsTopMost: true); this.LocationChanged += (sender, e) => { MoveConsoleWindow(); }; VirtualRoot.BuildCmdPath <CloseMainWindowCommand>(action: message => { UIThread.Execute(() => { this.Close(); }); }); this.BuildEventPath <PoolDelayPickedEvent>("从内核输出中提取了矿池延时时展示到界面", LogEnum.DevConsole, action: message => { UIThread.Execute(() => { if (message.IsDual) { Vm.StateBarVm.DualPoolDelayText = message.PoolDelayText; } else { Vm.StateBarVm.PoolDelayText = message.PoolDelayText; } }); }); this.BuildEventPath <MineStartedEvent>("开始挖矿后将清空矿池延时", LogEnum.DevConsole, action: message => { UIThread.Execute(() => { Vm.StateBarVm.PoolDelayText = string.Empty; Vm.StateBarVm.DualPoolDelayText = string.Empty; }); }); this.BuildEventPath <MineStopedEvent>("停止挖矿后将清空矿池延时", LogEnum.DevConsole, action: message => { UIThread.Execute(() => { Vm.StateBarVm.PoolDelayText = string.Empty; Vm.StateBarVm.DualPoolDelayText = string.Empty; }); }); this.BuildEventPath <Per1MinuteEvent>("挖矿中时自动切换为无界面模式 和 守护进程状态显示", LogEnum.DevConsole, action: message => { if (NTMinerRoot.IsUiVisible && NTMinerRoot.Instance.MinerProfile.IsAutoNoUi && NTMinerRoot.Instance.IsMining) { if (NTMinerRoot.MainWindowRendedOn.AddMinutes(NTMinerRoot.Instance.MinerProfile.AutoNoUiMinutes) < message.Timestamp) { VirtualRoot.Out.ShowSuccess($"界面展示{NTMinerRoot.Instance.MinerProfile.AutoNoUiMinutes}分钟后自动切换为无界面模式,可在选项页调整配置", "开源矿工"); VirtualRoot.Execute(new CloseMainWindowCommand()); } } }); this.BuildEventPath <CpuPackageStateChangedEvent>("CPU包状态变更后刷新Vm内存", LogEnum.None, action: message => { UIThread.Execute(UpdateCpuView); }); #if DEBUG var elapsedMilliseconds = Write.Stopwatch.Stop(); if (elapsedMilliseconds.ElapsedMilliseconds > NTStopwatch.ElapsedMilliseconds) { Write.DevTimeSpan($"耗时{elapsedMilliseconds} {this.GetType().Name}.ctor"); } #endif }
public MainWindow() { if (WpfUtil.IsInDesignMode) { return; } this.MinHeight = 430; this.MinWidth = 640; this.Width = AppRoot.MainWindowWidth; this.Height = AppRoot.MainWindowHeight; #if DEBUG NTStopwatch.Start(); #endif ConsoleWindow.Instance.Show(); ConsoleWindow.Instance.MouseDown += (sender, e) => { MoveConsoleWindow(); }; this.Owner = ConsoleWindow.Instance; 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 }; this.ConsoleRectangle.IsVisibleChanged += (sender, e) => { MoveConsoleWindow(); }; this.ConsoleRectangle.SizeChanged += (s, e) => { MoveConsoleWindow(); }; this.SizeChanged += (s, e) => { #region if (this.Width < 860) { this.CloseLeftDrawer(); this.BtnAboutNTMiner.Visibility = Visibility.Collapsed; } else { this.OpenLeftDrawer(); 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.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 (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()); 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 }
private ColumnsShowViewModels() { if (WpfUtil.IsInDesignMode) { return; } #if DEBUG NTStopwatch.Start(); #endif this.Add = new DelegateCommand(() => { WpfUtil.ShowInputDialog("列分组名称", string.Empty, string.Empty, columnsShowName => { if (string.IsNullOrEmpty(columnsShowName)) { return("列分组名称是必须的"); } return(string.Empty); }, onOk: columnsShowName => { ColumnsShowData entity = new ColumnsShowData { ColumnsShowName = columnsShowName, LastActivedOnText = true, BootTimeSpanText = true, MineTimeSpanText = true, Work = true, MinerGroup = true, MinerName = true, WorkerName = true, LocalIp = true, MinerIp = true, GpuType = true, MainCoinCode = true, MainCoinSpeedText = true, MainCoinRejectPercentText = true }; NTMinerContext.Instance.MinerStudioContext.ColumnsShowSet.AddOrUpdate(entity); }); }); AppRoot.AddEventPath <ColumnsShowAddedOrUpdatedEvent>("添加或修改了列分组后刷新VM内存", LogEnum.DevConsole, action: message => { if (!_dicById.TryGetValue(message.Source.GetId(), out ColumnsShowViewModel vm)) { vm = new ColumnsShowViewModel(message.Source); _dicById.Add(message.Source.GetId(), vm); OnPropertyChanged(nameof(List)); MinerClientsWindowVm.ColumnsShow = vm; } else { vm.Update(message.Source); } }, location: this.GetType()); AppRoot.AddEventPath <ColumnsRemovedEvent>("删除了列分组后刷新Vm内存", LogEnum.DevConsole, action: message => { if (_dicById.ContainsKey(message.Source.Id)) { _dicById.Remove(message.Source.Id); OnPropertyChanged(nameof(List)); if (_dicById.TryGetValue(ColumnsShowData.PleaseSelect.Id, out ColumnsShowViewModel vm)) { MinerClientsWindowVm.ColumnsShow = vm; } } }, this.GetType()); foreach (var item in NTMinerContext.Instance.MinerStudioContext.ColumnsShowSet.GetAll()) { _dicById.Add(item.Id, new ColumnsShowViewModel(item)); } #if DEBUG var elapsedMilliseconds = NTStopwatch.Stop(); if (elapsedMilliseconds.ElapsedMilliseconds > NTStopwatch.ElapsedMilliseconds) { Write.DevTimeSpan($"耗时{elapsedMilliseconds} {this.GetType().Name}.ctor"); } #endif }
public MinerProfileViewModel() { #if DEBUG NTStopwatch.Start(); #endif if (WpfUtil.IsInDesignMode) { return; } if (Instance != null) { throw new InvalidProgramException(); } if (this.IsCreateShortcut) { CreateShortcut(); } this.Up = new DelegateCommand <string>(propertyName => { #region if (!_propertyInfos.TryGetValue(propertyName, out PropertyInfo propertyInfo)) { propertyInfo = this.GetType().GetProperty(propertyName); if (propertyInfo == null) { Write.DevError(() => $"类型{this.GetType().FullName}不具有名称为{propertyName}的属性"); return; } _propertyInfos.Add(propertyName, propertyInfo); } if (propertyInfo.PropertyType == typeof(int)) { propertyInfo.SetValue(this, (int)propertyInfo.GetValue(this, null) + 1, null); } else if (propertyInfo.PropertyType == typeof(double)) { propertyInfo.SetValue(this, Math.Round((double)propertyInfo.GetValue(this, null) + 0.1, 2), null); } #endregion }); this.Down = new DelegateCommand <string>(propertyName => { #region if (!_propertyInfos.TryGetValue(propertyName, out PropertyInfo propertyInfo)) { propertyInfo = this.GetType().GetProperty(propertyName); if (propertyInfo == null) { Write.DevError(() => $"类型{this.GetType().FullName}不具有名称为{propertyName}的属性"); return; } _propertyInfos.Add(propertyName, propertyInfo); } if (propertyInfo.PropertyType == typeof(int)) { int value = (int)propertyInfo.GetValue(this, null); if (value > 0) { propertyInfo.SetValue(this, value - 1, null); } } else if (propertyInfo.PropertyType == typeof(double)) { double value = (double)propertyInfo.GetValue(this, null); if (value > 0.1) { propertyInfo.SetValue(this, Math.Round(value - 0.1, 2), null); } } #endregion }); this.WsRetry = new DelegateCommand(() => { RpcRoot.Client.NTMinerDaemonService.StartOrStopWsAsync(isResetFailCount: true); IsConnecting = true; }); bool isRefreshed = false; if (ClientAppType.IsMinerClient) { VirtualRoot.AddEventPath <StartingMineFailedEvent>("开始挖矿失败", LogEnum.DevConsole, action: message => { IsMining = false; Write.UserError(message.Message); }, location: this.GetType()); // 群控客户端已经有一个执行RefreshWsStateCommand命令的路径了 VirtualRoot.AddCmdPath <RefreshWsStateCommand>(message => { #region if (message.WsClientState != null) { isRefreshed = true; this.IsWsOnline = message.WsClientState.Status == WsClientStatus.Open; if (message.WsClientState.ToOut) { VirtualRoot.Out.ShowWarn(message.WsClientState.Description, autoHideSeconds: 3); } if (!message.WsClientState.ToOut || !this.IsWsOnline) { this.WsDescription = message.WsClientState.Description; } if (!this.IsWsOnline) { if (message.WsClientState.LastTryOn != DateTime.MinValue) { this.WsLastTryOn = message.WsClientState.LastTryOn; } if (message.WsClientState.NextTrySecondsDelay > 0) { WsNextTrySecondsDelay = message.WsClientState.NextTrySecondsDelay; } } } #endregion }, this.GetType(), LogEnum.DevConsole); VirtualRoot.AddEventPath <Per1SecondEvent>("外网群控重试秒表倒计时", LogEnum.None, action: message => { if (IsOuterUserEnabled && !IsWsOnline) { if (WsNextTrySecondsDelay > 0) { WsNextTrySecondsDelay--; } OnPropertyChanged(nameof(WsLastTryOnText)); } }, this.GetType()); VirtualRoot.AddEventPath <WsServerOkEvent>("服务器Ws服务已可用", LogEnum.DevConsole, action: message => { if (IsOuterUserEnabled && !IsWsOnline) { StartOrStopWs(); } }, this.GetType()); if (IsOuterUserEnabled) { RpcRoot.Client.NTMinerDaemonService.GetWsDaemonStateAsync((WsClientState state, Exception e) => { if (state != null && !isRefreshed) { this.IsWsOnline = state.Status == WsClientStatus.Open; this.WsDescription = state.Description; if (state.NextTrySecondsDelay > 0) { this.WsNextTrySecondsDelay = state.NextTrySecondsDelay; } this.WsLastTryOn = state.LastTryOn; } }); } } NTMinerContext.SetRefreshArgsAssembly((reason) => { Write.DevDebug(() => $"RefreshArgsAssembly" + reason, ConsoleColor.Cyan); #if DEBUG NTStopwatch.Start(); #endif #region 确保双挖权重在合法的范围内 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; } NTMinerContext.Instance.MinerProfile.SetCoinKernelProfileProperty(coinKernelProfile.CoinKernelId, nameof(coinKernelProfile.DualCoinWeight), coinKernelProfile.DualCoinWeight); } } } #endregion NTMinerContext.Instance.CurrentMineContext = NTMinerContext.Instance.CreateMineContext(); if (NTMinerContext.Instance.CurrentMineContext != null) { this.ArgsAssembly = NTMinerContext.Instance.CurrentMineContext.CommandLine; } else { this.ArgsAssembly = string.Empty; } #if DEBUG var milliseconds = NTStopwatch.Stop(); if (milliseconds.ElapsedMilliseconds > NTStopwatch.ElapsedMilliseconds) { Write.DevTimeSpan($"耗时{milliseconds} {this.GetType().Name}.SetRefreshArgsAssembly"); } #endif }); VirtualRoot.AddEventPath <ServerContextVmsReInitedEvent>("ServerContext的VM集刷新后刷新视图界面", LogEnum.DevConsole, action: message => { OnPropertyChanged(nameof(CoinVm)); }, location: this.GetType()); AppRoot.AddCmdPath <RefreshAutoBootStartCommand>("刷新开机启动和自动挖矿的展示", LogEnum.DevConsole, action: message => { MinerProfileData data = NTMinerContext.Instance.ServerContext.CreateLocalRepository <MinerProfileData>().GetByKey(this.Id); if (data != null) { this.IsAutoBoot = data.IsAutoBoot; this.IsAutoStart = data.IsAutoStart; } }, location: this.GetType()); AppRoot.AddEventPath <MinerProfilePropertyChangedEvent>("MinerProfile设置变更后刷新VM内存", LogEnum.DevConsole, action: message => { OnPropertyChanged(message.PropertyName); }, location: this.GetType()); VirtualRoot.AddEventPath <LocalContextVmsReInitedEvent>("本地上下文视图模型集刷新后刷新界面", LogEnum.DevConsole, action: message => { AllPropertyChanged(); if (CoinVm != null) { CoinVm.OnPropertyChanged(nameof(CoinVm.Wallets)); CoinVm.CoinKernel?.CoinKernelProfile.SelectedDualCoin?.OnPropertyChanged(nameof(CoinVm.Wallets)); CoinVm.CoinProfile?.OnPropertyChanged(nameof(CoinVm.CoinProfile.SelectedWallet)); CoinVm.CoinKernel?.CoinKernelProfile.SelectedDualCoin?.CoinProfile?.OnPropertyChanged(nameof(CoinVm.CoinProfile.SelectedDualCoinWallet)); } }, location: this.GetType()); VirtualRoot.AddEventPath <CoinVmAddedEvent>("Vm集添加了新币种后刷新MinerProfileVm内存", LogEnum.DevConsole, action: message => { OnPropertyChanged(nameof(CoinVm)); }, this.GetType()); VirtualRoot.AddEventPath <CoinVmRemovedEvent>("Vm集删除了新币种后刷新MinerProfileVm内存", LogEnum.DevConsole, action: message => { OnPropertyChanged(nameof(CoinVm)); }, this.GetType()); #if DEBUG var elapsedMilliseconds = NTStopwatch.Stop(); if (elapsedMilliseconds.ElapsedMilliseconds > NTStopwatch.ElapsedMilliseconds) { Write.DevTimeSpan($"耗时{elapsedMilliseconds} {this.GetType().Name}.ctor"); } #endif }
public MainWindow() { this.MinHeight = 430; this.MinWidth = 640; this.Width = AppStatic.MainWindowWidth; this.Height = AppStatic.MainWindowHeight; #if DEBUG Write.Stopwatch.Restart(); #endif UIThread.StartTimer(); ConsoleWindow.Instance.OnSplashHided = MoveConsoleWindow; this.Owner = ConsoleWindow.Instance; InitializeComponent(); this.MainArea.SelectionChanged += (sender, e) => { var selectedItem = MainArea.SelectedItem; if (selectedItem == TabItemToolbox) { if (ToolboxContainer.Child == null) { ToolboxContainer.Child = new Toolbox(); } } else if (selectedItem == TabItemMinerProfileOption) { if (MinerProfileOptionContainer.Child == null) { MinerProfileOptionContainer.Child = new MinerProfileOption(); } } }; _borderBrush = this.BorderBrush; NTMinerRoot.RefreshArgsAssembly.Invoke(); if (Design.IsInDesignMode) { return; } ToogleLeft(); this.IsVisibleChanged += (sender, e) => { if (this.IsVisible) { NTMinerRoot.IsUiVisible = true; NTMinerRoot.MainWindowRendedOn = DateTime.Now; } else { NTMinerRoot.IsUiVisible = false; } MoveConsoleWindow(); }; this.ConsoleRectangle.IsVisibleChanged += (sender, e) => { MoveConsoleWindow(); }; this.StateChanged += (s, e) => { if (Vm.MinerProfile.IsShowInTaskbar) { ShowInTaskbar = true; } else { if (WindowState == WindowState.Minimized) { ShowInTaskbar = false; } else { ShowInTaskbar = true; } } if (WindowState == WindowState.Maximized) { ResizeCursors.Visibility = Visibility.Collapsed; this.BorderBrush = WpfUtil.BlackBrush; } else { ResizeCursors.Visibility = Visibility.Visible; this.BorderBrush = _borderBrush; } MoveConsoleWindow(); }; this.SizeChanged += (s, e) => { if (!ConsoleRectangle.IsVisible) { ConsoleWindow.Instance.Hide(); } }; this.ConsoleRectangle.SizeChanged += (s, e) => { MoveConsoleWindow(); }; EventHandler changeNotiCenterWindowLocation = NotiCenterWindow.CreateNotiCenterWindowLocationManager(this); this.Activated += (sender, e) => { changeNotiCenterWindowLocation(sender, e); NotiCenterWindow.Instance.SwitchOwner(this); }; this.LocationChanged += (sender, e) => { MoveConsoleWindow(); changeNotiCenterWindowLocation(sender, e); }; VirtualRoot.BuildCmdPath <CloseMainWindowCommand>(action: message => { UIThread.Execute(() => { if (NTMinerRoot.Instance.MinerProfile.IsCloseMeanExit) { VirtualRoot.Execute(new CloseNTMinerCommand()); return; } this.Close(); VirtualRoot.Out.ShowSuccess(message.Message, "开源矿工"); }); }); if (DevMode.IsDevMode) { this.WindowContextEventPath <ServerJsonVersionChangedEvent>("开发者模式展示ServerJsonVersion", LogEnum.DevConsole, action: message => { UIThread.Execute(() => { Vm.ServerJsonVersion = NTMinerRoot.Instance.GetServerJsonVersion(); }); }); } this.WindowContextEventPath <PoolDelayPickedEvent>("从内核输出中提取了矿池延时时展示到界面", LogEnum.DevConsole, action: message => { UIThread.Execute(() => { if (message.IsDual) { Vm.StateBarVm.DualPoolDelayText = message.PoolDelayText; } else { Vm.StateBarVm.PoolDelayText = message.PoolDelayText; } }); }); this.WindowContextEventPath <MineStartedEvent>("开始挖矿后将清空矿池延时", LogEnum.DevConsole, action: message => { UIThread.Execute(() => { Vm.StateBarVm.PoolDelayText = string.Empty; Vm.StateBarVm.DualPoolDelayText = string.Empty; }); }); this.WindowContextEventPath <MineStopedEvent>("停止挖矿后将清空矿池延时", LogEnum.DevConsole, action: message => { UIThread.Execute(() => { Vm.StateBarVm.PoolDelayText = string.Empty; Vm.StateBarVm.DualPoolDelayText = string.Empty; }); }); this.WindowContextEventPath <Per1MinuteEvent>("挖矿中时自动切换为无界面模式 和 守护进程状态显示", LogEnum.DevConsole, action: message => { if (NTMinerRoot.IsUiVisible && NTMinerRoot.Instance.MinerProfile.IsAutoNoUi && NTMinerRoot.Instance.IsMining) { if (NTMinerRoot.MainWindowRendedOn.AddMinutes(NTMinerRoot.Instance.MinerProfile.AutoNoUiMinutes) < message.Timestamp) { VirtualRoot.Execute(new CloseMainWindowCommand($"界面展示{NTMinerRoot.Instance.MinerProfile.AutoNoUiMinutes}分钟后自动切换为无界面模式,可在选项页调整配置")); } } Vm.RefreshDaemonStateBrush(); }); RefreshCpu(); #if DEBUG Write.DevTimeSpan($"耗时{Write.Stopwatch.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.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(); } } } } } }