public MinerProfileViewModel() { if (WpfUtil.IsInDesignMode) { return; } if (Instance != null) { throw new InvalidProgramException(); } if (this.IsCreateShortcut) { CreateShortcut(); } this.Up = new DelegateCommand <string>(propertyName => { WpfUtil.Up(this, propertyName); }); this.Down = new DelegateCommand <string>(propertyName => { WpfUtil.Down(this, propertyName); }); this.WsRetry = new DelegateCommand(() => { RpcRoot.Client.NTMinerDaemonService.StartOrStopWsAsync(isResetFailCount: true); IsConnecting = true; }); if (ClientAppType.IsMinerClient) { VirtualRoot.AddEventPath <StartingMineFailedEvent>("开始挖矿失败", LogEnum.DevConsole, action: message => { IsMining = false; NTMinerConsole.UserError(message.Message); }, location: this.GetType()); // 群控客户端已经有一个执行RefreshWsStateCommand命令的路径了 VirtualRoot.AddCmdPath <RefreshWsStateCommand>(message => { #region if (message.WsClientState != null) { 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--; } else if (WsLastTryOn == DateTime.MinValue) { RpcRoot.Client.NTMinerDaemonService.GetWsDaemonStateAsync((WsClientState state, Exception e) => { if (state != null) { this.IsWsOnline = state.Status == WsClientStatus.Open; this.WsDescription = state.Description; if (state.NextTrySecondsDelay > 0) { this.WsNextTrySecondsDelay = state.NextTrySecondsDelay; } this.WsLastTryOn = state.LastTryOn; } }); } OnPropertyChanged(nameof(WsLastTryOnText)); } }, this.GetType()); VirtualRoot.AddEventPath <WsServerOkEvent>("服务器Ws服务已可用", LogEnum.DevConsole, action: message => { if (IsOuterUserEnabled && !IsWsOnline) { StartOrStopWs(); } }, this.GetType()); } NTMinerContext.SetRefreshArgsAssembly((reason) => { NTMinerConsole.DevDebug(() => $"RefreshArgsAssembly" + reason, ConsoleColor.Cyan); #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; } }); 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 <LocalContextReInitedEventHandledEvent>("本地上下文视图模型集刷新后刷新界面", 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 ((IsAutoStart || CommandLineArgs.IsAutoStart) && IsNoUi) { NTMinerConsole.Disable(); } }