Пример #1
0
 public LoadKernelOutputKeywordCommand()
 {
     this.KnowKernelOutputKeywordTimestamp = Timestamp.GetTimestamp();
 }
Пример #2
0
 public void Init(Action callback)
 {
     Task.Factory.StartNew(() => {
         bool isWork = Environment.GetCommandLineArgs().Contains("--work", StringComparer.OrdinalIgnoreCase);
         if (isWork)   // 是作业
         {
             DoInit(isWork, callback);
             if (ClientAppType.IsMinerClient)
             {
                 NTMinerRegistry.SetIsLastIsWork(true);
             }
         }
         else   // 不是作业
         {
             if (ClientAppType.IsMinerClient)
             {
                 NTMinerRegistry.SetIsLastIsWork(false);
             }
             // 如果是Debug模式且不是群控客户端则使用本地数据库初始化
             bool useLocalDb = DevMode.IsDevMode && !ClientAppType.IsMinerStudio;
             if (useLocalDb)
             {
                 DoInit(isWork: false, callback: callback);
             }
             else
             {
                 Logger.InfoDebugLine(nameof(GetAliyunServerJson));
                 GetAliyunServerJson((data) => {
                     // 如果server.json未下载成功则不覆写本地server.json
                     if (data != null && data.Length != 0)
                     {
                         Logger.InfoDebugLine($"{nameof(GetAliyunServerJson)}成功");
                         var serverJson = Encoding.UTF8.GetString(data);
                         if (!string.IsNullOrEmpty(serverJson))
                         {
                             HomePath.WriteServerJsonFile(serverJson);
                         }
                         RpcRoot.OfficialServer.AppSettingService.GetJsonFileVersionAsync(HomePath.ExportServerJsonFileName, serverState => {
                             SetServerJsonVersion(serverState.JsonFileVersion);
                             AppVersionChangedEvent.PublishIfNewVersion(serverState.MinerClientVersion);
                             if (Math.Abs((long)Timestamp.GetTimestamp() - (long)serverState.Time) >= Timestamp.DesyncSeconds)
                             {
                                 Write.UserWarn($"本机和服务器时间不同步,请调整,本地:{DateTime.Now.ToString()},服务器:{Timestamp.FromTimestamp(serverState.Time).ToString()}。此问题不影响挖矿。");
                             }
                         });
                     }
                     else
                     {
                         if (!File.Exists(HomePath.ServerJsonFileFullName))
                         {
                             VirtualRoot.ThisLocalError(nameof(NTMinerContext), "配置文件下载失败,这是第一次运行开源矿工,配置文件至少需要成功下载一次,请检查网络是否可用", OutEnum.Warn);
                         }
                         else
                         {
                             VirtualRoot.ThisLocalWarn(nameof(NTMinerContext), "配置文件下载失败,使用最近一次成功下载的配置文件");
                         }
                     }
                     DoInit(isWork, callback);
                 });
                 #region 发生了用户活动时检查serverJson是否有新版本
                 VirtualRoot.AddEventPath <UserActionEvent>("发生了用户活动时检查serverJson是否有新版本", LogEnum.DevConsole,
                                                            action: message => {
                     RefreshServerJsonFile();
                 }, location: this.GetType());
                 #endregion
             }
         }
         VirtualRoot.ThisLocalInfo(nameof(NTMinerContext), $"启动{VirtualRoot.AppName}");
     });
 }
Пример #3
0
 public LoadNewServerMessageCommand()
 {
     this.KnowServerMessageTimestamp = Timestamp.GetTimestamp();
 }
 public static void ExportWorkJson(MineWorkData mineWorkData, out string localJson, out string serverJson)
 {
     localJson  = string.Empty;
     serverJson = string.Empty;
     try {
         var                    root            = Current;
         var                    minerProfile    = root.MinerProfile;
         CoinProfileData        mainCoinProfile = new CoinProfileData(minerProfile.GetCoinProfile(minerProfile.CoinId));
         List <CoinProfileData> coinProfiles    = new List <CoinProfileData> {
             mainCoinProfile
         };
         List <PoolProfileData> poolProfiles        = new List <PoolProfileData>();
         CoinKernelProfileData  coinKernelProfile   = new CoinKernelProfileData(minerProfile.GetCoinKernelProfile(mainCoinProfile.CoinKernelId));
         PoolProfileData        mainCoinPoolProfile = new PoolProfileData(minerProfile.GetPoolProfile(mainCoinProfile.PoolId));
         poolProfiles.Add(mainCoinPoolProfile);
         if (coinKernelProfile.IsDualCoinEnabled)
         {
             CoinProfileData dualCoinProfile = new CoinProfileData(minerProfile.GetCoinProfile(coinKernelProfile.DualCoinId));
             coinProfiles.Add(dualCoinProfile);
             PoolProfileData dualCoinPoolProfile = new PoolProfileData(minerProfile.GetPoolProfile(dualCoinProfile.DualCoinPoolId));
             poolProfiles.Add(dualCoinPoolProfile);
         }
         LocalJsonDb localJsonObj = new LocalJsonDb {
             MinerProfile = new MinerProfileData(minerProfile)
             {
                 MinerName = "{{MinerName}}"
             },
             MineWork           = mineWorkData,
             CoinProfiles       = coinProfiles.ToArray(),
             CoinKernelProfiles = new CoinKernelProfileData[] { coinKernelProfile },
             PoolProfiles       = poolProfiles.ToArray(),
             TimeStamp          = Timestamp.GetTimestamp(),
             Pools   = root.PoolSet.Where(a => poolProfiles.Any(b => b.PoolId == a.GetId())).Select(a => new PoolData(a)).ToArray(),
             Wallets = minerProfile.GetWallets().Select(a => new WalletData(a)).ToArray()
         };
         localJson = VirtualRoot.JsonSerializer.Serialize(localJsonObj);
         root.CoinKernelSet.TryGetCoinKernel(coinKernelProfile.CoinKernelId, out ICoinKernel coinKernel);
         root.KernelSet.TryGetKernel(coinKernel.KernelId, out IKernel kernel);
         var          coins         = root.CoinSet.Cast <CoinData>().Where(a => localJsonObj.CoinProfiles.Any(b => b.CoinId == a.Id)).ToArray();
         var          coinGroups    = root.CoinGroupSet.Cast <CoinGroupData>().Where(a => coins.Any(b => b.Id == a.CoinId)).ToArray();
         var          pools         = root.PoolSet.Cast <PoolData>().Where(a => localJsonObj.PoolProfiles.Any(b => b.PoolId == a.Id)).ToArray();
         ServerJsonDb serverJsonObj = new ServerJsonDb {
             Coins                   = coins,
             CoinGroups              = coinGroups,
             Pools                   = pools,
             TimeStamp               = Timestamp.GetTimestamp(),
             Groups                  = root.GroupSet.Cast <GroupData>().Where(a => coinGroups.Any(b => b.GroupId == a.Id)).ToArray(),
             KernelInputs            = root.KernelInputSet.Cast <KernelInputData>().Where(a => a.Id == kernel.KernelInputId).ToArray(),
             KernelOutputs           = root.KernelOutputSet.Cast <KernelOutputData>().Where(a => a.Id == kernel.KernelOutputId).ToArray(),
             KernelOutputFilters     = root.KernelOutputFilterSet.Cast <KernelOutputFilterData>().Where(a => a.KernelOutputId == kernel.KernelOutputId).ToArray(),
             KernelOutputTranslaters = root.KernelOutputTranslaterSet.Cast <KernelOutputTranslaterData>().Where(a => a.KernelOutputId == kernel.KernelOutputId).ToArray(),
             Kernels                 = new List <KernelData> {
                 (KernelData)kernel
             },
             CoinKernels = root.CoinKernelSet.Cast <CoinKernelData>().Where(a => localJsonObj.CoinKernelProfiles.Any(b => b.CoinKernelId == a.Id)).ToList(),
             PoolKernels = root.PoolKernelSet.Cast <PoolKernelData>().Where(a => !string.IsNullOrEmpty(a.Args) && pools.Any(b => b.Id == a.PoolId)).ToList(),
             SysDicItems = root.SysDicItemSet.Cast <SysDicItemData>().ToArray(),
             SysDics     = root.SysDicSet.Cast <SysDicData>().ToArray()
         };
         serverJson = VirtualRoot.JsonSerializer.Serialize(serverJsonObj);
     }
     catch (Exception e) {
         Logger.ErrorDebugLine(e.Message, e);
     }
 }