Exemple #1
0
        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.AddCmdPath <SetAutoStartCommand>(message => {
                    this.IsAutoStart = message.IsAutoStart;
                    this.IsAutoBoot  = message.IsAutoBoot;
                }, this.GetType(), LogEnum.None);
                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)
                        {
                            this.RefreshWsDaemonState();
                        }
                        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 => {
                this.OnPropertyChanged(nameof(IsAutoBoot));
                this.OnPropertyChanged(nameof(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());
        }
        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
        }
            private MinerProfileViewModel()
            {
#if DEBUG
                VirtualRoot.Stopwatch.Restart();
#endif
                if (Design.IsInDesignMode)
                {
                    return;
                }
                this.AutoStartDelaySecondsUp = new DelegateCommand(() => {
                    this.AutoStartDelaySeconds++;
                });
                this.AutoStartDelaySecondsDown = new DelegateCommand(() => {
                    if (this.AutoStartDelaySeconds > 0)
                    {
                        this.AutoStartDelaySeconds--;
                    }
                });
                this.AutoRestartKernelTimesUp = new DelegateCommand(() => {
                    this.AutoRestartKernelTimes++;
                });
                this.AutoRestartKernelTimesDown = new DelegateCommand(() => {
                    if (this.AutoRestartKernelTimes > 0)
                    {
                        this.AutoRestartKernelTimes--;
                    }
                });
                this.NoShareRestartKernelMinutesUp = new DelegateCommand(() => {
                    this.NoShareRestartKernelMinutes++;
                });
                this.NoShareRestartKernelMinutesDown = new DelegateCommand(() => {
                    if (this.NoShareRestartKernelMinutes > 0)
                    {
                        this.NoShareRestartKernelMinutes--;
                    }
                });
                this.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.EPriceUp = new DelegateCommand(() => {
                    this.EPrice = Math.Round(this.EPrice + 0.1, 2);
                });
                this.EPriceDown = new DelegateCommand(() => {
                    if (this.EPrice > 0.1)
                    {
                        this.EPrice = Math.Round(this.EPrice - 0.1, 2);
                    }
                });
                this.PowerAppendUp = new DelegateCommand(() => {
                    this.PowerAppend++;
                });
                this.PowerAppendDown = new DelegateCommand(() => {
                    if (this.PowerAppend > 0)
                    {
                        this.PowerAppend--;
                    }
                });
                this.MaxTempUp = new DelegateCommand(() => {
                    this.MaxTemp++;
                });
                this.MaxTempDown = new DelegateCommand(() => {
                    if (this.MaxTemp > 0)
                    {
                        this.MaxTemp--;
                    }
                });
                this.AutoNoUiMinutesUp = new DelegateCommand(() => {
                    this.AutoNoUiMinutes++;
                });
                this.AutoNoUiMinutesDown = new DelegateCommand(() => {
                    if (this.AutoNoUiMinutes > 0)
                    {
                        this.AutoNoUiMinutes--;
                    }
                });
                NTMinerRoot.SetRefreshArgsAssembly(() => {
                    if (CoinVm != null && CoinVm.CoinKernel != null && CoinVm.CoinKernel.Kernel != null)
                    {
                        var coinKernelProfile = CoinVm.CoinKernel.CoinKernelProfile;
                        var kernelInput       = CoinVm.CoinKernel.Kernel.KernelInputVm;
                        if (coinKernelProfile != null && kernelInput != null)
                        {
                            if (coinKernelProfile.IsDualCoinEnabled && !kernelInput.IsAutoDualWeight)
                            {
                                if (coinKernelProfile.DualCoinWeight > kernelInput.DualWeightMax)
                                {
                                    coinKernelProfile.DualCoinWeight = kernelInput.DualWeightMax;
                                }
                                else if (coinKernelProfile.DualCoinWeight < kernelInput.DualWeightMin)
                                {
                                    coinKernelProfile.DualCoinWeight = kernelInput.DualWeightMin;
                                }
                                NTMinerRoot.Instance.MinerProfile.SetCoinKernelProfileProperty(coinKernelProfile.CoinKernelId, nameof(coinKernelProfile.DualCoinWeight), coinKernelProfile.DualCoinWeight);
                            }
                        }
                    }
                    this.ArgsAssembly = NTMinerRoot.Instance.BuildAssembleArgs(out _, out _, out _);
                });
                VirtualRoot.On <ServerContextVmsReInitedEvent>("ServerContext的VM集刷新后刷新视图界面", LogEnum.DevConsole,
                                                               action: message => {
                    OnPropertyChanged(nameof(CoinVm));
                });
                Window <RefreshAutoBootStartCommand>("刷新开机启动和自动挖矿的展示", LogEnum.UserConsole,
                                                     action: message => {
                    OnPropertyChanged(nameof(IsAutoBoot));
                    OnPropertyChanged(nameof(IsAutoStart));
                });
                On <MinerProfilePropertyChangedEvent>("MinerProfile设置变更后刷新VM内存", LogEnum.DevConsole,
                                                      action: message => {
                    OnPropertyChanged(message.PropertyName);
                });
                On <MineWorkPropertyChangedEvent>("MineWork设置变更后刷新VM内存", LogEnum.DevConsole,
                                                  action: message => {
                    OnPropertyChanged(message.PropertyName);
                });

                VirtualRoot.On <LocalContextVmsReInitedEvent>("本地上下文视图模型集刷新后刷新界面", LogEnum.DevConsole,
                                                              action: message => {
                    AllPropertyChanged();
                    if (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.DevWarn($"耗时{VirtualRoot.Stopwatch.ElapsedMilliseconds}毫秒 {this.GetType().Name}.ctor");
#endif
            }
Exemple #4
0
        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 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
        }