public WsServerNodeAddressSet() { VirtualRoot.AddOnecePath <WebSocketServerStatedEvent>("WebSocket服务启动后上报节点信息,获取节点列表", LogEnum.UserConsole, action: _ => { ReportNodeAsync(callback: () => { RefreshNodes(callback: () => { Write.UserOk("Ws服务器节点地址集初始化完成"); VirtualRoot.RaiseEvent(new WsServerNodeAddressSetInitedEvent()); }); }); VirtualRoot.AddEventPath <Per10SecondEvent>("节点呼吸", LogEnum.UserConsole, action: message => { ReportNodeAsync(); }, this.GetType()); VirtualRoot.AddEventPath <Per1MinuteEvent>("敲响打扫时间到的铃声", LogEnum.UserConsole, action: message => { RefreshNodes(); }, typeof(WsRoot)); // 收到Mq消息之前一定已经初始化完成,因为Mq消费者在WsServerNodeAddressSetInitedEvent事件之后才会创建 VirtualRoot.AddEventPath <WsServerNodeRemovedMqMessage>("收到移除了服务器节点Mq消息后敲响打扫时间到的铃声", LogEnum.UserConsole, action: message => { if (message.WsServerAddress == ServerRoot.HostConfig.ThisServerAddress) { return; } RefreshNodes(); }, typeof(WsRoot)); VirtualRoot.AddEventPath <WsServerNodeAddedMqMessage>("收到添加了服务器节点Mq消息后敲响打扫时间到的铃声", LogEnum.UserConsole, action: message => { if (message.WsServerAddress == ServerRoot.HostConfig.ThisServerAddress) { return; } RefreshNodes(); }, typeof(WsRoot)); }, PathId.Empty, this.GetType()); }
public ReportDataProvider() { if (ClientAppType.IsMinerClient) { VirtualRoot.AddOnecePath <HasBoot5SecondEvent>("登录服务器并报告一次0算力", LogEnum.DevConsole, action: message => { // 报告0算力从而告知服务器该客户端当前在线的币种 ReportSpeed(); }, location: this.GetType(), pathId: PathId.Empty); VirtualRoot.AddEventPath <Per2MinuteEvent>("每两分钟上报一次", LogEnum.DevConsole, action: message => { // 如果服务端通过Ws通道最近获取过算力就不用上报算力了,因为获取的算力会通过Mq走内网传播给这里上报的目的服务器, // 而Daemon进程也会每2分钟周期走Ws通道上报一次算力,从而结果就是优先使用Ws通道上报算力,只要Ws通道在周期地上报 // 算力则就不会走Http通道上报算力了。 if (WsGetSpeedOn.AddSeconds(130) > message.BornOn) { return; } ReportSpeed(); }, location: this.GetType()); VirtualRoot.AddEventPath <MineStartedEvent>("开始挖矿后报告状态", LogEnum.DevConsole, action: message => { ReportSpeed(); }, location: this.GetType()); VirtualRoot.AddEventPath <MineStopedEvent>("停止挖矿后报告状态", LogEnum.DevConsole, action: message => { RpcRoot.OfficialServer.ReportService.ReportStateAsync(NTMinerContext.Id, isMining: false); }, location: this.GetType()); } }
public Reporter() { if (VirtualRoot.IsMinerClient) { VirtualRoot.AddOnecePath <HasBoot10SecondEvent>("登录服务器并报告一次0算力", LogEnum.DevConsole, action: message => { // 报告0算力从而告知服务器该客户端当前在线的币种 ReportSpeed(); }, location: this.GetType(), pathId: Guid.Empty); VirtualRoot.AddEventPath <Per2MinuteEvent>("每两分钟上报一次", LogEnum.DevConsole, action: message => { ReportSpeed(); }, location: this.GetType()); VirtualRoot.AddEventPath <MineStartedEvent>("开始挖矿后报告状态", LogEnum.DevConsole, action: message => { ReportSpeed(); }, location: this.GetType()); VirtualRoot.AddEventPath <MineStopedEvent>("停止挖矿后报告状态", LogEnum.DevConsole, action: message => { RpcRoot.Server.ReportService.ReportStateAsync(NTKeyword.OfficialServerHost, VirtualRoot.Id, isMining: false); }, location: this.GetType()); } }
private ConsoleWindow() { this.Width = AppRoot.MainWindowWidth; this.Height = AppRoot.MainWindowHeight; InitializeComponent(); this.Loaded += (sender, e) => { _thisWindowHandle = new WindowInteropHelper(this).Handle; IntPtr console = NTMinerConsole.GetOrAlloc(); SafeNativeMethods.SetWindowLong(console, SafeNativeMethods.GWL_STYLE, SafeNativeMethods.WS_VISIBLE); SafeNativeMethods.SetParent(console, _thisWindowHandle); hwndSource = PresentationSource.FromVisual((Visual)sender) as HwndSource; hwndSource.AddHook(new HwndSourceHook(WndProc)); if (AppUtil.IsHotKeyEnabled) { HotKeyUtil.RegHotKey = (key) => { if (!RegHotKey(key, out string message)) { VirtualRoot.Out.ShowError(message, autoHideSeconds: 4); return(false); } else { VirtualRoot.Out.ShowSuccess($"热键Ctrl + Alt + {key.ToString()} 设置成功"); return(true); } }; } }; // 延迟展示从而避免不需要展示红字的时候看到红字 VirtualRoot.AddOnecePath <HasBoot1SecondEvent>("启动一会后显式指引解决WindowsZoomBug的一行红字", LogEnum.None, action: message => { LbtnWindowsZoomBug.Visibility = Visibility.Visible; }, pathId: PathId.Empty, this.GetType()); }
protected AbstractMqMessagePath(string queue) : base(queue) { VirtualRoot.AddOnecePath <TEvent1>($"{typeof(TEvent1).Name}事件已经发生,可以订阅对应的Mq了", LogEnum.UserConsole, action: message => { _isEvent1Happended = true; }, PathId.Empty, this.GetType()); VirtualRoot.AddOnecePath <TEvent2>($"{typeof(TEvent2).Name}事件已经发生,可以订阅对应的Mq了", LogEnum.UserConsole, action: message => { _isEvent2Happended = true; }, PathId.Empty, this.GetType()); }
public CalcConfigSet(INTMinerRoot root) { _root = root; if (VirtualRoot.IsMinerClient) { VirtualRoot.AddOnecePath <HasBoot20SecondEvent>("启动一定时间后初始化收益计算器", LogEnum.DevConsole, action: message => { Init(forceRefresh: true); }, location: this.GetType(), pathId: Guid.Empty); } }
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.AddOnecePath <ClientSetInitedEvent>("矿机集初始化后开始拉取矿机算力的进程", LogEnum.None, action: message => { PullSpeedInit(); }, PathId.Empty, this.GetType()); }
private ConsoleWindow() { this.Width = AppRoot.MainWindowWidth; this.Height = AppRoot.MainWindowHeight; InitializeComponent(); this.Loaded += (sender, e) => { _thisWindowHandle = new WindowInteropHelper(this).Handle; IntPtr console = NTMinerConsole.GetOrAlloc(); SafeNativeMethods.SetWindowLong(console, SafeNativeMethods.GWL_STYLE, SafeNativeMethods.WS_VISIBLE); SafeNativeMethods.SetParent(console, _thisWindowHandle); hwndSource = PresentationSource.FromVisual((Visual)sender) as HwndSource; hwndSource.AddHook(new HwndSourceHook(Win32Proc.WindowProc)); }; // 延迟展示从而避免不需要展示红字的时候看到红字 VirtualRoot.AddOnecePath <HasBoot1SecondEvent>("启动一会后显式指引解决WindowsZoomBug的一行红字", LogEnum.None, action: message => { LbtnWindowsZoomBug.Visibility = Visibility.Visible; }, pathId: PathId.Empty, this.GetType()); }
public WsServerNodeAddressSet(IWsServerNodeRedis wsServerNodeRedis, IWsServerNodeMqSender wsServerNodeMqSender) : base(wsServerNodeRedis) { _wsServerNodeRedis = wsServerNodeRedis; _wsServerNodeMqSender = wsServerNodeMqSender; VirtualRoot.AddOnecePath <WebSocketServerStatedEvent>("WebSocket服务启动后上报节点信息,获取节点列表", LogEnum.UserConsole, action: _ => { ReportNodeAsync(callback: () => { base.Init(callback: () => { NTMinerConsole.UserOk("Ws服务器节点地址集初始化完成"); VirtualRoot.RaiseEvent(new WsServerNodeAddressSetInitedEvent()); }); _wsServerNodeMqSender.SendWsServerNodeAdded(ServerRoot.HostConfig.ThisServerAddress); }); VirtualRoot.AddEventPath <Per10SecondEvent>("节点呼吸", LogEnum.UserConsole, action: message => { ReportNodeAsync(); }, this.GetType()); VirtualRoot.AddEventPath <Per1MinuteEvent>("打扫", LogEnum.DevConsole, action: message => { VirtualRoot.RaiseEvent(new CleanTimeArrivedEvent(AsEnumerable().ToArray())); }, this.GetType()); }, PathId.Empty, this.GetType()); }
private void AddOnecePath <TMessage>(string description, LogEnum logType, Action <TMessage> action, Guid pathId, Type location) { var messagePathId = VirtualRoot.AddOnecePath(description, logType, action, pathId, location); _contextPathIds.Add(messagePathId); }
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.AddOnecePath <GetSelfWorkLocalJsonResponsedEvent>("获取到响应结果后填充Vm内存", LogEnum.DevConsole, action: message => { if (message.ClientId == _minerClientVm.ClientId) { string data = message.Data; EditJson(formType, WorkType.SelfWork, data); } }, PathId.Empty, typeof(MineWorkViewModel)); MinerStudioService.Instance.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); } } } } }