Exemplo n.º 1
0
        public static void AddMinerStudioSession(IWsSessionAdapter session)
        {
            if (!WsRoot.TryGetUser(session.AuthorizationBase64, out WsUserName wsUserName, out UserData userData, out string errMsg))
            {
                session.CloseAsync(WsCloseCode.Normal, errMsg);
                return;
            }
            IMinerStudioSession minerSession = MinerStudioSession.Create(userData, wsUserName, session.SessionId, WsRoot.WsServer.MinerStudioWsSessionsAdapter);

            WsRoot.MinerStudioSessionSet.Add(minerSession);
            session.SendAsync(new WsMessage(Guid.NewGuid(), WsMessage.ServerTime)
            {
                Data = Timestamp.GetTimestamp()
            }.SignToBytes(userData.Password));
        }
Exemplo n.º 2
0
        protected override void OnOpen()
        {
            base.OnOpen();
            if (!this.TryGetUser(out WsUserName wsUserName, out UserData userData))
            {
                this.CloseAsync();
                return;
            }
            IMinerStudioSession minerSession = MinerStudioSession.Create(userData, wsUserName, this.ID, Sessions);

            WsRoot.MinerStudioSessionSet.Add(minerSession);
            base.SendAsync(new WsMessage(Guid.NewGuid(), WsMessage.ServerTime)
            {
                Data = Timestamp.GetTimestamp()
            }.SignToBytes(userData.Password), completed: null);
        }
Exemplo n.º 3
0
 public void Init(Action callback)
 {
     Task.Factory.StartNew(() => {
         bool isSelfWork = Environment.GetCommandLineArgs().Contains("--selfWork", StringComparer.OrdinalIgnoreCase);
         bool isWork     = isSelfWork || Environment.GetCommandLineArgs().Contains("--work", StringComparer.OrdinalIgnoreCase);
         _workType       = isSelfWork ? WorkType.SelfWork : (isWork ? WorkType.MineWork : WorkType.None);
         if (ClientAppType.IsMinerClient)
         {
             NTMinerRegistry.SetWorkType(_workType);
         }
         if (isWork)
         {
             DoInit(callback);
         }
         else
         {
             // 如果是Debug模式且不是群控客户端则使用本地数据库初始化
             bool useLocalDb = DevMode.IsDevMode && !ClientAppType.IsMinerStudio;
             if (useLocalDb)
             {
                 DoInit(callback);
             }
             else
             {
                 Logger.InfoDebugLine(nameof(RpcRoot.OSSService.AliyunOSSService.GetAliyunServerJson));
                 RpcRoot.OSSService.AliyunOSSService.GetAliyunServerJson((data) => {
                     // 如果server.json未下载成功则不覆写本地server.json
                     if (data != null && data.Length != 0)
                     {
                         Logger.InfoDebugLine($"{nameof(RpcRoot.OSSService.AliyunOSSService.GetAliyunServerJson)} ok");
                         var serverJson = Encoding.UTF8.GetString(data);
                         if (!string.IsNullOrEmpty(serverJson))
                         {
                             HomePath.WriteServerJsonFile(serverJson);
                         }
                         RpcRoot.OfficialServer.AppSettingService.GetJsonFileVersionAsync(ClientAppType.AppType, HomePath.ExportServerJsonFileName, serverState => {
                             SetServerJsonVersion(serverState.JsonFileVersion);
                             AppVersionChangedEvent.PublishIfNewVersion(serverState.MinerClientVersion);
                             if (serverState.Time == 0)
                             {
                                 NTMinerConsole.UserWarn("网络不通或服务器暂时不可用,请检查矿机网络");
                             }
                             else if (Math.Abs((long)Timestamp.GetTimestamp() - (long)serverState.Time) >= Timestamp.DesyncSeconds)
                             {
                                 NTMinerConsole.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(callback);
                 });
             }
         }
         VirtualRoot.ThisLocalInfo(nameof(NTMinerContext), $"启动{VirtualRoot.AppName}");
     });
 }
Exemplo n.º 4
0
 public void Init(Action callback)
 {
     Task.Factory.StartNew(() => {
         bool isWork = Environment.GetCommandLineArgs().Contains("--work", StringComparer.OrdinalIgnoreCase);
         if (isWork)   // 是作业
         {
             DoInit(isWork, callback);
             if (VirtualRoot.IsMinerClient)
             {
                 NTMinerRegistry.SetIsLastIsWork(true);
             }
         }
         else   // 不是作业
         {
             if (VirtualRoot.IsMinerClient)
             {
                 NTMinerRegistry.SetIsLastIsWork(false);
             }
             // 如果是Debug模式且不是群控客户端则使用本地数据库初始化
             bool useLocalDb = DevMode.IsDebugMode && !VirtualRoot.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))
                         {
                             SpecialPath.WriteServerJsonFile(serverJson);
                         }
                         OfficialServer.GetJsonFileVersionAsync(MainAssemblyInfo.ServerJsonFileName, serverState => {
                             SetServerJsonVersion(serverState.JsonFileVersion);
                             AppVersionChangedEvent.PublishIfNewVersion(serverState.MinerClientVersion);
                             if (Math.Abs((long)Timestamp.GetTimestamp() - (long)serverState.Time) < Timestamp.DesyncSeconds)
                             {
                                 Logger.OkDebugLine($"本机和服务器时间一致或相差不超过 {Timestamp.DesyncSeconds.ToString()} 秒");
                             }
                             else
                             {
                                 Write.UserWarn($"本机和服务器时间不同步,请调整,本地:{DateTime.Now.ToString()},服务器:{Timestamp.FromTimestamp(serverState.Time).ToString()}。此问题不影响挖矿。");
                             }
                         });
                     }
                     else
                     {
                         if (!File.Exists(SpecialPath.ServerJsonFileFullName))
                         {
                             VirtualRoot.ThisLocalError(nameof(NTMinerRoot), "配置文件下载失败,这是第一次运行开源矿工,配置文件至少需要成功下载一次,请检查网络是否可用", OutEnum.Warn);
                         }
                         else
                         {
                             VirtualRoot.ThisLocalWarn(nameof(NTMinerRoot), "配置文件下载失败,使用最近一次成功下载的配置文件", OutEnum.Warn);
                         }
                     }
                     DoInit(isWork, callback);
                 });
                 #region 发生了用户活动时检查serverJson是否有新版本
                 VirtualRoot.BuildEventPath <UserActionEvent>("发生了用户活动时检查serverJson是否有新版本", LogEnum.DevConsole,
                                                              action: message => {
                     RefreshServerJsonFile();
                 });
                 #endregion
             }
         }
         VirtualRoot.ThisLocalInfo(nameof(NTMinerRoot), $"启动{VirtualRoot.AppName}");
     });
 }
Exemplo n.º 5
0
 public LoadKernelOutputKeywordCommand()
 {
     this.KnowKernelOutputKeywordTimestamp = Timestamp.GetTimestamp();
 }
Exemplo n.º 6
0
 public LoadNewServerMessageCommand()
 {
     this.KnowServerMessageTimestamp = Timestamp.GetTimestamp();
 }
Exemplo n.º 7
0
 public static ulong ToUlong(this DateTime time)
 {
     return(Timestamp.GetTimestamp(time));
 }
 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);
     }
 }