示例#1
0
        public ReportDataProvider()
        {
            if (ClientAppType.IsMinerClient)
            {
                VirtualRoot.BuildOnecePath <HasBoot5SecondEvent>("登录服务器并报告一次0算力", LogEnum.DevConsole,
                                                                 path: message => {
                    // 报告0算力从而告知服务器该客户端当前在线的币种
                    ReportSpeed();
                }, location: this.GetType(), pathId: PathId.Empty);

                VirtualRoot.BuildEventPath <Per2MinuteEvent>("每两分钟上报一次", LogEnum.DevConsole,
                                                             path: message => {
                    // 如果服务端通过Ws通道最近获取过算力就不用上报算力了,因为获取的算力会通过Mq走内网传播给这里上报的目的服务器,
                    // 而Daemon进程也会每2分钟周期走Ws通道上报一次算力,从而结果就是优先使用Ws通道上报算力,只要Ws通道在周期地上报
                    // 算力则就不会走Http通道上报算力了。
                    if (WsGetSpeedOn.AddSeconds(130) > message.BornOn)
                    {
                        return;
                    }
                    ReportSpeed();
                }, location: this.GetType());

                VirtualRoot.BuildEventPath <MineStartedEvent>("开始挖矿后报告状态", LogEnum.DevConsole,
                                                              path: message => {
                    ReportSpeed();
                }, location: this.GetType());

                VirtualRoot.BuildEventPath <MineStopedEvent>("停止挖矿后报告状态", LogEnum.DevConsole,
                                                             path: message => {
                    RpcRoot.OfficialServer.ReportService.ReportStateAsync(NTMinerContext.Id, isMining: false);
                }, location: this.GetType());
            }
        }
 protected AbstractMqMessagePath(string queue) : base(queue)
 {
     VirtualRoot.BuildOnecePath <TEvent1>($"{typeof(TEvent1).Name}事件已经发生,可以订阅对应的Mq了", LogEnum.UserConsole, path: message => {
         _isEvent1Happended = true;
     }, PathId.Empty, this.GetType());
     VirtualRoot.BuildOnecePath <TEvent2>($"{typeof(TEvent2).Name}事件已经发生,可以订阅对应的Mq了", LogEnum.UserConsole, path: message => {
         _isEvent2Happended = true;
     }, PathId.Empty, this.GetType());
 }
示例#3
0
 public CalcConfigSet(INTMinerContext ntminerContext)
 {
     _ntminerContext = ntminerContext;
     if (ClientAppType.IsMinerClient)
     {
         VirtualRoot.BuildOnecePath <HasBoot20SecondEvent>("初始化收益计算器", LogEnum.DevConsole, pathId: PathId.Empty, location: this.GetType(), PathPriority.Normal,
                                                           path: message => {
             Init();
         });
     }
 }
示例#4
0
 public CalcConfigSet(INTMinerContext root)
 {
     _root = root;
     if (ClientAppType.IsMinerClient)
     {
         VirtualRoot.BuildOnecePath <HasBoot20SecondEvent>("初始化收益计算器", LogEnum.DevConsole,
                                                           path: message => {
             Init();
         }, location: this.GetType(), pathId: PathId.Empty);
     }
 }
示例#5
0
 public ClientDataSet() : base(isPull: true, getDatas: callback => {
     Task.Factory.StartNew(() => {
         using (LiteDatabase db = CreateLocalDb()) {
             var col = db.GetCollection <MinerData>();
             callback?.Invoke(col.FindAll().Select(a => ClientData.Create(a)));
         }
     });
 }) {
     VirtualRoot.BuildOnecePath <ClientSetInitedEvent>("矿机集初始化后开始拉取矿机算力的进程", LogEnum.None, path: message => {
         PullSpeedInit();
     }, PathId.Empty, this.GetType());
 }
 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();
         });
     });
 }
示例#7
0
 public WsServerNodeAddressSet(IWsServerNodeRedis wsServerNodeRedis, IWsServerNodeMqSender wsServerNodeMqSender) : base(wsServerNodeRedis)
 {
     _wsServerNodeRedis    = wsServerNodeRedis;
     _wsServerNodeMqSender = wsServerNodeMqSender;
     VirtualRoot.BuildOnecePath <WebSocketServerStatedEvent>("WebSocket服务启动后上报节点信息,获取节点列表", LogEnum.UserConsole, path: _ => {
         ReportNodeAsync(callback: () => {
             base.Init(callback: () => {
                 NTMinerConsole.UserOk("Ws服务器节点地址集初始化完成");
                 VirtualRoot.RaiseEvent(new WsServerNodeAddressSetInitedEvent());
             });
             _wsServerNodeMqSender.SendWsServerNodeAdded(ServerRoot.HostConfig.ThisServerAddress);
         });
         VirtualRoot.BuildEventPath <Per10SecondEvent>("节点呼吸", LogEnum.UserConsole, path: message => {
             ReportNodeAsync();
         }, this.GetType());
         VirtualRoot.BuildEventPath <Per1MinuteEvent>("打扫", LogEnum.DevConsole, path: message => {
             VirtualRoot.RaiseEvent(new CleanTimeArrivedEvent(AsEnumerable().ToArray()));
         }, this.GetType());
     }, PathId.Empty, this.GetType());
 }
示例#8
0
        private void AddOnecePath <TMessage>(string description, LogEnum logType, Guid pathId, Type location, Action <TMessage> path)
        {
            var messagePathId = VirtualRoot.BuildOnecePath(description, logType, pathId, location, PathPriority.Normal, path);

            _contextPathIds.Add(messagePathId);
        }
示例#9
0
 private void DoEdit(FormType?formType)
 {
     if (!MinerStudioRoot.MineWorkVms.TryGetMineWorkVm(this.Id, out MineWorkViewModel mineWorkVm) && !this.Id.IsSelfMineWorkId())
     {
         WpfUtil.ShowInputDialog("作业名称", string.Empty, string.Empty, workName => {
             if (string.IsNullOrEmpty(workName))
             {
                 return("作业名称是必须的");
             }
             return(string.Empty);
         }, onOk: workName => {
             new MineWorkViewModel(this)
             {
                 Name = workName
             }.Save.Execute(null);
         });
     }
     else
     {
         _minerClientVm = MinerStudioRoot.MinerClientsWindowVm.SelectedMinerClients.FirstOrDefault();
         if (_minerClientVm == null)
         {
             VirtualRoot.Out.ShowError("未选中矿机", autoHideSeconds: 4);
             return;
         }
         if (this.Id.IsSelfMineWorkId())
         {
             SelfMineWork.Description = $"{_minerClientVm.GetMinerOrClientName()} 矿机的单机作业";
             if (RpcRoot.IsOuterNet)
             {
                 if (!_minerClientVm.IsOuterUserEnabled)
                 {
                     VirtualRoot.Out.ShowError("无法操作,因为选中的矿机未开启外网群控。", autoHideSeconds: 6);
                     return;
                 }
                 VirtualRoot.BuildOnecePath <GetSelfWorkLocalJsonResponsedEvent>("填充Vm内存", LogEnum.DevConsole, path: message => {
                     if (message.ClientId == _minerClientVm.ClientId)
                     {
                         string data = message.Data;
                         EditJson(formType, WorkType.SelfWork, data);
                     }
                 }, PathId.Empty, typeof(MineWorkViewModel));
                 MinerStudioRoot.MinerStudioService.GetSelfWorkLocalJsonAsync(_minerClientVm);
             }
             else
             {
                 RpcRoot.Client.NTMinerDaemonService.GetSelfWorkLocalJsonAsync(_minerClientVm, (json, e) => {
                     string data = json;
                     EditJson(formType, WorkType.SelfWork, data);
                 });
             }
         }
         else
         {
             // 编辑作业前切换上下文
             // 根据workId下载json保存到本地并调用LocalJson.Instance.ReInit()
             if (RpcRoot.IsOuterNet)
             {
                 RpcRoot.OfficialServer.UserMineWorkService.GetLocalJsonAsync(this.Id, (response, e) => {
                     if (response.IsSuccess())
                     {
                         string data = response.Data;
                         EditJson(formType, WorkType.MineWork, data);
                     }
                 });
             }
             else
             {
                 try {
                     string localJsonFileFullName = MinerStudioPath.GetMineWorkLocalJsonFileFullName(this.Id);
                     string data = string.Empty;
                     if (File.Exists(localJsonFileFullName))
                     {
                         data = File.ReadAllText(localJsonFileFullName);
                     }
                     EditJson(formType, WorkType.MineWork, data);
                 }
                 catch (Exception e) {
                     Logger.ErrorDebugLine(e);
                 }
             }
         }
     }
 }
示例#10
0
        private void AddOnecePath <TMessage>(string description, LogEnum logType, Action <TMessage> action, Guid pathId, Type location)
        {
            var messagePathId = VirtualRoot.BuildOnecePath(description, logType, action, pathId, location);

            _contextPathIds.Add(messagePathId);
        }
 protected AbstractMqMessagePath(string queue) : base(queue)
 {
     VirtualRoot.BuildOnecePath <TEvent>($"{typeof(TEvent).Name}事件已经发生,可以订阅对应的Mq了", LogEnum.UserConsole, PathId.Empty, this.GetType(), PathPriority.Normal, path: message => {
         _isEventHappended = true;
     });
 }