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 KernelOutputKeywordSet(string dbFileFullName) { if (string.IsNullOrEmpty(dbFileFullName)) { throw new ArgumentNullException(nameof(dbFileFullName)); } _connectionString = $"filename={dbFileFullName}"; VirtualRoot.BuildCmdPath <AddOrUpdateKernelOutputKeywordCommand>(path: (message) => { InitOnece(); DataLevel dataLevel = DataLevel.Global; if (_dicById.TryGetValue(message.Input.GetId(), out KernelOutputKeywordData exist)) { exist.Update(message.Input); exist.SetDataLevel(dataLevel); using (LiteDatabase db = new LiteDatabase(_connectionString)) { var col = db.GetCollection <KernelOutputKeywordData>(); col.Update(exist); } } else { KernelOutputKeywordData entity = new KernelOutputKeywordData().Update(message.Input); entity.SetDataLevel(dataLevel); _dicById.Add(entity.Id, entity); if (!_dicByKernelOutputId.TryGetValue(entity.KernelOutputId, out List <IKernelOutputKeyword> list)) { list = new List <IKernelOutputKeyword>(); _dicByKernelOutputId.Add(entity.KernelOutputId, list); } list.Add(entity); using (LiteDatabase db = new LiteDatabase(_connectionString)) { var col = db.GetCollection <KernelOutputKeywordData>(); col.Insert(entity); } } }, location: this.GetType()); VirtualRoot.BuildCmdPath <RemoveKernelOutputKeywordCommand>(path: (message) => { InitOnece(); if (message == null || message.EntityId == Guid.Empty) { return; } if (!_dicById.ContainsKey(message.EntityId)) { return; } KernelOutputKeywordData entity = _dicById[message.EntityId]; _dicById.Remove(entity.GetId()); if (_dicByKernelOutputId.TryGetValue(entity.KernelOutputId, out List <IKernelOutputKeyword> list)) { list.Remove(entity); } using (LiteDatabase db = new LiteDatabase(_connectionString)) { var col = db.GetCollection <KernelOutputKeywordData>(); col.Delete(message.EntityId); } }, location: this.GetType()); }
public KernelOutputKeywordSet(string dbFileFullName, bool isServer) { if (string.IsNullOrEmpty(dbFileFullName)) { throw new ArgumentNullException(nameof(dbFileFullName)); } _connectionString = $"filename={dbFileFullName};journal=false"; _isServer = isServer; if (!isServer) { VirtualRoot.BuildCmdPath <LoadKernelOutputKeywordCommand>(action: message => { DateTime localTimestamp = VirtualRoot.LocalKernelOutputKeywordSetTimestamp; // 如果已知服务器端最新内核输出关键字时间戳不比本地已加载的最新内核输出关键字时间戳新就不用加载了 if (message.KnowKernelOutputKeywordTimestamp <= Timestamp.GetTimestamp(localTimestamp)) { return; } OfficialServer.KernelOutputKeywordService.GetKernelOutputKeywords((response, e) => { if (response.IsSuccess()) { KernelOutputKeywordData[] toRemoves = _dicById.Where(a => a.Value.DataLevel == DataLevel.Global).Select(a => a.Value).ToArray(); foreach (var item in toRemoves) { _dicById.Remove(item.Id); if (_dicByKernelOutputId.TryGetValue(item.KernelOutputId, out List <IKernelOutputKeyword> list)) { list.Remove(item); } } if (response.Data.Count != 0) { foreach (var item in response.Data) { item.SetDataLevel(DataLevel.Global); _dicById.Add(item.Id, item); if (!_dicByKernelOutputId.TryGetValue(item.KernelOutputId, out List <IKernelOutputKeyword> list)) { list = new List <IKernelOutputKeyword>(); _dicByKernelOutputId.Add(item.KernelOutputId, list); } list.Add(item); } if (response.Timestamp != Timestamp.GetTimestamp(localTimestamp)) { VirtualRoot.LocalKernelOutputKeywordSetTimestamp = Timestamp.FromTimestamp(response.Timestamp); } CacheServerKernelOutputKeywords(response.Data); VirtualRoot.RaiseEvent(new KernelOutputKeywordLoadedEvent(response.Data)); } } }); }); } VirtualRoot.BuildCmdPath <AddOrUpdateKernelOutputKeywordCommand>(action: (message) => { InitOnece(); if (isServer || !DevMode.IsDevMode) { DataLevel dataLevel = isServer ? DataLevel.Global : DataLevel.Profile; if (_dicById.TryGetValue(message.Input.GetId(), out KernelOutputKeywordData exist)) { exist.Update(message.Input); exist.SetDataLevel(dataLevel); using (LiteDatabase db = new LiteDatabase(_connectionString)) { var col = db.GetCollection <KernelOutputKeywordData>(); col.Update(exist); } if (!isServer) { VirtualRoot.RaiseEvent(new UserKernelOutputKeywordUpdatedEvent(message.Id, exist)); } } else { KernelOutputKeywordData entity = new KernelOutputKeywordData().Update(message.Input); entity.SetDataLevel(dataLevel); _dicById.Add(entity.Id, entity); if (!_dicByKernelOutputId.TryGetValue(entity.KernelOutputId, out List <IKernelOutputKeyword> list)) { list = new List <IKernelOutputKeyword>(); _dicByKernelOutputId.Add(entity.KernelOutputId, list); } list.Add(entity); using (LiteDatabase db = new LiteDatabase(_connectionString)) { var col = db.GetCollection <KernelOutputKeywordData>(); col.Insert(entity); } if (!isServer) { VirtualRoot.RaiseEvent(new UserKernelOutputKeywordAddedEvent(message.Id, entity)); } } } else if (DevMode.IsDevMode) { OfficialServer.KernelOutputKeywordService.AddOrUpdateKernelOutputKeywordAsync(KernelOutputKeywordData.Create(message.Input), (response, e) => { if (response.IsSuccess()) { VirtualRoot.Execute(new LoadKernelOutputKeywordCommand()); } }); } }); VirtualRoot.BuildCmdPath <RemoveKernelOutputKeywordCommand>(action: (message) => { InitOnece(); if (isServer || !DevMode.IsDevMode) { if (message == null || message.EntityId == Guid.Empty) { return; } if (!_dicById.ContainsKey(message.EntityId)) { return; } KernelOutputKeywordData entity = _dicById[message.EntityId]; _dicById.Remove(entity.GetId()); if (_dicByKernelOutputId.TryGetValue(entity.KernelOutputId, out List <IKernelOutputKeyword> list)) { list.Remove(entity); } using (LiteDatabase db = new LiteDatabase(_connectionString)) { var col = db.GetCollection <KernelOutputKeywordData>(); col.Delete(message.EntityId); } if (!isServer) { VirtualRoot.RaiseEvent(new UserKernelOutputKeywordRemovedEvent(message.Id, entity)); } } else if (DevMode.IsDevMode) { OfficialServer.KernelOutputKeywordService.RemoveKernelOutputKeyword(message.EntityId, (response, e) => { if (response.IsSuccess()) { VirtualRoot.Execute(new LoadKernelOutputKeywordCommand()); } }); } }); }
public KernelOutputKeywordSet(string dbFileFullName) { if (string.IsNullOrEmpty(dbFileFullName)) { throw new ArgumentNullException(nameof(dbFileFullName)); } _connectionString = $"filename={dbFileFullName}"; VirtualRoot.BuildCmdPath <AddOrUpdateKernelOutputKeywordCommand>(location: this.GetType(), LogEnum.DevConsole, path: (message) => { InitOnece(); DataLevel dataLevel = DataLevel.Global; if (_dicById.TryGetValue(message.Input.GetId(), out KernelOutputKeywordData exist)) { exist.Update(message.Input); exist.SetDataLevel(dataLevel); using (LiteDatabase db = new LiteDatabase(_connectionString)) { var col = db.GetCollection <KernelOutputKeywordData>(); col.Update(exist); } } else { KernelOutputKeywordData entity = new KernelOutputKeywordData().Update(message.Input); entity.SetDataLevel(dataLevel); _dicById.Add(entity.Id, entity); if (!_dicByKernelOutputId.TryGetValue(entity.KernelOutputId, out List <IKernelOutputKeyword> list)) { list = new List <IKernelOutputKeyword>(); _dicByKernelOutputId.Add(entity.KernelOutputId, list); } list.Add(entity); using (LiteDatabase db = new LiteDatabase(_connectionString)) { var col = db.GetCollection <KernelOutputKeywordData>(); col.Insert(entity); } } }); VirtualRoot.BuildCmdPath <RemoveKernelOutputKeywordCommand>(location: this.GetType(), LogEnum.DevConsole, path: (message) => { InitOnece(); if (message == null || message.EntityId == Guid.Empty) { return; } if (!_dicById.ContainsKey(message.EntityId)) { return; } KernelOutputKeywordData entity = _dicById[message.EntityId]; _dicById.Remove(entity.GetId()); if (_dicByKernelOutputId.TryGetValue(entity.KernelOutputId, out List <IKernelOutputKeyword> list)) { list.Remove(entity); if (list.Count == 0) { _dicByKernelOutputId.Remove(entity.KernelOutputId); } } using (LiteDatabase db = new LiteDatabase(_connectionString)) { var col = db.GetCollection <KernelOutputKeywordData>(); col.Delete(message.EntityId); } }); VirtualRoot.BuildCmdPath <ClearKernelOutputKeywordsCommand>(this.GetType(), LogEnum.DevConsole, message => { InitOnece(); if (message == null || message.ExceptedOutputIds == null || message.ExceptedOutputIds.Length == 0) { return; } var toRemoves = _dicById.Where(a => !message.ExceptedOutputIds.Contains(a.Value.KernelOutputId)).Select(a => a.Key).ToArray(); foreach (var item in toRemoves) { VirtualRoot.Execute(new RemoveKernelOutputKeywordCommand(item)); } }); }