示例#1
0
        public void GetIndexCharTest()
        {
            List <string> chars1 = new List <string>();
            List <string> chars2 = new List <string>();

            for (int i = 0; i < 12; i++)
            {
                chars1.Add(NTKeyword.GetIndexChar(i, string.Empty));
                chars2.Add(NTKeyword.GetIndexChar(i, ","));
            }
            Assert.AreEqual("0123456789ab", string.Join(string.Empty, chars1));
            Assert.AreEqual("0,1,2,3,4,5,6,7,8,9,10,11", string.Join(",", chars2));
        }
示例#2
0
        private static string GetDevicesArgs(IKernelInput kernelInput)
        {
            INTMinerContext ntminerContext = NTMinerContext.Instance;
            var             gpuSet         = ntminerContext.GpuSet;
            string          devicesArgs    = string.Empty;

            if (!string.IsNullOrWhiteSpace(kernelInput.DevicesArg))
            {
                int[] useDevices = gpuSet.GetUseDevices();
                if ((useDevices.Length != 0 && useDevices.Length != gpuSet.Count) || kernelInput.IsDeviceAllNotEqualsNone)
                {
                    string separator = kernelInput.DevicesSeparator;
                    // 因为空格在界面上不易被人读取所以以关键字代替空格
                    if (kernelInput.DevicesSeparator == NTKeyword.SpaceKeyword)
                    {
                        separator = " ";
                    }
                    List <string> gpuIndexes = new List <string>();
                    foreach (var index in useDevices)
                    {
                        int i = index;
                        if (kernelInput.DeviceBaseIndex != 0)
                        {
                            i = index + kernelInput.DeviceBaseIndex;
                        }
                        string nText = NTKeyword.GetIndexChar(i, separator);
                        gpuIndexes.Add(nText);
                    }
                    switch (gpuSet.GpuType)
                    {
                    case GpuType.Empty:
                        break;

                    case GpuType.NVIDIA:
                        devicesArgs = $"{kernelInput.DevicesArg} {string.Join(separator, gpuIndexes.Select(a => $"{kernelInput.NDevicePrefix}{a}{kernelInput.NDevicePostfix}"))}";
                        break;

                    case GpuType.AMD:
                        devicesArgs = $"{kernelInput.DevicesArg} {string.Join(separator, gpuIndexes.Select(a => $"{kernelInput.ADevicePrefix}{a}{kernelInput.ADevicePostfix}"))}";
                        break;

                    default:
                        break;
                    }
                }
            }
            return(devicesArgs);
        }
示例#3
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;
            });
            string GetRowArgsAssembly()
            {
                string argsAssembly = this.ArgsAssembly ?? "无";

                if (argsAssembly.Contains("{logfile}"))
                {
                    argsAssembly = Regex.Replace(argsAssembly, "\\s\\S+\\s\"\\{logfile\\}\"", string.Empty);
                }
                return(argsAssembly.Trim());
            }

            this.CopyArgsAssembly = new DelegateCommand(() => {
                string argsAssembly = GetRowArgsAssembly();
                Clipboard.SetDataObject(argsAssembly, true);
                VirtualRoot.Out.ShowSuccess("命令行", header: "复制成功");
            });
            if (ClientAppType.IsMinerClient)
            {
                if (this.IsSystemName)
                {
                    this.MinerName = NTKeyword.GetSafeMinerName(NTMinerContext.ThisPcName);
                }
                VirtualRoot.BuildCmdPath <SetAutoStartCommand>(this.GetType(), LogEnum.None, message => {
                    this.IsAutoStart = message.IsAutoStart;
                    this.IsAutoBoot  = message.IsAutoBoot;
                });
                VirtualRoot.BuildEventPath <StartingMineFailedEvent>("开始挖矿失败", LogEnum.DevConsole, location: this.GetType(), PathPriority.Normal,
                                                                     path: message => {
                    IsMining = false;
                    NTMinerConsole.UserError(message.Message);
                });
                // 群控客户端已经有一个执行RefreshWsStateCommand命令的路径了
                VirtualRoot.BuildCmdPath <RefreshWsStateCommand>(this.GetType(), LogEnum.DevConsole, message => {
                    #region
                    if (message.WsClientState != null)
                    {
                        this.WsServerIp = message.WsClientState.WsServerIp;
                        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
                });
                VirtualRoot.BuildEventPath <Per1SecondEvent>("外网群控重试秒表倒计时", LogEnum.None, this.GetType(), PathPriority.Normal, path: message => {
                    if (IsOuterUserEnabled && !IsWsOnline)
                    {
                        if (WsNextTrySecondsDelay > 0)
                        {
                            WsNextTrySecondsDelay--;
                        }
                        else if (WsLastTryOn == DateTime.MinValue)
                        {
                            this.RefreshWsDaemonState();
                        }
                        OnPropertyChanged(nameof(WsLastTryOnText));
                    }
                });
                VirtualRoot.BuildEventPath <WsServerOkEvent>("服务器Ws服务已可用", LogEnum.DevConsole, this.GetType(), PathPriority.Normal, path: message => {
                    if (IsOuterUserEnabled && !IsWsOnline)
                    {
                        StartOrStopWs();
                    }
                });
            }
            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 = MineContextFactory.CreateMineContext();
                if (NTMinerContext.Instance.CurrentMineContext != null)
                {
                    this.ArgsAssembly = NTMinerContext.Instance.CurrentMineContext.CommandLine;
                }
                else
                {
                    this.ArgsAssembly = string.Empty;
                }
            });
            AppRoot.BuildEventPath <AutoBootStartRefreshedEvent>("刷新开机启动和自动挖矿的展示", LogEnum.DevConsole, location: this.GetType(), PathPriority.Normal,
                                                                 path: message => {
                this.OnPropertyChanged(nameof(IsAutoBoot));
                this.OnPropertyChanged(nameof(IsAutoStart));
            });
            AppRoot.BuildEventPath <MinerProfilePropertyChangedEvent>("MinerProfile设置变更后刷新VM内存", LogEnum.DevConsole, location: this.GetType(), PathPriority.Normal,
                                                                      path: message => {
                OnPropertyChanged(message.PropertyName);
            });

            VirtualRoot.BuildEventPath <LocalContextReInitedEventHandledEvent>("本地上下文视图模型集刷新后刷新界面", LogEnum.DevConsole, location: this.GetType(), PathPriority.Normal,
                                                                               path: 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));
                }
            });
            VirtualRoot.BuildEventPath <CoinAddedEvent>("Vm集添加了新币种后刷新MinerProfileVm内存", LogEnum.DevConsole, this.GetType(), PathPriority.BelowNormal, path: message => {
                OnPropertyChanged(nameof(CoinVm));
            });
            VirtualRoot.BuildEventPath <CoinRemovedEvent>("Vm集删除了新币种后刷新MinerProfileVm内存", LogEnum.DevConsole, this.GetType(), PathPriority.BelowNormal, path: message => {
                OnPropertyChanged(nameof(CoinVm));
            });
        }