Beispiel #1
0
        static void Main()
        {
            VirtualRoot.StartTimer();
            try {
                // 将服务器地址设为localhost从而使用内网ip访问免于验证用户名密码
                NTKeyword.SetOfficialServerHost("localhost");
                NTMinerRegistry.SetAutoBoot("NTMiner.CalcConfigUpdater", true);
                VirtualRoot.BuildEventPath <Per10MinuteEvent>("每10分钟更新收益计算器", LogEnum.DevConsole,
                                                              action: message => {
                    UpdateAsync();
                });
                UpdateAsync();
                Write.UserInfo("输入exit并回车可以停止服务!");

                while (Console.ReadLine() != "exit")
                {
                }

                Write.UserOk($"服务停止成功: {DateTime.Now.ToString()}.");
            }
            catch (Exception e) {
                Logger.ErrorDebugLine(e);
            }

            System.Threading.Thread.Sleep(1000);
        }
Beispiel #2
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));
        }
        private string GetDevicesArgs(IKernelInput kernelInput)
        {
            string devicesArgs = string.Empty;

            if (!string.IsNullOrWhiteSpace(kernelInput.DevicesArg))
            {
                int[] useDevices = this.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);
        }
        // 从磁盘读取local.json反序列化为LocalJson对象
        private static void LocalJsonInit()
        {
            if (!_localJsonInited)
            {
                lock (_locker) {
                    if (!_localJsonInited)
                    {
                        string      localJson   = HomePath.ReadLocalJsonFile(_workType);
                        LocalJsonDb localJsonDb = null;
                        if (!string.IsNullOrEmpty(localJson))
                        {
                            localJsonDb = VirtualRoot.JsonSerializer.Deserialize <LocalJsonDb>(localJson);
                        }
                        if (localJsonDb == null)
                        {
                            if (ClientAppType.IsMinerClient)
                            {
                                localJsonDb = JsonDb.LocalJsonDb.ConvertFromNTMinerContext();
                                VirtualRoot.ThisLocalWarn(nameof(NTMinerContext), "当前作业由本机数据自动生成,因为本机没有作业记录,请先在群控端创建或编辑作业。", OutEnum.Warn, toConsole: true);
                            }
                            else
                            {
                                localJsonDb = new LocalJsonDb();
                            }
                        }
                        _localJsonDb = localJsonDb;

                        if (ClientAppType.IsMinerClient)
                        {
                            #region 因为是群控作业,将开机启动和自动挖矿设置为true
                            var repository = new LiteDbReadWriteRepository <MinerProfileData>(HomePath.LocalDbFileFullName);
                            MinerProfileData localProfile = repository.GetByKey(MinerProfileData.DefaultId);
                            if (localProfile != null)
                            {
                                MinerProfileData.CopyWorkIgnoreValues(localProfile, _localJsonDb.MinerProfile);
                                // 如果是作业模式则必须设置为开机自动重启
                                if (!localProfile.IsAutoBoot)
                                {
                                    localProfile.IsAutoBoot = true;
                                    repository.Update(localProfile);
                                }
                            }
                            _localJsonDb.MinerProfile.IsAutoBoot = true;
                            NTMinerRegistry.SetIsAutoStart(true);
                            #endregion

                            #region 矿机名
                            if (!string.IsNullOrEmpty(_workerName))
                            {
                                _localJsonDb.MinerProfile.MinerName = _workerName;
                            }
                            else
                            {
                                // 当用户使用群控作业但没有指定群控矿机名时使用从local.litedb中读取的矿工名
                                if (string.IsNullOrEmpty(_localJsonDb.MinerProfile.MinerName))
                                {
                                    if (localProfile != null)
                                    {
                                        _localJsonDb.MinerProfile.MinerName = localProfile.MinerName;
                                    }
                                    // 如果local.litedb中也没有矿机名则使用去除了特殊符号的本机机器名作为矿机名
                                    if (string.IsNullOrEmpty(_localJsonDb.MinerProfile.MinerName))
                                    {
                                        _localJsonDb.MinerProfile.MinerName = NTKeyword.GetSafeMinerName(ThisPcName);
                                    }
                                }
                            }
                            #endregion
                        }
                        _localJsonInited = true;
                    }
                }
            }
        }