private EthWalletSet() { Init(); VirtualRoot.BuildEventPath <Per24HourEvent>("刷新EthWalletSet列表", LogEnum.DevConsole, this.GetType(), PathPriority.Normal, path: message => { Init(); }); }
public KernelOutputKeywordsViewModel() { if (WpfUtil.IsInDesignMode) { return; } VirtualRoot.BuildEventPath<CurrentMineContextChangedEvent>("挖矿上下文变更后刷新内核输出关键字Vm视图集", LogEnum.DevConsole, path: message => { OnPropertyChanged(nameof(KernelOutputVm)); }, location: this.GetType()); this.Add = new DelegateCommand(() => { KernelOutputViewModel kernelOutputVm = KernelOutputVm; if (kernelOutputVm == null) { return; } var data = new KernelOutputKeywordData { Id = Guid.NewGuid(), MessageType = LocalMessageType.Info.GetName(), Keyword = string.Empty, Description = string.Empty, KernelOutputId = kernelOutputVm.Id }; // 新建的内核输出关键字时的工作流:默认为Profile级,测试没问题后,然后在界面上提供个按钮转化为Global级提交到服务器 data.SetDataLevel(DataLevel.Profile); new KernelOutputKeywordViewModel(data).Edit.Execute(FormType.Add); }); }
public CaptchaSet(ICaptchaDataRedis redis) { _redis = redis; redis.GetAllAsync().ContinueWith(t => { if (t.Result != null && t.Result.Count != 0) { foreach (var item in t.Result) { _dicById.Add(item.Id, item); } } IsReadied = true; }); VirtualRoot.BuildEventPath <Per1MinuteEvent>("清理过期的验证码", LogEnum.DevConsole, this.GetType(), PathPriority.Normal, path: message => { // 验证码在内存中留存10分钟 DateTime time = message.BornOn.AddMinutes(-10); CaptchaData[] toRemoves; lock (_locker) { toRemoves = _dicById.Values.Where(a => a.CreatedOn <= time).ToArray(); } foreach (var item in toRemoves) { _dicById.Remove(item.Id); _redis.DeleteAsync(item); } }); }
public RemoteIpSet() { VirtualRoot.BuildEventPath <WsTcpClientAcceptedEvent>("收集Ws客户端IP和端口", LogEnum.None, path: message => { if (_dicByIp.TryGetValue(message.RemoteIp, out RemoteIpEntry entry)) { entry.IncActionTimes(); } else { entry = new RemoteIpEntry(message.RemoteIp); entry.IncActionTimes(); _dicByIp.Add(message.RemoteIp, entry); } }, this.GetType()); VirtualRoot.BuildEventPath <WebApiRequestEvent>("收集WebApi客户端IP和端口", LogEnum.None, path: message => { if (_dicByIp.TryGetValue(message.RemoteIp, out RemoteIpEntry entry)) { entry.IncActionTimes(); } else { entry = new RemoteIpEntry(message.RemoteIp); entry.IncActionTimes(); _dicByIp.Add(message.RemoteIp, entry); } }, this.GetType()); VirtualRoot.BuildEventPath <Per10SecondEvent>("周期找出恶意IP封掉", LogEnum.None, path: message => { // TODO:阿里云AuthorizeSecurityGroup }, this.GetType()); }
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()); } }
public KernelOutputKeywordsViewModel() { if (WpfUtil.IsInDesignMode) { return; } VirtualRoot.BuildEventPath <CurrentMineContextChangedEvent>("挖矿上下文变更后刷新内核输出关键字Vm视图集", LogEnum.DevConsole, action: message => { OnPropertyChanged(nameof(KernelOutputVm)); }); this.Add = new DelegateCommand(() => { KernelOutputViewModel kernelOutputVm = KernelOutputVm; if (kernelOutputVm == null) { return; } new KernelOutputKeywordViewModel(new KernelOutputKeywordData { Id = Guid.NewGuid(), MessageType = LocalMessageType.Info.GetName(), DataLevel = DevMode.IsDevMode? DataLevel.Global: DataLevel.Profile, Keyword = string.Empty, Description = string.Empty, KernelOutputId = kernelOutputVm.Id }).Edit.Execute(FormType.Add); }); }
/// <summary> /// 这里挺绕,逻辑是父类通过回调函数的参数声明一个接收矿工列表的方法,然后由 /// 子类调用该基类方法时传入矿工列表,从而父类收到了来自子类的矿工列表。因为 /// 该基类有两个子类,一个子类的数据源是redis一个子类的数据源是litedb。 /// </summary> /// <param name="isPull">内网群控传true,外网群控传false</param> /// <param name="getDatas"></param> public ClientDataSetBase(bool isPull, Action <Action <IEnumerable <ClientData> > > getDatas) { _isPull = isPull; Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); getDatas(clientDatas => { foreach (var clientData in clientDatas) { _dicByObjectId[clientData.Id] = clientData; _dicByClientId[clientData.ClientId] = clientData; } InitedOn = DateTime.Now; IsReadied = true; stopwatch.Stop(); NTMinerConsole.UserLine($"矿机集就绪,耗时 {stopwatch.GetElapsedSeconds().ToString("f2")} 秒", isPull ? MessageType.Debug : MessageType.Ok); VirtualRoot.RaiseEvent(new ClientSetInitedEvent()); }); if (!isPull) { VirtualRoot.BuildEventPath <Per1MinuteEvent>("周期清理不活跃的缓存数据", LogEnum.None, typeof(ClientDataSetBase), PathPriority.Normal, message => { DateTime time = message.BornOn.AddMinutes(-10); string[] loginNameToRemoves = _clientDatasByLoginName.Where(a => a.Value.LastAccessOn <= time).Select(a => a.Key).ToArray(); foreach (var loginName in loginNameToRemoves) { _clientDatasByLoginName.TryRemove(loginName, out _); } }); } }
public CaptchaSet(ICaptchaRedis redis) { _redis = redis; redis.GetAllAsync().ContinueWith(t => { if (t.Result != null && t.Result.Count != 0) { foreach (var item in t.Result) { _dicById.Add(item.Id, item); } } IsReadied = true; }); VirtualRoot.BuildEventPath <Per1MinuteEvent>("清理过期的验证码", LogEnum.DevConsole, path: message => { // 验证码在内存中留存10分钟 DateTime time = message.BornOn.AddMinutes(-10); List <CaptchaData> toRemoves = new List <CaptchaData>(); foreach (var item in _dicById.Values) { if (item.CreatedOn <= time) { toRemoves.Add(item); } } foreach (var item in toRemoves) { _dicById.Remove(item.Id); _redis.DeleteAsync(item); } }, this.GetType()); }
public CoinSnapshotSetBase(bool isPull, IClientDataSetBase clientSet) { _isPull = isPull; _clientSet = clientSet; LogEnum logType = isPull ? LogEnum.None : LogEnum.UserConsole; VirtualRoot.BuildEventPath <Per10SecondEvent>("周期性拍摄快照", logType, path: message => { Snapshot(message.BornOn); }, location: this.GetType()); VirtualRoot.BuildEventPath <Per2MinuteEvent>("周期性移除内存中20分钟前的快照", logType, path: message => { DateTime time = message.BornOn.AddMinutes(-20); var toRemoves = _dataList.Where(a => a.Timestamp < time).ToArray(); foreach (var item in toRemoves) { _dataList.Remove(item); } }, location: this.GetType()); VirtualRoot.BuildEventPath <HasBoot1MinuteEvent>("启动一会儿后清理一下很长时间之前的算力报告数据库文件", logType, path: message => { ClearReportDbFiles(message.BornOn); }, this.GetType()); VirtualRoot.BuildEventPath <Per24HourEvent>("每24小时清理一下很长时间之前的算力报告数据库文件", logType, path: message => { ClearReportDbFiles(message.BornOn); }, this.GetType()); }
public void AutoStart() { bool IsAutoStart = (MinerProfile.IsAutoStart || CommandLineArgs.IsAutoStart); if (IsAutoStart && !this.MinerProfile.IsMining) { this.MinerProfile.IsMining = true; int n = MinerProfile.AutoStartDelaySeconds; IMessagePathId handler = null; handler = VirtualRoot.BuildEventPath <Per1SecondEvent>("挖矿倒计时", LogEnum.None, action: message => { if (NTMinerRoot.IsAutoStartCanceled) { BtnStopText = $"尚未开始"; n = 0; } else { BtnStopText = $"倒计时{--n}"; } if (n <= 0) { VirtualRoot.DeletePath(handler); if (!NTMinerRoot.IsAutoStartCanceled) { BtnStopText = "正在挖矿"; MinerProfile.IsMining = true; VirtualRoot.ThisLocalInfo(nameof(StartStopMineButtonViewModel), $"自动开始挖矿", toConsole: true); NTMinerRoot.Instance.StartMine(); } } }); } }
public CalcConfigSet(INTMinerRoot root) { _root = root; VirtualRoot.BuildEventPath <MainWindowShowedEvent>("主界面显示后刷新收益计算器", LogEnum.DevConsole, action: message => { Init(forceRefresh: true); }); }
public MqCountSet() { VirtualRoot.BuildEventPath <MqCountReceivedMqEvent>("将收到的MqCountData数据更新到内存", LogEnum.None, this.GetType(), PathPriority.Normal, message => { if (!string.IsNullOrEmpty(message.AppId) && message.Data != null) { _dicByAppId[message.AppId] = message.Data; } }); }
public GpuNameSet() { VirtualRoot.BuildEventPath <ClientSetInitedEvent>("矿机列表初始化后计算显卡名称集合", LogEnum.DevConsole, path: message => { Init(); }, this.GetType()); VirtualRoot.BuildEventPath <Per10MinuteEvent>("周期刷新显卡名称集合", LogEnum.DevConsole, path: message => { Init(); }, this.GetType()); }
public MinerClientConsoleViewModel() { if (ClientAppType.IsMinerStudio) { VirtualRoot.BuildEventPath <MinerClientSelectionChangedEvent>("刷新矿机控制台输出", LogEnum.DevConsole, path: message => { bool isChanged = true; if (message.MinerClientVm != null && this._minerClientVm != null && this._minerClientVm.ClientId == message.MinerClientVm.ClientId) { isChanged = false; } LatestTimestamp = Timestamp.UnixBaseTime; if (isChanged) { lock (_locker) { _outLines.Clear(); try { Console.Clear(); } catch { } this._minerClientVm = message.MinerClientVm; } SendGetConsoleOutLinesMqMessage(isFast: true); } }, this.GetType()); VirtualRoot.BuildEventPath <ClientConsoleOutLinesEvent>("将收到的挖矿端控制台消息输出到输出窗口", LogEnum.DevConsole, path: message => { if (this._minerClientVm == null || this._minerClientVm.ClientId != message.ClientId || message.Data == null || message.Data.Count == 0) { return; } lock (_locker) { foreach (var item in message.Data) { _outLines.Add(item); NTMinerConsole.UserLine(item.Line, ConsoleColor.White, withPrefix: false); } // 因为客户端的时间可能不准所以不能使用客户端的时间 LatestTimestamp = DateTime.Now; } }, this.GetType()); VirtualRoot.BuildEventPath <Per5SecondEvent>("周期获取当前选中的那台矿机的控制台输出", LogEnum.DevConsole, path: message => { SendGetConsoleOutLinesMqMessage(isFast: false); }, this.GetType()); VirtualRoot.BuildEventPath <Per1SecondEvent>("客户端控制台输出倒计时秒表", LogEnum.None, path: message => { if (this._minerClientVm == null || this._latestTimestamp == Timestamp.UnixBaseTime) { return; } OnPropertyChanged(nameof(LatestTimeSpanText)); }, this.GetType()); } }
public CalcConfigSet(INTMinerContext ntminerContext) { _ntminerContext = ntminerContext; if (ClientAppType.IsMinerClient) { VirtualRoot.BuildEventPath <MineStartedEvent>("开始挖矿时加载收益计算器数据", LogEnum.DevConsole, location: this.GetType(), PathPriority.Normal, path: message => { Init(); }); } }
public AbstractWsClient(NTMinerAppType appType) { _appType = appType; _clientId = NTMinerRegistry.GetClientId(appType); VirtualRoot.BuildEventPath <Per1SecondEvent>("重试Ws连接的秒表倒计时", LogEnum.None, typeof(VirtualRoot), PathPriority.Normal, path: message => { if (_nextTrySecondsDelay > 0) { _nextTrySecondsDelay--; } }); VirtualRoot.BuildEventPath <Per10SecondEvent>("周期检查Ws连接", LogEnum.None, typeof(VirtualRoot), PathPriority.Normal, path: message => { if (_ws == null || _ws.ReadyState != WebSocketState.Open) { if (_continueCount >= _failConnCount) { _continueCount = 0; OpenOrCloseWs(); } else { _continueCount++; } } }); // 20秒是个不错的值,即不太频繁,也不太少 VirtualRoot.BuildEventPath <Per20SecondEvent>("周期Ws Ping", LogEnum.None, typeof(VirtualRoot), PathPriority.Normal, path: message => { if (_ws != null && _ws.ReadyState == WebSocketState.Open) { // 或者_ws.IsAlive,因为_ws.IsAlive内部也是一个Ping,所以用Ping从而显式化这里有个网络请求 Task.Factory.StartNew(() => { if (!_ws.Ping()) { _ws.CloseAsync(CloseStatusCode.Away); } }); } }); VirtualRoot.BuildEventPath <AppExitEvent>("退出程序时关闭Ws连接", LogEnum.DevConsole, this.GetType(), PathPriority.Normal, path: message => { _ws?.CloseAsync(CloseStatusCode.Normal, "客户端程序退出"); }); NetworkChange.NetworkAvailabilityChanged += (object sender, NetworkAvailabilityEventArgs e) => { if (e.IsAvailable) { 1.SecondsDelay().ContinueWith(t => { OpenOrCloseWs(isResetFailCount: true); }); } }; /// 1,进程启动后第一次连接时; NeedReWebSocket(); OpenOrCloseWs(); }
public MinerClientMessagesViewModel() { if (_called) { throw new InvalidProgramException("只能调用一次"); } _called = true; if (WpfUtil.IsInDesignMode) { return; } if (ClientAppType.IsMinerStudio) { VirtualRoot.BuildEventPath <MinerClientSelectionChangedEvent>("刷新矿机消息列表", LogEnum.DevConsole, path: message => { bool isChanged = true; if (message.MinerClientVm != null && this._minerClientVm != null && this._minerClientVm.ClientId == message.MinerClientVm.ClientId) { isChanged = false; } if (isChanged) { lock (_locker) { _vms.Clear(); this._minerClientVm = message.MinerClientVm; OnPropertyChanged(nameof(IsNoRecord)); } SendGetLocalMessagesMqMessage(isFast: true); } }, this.GetType()); VirtualRoot.BuildEventPath <ClientLocalMessagesEvent>("将收到的挖矿端本地消息展示到消息列表", LogEnum.DevConsole, path: message => { if (this._minerClientVm == null || this._minerClientVm.ClientId != message.ClientId) { return; } if (message.Data == null || message.Data.Count == 0) { return; } UIThread.Execute(() => { foreach (var item in message.Data) { _vms.Insert(0, new LocalMessageDtoViewModel(item)); } OnPropertyChanged(nameof(IsNoRecord)); }); }, location: this.GetType()); VirtualRoot.BuildEventPath <Per5SecondEvent>("周期获取当前选中的那台矿机的本地消息", LogEnum.DevConsole, path: message => { SendGetLocalMessagesMqMessage(isFast: false); }, this.GetType()); } }
private void PullSpeedInit() { if (_isPullSpeedInited) { return; } _isPullSpeedInited = true; VirtualRoot.BuildEventPath <Per10SecondEvent>("周期拉取矿机状态", LogEnum.DevConsole, this.GetType(), PathPriority.Normal, message => { if (RpcRoot.IsOuterNet) { return; } Task.Factory.StartNew(() => { NTMinerConsole.DevDebug("周期拉取数据更新拍照源数据"); ClientData[] clientDatas = _dicByObjectId.Values.ToArray(); Task[] tasks = clientDatas.Select(CreatePullTask).ToArray(); Task.WaitAll(tasks, 5 * 1000); if (RpcRoot.IsOuterNet) { return; } #region 将NoSpeedSeconds秒内更新过的记录持久化到磁盘 List <MinerData> minerDatas = new List <MinerData>(); DateTime time = message.BornOn.AddSeconds(-20); foreach (var clientData in _dicByObjectId.Values) { if (clientData.MinerActiveOn > time) { minerDatas.Add(MinerData.Create(clientData)); } else { clientData.IsMining = false; clientData.MainCoinSpeed = 0; clientData.DualCoinSpeed = 0; foreach (var item in clientData.GpuTable) { item.MainCoinSpeed = 0; item.DualCoinSpeed = 0; } } } if (minerDatas.Count > 0) { DoUpdateSave(minerDatas); } #endregion }); }); }
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()); }); }
public MinerProfileOption() { this.Vm = AppRoot.MinerProfileVm; this.DataContext = AppRoot.MinerProfileVm; InitializeComponent(); _outerUserGroupBg = OuterUserGroup.BorderBrush; _automationGroupBg = AutomationGroup.BorderBrush; this.OnLoaded(window => { VirtualRoot.BuildEventPath <SignUpedEvent>("注册了新外网群控用户后自动填入外网群控用户名", LogEnum.None, path: message => { this.Vm.OuterUserId = message.LoginName; }, this.GetType()); }); }
public ServerMessagesViewModel() { if (WpfUtil.IsInDesignMode) { return; } foreach (var messageType in EnumItem <ServerMessageType> .GetEnumItems()) { _count.Add(messageType.Value, new MessageTypeItem <ServerMessageType>(messageType, ServerMessageViewModel.GetIcon, ServerMessageViewModel.GetIconFill, RefreshQueryResults)); } Init(); this.Add = new DelegateCommand(() => { new ServerMessageViewModel(new ServerMessageData { Id = Guid.NewGuid(), MessageType = ServerMessageType.Info.GetName(), Provider = "admin", Content = string.Empty, Timestamp = DateTime.MinValue }).Edit.Execute(FormType.Add); }); this.ClearKeyword = new DelegateCommand(() => { this.Keyword = string.Empty; }); this.Clear = new DelegateCommand(() => { this.ShowDialog(new DialogWindowViewModel(message: "确定清空吗?", title: "确认", onYes: () => { VirtualRoot.Execute(new ClearServerMessages()); })); }); VirtualRoot.BuildEventPath <ServerMessagesClearedEvent>("清空了本地存储的服务器消息后刷新Vm内存", LogEnum.DevConsole, action: message => { UIThread.Execute(() => { Init(); }); }); VirtualRoot.BuildEventPath <NewServerMessageLoadedEvent>("从服务器加载了新消息后刷新Vm内存", LogEnum.DevConsole, action: message => { UIThread.Execute(() => { foreach (var item in message.Data) { var vm = new ServerMessageViewModel(item); _serverMessageVms.Insert(0, vm); if (IsSatisfyQuery(vm)) { _queyResults.Insert(0, vm); } } OnPropertyChanged(nameof(IsNoRecord)); }); }); _serverMessageVms = new ObservableCollection <ServerMessageViewModel>(NTMinerRoot.Instance.ServerMessageSet.Select(a => new ServerMessageViewModel(a))); }
public WsServerNodeAddressSet(IWsServerNodeRedis wsServerNodeRedis) : base(wsServerNodeRedis) { VirtualRoot.BuildEventPath <Per10SecondEvent>("清理掉离线的WsServer节点", LogEnum.None, path: message => { wsServerNodeRedis.GetAllAddress().ContinueWith(t => { var offlines = GetOfflineAddress(t.Result); if (offlines != null && offlines.Count != 0) { wsServerNodeRedis.ClearAsync(offlines).ContinueWith(_ => { NTMinerConsole.UserWarn($"清理了 {offlines.Count} 条"); }); } }); }, this.GetType()); }
public WsServerNodeAddressSet(IWsServerNodeRedis wsServerNodeRedis) : base(wsServerNodeRedis) { VirtualRoot.BuildEventPath <Per5MinuteEvent>("清理掉离线的WsServer节点", LogEnum.None, this.GetType(), PathPriority.Normal, path: message => { wsServerNodeRedis.GetAllAddress().ContinueWith(t => { var offlines = t.Result.Where(a => IsOffline(a.Value, message.BornOn)).Select(a => a.Key).ToArray(); if (offlines != null && offlines.Length != 0) { wsServerNodeRedis.ClearAsync(offlines).ContinueWith(_ => { NTMinerConsole.UserWarn($"清理了 {offlines.Length.ToString()} 条"); }); } }); }); }
public MainMenuViewModel() { if (WpfUtil.IsInDesignMode) { return; } VirtualRoot.BuildEventPath <MinerStudioServiceSwitchedEvent>("群控后台客户端服务类型切换后刷新菜单的展示状态", LogEnum.DevConsole, this.GetType(), PathPriority.Normal, path: message => { this.OnPropertyChanged(nameof(LoginName)); this.OnPropertyChanged(nameof(IsMinerStudioLocalOrOuterAdminVisible)); this.OnPropertyChanged(nameof(IsMinerStudioOuterAdmin)); this.OnPropertyChanged(nameof(IsMinerStudioOuterAdminVisible)); this.OnPropertyChanged(nameof(IsMinerStudioOuterVisible)); this.OnPropertyChanged(nameof(IsMinerStudioLocalVisible)); }); }
public MainWindowViewModel() { this.Start = new DelegateCommand(() => { if (IsScanning) { IsScanning = false; } else { if (_fromIpAddressVm.IsAnyEmpty || _toIpAddressVm.IsAnyEmpty) { throw new ValidationException("IP地址不能为空"); } if (!IPAddress.TryParse(_fromIpAddressVm.AddressText, out _) || !IPAddress.TryParse(_toIpAddressVm.AddressText, out _)) { throw new ValidationException("IP地址格式不正确"); } if (Results.Count != 0) { Results.Clear(); } List <string> ipList = Net.IpUtil.CreateIpRange(_fromIpAddressVm.AddressText, _toIpAddressVm.AddressText); Task.Factory.StartNew(() => { Scan(ipList.ToArray()); }); } }); VirtualRoot.BuildEventPath <LocalIpSetInitedEvent>("本机IP集刷新后刷新状态栏", LogEnum.DevConsole, location: this.GetType(), PathPriority.Normal, path: message => { LocalIps = GetLocalIps(); }); Task.Factory.StartNew(() => { var localIp = VirtualRoot.LocalIpSet.AsEnumerable().FirstOrDefault(); if (localIp != null) { if (!string.IsNullOrEmpty(localIp.DefaultIPGateway)) { string[] parts = localIp.DefaultIPGateway.Split('.'); parts[parts.Length - 1] = "1"; this.FromIpAddressVm = new IpAddressViewModel(string.Join(".", parts)); parts[parts.Length - 1] = "254"; this.ToIpAddressVm = new IpAddressViewModel(string.Join(".", parts)); } } LocalIps = GetLocalIps(); }); }
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(); }); }
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(); }); }); }
internal ClientSet() { GetSpeed(); VirtualRoot.BuildEventPath <Per20SecondEvent>("周期性将内存中3分钟内活跃的ClientData列表刷入磁盘", LogEnum.DevConsole, action: message => { InitOnece(); List <MinerData> minerDatas = new List <MinerData>(); lock (_locker) { DateTime time = message.Timestamp.AddMinutes(-3); foreach (var clientData in _dicByObjectId.Values) { if (clientData.ModifiedOn > time) { minerDatas.Add(new MinerData { CreatedOn = clientData.CreatedOn, GroupId = clientData.GroupId, Id = clientData.Id, ClientId = clientData.ClientId, ClientName = clientData.ClientName, MinerIp = clientData.MinerIp, MACAddress = clientData.MACAddress, MinerName = clientData.MinerName, WindowsLoginName = clientData.WindowsLoginName, WindowsPassword = clientData.WindowsPassword, WorkId = clientData.WorkId }); } else { clientData.IsMining = false; clientData.MainCoinSpeed = 0; clientData.DualCoinSpeed = 0; foreach (var item in clientData.GpuTable) { item.MainCoinSpeed = 0; item.DualCoinSpeed = 0; } } } } using (LiteDatabase db = HostRoot.CreateLocalDb()) { var col = db.GetCollection <MinerData>(); col.Upsert(minerDatas); } }); }
public NTMinerFileSelectViewModel(Action <NTMinerFileViewModel> onOk) { OnOk = onOk; _selectedResult = null; _ntminerFileVms = new List <NTMinerFileViewModel>(); // 因为NTMinerFiles列表是异步初始化的,下面填充几个空对象的目的是解决WPFpopup的某个BUG,否则第一次打开popup的时候位置不对。 for (int i = 0; i < 7; i++) { _ntminerFileVms.Add(NTMinerFileViewModel.Empty); } VirtualRoot.BuildEventPath <NTMinerFileSetInitedEvent>("开源矿工程序版本文件集初始化后刷新Vm内存", LogEnum.DevConsole, this.GetType(), PathPriority.Normal, path: message => { var ntminerFiles = MinerStudioRoot.ReadOnlyNTMinerFileSet.AsEnumerable().Where(a => a.AppType == NTMinerAppType.MinerClient); NTMinerFileVms = ntminerFiles.OrderByDescending(a => a.GetVersion()).Select(a => new NTMinerFileViewModel(a)).ToList(); }); // 触发从远程加载数据的逻辑 VirtualRoot.Execute(new RefreshNTMinerFileSetCommand()); }
internal CoinSnapshotSet(IHostRoot root) { _root = root; VirtualRoot.BuildEventPath <Per10SecondEvent>("周期性拍摄快照", LogEnum.DevConsole, action: message => { Snapshot(message.Timestamp); }); VirtualRoot.BuildEventPath <Per2MinuteEvent>("周期性拍摄快照", LogEnum.DevConsole, action: message => { DateTime time = DateTime.Now.AddMinutes(-20); List <CoinSnapshotData> toRemoves = _dataList.Where(a => a.Timestamp < time).ToList(); foreach (var item in toRemoves) { _dataList.Remove(item); } }); }