Beispiel #1
0
        // 从磁盘读取local.json反序列化为LocalJson对象
        private static void LocalJsonInit()
        {
            if (!_localJsonInited)
            {
                lock (_locker) {
                    if (!_localJsonInited)
                    {
                        string localJson = HomePath.ReadLocalJsonFile();
                        if (!string.IsNullOrEmpty(localJson))
                        {
                            LocalJsonDb data = VirtualRoot.JsonSerializer.Deserialize <LocalJsonDb>(localJson);
                            _localJson = data ?? new LocalJsonDb();
                        }
                        else
                        {
                            _localJson = new LocalJsonDb();
                        }

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

                        #region 矿机名
                        // 当用户使用群控作业但没有指定群控矿机名时使用从local.litedb中读取的矿工名
                        if (string.IsNullOrEmpty(_localJson.MinerProfile.MinerName))
                        {
                            if (localProfile != null)
                            {
                                _localJson.MinerProfile.MinerName = localProfile.MinerName;
                            }
                            // 如果local.litedb中也没有矿机名则使用去除了特殊符号的本机机器名作为矿机名
                            if (string.IsNullOrEmpty(_localJson.MinerProfile.MinerName))
                            {
                                string minerName = Environment.MachineName;
                                minerName = new string(minerName.ToCharArray().Where(a => !NTKeyword.InvalidMinerNameChars.Contains(a)).ToArray());
                                _localJson.MinerProfile.MinerName = minerName;
                            }
                        }
                        #endregion
                        _localJsonInited = true;
                    }
                }
            }
        }
 // 从磁盘读取local.json反序列化为LocalJson对象
 private static void LocalJsonInit()
 {
     if (!_localJsonInited)
     {
         lock (_localJsonlocker) {
             if (!_localJsonInited)
             {
                 string localJson = SpecialPath.ReadLocalJsonFile();
                 if (!string.IsNullOrEmpty(localJson))
                 {
                     try {
                         LocalJsonDb data = VirtualRoot.JsonSerializer.Deserialize <LocalJsonDb>(localJson);
                         _localJson = data ?? new LocalJsonDb();
                     }
                     catch (Exception e) {
                         Logger.ErrorDebugLine(e);
                     }
                 }
                 else
                 {
                     _localJson = new LocalJsonDb();
                 }
                 // 因为是群控作业,将开机启动和自动挖矿设置为true
                 var repository = new LiteDbReadWriteRepository <MinerProfileData>(VirtualRoot.LocalDbFileFullName);
                 MinerProfileData localProfile = repository.GetByKey(MinerProfileData.DefaultId);
                 if (localProfile != null)
                 {
                     if (localProfile.IsAutoStart == false || localProfile.IsAutoBoot == false)
                     {
                         localProfile.IsAutoBoot  = true;
                         localProfile.IsAutoStart = true;
                         repository.Update(localProfile);
                     }
                 }
                 _localJson.MinerProfile.IsAutoBoot  = true;
                 _localJson.MinerProfile.IsAutoStart = true;
                 // 这里的逻辑是,当用户在主界面填写矿工名时,矿工名会被交换到注册表从而当用户使用群控但没有填写群控矿工名时作为缺省矿工名
                 // 但是旧版本的挖矿端并没有把矿工名交换到注册表去所以当注册表中没有矿工名时需读取local.litedb中的矿工名
                 if (string.IsNullOrEmpty(_localJson.MinerProfile.MinerName))
                 {
                     _localJson.MinerProfile.MinerName = NTMinerRegistry.GetMinerName();
                     if (string.IsNullOrEmpty(_localJson.MinerProfile.MinerName))
                     {
                         if (localProfile != null)
                         {
                             _localJson.MinerProfile.MinerName = localProfile.MinerName;
                         }
                     }
                 }
                 _localJsonInited = true;
             }
         }
     }
 }
Beispiel #3
0
 // 从磁盘读取local.json反序列化为LocalJson对象
 private static void LocalJsonInit()
 {
     if (!_localJsonInited)
     {
         lock (_localJsonlocker) {
             if (!_localJsonInited)
             {
                 string localJson = SpecialPath.ReadLocalJsonFile();
                 if (!string.IsNullOrEmpty(localJson))
                 {
                     try {
                         LocalJsonDb data = VirtualRoot.JsonSerializer.Deserialize <LocalJsonDb>(localJson);
                         _localJson = data ?? new LocalJsonDb();
                     }
                     catch (Exception e) {
                         Logger.ErrorDebugLine(e);
                     }
                 }
                 else
                 {
                     _localJson = new LocalJsonDb();
                 }
                 // 这里的逻辑是,当用户在主界面填写矿工名时,矿工名会被交换到注册表从而当用户使用群控但没有填写群控矿工名时作为缺省矿工名
                 // 但是旧版本的挖矿端并没有把矿工名交换到注册表去所以当注册表中没有矿工名时需读取local.litedb中的矿工名
                 if (string.IsNullOrEmpty(_localJson.MinerProfile.MinerName))
                 {
                     _localJson.MinerProfile.MinerName = GetMinerName();
                     if (string.IsNullOrEmpty(_localJson.MinerProfile.MinerName))
                     {
                         var repository = new LiteDbReadWriteRepository <Profile.MinerProfileData>(SpecialPath.LocalDbFileFullName);
                         Profile.MinerProfileData data = repository.GetByKey(Profile.MinerProfileData.DefaultId);
                         if (data != null)
                         {
                             _localJson.MinerProfile.MinerName = data.MinerName;
                         }
                     }
                 }
                 _localJsonInited = true;
             }
         }
     }
 }
        // 从磁盘读取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;
                    }
                }
            }
        }