예제 #1
0
 public void SetIncorrectShare(int gpuIndex, int incorrectShare)
 {
     InitOnece();
     if (!_currentGpuSpeed.TryGetValue(gpuIndex, out GpuSpeed gpuSpeed))
     {
         return;
     }
     CheckReset();
     gpuSpeed.SetMainCoinIncorrectShare(incorrectShare);
     VirtualRoot.RaiseEvent(new IncorrectShareSetedEvent(Guid.Empty, gpuSpeed: gpuSpeed));
 }
예제 #2
0
 public void IncreaseAcceptShare(int gpuIndex)
 {
     InitOnece();
     if (!_currentGpuSpeed.TryGetValue(gpuIndex, out GpuSpeed gpuSpeed))
     {
         return;
     }
     CheckReset();
     gpuSpeed.IncreaseMainCoinAcceptShare();
     VirtualRoot.RaiseEvent(new AcceptShareIncreasedEvent(Guid.Empty, gpuSpeed: gpuSpeed));
 }
예제 #3
0
 public void GetOperationResultsAsync(IMinerData client, long afterTime)
 {
     RpcRoot.GetAsync <List <OperationResultData> >(client.GetLocalIp(), NTKeyword.NTMinerDaemonPort, _daemonControllerName, nameof(INTMinerDaemonController.GetOperationResults), new Dictionary <string, string> {
         { "afterTime", afterTime.ToString() }
     }, (data, e) => {
         if (data != null || data.Count > 0)
         {
             VirtualRoot.RaiseEvent(new ClientOperationResultsEvent(client.ClientId, data));
         }
     }, timeountMilliseconds: 3000);
 }
예제 #4
0
        public PoolKernelSet(IServerContext context)
        {
            _context = context;
            _context.AddCmdPath <AddPoolKernelCommand>("处理添加矿池级内核命令", LogEnum.DevConsole,
                                                       action: message => {
                if (!_dicById.ContainsKey(message.Input.GetId()))
                {
                    var entity = new PoolKernelData().Update(message.Input);
                    _dicById.Add(message.Input.GetId(), entity);
                    var repository = NTMinerRoot.CreateServerRepository <PoolKernelData>();
                    repository.Add(entity);
                    VirtualRoot.RaiseEvent(new PoolKernelAddedEvent(message.MessageId, message.Input));
                }
            }, location: this.GetType());
            _context.AddCmdPath <RemovePoolKernelCommand>("处理移除矿池级内核命令", LogEnum.DevConsole,
                                                          action: message => {
                if (_dicById.ContainsKey(message.EntityId))
                {
                    var entity = _dicById[message.EntityId];
                    _dicById.Remove(message.EntityId);
                    var repository = NTMinerRoot.CreateServerRepository <PoolKernelData>();
                    repository.Remove(message.EntityId);
                    VirtualRoot.RaiseEvent(new PoolKernelRemovedEvent(message.MessageId, entity));
                }
            }, location: this.GetType());
            _context.AddCmdPath <UpdatePoolKernelCommand>("更新矿池内核", LogEnum.DevConsole,
                                                          action: (message) => {
                InitOnece();
                if (message == null || message.Input == null || message.Input.GetId() == Guid.Empty)
                {
                    throw new ArgumentNullException();
                }
                if (!_context.PoolSet.Contains(message.Input.PoolId))
                {
                    throw new ValidationException("there is no pool with id" + message.Input.PoolId);
                }
                if (!_dicById.ContainsKey(message.Input.GetId()))
                {
                    return;
                }
                PoolKernelData entity = _dicById[message.Input.GetId()];
                if (ReferenceEquals(entity, message.Input))
                {
                    return;
                }
                entity.Update(message.Input);
                var repository = NTMinerRoot.CreateServerRepository <PoolKernelData>();
                repository.Update(entity);

                VirtualRoot.RaiseEvent(new PoolKernelUpdatedEvent(message.MessageId, entity));
            }, location: this.GetType());
        }
예제 #5
0
        public void IncreaseIncorrectShare(int gpuIndex)
        {
            InitOnece();
            GpuSpeed gpuSpeed;

            if (!_currentGpuSpeed.TryGetValue(gpuIndex, out gpuSpeed))
            {
                return;
            }
            CheckReset();
            gpuSpeed.IncreaseMainCoinIncorrectShare();
            VirtualRoot.RaiseEvent(new IncorrectShareIncreasedEvent(gpuSpeed: gpuSpeed));
        }
예제 #6
0
 public ReadOnlyCalcConfigSet(ICalcConfigDataRedis redis)
 {
     _redis = redis;
     VirtualRoot.BuildEventPath <Per10MinuteEvent>("周期从redis加载收益计算器配置数据", LogEnum.DevConsole, typeof(ReadOnlyCalcConfigSet), PathPriority.Normal, message => {
         Load();
     });
     VirtualRoot.BuildEventPath <CalcConfigsUpdatedMqEvent>("收到CalcConfigsUpdated Mq消息后从redis加载数据刷新内存中的收益计算器数据集", LogEnum.DevConsole, typeof(ReadOnlyCalcConfigSet), PathPriority.Normal, message => {
         Load();
     });
     Load().ContinueWith(t => {
         VirtualRoot.RaiseEvent(new CalcConfigSetInitedEvent());
     });
 }
예제 #7
0
 protected override Dictionary <string, Action <BasicDeliverEventArgs> > GetPaths()
 {
     return(new Dictionary <string, Action <BasicDeliverEventArgs> > {
         [MqKeyword.MqCountRoutingKey] = ea => {
             string appId = ea.BasicProperties.AppId;
             MqCountData data = MqCountMqBodyUtil.GetMqCountMqReceiveBody(ea.Body);
             if (data != null)
             {
                 VirtualRoot.RaiseEvent(new MqCountReceivedMqEvent(appId, data, ea.GetTimestamp()));
             }
         }
     });
 }
예제 #8
0
        protected sealed override Dictionary <string, Action <BasicDeliverEventArgs> > GetPaths()
        {
            var paths = new Dictionary <string, Action <BasicDeliverEventArgs> > {
                [MqKeyword.UserAddedRoutingKey] = ea => {
                    string loginName = UserMqBodyUtil.GetLoginNameMqReceiveBody(ea.Body);
                    string appId     = ea.BasicProperties.AppId;
                    VirtualRoot.RaiseEvent(new UserAddedMqEvent(appId, loginName, ea.GetTimestamp()));
                },
                [MqKeyword.UserUpdatedRoutingKey] = ea => {
                    string loginName = UserMqBodyUtil.GetLoginNameMqReceiveBody(ea.Body);
                    string appId     = ea.BasicProperties.AppId;
                    VirtualRoot.RaiseEvent(new UserUpdatedMqEvent(appId, loginName, ea.GetTimestamp()));
                },
                [MqKeyword.UserRemovedRoutingKey] = ea => {
                    string loginName = UserMqBodyUtil.GetLoginNameMqReceiveBody(ea.Body);
                    string appId     = ea.BasicProperties.AppId;
                    VirtualRoot.RaiseEvent(new UserRemovedMqEvent(appId, loginName, ea.GetTimestamp()));
                },
                [MqKeyword.UserEnabledRoutingKey] = ea => {
                    string loginName = UserMqBodyUtil.GetLoginNameMqReceiveBody(ea.Body);
                    string appId     = ea.BasicProperties.AppId;
                    VirtualRoot.RaiseEvent(new UserEnabledMqEvent(appId, loginName, ea.GetTimestamp()));
                },
                [MqKeyword.UserDisabledRoutingKey] = ea => {
                    string loginName = UserMqBodyUtil.GetLoginNameMqReceiveBody(ea.Body);
                    string appId     = ea.BasicProperties.AppId;
                    VirtualRoot.RaiseEvent(new UserDisabledMqEvent(appId, loginName, ea.GetTimestamp()));
                },
                [MqKeyword.UserPasswordChangedRoutingKey] = ea => {
                    string loginName = UserMqBodyUtil.GetLoginNameMqReceiveBody(ea.Body);
                    string appId     = ea.BasicProperties.AppId;
                    VirtualRoot.RaiseEvent(new UserPasswordChangedMqEvent(appId, loginName, ea.GetTimestamp()));
                },
                // 该事件通常不会发生,因为用户注册的时候已经生成了RSA公私钥对了,RSA非空时不会更新
                [MqKeyword.UserRSAKeyUpdatedRoutingKey] = ea => {
                    string loginName = UserMqBodyUtil.GetLoginNameMqReceiveBody(ea.Body);
                    string appId     = ea.BasicProperties.AppId;
                    VirtualRoot.RaiseEvent(new UserRSAKeyUpdatedMqEvent(appId, loginName, ea.GetTimestamp()));
                }
            };
            var dic = DoGetPaths();

            if (dic != null)
            {
                foreach (var kv in dic)
                {
                    paths[kv.Key] = kv.Value;
                }
            }
            return(paths);
        }
예제 #9
0
 public void Clear()
 {
     if (string.IsNullOrEmpty(_connectionString))
     {
         return;
     }
     using (LiteDatabase db = new LiteDatabase(_connectionString)) {
         lock (_locker) {
             _records.Clear();
         }
         db.DropCollection(nameof(LocalMessageData));
     }
     VirtualRoot.RaiseEvent(new LocalMessageClearedEvent());
 }
예제 #10
0
 public void SetRejectShare(int gpuIndex, int rejectShare)
 {
     InitOnece();
     if (!_currentGpuSpeed.TryGetValue(gpuIndex, out GpuSpeed gpuSpeed))
     {
         return;
     }
     CheckReset();
     if (gpuSpeed.MainCoinSpeed.RejectShare != rejectShare)
     {
         gpuSpeed.SetMainCoinRejectShare(rejectShare);
         VirtualRoot.RaiseEvent(new RejectShareSetedEvent(Guid.Empty, gpuSpeed: gpuSpeed));
     }
 }
예제 #11
0
        public void Init(bool forceRefresh = false)
        {
            DateTime now = DateTime.Now;

            // 如果未显示主界面则收益计算器也不用更新了
            if ((_initedOn == DateTime.MinValue || NTMinerRoot.IsUiVisible || VirtualRoot.IsMinerStudio) && (forceRefresh || _initedOn.AddMinutes(10) < now))
            {
                _initedOn = now;
                RpcRoot.OfficialServer.ControlCenterService.GetCalcConfigsAsync(data => {
                    Init(data);
                    VirtualRoot.RaiseEvent(new CalcConfigSetInitedEvent());
                });
            }
        }
예제 #12
0
        private void ReceiveServerMessage(List <ServerMessageData> data)
        {
            if (data == null)
            {
                return;
            }
            InitOnece();
            DateTime localTimestamp = VirtualRoot.LocalServerMessageSetTimestamp;
            LinkedList <ServerMessageData> newDatas = new LinkedList <ServerMessageData>();

            lock (_locker) {
                DateTime maxTime = localTimestamp;
                foreach (var item in data.OrderBy(a => a.Timestamp))
                {
                    if (item.Timestamp > maxTime)
                    {
                        maxTime = item.Timestamp;
                    }
                    newDatas.AddLast(item);
                    var exist = _linkedList.FirstOrDefault(a => a.Id == item.Id);
                    if (exist != null)
                    {
                        _linkedList.Remove(exist);
                    }
                    if (!item.IsDeleted)
                    {
                        _linkedList.AddFirst(item);
                    }
                }
                if (maxTime != localTimestamp)
                {
                    VirtualRoot.LocalServerMessageSetTimestamp = maxTime;
                }
            }
            using (LiteDatabase db = new LiteDatabase(_connectionString)) {
                var col = db.GetCollection <ServerMessageData>();
                foreach (var item in newDatas)
                {
                    if (item.IsDeleted)
                    {
                        col.Delete(item.Id);
                    }
                    else
                    {
                        col.Upsert(item);
                    }
                }
            }
            VirtualRoot.RaiseEvent(new NewServerMessageLoadedEvent(newDatas));
        }
예제 #13
0
 public MinerProfile(INTMinerContext ntminerContext)
 {
     _ntminerContext = ntminerContext;
     VirtualRoot.BuildCmdPath <RefreshAutoBootStartCommand>(location: this.GetType(), LogEnum.DevConsole, path: message => {
         var minerProfileRepository = ntminerContext.ServerContext.CreateLocalRepository <MinerProfileData>();
         var data = minerProfileRepository.GetAll().FirstOrDefault();
         if (data != null && _data != null)
         {
             _data.IsAutoBoot  = data.IsAutoBoot;
             _data.IsAutoStart = data.IsAutoStart;
             VirtualRoot.RaiseEvent(new AutoBootStartRefreshedEvent());
         }
     });
     Init(ntminerContext);
 }
예제 #14
0
 private void RefreshNodes(Action callback = null)
 {
     RpcRoot.OfficialServer.WsServerNodeService.GetNodeAddressesAsync((response, e) => {
         if (response.IsSuccess())
         {
             _nodeAddresses = response.Data;
             VirtualRoot.RaiseEvent(new CleanTimeArrivedEvent(GetNodeAddresses(response.Data)));
         }
         else
         {
             Write.UserError("获取节点列表失败:" + response.ReadMessage(e));
         }
         callback?.Invoke();
     });
 }
예제 #15
0
 public void RefreshGpuState(IGpu gpu)
 {
     if (gpu.Index == NTMinerContext.GpuAllId)
     {
         return;
     }
     try {
         OverClockRange range = _gpuHelper.GetClockRange(gpu.GetOverClockId());
         gpu.UpdateState(range);
     }
     catch (System.Exception e) {
         Logger.ErrorDebugLine(e);
     }
     VirtualRoot.RaiseEvent(new GpuStateChangedEvent(Guid.Empty, gpu));
 }
예제 #16
0
 public void Init(List <UserAppSettingData> userAppSettings)
 {
     if (_userAppSettings != userAppSettings)
     {
         _userAppSettings = userAppSettings;
         if (userAppSettings != null && userAppSettings.Count != 0)
         {
             foreach (var item in userAppSettings)
             {
                 _dicByKey[item.Key] = item;
             }
         }
         VirtualRoot.RaiseEvent(new UserAppSettingSetInitedEvent());
     }
 }
 protected override Dictionary <string, Action <BasicDeliverEventArgs> > GetPaths()
 {
     return(new Dictionary <string, Action <BasicDeliverEventArgs> > {
         [MqKeyword.WsServerNodeAddedRoutingKey] = ea => {
             string wsServerAddress = WsServerNodeMqBodyUtil.GetWsServerNodeAddressMqReceiveBody(ea.Body);
             string appId = ea.BasicProperties.AppId;
             VirtualRoot.RaiseEvent(new WsServerNodeAddedMqEvent(appId, wsServerAddress));
         },
         [MqKeyword.WsServerNodeRemovedRoutingKey] = ea => {
             string wsServerAddress = WsServerNodeMqBodyUtil.GetWsServerNodeAddressMqReceiveBody(ea.Body);
             string appId = ea.BasicProperties.AppId;
             VirtualRoot.RaiseEvent(new WsServerNodeRemovedMqEvent(appId, wsServerAddress));
         }
     });
 }
예제 #18
0
 public LocalMessageSet(string dbFileFullName)
 {
     if (!string.IsNullOrEmpty(dbFileFullName))
     {
         _connectionString = $"filename={dbFileFullName};journal=false";
     }
     VirtualRoot.AddCmdPath <AddLocalMessageCommand>(action: message => {
         if (string.IsNullOrEmpty(_connectionString))
         {
             return;
         }
         InitOnece();
         var data = LocalMessageData.Create(message.Input);
         // TODO:批量持久化,异步持久化
         List <ILocalMessage> removes = new List <ILocalMessage>();
         lock (_locker) {
             _records.AddFirst(data);
             while (_records.Count > NTKeyword.LocalMessageSetCapacity)
             {
                 var toRemove = _records.Last;
                 removes.Add(toRemove.Value);
                 _records.RemoveLast();
                 using (LiteDatabase db = new LiteDatabase(_connectionString)) {
                     var col = db.GetCollection <LocalMessageData>();
                     col.Delete(toRemove.Value.Id);
                 }
             }
         }
         using (LiteDatabase db = new LiteDatabase(_connectionString)) {
             var col = db.GetCollection <LocalMessageData>();
             col.Insert(data);
         }
         VirtualRoot.RaiseEvent(new LocalMessageAddedEvent(message.Id, data, removes));
     }, location: this.GetType());
     VirtualRoot.AddCmdPath <ClearLocalMessageSetCommand>(action: message => {
         if (string.IsNullOrEmpty(_connectionString))
         {
             return;
         }
         lock (_locker) {
             _records.Clear();
         }
         using (LiteDatabase db = new LiteDatabase(_connectionString)) {
             db.DropCollection(nameof(LocalMessageData));
         }
         VirtualRoot.RaiseEvent(new LocalMessageSetClearedEvent());
     }, location: this.GetType());
 }
예제 #19
0
        private void ContinueCreateProcess()
        {
            Thread.Sleep(1000);
            if (this != NTMinerContext.Instance.LockedMineContext)
            {
                NTMinerConsole.UserWarn("结束开始挖矿");
                return;
            }

            // 执行文件书写器
            this.ExecuteFileWriters();

            // 分离命令名和参数
            GetCmdNameAndArguments(out string kernelExeFileFullName, out string arguments);
            // 这是不应该发生的,如果发生很可能是填写命令的时候拼写错误了
            if (!File.Exists(kernelExeFileFullName))
            {
                NTMinerConsole.UserError(kernelExeFileFullName + "文件不存在,可能是被杀软删除导致,请退出杀毒软件重试或者QQ群联系小编,解释:大部分挖矿内核会报毒,不是开源矿工的问题也不是杀软的问题,也不是挖矿内核的问题,是挖矿这件事情的问题,可能是挖矿符合了病毒的定义。");
            }
            if (this.KernelProcessType == KernelProcessType.Logfile)
            {
                arguments = arguments.Replace(NTKeyword.LogFileParameterName, this.LogFileFullName);
            }
            NTMinerConsole.UserOk($"\"{kernelExeFileFullName}\" {arguments}");
            NTMinerConsole.UserInfo($"有请内核上场");
            if (this != NTMinerContext.Instance.LockedMineContext)
            {
                NTMinerConsole.UserWarn("结束开始挖矿");
                return;
            }
            NTMinerConsole.InitOnece(isForce: true, initHide: !NTMinerContext.IsUiVisible);
            switch (this.KernelProcessType)
            {
            case KernelProcessType.Logfile:
                CreateLogfileProcess(kernelExeFileFullName, arguments);
                break;

            case KernelProcessType.Pip:
                CreatePipProcess(kernelExeFileFullName, arguments);
                break;

            default:
                throw new InvalidProgramException();
            }
            this.ProcessCreatedOn = DateTime.Now;
            KernelProcessDaemon();
            VirtualRoot.RaiseEvent(new MineStartedEvent(this));
        }
예제 #20
0
 public void QueryClientsAsync(QueryClientsRequest query)
 {
     try {
         var data = _clientDataSet.QueryClients(
             user: null,
             query,
             out int total,
             out List <CoinSnapshotData> latestSnapshots,
             out int totalOnlineCount,
             out int totalMiningCount);
         VirtualRoot.RaiseEvent(new QueryClientsResponseEvent(QueryClientsResponse.Ok(data, total, latestSnapshots, totalMiningCount, totalOnlineCount)));
     }
     catch (Exception e) {
         VirtualRoot.RaiseEvent(new QueryClientsResponseEvent(ResponseBase.ServerError <QueryClientsResponse>(e.Message)));
     }
 }
예제 #21
0
 protected override void Init()
 {
     RpcRoot.OfficialServer.NTMinerWalletService.GetNTMinerWalletsAsync((response, e) => {
         if (response.IsSuccess())
         {
             foreach (var item in response.Data)
             {
                 if (!_dicById.ContainsKey(item.GetId()))
                 {
                     _dicById.Add(item.GetId(), item);
                 }
             }
         }
         VirtualRoot.RaiseEvent(new NTMinerWalletSetInitedEvent());
     });
 }
예제 #22
0
 protected override Dictionary <string, Action <BasicDeliverEventArgs> > GetPaths()
 {
     return(new Dictionary <string, Action <BasicDeliverEventArgs> > {
         [_queryClientsForWsResponseRoutingKey] = ea => {
             string appId = ea.BasicProperties.AppId;
             string mqCorrelationId = ea.BasicProperties.CorrelationId;
             string loginName = ea.BasicProperties.ReadHeaderString(MqKeyword.LoginNameHeaderName);
             string sessionId = ea.BasicProperties.ReadHeaderString(MqKeyword.SessionIdHeaderName);
             QueryClientsResponse response = MinerClientMqBodyUtil.GetQueryClientsResponseMqReceiveBody(ea.Body);
             if (response != null)
             {
                 VirtualRoot.RaiseEvent(new QueryClientsForWsResponseMqEvent(appId, mqCorrelationId, ea.GetTimestamp(), loginName, sessionId, response));
             }
         }
     });
 }
예제 #23
0
        public void LoadGpuState(int gpuIndex) {
            if (gpuIndex == NTMinerContext.GpuAllId) {
                return;
            }
            adlHelper.GetPowerFanTemp(gpuIndex, out uint power, out uint fanSpeed, out int temp);

            Gpu gpu = _gpus[gpuIndex];
            bool isChanged = gpu.Temperature != temp || gpu.PowerUsage != power || gpu.FanSpeed != fanSpeed;
            gpu.Temperature = temp;
            gpu.PowerUsage = power;
            gpu.FanSpeed = fanSpeed;

            if (isChanged) {
                VirtualRoot.RaiseEvent(new GpuStateChangedEvent(Guid.Empty, gpu));
            }
        }
예제 #24
0
 public UserViewModel()
 {
     this.Enable = new DelegateCommand(() => {
         if (!ClientAppType.IsMinerStudio)
         {
             return;
         }
         if (this.IsEnabled)
         {
             return;
         }
         this.ShowSoftDialog(new DialogWindowViewModel(message: $"您确定启用{this.LoginName}吗?", title: "确认", onYes: () => {
             RpcRoot.OfficialServer.UserService.EnableUserAsync(this.LoginName, (response, exception) => {
                 if (response.IsSuccess())
                 {
                     VirtualRoot.RaiseEvent(new UserEnabledEvent(Guid.Empty, this));
                 }
                 else
                 {
                     VirtualRoot.Out.ShowError(response.ReadMessage(exception), autoHideSeconds: 4);
                 }
             });
         }));
     });
     this.Disable = new DelegateCommand(() => {
         if (!ClientAppType.IsMinerStudio)
         {
             return;
         }
         if (!this.IsEnabled)
         {
             return;
         }
         this.ShowSoftDialog(new DialogWindowViewModel(message: $"您确定禁用{this.LoginName}吗?", title: "确认", onYes: () => {
             RpcRoot.OfficialServer.UserService.DisableUserAsync(this.LoginName, (response, exception) => {
                 if (response.IsSuccess())
                 {
                     VirtualRoot.RaiseEvent(new UserDisabledEvent(Guid.Empty, this));
                 }
                 else
                 {
                     VirtualRoot.Out.ShowError(response.ReadMessage(exception), autoHideSeconds: 4);
                 }
             });
         }));
     });
 }
예제 #25
0
 public LocalMessageSet()
 {
     if (ClientAppType.IsMinerClient)
     {
         LocalMessageDtoSet = new LocalMessageDtoSet();
     }
     VirtualRoot.BuildCmdPath <AddLocalMessageCommand>(location: this.GetType(), LogEnum.DevConsole, path: message => {
         InitOnece();
         var data = LocalMessageData.Create(message.Input);
         List <ILocalMessage> removeds = new List <ILocalMessage>();
         lock (_dbToInserts) {
             _records.AddFirst(data);
             _dbToInserts.Add(data);
             while (_records.Count > NTKeyword.LocalMessageSetCapacity)
             {
                 var toRemove = _records.Last.Value;
                 removeds.Add(toRemove);
                 _records.RemoveLast();
             }
             _dbToRemoveIds.AddRange(removeds.Select(a => a.Id));
         }
         LocalMessageDtoSet.Add(data.ToDto());
         VirtualRoot.RaiseEvent(new LocalMessageAddedEvent(message.MessageId, data, removeds));
     });
     VirtualRoot.BuildCmdPath <ClearLocalMessageSetCommand>(location: this.GetType(), LogEnum.DevConsole, path: message => {
         lock (_dbToInserts) {
             _records.Clear();
             _dbToRemoveIds.Clear();
             _dbToInserts.Clear();
         }
         try {
             using (LiteDatabase db = new LiteDatabase(ConnString)) {
                 db.DropCollection(nameof(LocalMessageData));
             }
         }
         catch (Exception e) {
             Logger.ErrorDebugLine(e);
         }
         VirtualRoot.RaiseEvent(new LocalMessageSetClearedEvent());
     });
     VirtualRoot.BuildEventPath <Per1MinuteEvent>("周期保存LocalMessage到数据库", LogEnum.DevConsole, this.GetType(), PathPriority.Normal, path: message => {
         SaveToDb();
     });
     VirtualRoot.BuildEventPath <AppExitEvent>("程序退出时保存LocalMessage到数据库", LogEnum.DevConsole, this.GetType(), PathPriority.Normal, path: message => {
         SaveToDb();
     });
 }
예제 #26
0
 public SignUpPageViewModel()
 {
     if (WpfUtil.IsInDesignMode)
     {
         return;
     }
     this.RefreshCaptcha = new DelegateCommand(() => {
         ActionCaptchaId = Guid.NewGuid();
     });
     this.SignUp = new DelegateCommand(() => {
         if (string.IsNullOrEmpty(this.LoginName))
         {
             VirtualRoot.Out.ShowError("登录名不能为空", autoHideSeconds: 4);
             return;
         }
         else if (string.IsNullOrEmpty(this.Password))
         {
             VirtualRoot.Out.ShowError("密码不能为空", autoHideSeconds: 4);
             return;
         }
         else if (this.Password != this.PasswordAgain)
         {
             VirtualRoot.Out.ShowError("两次输入的密码不一致", autoHideSeconds: 4);
             return;
         }
         else if (string.IsNullOrEmpty(this.ActionCaptcha))
         {
             VirtualRoot.Out.ShowError("未输入图片验证码", autoHideSeconds: 4);
             return;
         }
         var data           = SignUpRequest.Create(this);
         data.Password      = HashUtil.Sha1(data.Password);
         data.PasswordAgain = HashUtil.Sha1(data.PasswordAgain);
         RpcRoot.OfficialServer.UserService.SignUpAsync(data, (response, e) => {
             if (response.IsSuccess())
             {
                 VirtualRoot.RaiseEvent(new SignUpedEvent(data.LoginName));
                 VirtualRoot.Execute(new CloseWindowCommand(this.Id));
                 VirtualRoot.Out.ShowSuccess("注册成功。");
             }
             else
             {
                 VirtualRoot.Out.ShowError(response.ReadMessage(e));
             }
         });
     });
 }
            public void SendGetLocalMessagesMqMessage()
            {
                if (this._minerClientVm == null || !IsMinerClientMessagesVisible)
                {
                    return;
                }
                foreach (var vm in _vms)
                {
                    vm.OnPropertyChanged(nameof(LocalMessageDtoViewModel.TimestampText));
                }
                if (_preSendMqMessageOn.AddSeconds(4) > DateTime.Now && _preMinerClientVm == _minerClientVm)
                {
                    return;
                }
                _preSendMqMessageOn = DateTime.Now;
                _preMinerClientVm   = _minerClientVm;
                long afterTime     = 0;
                var  minerClientVm = this._minerClientVm;

                lock (_locker) {
                    var item = _vms.FirstOrDefault();
                    if (item != null)
                    {
                        afterTime = item.Timestamp;
                    }
                }
                if (RpcRoot.IsOuterNet)
                {
                    WsClient.SendAsync(new WsMessage(Guid.NewGuid(), WsMessage.GetLocalMessages)
                    {
                        Data = new WrapperClientIdData {
                            ClientId = minerClientVm.ClientId,
                            Data     = afterTime
                        }
                    });
                }
                else
                {
                    RpcRoot.Client.MinerClientService.GetLocalMessagesAsync(minerClientVm.GetLocalIp(), afterTime, (data, e) => {
                        if (data != null || data.Count > 0)
                        {
                            VirtualRoot.RaiseEvent(new ClientLocalMessagesEvent(minerClientVm.ClientId, data));
                        }
                    });
                }
            }
예제 #28
0
 public WsServerNodeAddressSet(IWsServerNodeRedis wsServerNodeRedis, IWsServerNodeMqSender wsServerNodeMqSender) : base(wsServerNodeRedis)
 {
     _wsServerNodeRedis    = wsServerNodeRedis;
     _wsServerNodeMqSender = wsServerNodeMqSender;
     VirtualRoot.BuildOnecePath <WebSocketServerStatedEvent>("上报节点信息,获取节点列表", LogEnum.UserConsole, PathId.Empty, this.GetType(), PathPriority.Normal, path: _ => {
         ReportNodeAsync(callback: () => {
             base.Init(callback: () => {
                 NTMinerConsole.UserOk("Ws服务器节点地址集初始化完成");
                 VirtualRoot.RaiseEvent(new WsServerNodeAddressSetInitedEvent());
             });
             _wsServerNodeMqSender.SendWsServerNodeAdded();
         });
         VirtualRoot.BuildEventPath <Per10SecondEvent>("节点呼吸", LogEnum.UserConsole, this.GetType(), PathPriority.Normal, path: message => {
             ReportNodeAsync();
         });
     });
 }
예제 #29
0
        public void Init(bool forceRefresh = false)
        {
            DateTime now = DateTime.Now;

            // 如果未显示主界面则收益计算器也不用更新了
            if ((_initedOn == DateTime.MinValue || NTMinerContext.IsUiVisible || ClientAppType.IsMinerStudio) && (forceRefresh || _initedOn.AddMinutes(10) < now))
            {
                _initedOn = now;
                RpcRoot.OfficialServer.CalcConfigBinaryService.GetCalcConfigsAsync(data => {
                    if (data != null && data.Count != 0)
                    {
                        Init(data);
                        VirtualRoot.RaiseEvent(new CalcConfigSetInitedEvent());
                    }
                });
            }
        }
예제 #30
0
        public void Remove(Guid id)
        {
            InitOnece();
            ColumnsShowData entity;

            lock (_locker) {
                if (_dicById.TryGetValue(id, out entity))
                {
                    _dicById.Remove(id);
                    var repository = VirtualRoot.CreateLocalRepository <ColumnsShowData>();
                    repository.Remove(id);
                }
            }
            if (entity != null)
            {
                VirtualRoot.RaiseEvent(new ColumnsRemovedEvent(Guid.Empty, entity));
            }
        }