public GpuProfileSet(INTMinerRoot root) { VirtualRoot.Window <AddOrUpdateGpuProfileCommand>("处理添加或更新Gpu超频数据命令", LogEnum.DevConsole, action: message => { GpuProfileData data = _data.GpuProfiles.FirstOrDefault(a => a.CoinId == message.Input.CoinId && a.Index == message.Input.Index); if (data != null) { data.Update(message.Input); Save(); } else { data = new GpuProfileData(message.Input); _data.GpuProfiles.Add(data); Save(); } VirtualRoot.Happened(new GpuProfileAddedOrUpdatedEvent(data)); }); VirtualRoot.Window <CoinOverClockCommand>("处理币种超频命令", LogEnum.DevConsole, action: message => { Task.Factory.StartNew(() => { CoinOverClock(root, message.CoinId); VirtualRoot.Happened(new CoinOverClockDoneEvent(message.Id)); }); }); }
public LocalAppSettingSet(string dbFileFullName) { _dbFileFullName = dbFileFullName; VirtualRoot.Window <ChangeLocalAppSettingCommand>("处理设置AppSetting命令", LogEnum.DevConsole, action: message => { if (message.AppSetting == null) { return; } if (_dicByKey.TryGetValue(message.AppSetting.Key, out AppSettingData entity)) { entity.Value = message.AppSetting.Value; using (LiteDatabase db = new LiteDatabase(_dbFileFullName)) { var col = db.GetCollection <AppSettingData>(); col.Update(entity); } } else { entity = AppSettingData.Create(message.AppSetting); _dicByKey.Add(message.AppSetting.Key, entity); using (LiteDatabase db = new LiteDatabase(_dbFileFullName)) { var col = db.GetCollection <AppSettingData>(); col.Insert(entity); } } VirtualRoot.Happened(new LocalAppSettingChangedEvent(entity)); }); }
private LangSet() { VirtualRoot.Window <RefreshLangSetCommand>("处理刷新语言命令", LogEnum.DevConsole, action: message => { _isInited = false; VirtualRoot.Happened(new LangSetRefreshedEvent()); }); VirtualRoot.Window <AddLangCommand>("处理添加语言命令", LogEnum.DevConsole, action: message => { if (_langs.All(a => a.GetId() != message.Input.GetId() && a.Code != message.Input.Code)) { Lang entity = new Lang().Update(message.Input); _langs.Add(entity); var repository = Repository.CreateLanguageRepository <Lang>(); repository.Add(entity); VirtualRoot.Happened(new LangAddedEvent(entity)); } }); VirtualRoot.Window <UpdateLangCommand>("处理修改语言命令", LogEnum.DevConsole, action: message => { Lang entity = _langs.FirstOrDefault(a => a.GetId() == message.Input.GetId()); if (entity != null) { entity.Update(message.Input); var repository = Repository.CreateLanguageRepository <Lang>(); repository.Update(entity); VirtualRoot.Happened(new LangUpdatedEvent(entity)); } }); VirtualRoot.Window <RemoveLangCommand>("处理删除语言命令", LogEnum.DevConsole, action: message => { var entity = _langs.FirstOrDefault(a => a.GetId() == message.EntityId); if (entity != null) { var toRemoveLangItemIds = new List <Guid>(); foreach (var g in LangViewItemSet.Instance.GetLangItems(message.EntityId)) { foreach (var langItem in g.Value) { toRemoveLangItemIds.Add(langItem.GetId()); } } foreach (var id in toRemoveLangItemIds) { VirtualRoot.Execute(new RemoveLangViewItemCommand(id)); } _langs.Remove(entity); var repository = Repository.CreateLanguageRepository <Lang>(); repository.Remove(entity.GetId()); VirtualRoot.Happened(new LangRemovedEvent(entity)); } }); }
public PoolKernelSet(INTMinerRoot root, bool isUseJson) { _root = root; _isUseJson = isUseJson; VirtualRoot.Window <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>(isUseJson); repository.Add(entity); VirtualRoot.Happened(new PoolKernelAddedEvent(message.Input)); } }).AddToCollection(root.ContextHandlers); VirtualRoot.Window <RemovePoolKernelCommand>("处理移除矿池级内核命令", LogEnum.DevConsole, action: message => { if (_dicById.ContainsKey(message.EntityId)) { var entity = _dicById[message.EntityId]; _dicById.Remove(message.EntityId); var repository = NTMinerRoot.CreateServerRepository <PoolKernelData>(isUseJson); repository.Remove(message.EntityId); VirtualRoot.Happened(new PoolKernelRemovedEvent(entity)); } }).AddToCollection(root.ContextHandlers); VirtualRoot.Window <UpdatePoolKernelCommand>("更新矿池内核", LogEnum.DevConsole, action: (message) => { InitOnece(); if (message == null || message.Input == null || message.Input.GetId() == Guid.Empty) { throw new ArgumentNullException(); } if (!_root.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>(isUseJson); repository.Update(entity); VirtualRoot.Happened(new PoolKernelUpdatedEvent(entity)); }).AddToCollection(root.ContextHandlers); }
public void Register(INTMinerRoot root) { VirtualRoot.Window <AddOrUpdateGpuProfileCommand>("处理添加或更新Gpu超频数据命令", LogEnum.DevConsole, action: message => { GpuProfileData data = _data.GpuProfiles.FirstOrDefault(a => a.CoinId == message.Input.CoinId && a.Index == message.Input.Index); if (data != null) { data.Update(message.Input); Save(); } else { data = new GpuProfileData(message.Input); _data.GpuProfiles.Add(data); Save(); } VirtualRoot.Happened(new GpuProfileAddedOrUpdatedEvent(data)); }); VirtualRoot.Window <OverClockCommand>("处理超频命令", LogEnum.DevConsole, action: message => { if (root.GpuSet.TryGetGpu(message.Input.Index, out IGpu gpu)) { message.Input.OverClock(gpu.OverClock); } }); VirtualRoot.Window <CoinOverClockCommand>("处理币种超频命令", LogEnum.DevConsole, action: message => { if (IsOverClockGpuAll(message.CoinId)) { GpuProfileData overClockData = _data.GpuProfiles.FirstOrDefault(a => a.CoinId == message.CoinId && a.Index == NTMinerRoot.GpuAllId); if (overClockData != null) { VirtualRoot.Execute(new OverClockCommand(overClockData)); } } else { foreach (var overClockData in _data.GpuProfiles.Where(a => a.CoinId == message.CoinId)) { if (overClockData.Index != NTMinerRoot.GpuAllId) { VirtualRoot.Execute(new OverClockCommand(overClockData)); } } } }); }
private MinerProfileViewModel() { if (Design.IsInDesignMode) { return; } NTMinerRoot.RefreshArgsAssembly = () => { this.ArgsAssembly = NTMinerRoot.Current.BuildAssembleArgs(); }; NTMinerRoot.Current.OnReRendContext += () => { OnPropertyChanged(nameof(CoinVm)); }; VirtualRoot.Window <RefreshAutoBootStartCommand>("刷新开机自动启动和启动后自动开始挖矿的展示", LogEnum.UserConsole, action: message => { OnPropertyChanged(nameof(IsAutoBoot)); OnPropertyChanged(nameof(IsAutoStart)); }); VirtualRoot.On <MinerProfilePropertyChangedEvent>("MinerProfile设置变更后刷新VM内存", LogEnum.DevConsole, action: message => { OnPropertyChanged(message.PropertyName); }); VirtualRoot.On <MineWorkPropertyChangedEvent>("MineWork设置变更后刷新VM内存", LogEnum.DevConsole, action: message => { OnPropertyChanged(message.PropertyName); }); NTMinerRoot.Current.OnReRendMinerProfile += () => { MinerProfileIndexViewModel.Current.OnPropertyChanged(nameof(MinerProfileIndexViewModel.CoinVms)); this.CoinVm.CoinKernel?.OnPropertyChanged(nameof(CoinKernelViewModel.CoinKernelProfile)); OnPropertyChanged(nameof(CoinVm)); OnPropertyChanged(nameof(MinerName)); OnPropertyChanged(nameof(IsFreeClient)); OnPropertyChanged(nameof(MineWork)); OnPropertyChanged(nameof(IsWorker)); OnPropertyChanged(nameof(IsAutoBoot)); OnPropertyChanged(nameof(IsNoShareRestartKernel)); OnPropertyChanged(nameof(NoShareRestartKernelMinutes)); OnPropertyChanged(nameof(IsPeriodicRestartKernel)); OnPropertyChanged(nameof(PeriodicRestartKernelHours)); OnPropertyChanged(nameof(IsPeriodicRestartComputer)); OnPropertyChanged(nameof(PeriodicRestartComputerHours)); OnPropertyChanged(nameof(IsAutoStart)); OnPropertyChanged(nameof(IsAutoRestartKernel)); }; NTMinerRoot.RefreshArgsAssembly.Invoke(); }
public CoinGroupSet(INTMinerRoot root, bool isUseJson) { _root = root; _isUseJson = isUseJson; VirtualRoot.Window <AddCoinGroupCommand>("添加币组", LogEnum.DevConsole, action: (message) => { InitOnece(); if (message == null || message.Input == null || message.Input.GetId() == Guid.Empty) { throw new ArgumentNullException(); } if (_dicById.ContainsKey(message.Input.GetId())) { return; } CoinGroupData entity = new CoinGroupData().Update(message.Input); if (ReferenceEquals(entity, message.Input)) { return; } _dicById.Add(entity.Id, entity); var repository = NTMinerRoot.CreateServerRepository <CoinGroupData>(isUseJson); repository.Add(entity); VirtualRoot.Happened(new CoinGroupAddedEvent(entity)); }).AddToCollection(root.ContextHandlers); VirtualRoot.Window <RemoveCoinGroupCommand>("移除币组", LogEnum.DevConsole, action: (message) => { InitOnece(); if (message == null || message.EntityId == Guid.Empty) { throw new ArgumentNullException(); } if (!_dicById.ContainsKey(message.EntityId)) { return; } CoinGroupData entity = _dicById[message.EntityId]; _dicById.Remove(entity.GetId()); var repository = NTMinerRoot.CreateServerRepository <CoinGroupData>(isUseJson); repository.Remove(message.EntityId); VirtualRoot.Happened(new CoinGroupRemovedEvent(entity)); }).AddToCollection(root.ContextHandlers); }
public UserSet(string dbFileFullName) { _dbFileFullName = dbFileFullName; VirtualRoot.Window <AddUserCommand>("处理添加用户命令", LogEnum.DevConsole, action: message => { if (!_dicByLoginName.ContainsKey(message.User.LoginName)) { UserData entity = new UserData(message.User); _dicByLoginName.Add(message.User.LoginName, entity); using (LiteDatabase db = new LiteDatabase(_dbFileFullName)) { var col = db.GetCollection <UserData>(); col.Insert(entity); } VirtualRoot.Happened(new UserAddedEvent(entity)); } }); VirtualRoot.Window <UpdateUserCommand>("处理修改用户命令", LogEnum.DevConsole, action: message => { if (_dicByLoginName.ContainsKey(message.User.LoginName)) { UserData entity = _dicByLoginName[message.User.LoginName]; entity.Update(message.User); using (LiteDatabase db = new LiteDatabase(_dbFileFullName)) { var col = db.GetCollection <UserData>(); col.Update(entity); } VirtualRoot.Happened(new UserUpdatedEvent(entity)); } }); VirtualRoot.Window <RemoveUserCommand>("处理删除用户命令", LogEnum.DevConsole, action: message => { if (_dicByLoginName.ContainsKey(message.LoginName)) { UserData entity = _dicByLoginName[message.LoginName]; _dicByLoginName.Remove(entity.LoginName); using (LiteDatabase db = new LiteDatabase(_dbFileFullName)) { var col = db.GetCollection <UserData>(); col.Delete(message.LoginName); } VirtualRoot.Happened(new UserRemovedEvent(entity)); } }); }
public OverClockDataSet(INTMinerRoot root) { _root = root; VirtualRoot.Window <AddOverClockDataCommand>("添加超频建议", LogEnum.DevConsole, action: (message) => { InitOnece(); if (message == null || message.Input == null || message.Input.GetId() == Guid.Empty) { throw new ArgumentNullException(); } if (string.IsNullOrEmpty(message.Input.Name)) { throw new ValidationException("OverClockData name can't be null or empty"); } if (_dicById.ContainsKey(message.Input.GetId())) { return; } OverClockData entity = new OverClockData().Update(message.Input); OfficialServer.OverClockDataService.AddOrUpdateOverClockDataAsync(entity, (response, e) => { if (response.IsSuccess()) { _dicById.Add(entity.Id, entity); VirtualRoot.Happened(new OverClockDataAddedEvent(entity)); } else { Write.UserLine(response.ReadMessage(e), ConsoleColor.Red); } }); }); VirtualRoot.Window <UpdateOverClockDataCommand>("更新超频建议", LogEnum.DevConsole, action: (message) => { InitOnece(); if (message == null || message.Input == null || message.Input.GetId() == Guid.Empty) { throw new ArgumentNullException(); } if (string.IsNullOrEmpty(message.Input.Name)) { throw new ValidationException("minerGroup name can't be null or empty"); } if (!_dicById.ContainsKey(message.Input.GetId())) { return; } OverClockData entity = _dicById[message.Input.GetId()]; OverClockData oldValue = new OverClockData().Update(entity); entity.Update(message.Input); OfficialServer.OverClockDataService.AddOrUpdateOverClockDataAsync(entity, (response, e) => { if (!response.IsSuccess()) { entity.Update(oldValue); VirtualRoot.Happened(new OverClockDataUpdatedEvent(entity)); Write.UserLine(response.ReadMessage(e), ConsoleColor.Red); } }); VirtualRoot.Happened(new OverClockDataUpdatedEvent(entity)); }); VirtualRoot.Window <RemoveOverClockDataCommand>("移除超频建议", LogEnum.DevConsole, action: (message) => { InitOnece(); if (message == null || message.EntityId == Guid.Empty) { throw new ArgumentNullException(); } if (!_dicById.ContainsKey(message.EntityId)) { return; } OverClockData entity = _dicById[message.EntityId]; OfficialServer.OverClockDataService.RemoveOverClockDataAsync(entity.Id, (response, e) => { if (response.IsSuccess()) { _dicById.Remove(entity.Id); VirtualRoot.Happened(new OverClockDataRemovedEvent(entity)); } else { Write.UserLine(response.ReadMessage(e), ConsoleColor.Red); } }); }); }
public override void Link() { VirtualRoot.Window <ShowDialogWindowCommand>(LogEnum.DevConsole, action: message => { UIThread.Execute(() => { DialogWindow.ShowDialog(message: message.Message, title: message.Title, onYes: message.OnYes, icon: message.Icon); }); }); VirtualRoot.Window <ShowQQGroupQrCodeCommand>(LogEnum.DevConsole, action: message => { UIThread.Execute(() => { QQGroupQrCode.ShowWindow(); }); }); VirtualRoot.Window <ShowCalcCommand>(LogEnum.DevConsole, action: message => { UIThread.Execute(() => { Calc.ShowWindow(message.CoinVm); }); }); VirtualRoot.Window <ShowEthNoDevFeeCommand>(LogEnum.DevConsole, action: message => { UIThread.Execute(() => { EthNoDevFeeEdit.ShowWindow(); }); }); VirtualRoot.Window <ShowCalcConfigCommand>(LogEnum.DevConsole, action: message => { UIThread.Execute(() => { CalcConfig.ShowWindow(); }); }); VirtualRoot.Window <ShowMinerClientsWindowCommand>(LogEnum.DevConsole, action: message => { UIThread.Execute(() => { MinerClientsWindow.ShowWindow(); }); }); VirtualRoot.Window <ShowNTMinerUpdaterConfigCommand>(LogEnum.DevConsole, action: message => { UIThread.Execute(() => { NTMinerUpdaterConfig.ShowWindow(); }); }); VirtualRoot.Window <ShowAboutPageCommand>(LogEnum.DevConsole, action: message => { UIThread.Execute(() => { AboutPage.ShowWindow(); }); }); VirtualRoot.Window <ShowKernelOutputPageCommand>(LogEnum.DevConsole, action: message => { UIThread.Execute(() => { KernelOutputPage.ShowWindow(message.SelectedKernelOutputVm); }); }); VirtualRoot.Window <ShowKernelInputPageCommand>(LogEnum.DevConsole, action: message => { UIThread.Execute(() => { KernelInputPage.ShowWindow(); }); }); VirtualRoot.Window <ShowCoinPageCommand>(LogEnum.DevConsole, action: message => { UIThread.Execute(() => { CoinPage.ShowWindow(message.CurrentCoin, message.TabType); }); }); VirtualRoot.Window <ShowGroupPageCommand>(LogEnum.DevConsole, action: message => { UIThread.Execute(() => { GroupPage.ShowWindow(); }); }); VirtualRoot.Window <ShowSysDicPageCommand>(LogEnum.DevConsole, action: message => { UIThread.Execute(() => { SysDicPage.ShowWindow(); }); }); VirtualRoot.Window <ShowVirtualMemoryCommand>(LogEnum.DevConsole, action: message => { UIThread.Execute(() => { VirtualMemory.ShowWindow(); }); }); VirtualRoot.Window <ShowRestartWindowsCommand>(LogEnum.DevConsole, action: message => { UIThread.Execute(() => { RestartWindows.ShowDialog(); }); }); VirtualRoot.Window <ShowNotificationSampleCommand>(LogEnum.DevConsole, action: message => { UIThread.Execute(() => { NotificationSample.ShowWindow(); }); }); VirtualRoot.Window <ShowPropertyCommand>(LogEnum.DevConsole, action: message => { UIThread.Execute(() => { Property.ShowWindow(); }); }); VirtualRoot.Window <ShowChartsWindowCommand>(LogEnum.DevConsole, action: message => { UIThread.Execute(() => { ChartsWindow.ShowWindow(); }); }); VirtualRoot.Window <ShowOverClockDataPageCommand>(LogEnum.DevConsole, action: message => { UIThread.Execute(() => { OverClockDataPage.ShowWindow(); }); }); VirtualRoot.Window <ShowUserPageCommand>(LogEnum.DevConsole, action: message => { UIThread.Execute(() => { UserPage.ShowWindow(); }); }); VirtualRoot.Window <ShowKernelsWindowCommand>(LogEnum.DevConsole, action: message => { UIThread.Execute(() => { KernelsWindow.ShowWindow(); }); }); VirtualRoot.Window <ShowKernelDownloaderCommand>(LogEnum.DevConsole, action: message => { UIThread.Execute(() => { KernelDownloading.ShowWindow(message.KernelId, message.DownloadComplete); }); }); VirtualRoot.Window <EnvironmentVariableEditCommand>(LogEnum.DevConsole, action: message => { UIThread.Execute(() => { EnvironmentVariableEdit.ShowWindow(message.CoinKernelVm, message.EnvironmentVariable); }); }); VirtualRoot.Window <InputSegmentEditCommand>(LogEnum.DevConsole, action: message => { UIThread.Execute(() => { InputSegmentEdit.ShowWindow(message.CoinKernelVm, message.Segment); }); }); VirtualRoot.Window <CoinKernelEditCommand>(LogEnum.DevConsole, action: message => { UIThread.Execute(() => { CoinKernelEdit.ShowWindow(message.FormType, message.Source); }); }); VirtualRoot.Window <CoinEditCommand>(LogEnum.DevConsole, action: message => { UIThread.Execute(() => { CoinEdit.ShowWindow(message.FormType, message.Source); }); }); VirtualRoot.Window <ColumnsShowEditCommand>(LogEnum.DevConsole, action: message => { UIThread.Execute(() => { ColumnsShowEdit.ShowWindow(message.FormType, message.Source); }); }); VirtualRoot.Window <ShowContainerWindowCommand>(LogEnum.DevConsole, action: message => { UIThread.Execute(() => { ContainerWindow window = ContainerWindow.GetWindow(message.Vm); window?.ShowWindow(); }); }); VirtualRoot.Window <ShowSpeedChartsCommand>(LogEnum.DevConsole, action: message => { UIThread.Execute(() => { SpeedCharts.ShowWindow(message.GpuSpeedVm); }); }); VirtualRoot.Window <ShowFileWriterPageCommand>(LogEnum.DevConsole, action: message => { UIThread.Execute(() => { FileWriterPage.ShowWindow(); }); }); VirtualRoot.Window <FileWriterEditCommand>(LogEnum.DevConsole, action: message => { UIThread.Execute(() => { FileWriterEdit.ShowWindow(message.FormType, message.Source); }); }); VirtualRoot.Window <ShowFragmentWriterPageCommand>(LogEnum.DevConsole, action: message => { UIThread.Execute(() => { FragmentWriterPage.ShowWindow(); }); }); VirtualRoot.Window <FragmentWriterEditCommand>(LogEnum.DevConsole, action: message => { UIThread.Execute(() => { FragmentWriterEdit.ShowWindow(message.FormType, message.Source); }); }); VirtualRoot.Window <GroupEditCommand>(LogEnum.DevConsole, action: message => { UIThread.Execute(() => { GroupEdit.ShowWindow(message.FormType, message.Source); }); }); VirtualRoot.Window <KernelInputEditCommand>(LogEnum.DevConsole, action: message => { UIThread.Execute(() => { KernelInputEdit.ShowWindow(message.FormType, message.Source); }); }); VirtualRoot.Window <KernelOutputFilterEditCommand>(LogEnum.DevConsole, action: message => { UIThread.Execute(() => { KernelOutputFilterEdit.ShowWindow(message.FormType, message.Source); }); }); VirtualRoot.Window <KernelOutputTranslaterEditCommand>(LogEnum.DevConsole, action: message => { UIThread.Execute(() => { KernelOutputTranslaterEdit.ShowWindow(message.FormType, message.Source); }); }); VirtualRoot.Window <KernelOutputEditCommand>(LogEnum.DevConsole, action: message => { UIThread.Execute(() => { KernelOutputEdit.ShowWindow(message.FormType, message.Source); }); }); VirtualRoot.Window <ShowPackagesWindowCommand>(LogEnum.DevConsole, action: message => { UIThread.Execute(() => { PackagesWindow.ShowWindow(); }); }); VirtualRoot.Window <KernelEditCommand>(LogEnum.DevConsole, action: message => { UIThread.Execute(() => { KernelEdit.ShowWindow(message.FormType, message.Source); }); }); VirtualRoot.Window <ShowLogColorCommand>(LogEnum.DevConsole, action: message => { UIThread.Execute(() => { LogColor.ShowWindow(); }); }); VirtualRoot.Window <ShowMinerClientSettingCommand>(LogEnum.DevConsole, action: message => { UIThread.Execute(() => { MinerClientSetting.ShowWindow(message.Vm); }); }); VirtualRoot.Window <ShowMinerNamesSeterCommand>(LogEnum.DevConsole, action: message => { UIThread.Execute(() => { MinerNamesSeter.ShowWindow(message.Vm); }); }); VirtualRoot.Window <ShowGpuProfilesPageCommand>(LogEnum.DevConsole, action: message => { UIThread.Execute(() => { GpuProfilesPage.ShowWindow(message.MinerClientsWindowVm); }); }); VirtualRoot.Window <ShowMinerClientAddCommand>(LogEnum.DevConsole, action: message => { UIThread.Execute(() => { MinerClientAdd.ShowWindow(); }); }); VirtualRoot.Window <MinerGroupEditCommand>(LogEnum.DevConsole, action: message => { UIThread.Execute(() => { MinerGroupEdit.ShowWindow(message.FormType, message.Source); }); }); VirtualRoot.Window <MineWorkEditCommand>(LogEnum.DevConsole, action: message => { UIThread.Execute(() => { MineWorkEdit.ShowWindow(message.FormType, message.Source); }); }); VirtualRoot.Window <OverClockDataEditCommand>(LogEnum.DevConsole, action: message => { UIThread.Execute(() => { OverClockDataEdit.ShowWindow(message.FormType, message.Source); }); }); VirtualRoot.Window <PackageEditCommand>(LogEnum.DevConsole, action: message => { UIThread.Execute(() => { PackageEdit.ShowWindow(message.FormType, message.Source); }); }); VirtualRoot.Window <PoolKernelEditCommand>(LogEnum.DevConsole, action: message => { UIThread.Execute(() => { PoolKernelEdit.ShowWindow(message.FormType, message.Source); }); }); VirtualRoot.Window <PoolEditCommand>(LogEnum.DevConsole, action: message => { UIThread.Execute(() => { PoolEdit.ShowWindow(message.FormType, message.Source); }); }); VirtualRoot.Window <ShowControlCenterHostConfigCommand>(LogEnum.DevConsole, action: message => { UIThread.Execute(() => { ControlCenterHostConfig.ShowWindow(); }); }); VirtualRoot.Window <SysDicItemEditCommand>(LogEnum.DevConsole, action: message => { UIThread.Execute(() => { SysDicItemEdit.ShowWindow(message.FormType, message.Source); }); }); VirtualRoot.Window <SysDicEditCommand>(LogEnum.DevConsole, action: message => { UIThread.Execute(() => { SysDicEdit.ShowWindow(message.FormType, message.Source); }); }); VirtualRoot.Window <UserEditCommand>(LogEnum.DevConsole, action: message => { UIThread.Execute(() => { UserEdit.ShowWindow(message.FormType, message.Source); }); }); VirtualRoot.Window <WalletEditCommand>(LogEnum.DevConsole, action: message => { UIThread.Execute(() => { WalletEdit.ShowWindow(message.FormType, message.Source); }); }); }
public MinerGroupSet(INTMinerRoot root) { _root = root; VirtualRoot.Window <AddMinerGroupCommand>("添加矿机分组", LogEnum.DevConsole, action: (message) => { InitOnece(); if (message == null || message.Input == null || message.Input.GetId() == Guid.Empty) { throw new ArgumentNullException(); } if (string.IsNullOrEmpty(message.Input.Name)) { throw new ValidationException("minerGroup name can't be null or empty"); } if (_dicById.ContainsKey(message.Input.GetId())) { return; } MinerGroupData entity = new MinerGroupData().Update(message.Input); Server.ControlCenterService.AddOrUpdateMinerGroupAsync(entity, (response, exception) => { if (response.IsSuccess()) { _dicById.Add(entity.Id, entity); VirtualRoot.Happened(new MinerGroupAddedEvent(entity)); } else if (response != null) { Write.UserLine(response.Description, ConsoleColor.Red); } }); }); VirtualRoot.Window <UpdateMinerGroupCommand>("更新矿机分组", LogEnum.DevConsole, action: (message) => { InitOnece(); if (message == null || message.Input == null || message.Input.GetId() == Guid.Empty) { throw new ArgumentNullException(); } if (string.IsNullOrEmpty(message.Input.Name)) { throw new ValidationException("minerGroup name can't be null or empty"); } if (!_dicById.ContainsKey(message.Input.GetId())) { return; } MinerGroupData entity = _dicById[message.Input.GetId()]; MinerGroupData oldValue = new MinerGroupData().Update(entity); entity.Update(message.Input); Server.ControlCenterService.AddOrUpdateMinerGroupAsync(entity, (response, exception) => { if (!response.IsSuccess()) { entity.Update(oldValue); VirtualRoot.Happened(new MinerGroupUpdatedEvent(entity)); if (response != null) { Write.UserLine(response.Description, ConsoleColor.Red); } } }); VirtualRoot.Happened(new MinerGroupUpdatedEvent(entity)); }); VirtualRoot.Window <RemoveMinerGroupCommand>("移除矿机分组", LogEnum.DevConsole, action: (message) => { InitOnece(); if (message == null || message.EntityId == Guid.Empty) { throw new ArgumentNullException(); } if (!_dicById.ContainsKey(message.EntityId)) { return; } MinerGroupData entity = _dicById[message.EntityId]; Server.ControlCenterService.RemoveMinerGroupAsync(entity.Id, (response, exception) => { if (response.IsSuccess()) { _dicById.Remove(entity.Id); VirtualRoot.Happened(new MinerGroupRemovedEvent(entity)); } else if (response != null) { Write.UserLine(response.Description, ConsoleColor.Red); } }); }); }
public CoinKernelSet(INTMinerRoot root, bool isUseJson) { _root = root; _isUseJson = isUseJson; VirtualRoot.Window <AddCoinKernelCommand>("添加币种内核", LogEnum.DevConsole, action: (message) => { InitOnece(); if (message == null || message.Input == null || message.Input.GetId() == Guid.Empty) { throw new ArgumentNullException(); } if (!_root.CoinSet.Contains(message.Input.CoinId)) { throw new ValidationException("there is no coin with id" + message.Input.CoinId); } if (_dicById.ContainsKey(message.Input.GetId())) { return; } if (_dicById.Values.Any(a => a.CoinId == message.Input.CoinId && a.KernelId == message.Input.KernelId)) { return; } CoinKernelData entity = new CoinKernelData().Update(message.Input); _dicById.Add(entity.Id, entity); var repository = NTMinerRoot.CreateServerRepository <CoinKernelData>(isUseJson); repository.Add(entity); VirtualRoot.Happened(new CoinKernelAddedEvent(entity)); ICoin coin; if (root.CoinSet.TryGetCoin(message.Input.CoinId, out coin)) { IPool[] pools = root.PoolSet.Where(a => a.CoinId == coin.GetId()).ToArray(); foreach (IPool pool in pools) { Guid poolKernelId = Guid.NewGuid(); var poolKernel = new PoolKernelData() { Id = poolKernelId, Args = string.Empty, Description = string.Empty, KernelId = message.Input.KernelId, PoolId = pool.GetId() }; VirtualRoot.Execute(new AddPoolKernelCommand(poolKernel)); } } }).AddToCollection(root.ContextHandlers); VirtualRoot.Window <UpdateCoinKernelCommand>("更新币种内核", LogEnum.DevConsole, action: (message) => { InitOnece(); if (message == null || message.Input == null || message.Input.GetId() == Guid.Empty) { throw new ArgumentNullException(); } if (!_root.CoinSet.Contains(message.Input.CoinId)) { throw new ValidationException("there is no coin with id" + message.Input.CoinId); } if (!_dicById.ContainsKey(message.Input.GetId())) { return; } CoinKernelData entity = _dicById[message.Input.GetId()]; if (ReferenceEquals(entity, message.Input)) { return; } entity.Update(message.Input); var repository = NTMinerRoot.CreateServerRepository <CoinKernelData>(isUseJson); repository.Update(entity); VirtualRoot.Happened(new CoinKernelUpdatedEvent(entity)); }).AddToCollection(root.ContextHandlers); VirtualRoot.Window <RemoveCoinKernelCommand>("移除币种内核", LogEnum.DevConsole, action: (message) => { InitOnece(); if (message == null || message.EntityId == Guid.Empty) { throw new ArgumentNullException(); } if (!_dicById.ContainsKey(message.EntityId)) { return; } CoinKernelData entity = _dicById[message.EntityId]; _dicById.Remove(entity.Id); var repository = NTMinerRoot.CreateServerRepository <CoinKernelData>(isUseJson); repository.Remove(entity.Id); VirtualRoot.Happened(new CoinKernelRemovedEvent(entity)); ICoin coin; if (root.CoinSet.TryGetCoin(entity.CoinId, out coin)) { List <Guid> toRemoves = new List <Guid>(); IPool[] pools = root.PoolSet.Where(a => a.CoinId == coin.GetId()).ToArray(); foreach (IPool pool in pools) { foreach (PoolKernelData poolKernel in root.PoolKernelSet.Where(a => a.PoolId == pool.GetId() && a.KernelId == entity.KernelId)) { toRemoves.Add(poolKernel.Id); } } foreach (Guid poolKernelId in toRemoves) { VirtualRoot.Execute(new RemovePoolKernelCommand(poolKernelId)); } } }).AddToCollection(root.ContextHandlers); }
public KernelSet(INTMinerRoot root, bool isUseJson) { _root = root; _isUseJson = isUseJson; VirtualRoot.Window <AddKernelCommand>("添加内核", LogEnum.DevConsole, action: message => { InitOnece(); if (message == null || message.Input == null || message.Input.GetId() == Guid.Empty) { throw new ArgumentNullException(); } if (string.IsNullOrEmpty(message.Input.Code)) { throw new ValidationException("package code can't be null or empty"); } if (_dicById.ContainsKey(message.Input.GetId())) { return; } KernelData entity = new KernelData().Update(message.Input); _dicById.Add(entity.Id, entity); IRepository <KernelData> repository = NTMinerRoot.CreateServerRepository <KernelData>(isUseJson); repository.Add(entity); VirtualRoot.Happened(new KernelAddedEvent(entity)); }).AddToCollection(root.ContextHandlers); VirtualRoot.Window <UpdateKernelCommand>("更新内核", LogEnum.DevConsole, action: message => { InitOnece(); if (message == null || message.Input == null || message.Input.GetId() == Guid.Empty) { throw new ArgumentNullException(); } if (string.IsNullOrEmpty(message.Input.Code)) { throw new ValidationException("package code can't be null or empty"); } if (!_dicById.ContainsKey(message.Input.GetId())) { return; } KernelData entity = _dicById[message.Input.GetId()]; if (ReferenceEquals(entity, message.Input)) { return; } entity.Update(message.Input); IRepository <KernelData> repository = NTMinerRoot.CreateServerRepository <KernelData>(isUseJson); repository.Update(entity); VirtualRoot.Happened(new KernelUpdatedEvent(entity)); }).AddToCollection(root.ContextHandlers); VirtualRoot.Window <RemoveKernelCommand>("移除内核", LogEnum.DevConsole, action: message => { InitOnece(); if (message == null || message.EntityId == Guid.Empty) { throw new ArgumentNullException(); } if (!_dicById.ContainsKey(message.EntityId)) { return; } KernelData entity = _dicById[message.EntityId]; List <Guid> coinKernelIds = root.CoinKernelSet.Where(a => a.KernelId == entity.Id).Select(a => a.GetId()).ToList(); foreach (var coinKernelId in coinKernelIds) { VirtualRoot.Execute(new RemoveCoinKernelCommand(coinKernelId)); } _dicById.Remove(entity.Id); IRepository <KernelData> repository = NTMinerRoot.CreateServerRepository <KernelData>(isUseJson); repository.Remove(entity.Id); VirtualRoot.Happened(new KernelRemovedEvent(entity)); }).AddToCollection(root.ContextHandlers); }
public CoinSet(INTMinerRoot root, bool isUseJson) { _root = root; _isUseJson = isUseJson; VirtualRoot.Window <AddCoinCommand>("添加币种", LogEnum.DevConsole, action: message => { InitOnece(); if (message == null || message.Input == null || message.Input.GetId() == Guid.Empty) { throw new ArgumentNullException(); } if (string.IsNullOrEmpty(message.Input.Code)) { throw new ValidationException("coin code can't be null or empty"); } if (_dicById.ContainsKey(message.Input.GetId())) { return; } if (_dicByCode.ContainsKey(message.Input.Code)) { throw new DuplicateCodeException(); } CoinData entity = new CoinData().Update(message.Input); _dicById.Add(entity.Id, entity); _dicByCode.Add(entity.Code, entity); var repository = NTMinerRoot.CreateServerRepository <CoinData>(isUseJson); repository.Add(entity); VirtualRoot.Happened(new CoinAddedEvent(entity)); }).AddToCollection(root.ContextHandlers); VirtualRoot.Window <UpdateCoinCommand>("更新币种", LogEnum.DevConsole, action: message => { InitOnece(); if (message == null || message.Input == null || message.Input.GetId() == Guid.Empty) { throw new ArgumentNullException(); } if (string.IsNullOrEmpty(message.Input.Code)) { throw new ValidationException("coin code can't be null or empty"); } if (!_dicById.ContainsKey(message.Input.GetId())) { return; } CoinData entity = _dicById[message.Input.GetId()]; if (ReferenceEquals(entity, message.Input)) { return; } entity.Update(message.Input); var repository = NTMinerRoot.CreateServerRepository <CoinData>(isUseJson); repository.Update(entity); VirtualRoot.Happened(new CoinUpdatedEvent(message.Input)); }).AddToCollection(root.ContextHandlers); VirtualRoot.Window <RemoveCoinCommand>("移除币种", LogEnum.DevConsole, action: message => { InitOnece(); if (message == null || message.EntityId == Guid.Empty) { throw new ArgumentNullException(); } if (!_dicById.ContainsKey(message.EntityId)) { return; } CoinData entity = _dicById[message.EntityId]; Guid[] toRemoves = root.PoolSet.Where(a => a.CoinId == entity.Id).Select(a => a.GetId()).ToArray(); foreach (var id in toRemoves) { VirtualRoot.Execute(new RemovePoolCommand(id)); } toRemoves = root.CoinKernelSet.Where(a => a.CoinId == entity.Id).Select(a => a.GetId()).ToArray(); foreach (var id in toRemoves) { VirtualRoot.Execute(new RemoveCoinKernelCommand(id)); } toRemoves = root.MinerProfile.GetWallets().Where(a => a.CoinId == entity.Id).Select(a => a.GetId()).ToArray(); foreach (var id in toRemoves) { VirtualRoot.Execute(new RemoveWalletCommand(id)); } toRemoves = root.CoinGroupSet.Where(a => a.CoinId == entity.Id).Select(a => a.GetId()).ToArray(); foreach (var id in toRemoves) { VirtualRoot.Execute(new RemoveCoinGroupCommand(id)); } _dicById.Remove(entity.Id); if (_dicByCode.ContainsKey(entity.Code)) { _dicByCode.Remove(entity.Code); } var repository = NTMinerRoot.CreateServerRepository <CoinData>(isUseJson); repository.Remove(entity.Id); VirtualRoot.Happened(new CoinRemovedEvent(entity)); }).AddToCollection(root.ContextHandlers); }
public MineWorkSet(INTMinerRoot root) { _root = root; VirtualRoot.Window <AddMineWorkCommand>("添加工作", LogEnum.DevConsole, action: (message) => { InitOnece(); if (message == null || message.Input == null || message.Input.GetId() == Guid.Empty) { throw new ArgumentNullException(); } if (_dicById.ContainsKey(message.Input.GetId())) { return; } MineWorkData entity = new MineWorkData().Update(message.Input); var response = Server.ControlCenterService.AddOrUpdateMineWork(entity); if (response.IsSuccess()) { _dicById.Add(entity.Id, entity); VirtualRoot.Happened(new MineWorkAddedEvent(entity)); } else { Write.UserLine(response?.Description, ConsoleColor.Red); } }); VirtualRoot.Window <UpdateMineWorkCommand>("更新工作", LogEnum.DevConsole, action: (message) => { InitOnece(); if (message == null || message.Input == null || message.Input.GetId() == Guid.Empty) { throw new ArgumentNullException(); } if (!_dicById.ContainsKey(message.Input.GetId())) { return; } MineWorkData entity = _dicById[message.Input.GetId()]; MineWorkData oldValue = new MineWorkData().Update(entity); entity.Update(message.Input); Server.ControlCenterService.AddOrUpdateMineWorkAsync(entity, (response, exception) => { if (!response.IsSuccess()) { entity.Update(oldValue); VirtualRoot.Happened(new MineWorkUpdatedEvent(entity)); if (response != null) { Write.UserLine(response.Description, ConsoleColor.Red); } } }); VirtualRoot.Happened(new MineWorkUpdatedEvent(entity)); }); VirtualRoot.Window <RemoveMineWorkCommand>("移除工作", LogEnum.DevConsole, action: (message) => { InitOnece(); if (message == null || message.EntityId == Guid.Empty) { throw new ArgumentNullException(); } if (!_dicById.ContainsKey(message.EntityId)) { return; } MineWorkData entity = _dicById[message.EntityId]; Server.ControlCenterService.RemoveMineWorkAsync(entity.Id, (response, exception) => { if (response.IsSuccess()) { _dicById.Remove(entity.Id); VirtualRoot.Happened(new MineWorkRemovedEvent(entity)); } else if (response != null) { Write.UserLine(response.Description, ConsoleColor.Red); } }); }); }
public KernelInputSet(INTMinerRoot root, bool isUseJson) { _root = root; _isUseJson = isUseJson; VirtualRoot.Window <AddKernelInputCommand>("添加内核输入组", LogEnum.DevConsole, action: (message) => { InitOnece(); if (message == null || message.Input == null || message.Input.GetId() == Guid.Empty) { throw new ArgumentNullException(); } if (_dicById.ContainsKey(message.Input.GetId())) { return; } KernelInputData entity = new KernelInputData().Update(message.Input); _dicById.Add(entity.Id, entity); var repository = NTMinerRoot.CreateServerRepository <KernelInputData>(isUseJson); repository.Add(entity); VirtualRoot.Happened(new KernelInputAddedEvent(entity)); }).AddToCollection(root.ContextHandlers); VirtualRoot.Window <UpdateKernelInputCommand>("更新内核输入组", LogEnum.DevConsole, action: (message) => { InitOnece(); if (message == null || message.Input == null || message.Input.GetId() == Guid.Empty) { throw new ArgumentNullException(); } if (string.IsNullOrEmpty(message.Input.Name)) { throw new ValidationException("KernelInput name can't be null or empty"); } if (!_dicById.ContainsKey(message.Input.GetId())) { return; } KernelInputData entity = _dicById[message.Input.GetId()]; if (ReferenceEquals(entity, message.Input)) { return; } entity.Update(message.Input); var repository = NTMinerRoot.CreateServerRepository <KernelInputData>(isUseJson); repository.Update(entity); VirtualRoot.Happened(new KernelInputUpdatedEvent(entity)); }).AddToCollection(root.ContextHandlers); VirtualRoot.Window <RemoveKernelInputCommand>("移除内核输入组", LogEnum.DevConsole, action: (message) => { InitOnece(); if (message == null || message.EntityId == Guid.Empty) { throw new ArgumentNullException(); } if (!_dicById.ContainsKey(message.EntityId)) { return; } KernelInputData entity = _dicById[message.EntityId]; _dicById.Remove(entity.GetId()); var repository = NTMinerRoot.CreateServerRepository <KernelInputData>(isUseJson); repository.Remove(message.EntityId); VirtualRoot.Happened(new KernelInputRemovedEvent(entity)); }).AddToCollection(root.ContextHandlers); }
public KernelOutputSet(INTMinerRoot root, bool isUseJson) { _root = root; _isUseJson = isUseJson; VirtualRoot.Window <AddKernelOutputCommand>("添加内核输出组", LogEnum.DevConsole, action: (message) => { InitOnece(); if (message == null || message.Input == null || message.Input.GetId() == Guid.Empty) { throw new ArgumentNullException(); } if (_dicById.ContainsKey(message.Input.GetId())) { return; } KernelOutputData entity = new KernelOutputData().Update(message.Input); _dicById.Add(entity.Id, entity); var repository = NTMinerRoot.CreateServerRepository <KernelOutputData>(isUseJson); repository.Add(entity); VirtualRoot.Happened(new KernelOutputAddedEvent(entity)); }).AddToCollection(root.ContextHandlers); VirtualRoot.Window <UpdateKernelOutputCommand>("更新内核输出组", LogEnum.DevConsole, action: (message) => { InitOnece(); if (message == null || message.Input == null || message.Input.GetId() == Guid.Empty) { throw new ArgumentNullException(); } if (string.IsNullOrEmpty(message.Input.Name)) { throw new ValidationException("KernelOutput name can't be null or empty"); } if (!_dicById.ContainsKey(message.Input.GetId())) { return; } KernelOutputData entity = _dicById[message.Input.GetId()]; if (ReferenceEquals(entity, message.Input)) { return; } entity.Update(message.Input); var repository = NTMinerRoot.CreateServerRepository <KernelOutputData>(isUseJson); repository.Update(entity); VirtualRoot.Happened(new KernelOutputUpdatedEvent(entity)); }).AddToCollection(root.ContextHandlers); VirtualRoot.Window <RemoveKernelOutputCommand>("移除内核输出组", LogEnum.DevConsole, action: (message) => { InitOnece(); if (message == null || message.EntityId == Guid.Empty) { throw new ArgumentNullException(); } if (!_dicById.ContainsKey(message.EntityId)) { return; } IKernel[] outputUsers = root.KernelSet.Where(a => a.KernelOutputId == message.EntityId).ToArray(); if (outputUsers.Length != 0) { throw new ValidationException($"这些内核在使用该内核输出组,删除前请先解除使用:{string.Join(",", outputUsers.Select(a => a.GetFullName()))}"); } KernelOutputData entity = _dicById[message.EntityId]; List <Guid> kernelOutputFilterIds = root.KernelOutputFilterSet.Where(a => a.KernelOutputId == entity.Id).Select(a => a.GetId()).ToList(); List <Guid> kernelOutputTranslaterIds = root.KernelOutputTranslaterSet.Where(a => a.KernelOutputId == entity.Id).Select(a => a.GetId()).ToList(); foreach (var kernelOutputFilterId in kernelOutputFilterIds) { VirtualRoot.Execute(new RemoveKernelOutputFilterCommand(kernelOutputFilterId)); } foreach (var kernelOutputTranslaterId in kernelOutputTranslaterIds) { VirtualRoot.Execute(new RemoveKernelOutputTranslaterCommand(kernelOutputTranslaterId)); } _dicById.Remove(entity.GetId()); var repository = NTMinerRoot.CreateServerRepository <KernelOutputData>(isUseJson); repository.Remove(message.EntityId); VirtualRoot.Happened(new KernelOutputRemovedEvent(entity)); }).AddToCollection(root.ContextHandlers); }
public GroupSet(INTMinerRoot root, bool isUseJson) { _isUseJson = isUseJson; _root = root; VirtualRoot.Window <AddGroupCommand>("添加组", LogEnum.DevConsole, action: (message) => { InitOnece(); if (message == null || message.Input == null || message.Input.GetId() == Guid.Empty) { throw new ArgumentNullException(); } if (_dicById.ContainsKey(message.Input.GetId())) { return; } GroupData entity = new GroupData().Update(message.Input); _dicById.Add(entity.Id, entity); var repository = NTMinerRoot.CreateServerRepository <GroupData>(isUseJson); repository.Add(entity); VirtualRoot.Happened(new GroupAddedEvent(entity)); }).AddToCollection(root.ContextHandlers); VirtualRoot.Window <UpdateGroupCommand>("更新组", LogEnum.DevConsole, action: (message) => { InitOnece(); if (message == null || message.Input == null || message.Input.GetId() == Guid.Empty) { throw new ArgumentNullException(); } if (string.IsNullOrEmpty(message.Input.Name)) { throw new ValidationException("Group name can't be null or empty"); } if (!_dicById.ContainsKey(message.Input.GetId())) { return; } GroupData entity = _dicById[message.Input.GetId()]; if (ReferenceEquals(entity, message.Input)) { return; } entity.Update(message.Input); var repository = NTMinerRoot.CreateServerRepository <GroupData>(isUseJson); repository.Update(entity); VirtualRoot.Happened(new GroupUpdatedEvent(entity)); }).AddToCollection(root.ContextHandlers); VirtualRoot.Window <RemoveGroupCommand>("移除组", LogEnum.DevConsole, action: (message) => { InitOnece(); if (message == null || message.EntityId == Guid.Empty) { throw new ArgumentNullException(); } if (!_dicById.ContainsKey(message.EntityId)) { return; } GroupData entity = _dicById[message.EntityId]; Guid[] toRemoves = root.CoinGroupSet.GetGroupCoinIds(entity.Id).ToArray(); foreach (var id in toRemoves) { VirtualRoot.Execute(new RemoveCoinGroupCommand(id)); } _dicById.Remove(entity.GetId()); var repository = NTMinerRoot.CreateServerRepository <GroupData>(isUseJson); repository.Remove(message.EntityId); VirtualRoot.Happened(new GroupRemovedEvent(entity)); }).AddToCollection(root.ContextHandlers); }
public SysDicItemSet(INTMinerRoot root, bool isUseJson) { _root = root; _isUseJson = isUseJson; VirtualRoot.Window <AddSysDicItemCommand>("添加系统字典项", LogEnum.DevConsole, action: (message) => { InitOnece(); if (message == null || message.Input == null || message.Input.GetId() == Guid.Empty) { throw new ArgumentNullException(); } if (string.IsNullOrEmpty(message.Input.Code)) { throw new ValidationException("dicitem code can't be null or empty"); } if (_dicById.ContainsKey(message.Input.GetId())) { return; } if (!_dicByDicId.ContainsKey(message.Input.DicId)) { _dicByDicId.Add(message.Input.DicId, new Dictionary <string, SysDicItemData>(StringComparer.OrdinalIgnoreCase)); } if (_dicByDicId[message.Input.DicId].ContainsKey(message.Input.Code)) { throw new DuplicateCodeException(); } SysDicItemData entity = new SysDicItemData().Update(message.Input); _dicById.Add(entity.Id, entity); _dicByDicId[message.Input.DicId].Add(entity.Code, entity); var repository = NTMinerRoot.CreateServerRepository <SysDicItemData>(isUseJson); repository.Add(entity); VirtualRoot.Happened(new SysDicItemAddedEvent(entity)); }).AddToCollection(root.ContextHandlers); VirtualRoot.Window <UpdateSysDicItemCommand>("更新系统字典项", LogEnum.DevConsole, action: (message) => { InitOnece(); if (message == null || message.Input == null || message.Input.GetId() == Guid.Empty) { throw new ArgumentNullException(); } if (string.IsNullOrEmpty(message.Input.Code)) { throw new ValidationException("sysDicItem code can't be null or empty"); } if (!_dicById.ContainsKey(message.Input.GetId())) { return; } SysDicItemData entity = _dicById[message.Input.GetId()]; if (ReferenceEquals(entity, message.Input)) { return; } entity.Update(message.Input); var repository = NTMinerRoot.CreateServerRepository <SysDicItemData>(isUseJson); repository.Update(entity); VirtualRoot.Happened(new SysDicItemUpdatedEvent(entity)); }).AddToCollection(root.ContextHandlers); VirtualRoot.Window <RemoveSysDicItemCommand>("移除系统字典项", LogEnum.DevConsole, action: (message) => { InitOnece(); if (message == null || message.EntityId == Guid.Empty) { throw new ArgumentNullException(); } if (!_dicById.ContainsKey(message.EntityId)) { return; } SysDicItemData entity = _dicById[message.EntityId]; _dicById.Remove(entity.Id); if (_dicByDicId.ContainsKey(entity.DicId)) { if (_dicByDicId[entity.DicId].ContainsKey(entity.Code)) { _dicByDicId[entity.DicId].Remove(entity.Code); } } var repository = NTMinerRoot.CreateServerRepository <SysDicItemData>(isUseJson); repository.Remove(entity.Id); VirtualRoot.Happened(new SysDicItemRemovedEvent(entity)); }).AddToCollection(root.ContextHandlers); }
private LangViewItemSet() { VirtualRoot.Window <RefreshLangViewItemSetCommand>("处理刷新语言项命令", LogEnum.DevConsole, action: message => { _isInited = false; VirtualRoot.Happened(new LangViewItemSetRefreshedEvent()); }); VirtualRoot.Window <AddLangViewItemCommand>("处理添加语言项命令", LogEnum.DevConsole, action: message => { if (_dicById.ContainsKey(message.Input.GetId())) { return; } if (LangSet.Instance.TryGetLang(message.Input.LangId, out _)) { if (!_dicByLangAndView.ContainsKey(message.Input.LangId)) { _dicByLangAndView.Add(message.Input.LangId, new Dictionary <string, List <ILangViewItem> >()); } var dic = _dicByLangAndView[message.Input.LangId]; if (!dic.ContainsKey(message.Input.ViewId)) { dic.Add(message.Input.ViewId, new List <ILangViewItem>()); } var entity = new LangViewItem().Update(message.Input); dic[message.Input.ViewId].Add(entity); _dicById.Add(message.Input.GetId(), entity); var repository = Repository.CreateLanguageRepository <LangViewItem>(); repository.Add(entity); VirtualRoot.Happened(new LangViewItemAddedEvent(entity)); } }); VirtualRoot.Window <UpdateLangViewItemCommand>("处理修改语言项命令", LogEnum.DevConsole, action: message => { if (_dicById.ContainsKey(message.Input.GetId())) { var entity = _dicById[message.Input.GetId()]; entity.Update(message.Input); var repository = Repository.CreateLanguageRepository <LangViewItem>(); repository.Update(entity); VirtualRoot.Happened(new LangViewItemUpdatedEvent(entity)); } }); VirtualRoot.Window <RemoveLangViewItemCommand>("处理删除语言项命令", LogEnum.DevConsole, action: message => { if (_dicById.ContainsKey(message.EntityId)) { var entity = _dicById[message.EntityId]; _dicById.Remove(message.EntityId); ILang lang; if (LangSet.Instance.TryGetLang(entity.LangId, out lang)) { if (_dicByLangAndView.ContainsKey(entity.LangId)) { var dic = _dicByLangAndView[entity.LangId]; if (dic.ContainsKey(entity.ViewId) && dic[entity.ViewId].Contains(entity)) { dic[entity.ViewId].Remove(entity); if (dic[entity.ViewId].Count == 0) { dic.Remove(entity.ViewId); } } if (_dicByLangAndView.Count == 0) { _dicByLangAndView.Remove(entity.LangId); } } } var repository = Repository.CreateLanguageRepository <LangViewItem>(); repository.Remove(entity.Id); VirtualRoot.Happened(new LangViewItemRemovedEvent(entity)); } }); }
public PoolSet(INTMinerRoot root, bool isUseJson) { _root = root; _isUseJson = isUseJson; VirtualRoot.Window <AddPoolCommand>("添加矿池", LogEnum.DevConsole, action: (message) => { InitOnece(); if (message == null || message.Input == null || message.Input.GetId() == Guid.Empty) { throw new ArgumentNullException(); } if (!_root.CoinSet.Contains(message.Input.CoinId)) { throw new ValidationException("there is no coin with id " + message.Input.CoinId); } if (string.IsNullOrEmpty(message.Input.Server)) { throw new ValidationException("pool poolurl can't be null or empty"); } if (_dicById.ContainsKey(message.Input.GetId())) { return; } PoolData entity = new PoolData().Update(message.Input); _dicById.Add(entity.Id, entity); if (VirtualRoot.IsMinerStudio) { Server.ControlCenterService.AddOrUpdatePoolAsync(entity, callback: null); } else { var repository = CreateCompositeRepository <PoolData>(isUseJson); repository.Add(entity); } VirtualRoot.Happened(new PoolAddedEvent(entity)); ICoin coin; if (root.CoinSet.TryGetCoin(message.Input.CoinId, out coin)) { ICoinKernel[] coinKernels = root.CoinKernelSet.Where(a => a.CoinId == coin.GetId()).ToArray(); foreach (ICoinKernel coinKernel in coinKernels) { Guid poolKernelId = Guid.NewGuid(); var poolKernel = new PoolKernelData() { Id = poolKernelId, Args = string.Empty, Description = string.Empty, KernelId = coinKernel.KernelId, PoolId = message.Input.GetId() }; VirtualRoot.Execute(new AddPoolKernelCommand(poolKernel)); } } }).AddToCollection(root.ContextHandlers); VirtualRoot.Window <UpdatePoolCommand>("更新矿池", LogEnum.DevConsole, action: (message) => { InitOnece(); if (message == null || message.Input == null || message.Input.GetId() == Guid.Empty) { throw new ArgumentNullException(); } if (!_root.CoinSet.Contains(message.Input.CoinId)) { throw new ValidationException("there is no coin with id " + message.Input.CoinId); } if (string.IsNullOrEmpty(message.Input.Server)) { throw new ValidationException("pool poolurl can't be null or empty"); } if (string.IsNullOrEmpty(message.Input.Name)) { throw new ValidationException("pool name can't be null or empty"); } if (!_dicById.ContainsKey(message.Input.GetId())) { return; } PoolData entity = _dicById[message.Input.GetId()]; if (ReferenceEquals(entity, message.Input)) { return; } entity.Update(message.Input); if (VirtualRoot.IsMinerStudio) { Server.ControlCenterService.AddOrUpdatePoolAsync(entity, callback: null); } else { var repository = CreateCompositeRepository <PoolData>(isUseJson); repository.Update(new PoolData().Update(message.Input)); } VirtualRoot.Happened(new PoolUpdatedEvent(entity)); }).AddToCollection(root.ContextHandlers); VirtualRoot.Window <RemovePoolCommand>("移除矿池", LogEnum.DevConsole, action: (message) => { InitOnece(); if (message == null || message.EntityId == Guid.Empty) { throw new ArgumentNullException(); } if (!_dicById.ContainsKey(message.EntityId)) { return; } PoolData entity = _dicById[message.EntityId]; _dicById.Remove(entity.GetId()); if (VirtualRoot.IsMinerStudio) { Server.ControlCenterService.RemovePoolAsync(entity.Id, callback: null); } else { var repository = CreateCompositeRepository <PoolData>(isUseJson); repository.Remove(message.EntityId); } VirtualRoot.Happened(new PoolRemovedEvent(entity)); Guid[] toRemoves = root.PoolKernelSet.Where(a => a.PoolId == message.EntityId).Select(a => a.GetId()).ToArray(); foreach (Guid poolKernelId in toRemoves) { VirtualRoot.Execute(new RemovePoolKernelCommand(poolKernelId)); } }).AddToCollection(root.ContextHandlers); }
public override void Link() { VirtualRoot.Window <ShowDialogWindowCommand>(LogEnum.DevConsole, action: message => { UIThread.Execute(() => { DialogWindow.ShowDialog(message: message.Message, title: message.Title, onYes: message.OnYes, icon: message.Icon); }); }); VirtualRoot.Window <ShowQQGroupQrCodeCommand>(LogEnum.DevConsole, action: message => { UIThread.Execute(() => { QQGroupQrCode.ShowWindow(); }); }); VirtualRoot.Window <ShowCalcCommand>(LogEnum.DevConsole, action: message => { UIThread.Execute(() => { Calc.ShowWindow(message.CoinVm); }); }); VirtualRoot.Window <ShowFileDownloaderCommand>(LogEnum.DevConsole, action: message => { UIThread.Execute(() => { FileDownloader.ShowWindow(message.DownloadFileUrl, message.FileTitle, message.DownloadComplete); }); }); VirtualRoot.Window <ShowAboutPageCommand>(LogEnum.DevConsole, action: message => { UIThread.Execute(() => { AboutPage.ShowWindow(); }); }); VirtualRoot.Window <ShowKernelOutputPageCommand>(LogEnum.DevConsole, action: message => { UIThread.Execute(() => { KernelOutputPage.ShowWindow(message.SelectedKernelOutputVm); }); }); VirtualRoot.Window <ShowKernelInputPageCommand>(LogEnum.DevConsole, action: message => { UIThread.Execute(() => { KernelInputPage.ShowWindow(); }); }); VirtualRoot.Window <ShowGroupPageCommand>(LogEnum.DevConsole, action: message => { UIThread.Execute(() => { GroupPage.ShowWindow(); }); }); VirtualRoot.Window <ShowSysDicPageCommand>(LogEnum.DevConsole, action: message => { UIThread.Execute(() => { SysDicPage.ShowWindow(); }); }); VirtualRoot.Window <ShowVirtualMemoryCommand>(LogEnum.DevConsole, action: message => { UIThread.Execute(() => { VirtualMemory.ShowWindow(); }); }); VirtualRoot.Window <ShowRestartWindowsCommand>(LogEnum.DevConsole, action: message => { UIThread.Execute(() => { RestartWindows.ShowDialog(); }); }); VirtualRoot.Window <ShowNotificationSampleCommand>(LogEnum.DevConsole, action: message => { UIThread.Execute(() => { NotificationSample.ShowWindow(); }); }); VirtualRoot.Window <ShowOuterPropertyCommand>(LogEnum.DevConsole, action: message => { UIThread.Execute(() => { OuterProperty.ShowWindow(); }); }); VirtualRoot.Window <ShowInnerPropertyCommand>(LogEnum.DevConsole, action: message => { UIThread.Execute(() => { InnerProperty.ShowWindow(); }); }); VirtualRoot.Window <ShowUserPageCommand>(LogEnum.DevConsole, action: message => { UIThread.Execute(() => { UserPage.ShowWindow(); }); }); VirtualRoot.Window <ShowKernelDownloaderCommand>(LogEnum.DevConsole, action: message => { UIThread.Execute(() => { KernelDownloading.ShowWindow(message.KernelId, message.DownloadComplete); }); }); VirtualRoot.Window <EnvironmentVariableEditCommand>(LogEnum.DevConsole, action: message => { UIThread.Execute(() => { EnvironmentVariableEdit.ShowWindow(message.CoinKernelVm, message.EnvironmentVariable); }); }); VirtualRoot.Window <InputSegmentEditCommand>(LogEnum.DevConsole, action: message => { UIThread.Execute(() => { InputSegmentEdit.ShowWindow(message.CoinKernelVm, message.Segment); }); }); VirtualRoot.Window <CoinKernelEditCommand>(LogEnum.DevConsole, action: message => { UIThread.Execute(() => { CoinKernelEdit.ShowWindow(message.FormType, message.Source); }); }); VirtualRoot.Window <CoinEditCommand>(LogEnum.DevConsole, action: message => { UIThread.Execute(() => { CoinEdit.ShowWindow(message.FormType, message.Source); }); }); VirtualRoot.Window <ShowContainerWindowCommand>(LogEnum.DevConsole, action: message => { UIThread.Execute(() => { ContainerWindow window = ContainerWindow.GetWindow(message.Vm); window?.ShowWindow(); }); }); VirtualRoot.Window <GroupEditCommand>(LogEnum.DevConsole, action: message => { UIThread.Execute(() => { GroupEdit.ShowWindow(message.FormType, message.Source); }); }); VirtualRoot.Window <KernelInputEditCommand>(LogEnum.DevConsole, action: message => { UIThread.Execute(() => { KernelInputEdit.ShowWindow(message.FormType, message.Source); }); }); VirtualRoot.Window <KernelOutputFilterEditCommand>(LogEnum.DevConsole, action: message => { UIThread.Execute(() => { KernelOutputFilterEdit.ShowWindow(message.FormType, message.Source); }); }); VirtualRoot.Window <KernelOutputTranslaterEditCommand>(LogEnum.DevConsole, action: message => { UIThread.Execute(() => { KernelOutputTranslaterEdit.ShowWindow(message.FormType, message.Source); }); }); VirtualRoot.Window <KernelOutputEditCommand>(LogEnum.DevConsole, action: message => { UIThread.Execute(() => { KernelOutputEdit.ShowWindow(message.FormType, message.Source); }); }); VirtualRoot.Window <ShowPackagesWindowCommand>(LogEnum.DevConsole, action: message => { UIThread.Execute(() => { PackagesWindow.ShowWindow(); }); }); VirtualRoot.Window <KernelEditCommand>(LogEnum.DevConsole, action: message => { UIThread.Execute(() => { KernelEdit.ShowWindow(message.FormType, message.Source); }); }); VirtualRoot.Window <ShowLogColorCommand>(LogEnum.DevConsole, action: message => { UIThread.Execute(() => { LogColor.ShowWindow(); }); }); VirtualRoot.Window <ShowGpuProfilesPageCommand>(LogEnum.DevConsole, action: message => { UIThread.Execute(() => { GpuProfilesPage.ShowWindow(message.MinerClientsWindowVm); }); }); VirtualRoot.Window <PackageEditCommand>(LogEnum.DevConsole, action: message => { UIThread.Execute(() => { PackageEdit.ShowWindow(message.FormType, message.Source); }); }); VirtualRoot.Window <PoolKernelEditCommand>(LogEnum.DevConsole, action: message => { UIThread.Execute(() => { PoolKernelEdit.ShowWindow(message.FormType, message.Source); }); }); VirtualRoot.Window <PoolEditCommand>(LogEnum.DevConsole, action: message => { UIThread.Execute(() => { PoolEdit.ShowWindow(message.FormType, message.Source); }); }); VirtualRoot.Window <SysDicItemEditCommand>(LogEnum.DevConsole, action: message => { UIThread.Execute(() => { SysDicItemEdit.ShowWindow(message.FormType, message.Source); }); }); VirtualRoot.Window <SysDicEditCommand>(LogEnum.DevConsole, action: message => { UIThread.Execute(() => { SysDicEdit.ShowWindow(message.FormType, message.Source); }); }); VirtualRoot.Window <UserEditCommand>(LogEnum.DevConsole, action: message => { UIThread.Execute(() => { UserEdit.ShowWindow(message.FormType, message.Source); }); }); VirtualRoot.Window <WalletEditCommand>(LogEnum.DevConsole, action: message => { UIThread.Execute(() => { WalletEdit.ShowWindow(message.FormType, message.Source); }); }); }
public ColumnsShowSet(INTMinerRoot root) { _root = root; VirtualRoot.Window <AddColumnsShowCommand>("添加列显", LogEnum.DevConsole, action: (message) => { InitOnece(); if (message == null || message.Input == null || message.Input.GetId() == Guid.Empty || message.Input.GetId() == ColumnsShowData.PleaseSelect.Id) { throw new ArgumentNullException(); } if (_dicById.ContainsKey(message.Input.GetId())) { return; } ColumnsShowData entity = new ColumnsShowData().Update(message.Input); Server.ControlCenterService.AddOrUpdateColumnsShowAsync(entity, (response, exception) => { if (response.IsSuccess()) { _dicById.Add(entity.Id, entity); VirtualRoot.Happened(new ColumnsShowAddedEvent(entity)); } else { Write.UserLine(response.ReadMessage(exception), ConsoleColor.Red); } }); }); VirtualRoot.Window <UpdateColumnsShowCommand>("更新列显", LogEnum.DevConsole, action: (message) => { InitOnece(); if (message == null || message.Input == null || message.Input.GetId() == Guid.Empty) { throw new ArgumentNullException(); } if (!_dicById.ContainsKey(message.Input.GetId())) { return; } ColumnsShowData entity = _dicById[message.Input.GetId()]; ColumnsShowData oldValue = new ColumnsShowData().Update(entity); entity.Update(message.Input); Server.ControlCenterService.AddOrUpdateColumnsShowAsync(entity, (response, exception) => { if (!response.IsSuccess()) { entity.Update(oldValue); VirtualRoot.Happened(new ColumnsShowUpdatedEvent(entity)); Write.UserLine(response.ReadMessage(exception), ConsoleColor.Red); } }); VirtualRoot.Happened(new ColumnsShowUpdatedEvent(entity)); }); VirtualRoot.Window <RemoveColumnsShowCommand>("移除列显", LogEnum.DevConsole, action: (message) => { InitOnece(); if (message == null || message.EntityId == Guid.Empty || message.EntityId == ColumnsShowData.PleaseSelect.Id) { throw new ArgumentNullException(); } if (!_dicById.ContainsKey(message.EntityId)) { return; } ColumnsShowData entity = _dicById[message.EntityId]; Server.ControlCenterService.RemoveColumnsShowAsync(entity.Id, (response, exception) => { if (response.IsSuccess()) { _dicById.Remove(entity.Id); VirtualRoot.Happened(new ColumnsShowRemovedEvent(entity)); } else { Write.UserLine(response.ReadMessage(exception), ConsoleColor.Red); } }); }); }
public WalletSet(INTMinerRoot root) { _root = root; VirtualRoot.Window <AddWalletCommand>("添加钱包", LogEnum.DevConsole, action: message => { InitOnece(); if (message == null || message.Input == null || message.Input.GetId() == Guid.Empty) { throw new ArgumentNullException(); } if (!_root.CoinSet.Contains(message.Input.CoinId)) { throw new ValidationException("there is not coin with id " + message.Input.CoinId); } if (string.IsNullOrEmpty(message.Input.Address)) { throw new ValidationException("wallet code and Address can't be null or empty"); } if (_dicById.ContainsKey(message.Input.GetId())) { return; } WalletData entity = new WalletData().Update(message.Input); _dicById.Add(entity.Id, entity); AddWallet(entity); VirtualRoot.Happened(new WalletAddedEvent(entity)); }); VirtualRoot.Window <UpdateWalletCommand>("更新钱包", LogEnum.DevConsole, action: message => { InitOnece(); if (message == null || message.Input == null || message.Input.GetId() == Guid.Empty) { throw new ArgumentNullException(); } if (!_root.CoinSet.Contains(message.Input.CoinId)) { throw new ValidationException("there is not coin with id " + message.Input.CoinId); } if (string.IsNullOrEmpty(message.Input.Address)) { throw new ValidationException("wallet Address can't be null or empty"); } if (string.IsNullOrEmpty(message.Input.Name)) { throw new ValidationException("wallet name can't be null or empty"); } if (!_dicById.ContainsKey(message.Input.GetId())) { return; } WalletData entity = _dicById[message.Input.GetId()]; entity.Update(message.Input); UpdateWallet(entity); VirtualRoot.Happened(new WalletUpdatedEvent(entity)); }); VirtualRoot.Window <RemoveWalletCommand>("移除钱包", LogEnum.DevConsole, action: (message) => { InitOnece(); if (message == null || message.EntityId == Guid.Empty) { throw new ArgumentNullException(); } if (!_dicById.ContainsKey(message.EntityId)) { return; } WalletData entity = _dicById[message.EntityId]; _dicById.Remove(entity.GetId()); RemoveWallet(entity.Id); VirtualRoot.Happened(new WalletRemovedEvent(entity)); }); }
public ServerAppSettingSet(INTMinerRoot root) { _root = root; VirtualRoot.Window <ChangeServerAppSettingCommand>("处理设置AppSetting命令", LogEnum.DevConsole, action: message => { if (message.AppSetting == null) { return; } AppSettingData oldValue; if (_dicByKey.TryGetValue(message.AppSetting.Key, out AppSettingData entity)) { oldValue = new AppSettingData { Key = entity.Key, Value = entity.Value }; entity.Value = message.AppSetting.Value; } else { entity = AppSettingData.Create(message.AppSetting); oldValue = null; _dicByKey.Add(message.AppSetting.Key, entity); } Server.AppSettingService.SetAppSettingAsync(entity, (response, exception) => { if (!response.IsSuccess()) { if (oldValue == null) { _dicByKey.Remove(message.AppSetting.Key); } else { entity.Value = oldValue.Value; } Write.UserFail(response.ReadMessage(exception)); VirtualRoot.Happened(new ServerAppSettingChangedEvent(entity)); } }); VirtualRoot.Happened(new ServerAppSettingChangedEvent(entity)); }); VirtualRoot.Window <ChangeServerAppSettingsCommand>("处理批量设置AppSetting命令", LogEnum.DevConsole, action: message => { if (message.AppSettings == null) { return; } foreach (var item in message.AppSettings) { AppSettingData oldValue; if (_dicByKey.TryGetValue(item.Key, out AppSettingData entity)) { oldValue = new AppSettingData { Key = entity.Key, Value = entity.Value }; entity.Value = item.Value; } else { entity = AppSettingData.Create(item); oldValue = null; _dicByKey.Add(item.Key, entity); } VirtualRoot.Happened(new ServerAppSettingChangedEvent(entity)); } Server.AppSettingService.SetAppSettingsAsync(message.AppSettings.Select(a => AppSettingData.Create(a)).ToList(), (response, exception) => { }); }); }
public SysDicSet(INTMinerRoot root, bool isUseJson) { _root = root; _isUseJson = isUseJson; VirtualRoot.Window <AddSysDicCommand>("添加系统字典", LogEnum.DevConsole, action: message => { InitOnece(); if (message == null || message.Input == null || message.Input.GetId() == Guid.Empty) { throw new ArgumentNullException(); } if (string.IsNullOrEmpty(message.Input.Code)) { throw new ValidationException("dic code can't be null or empty"); } if (_dicById.ContainsKey(message.Input.GetId())) { return; } if (_dicByCode.ContainsKey(message.Input.Code)) { throw new DuplicateCodeException(); } SysDicData entity = new SysDicData().Update(message.Input); _dicById.Add(entity.Id, entity); _dicByCode.Add(entity.Code, entity); var repository = NTMinerRoot.CreateServerRepository <SysDicData>(isUseJson); repository.Add(entity); VirtualRoot.Happened(new SysDicAddedEvent(entity)); }).AddToCollection(root.ContextHandlers); VirtualRoot.Window <UpdateSysDicCommand>("更新系统字典", LogEnum.DevConsole, action: message => { InitOnece(); if (message == null || message.Input == null || message.Input.GetId() == Guid.Empty) { throw new ArgumentNullException(); } if (string.IsNullOrEmpty(message.Input.Code)) { throw new ValidationException("sysDic code can't be null or empty"); } if (!_dicById.ContainsKey(message.Input.GetId())) { return; } SysDicData entity = _dicById[message.Input.GetId()]; if (ReferenceEquals(entity, message.Input)) { return; } entity.Update(message.Input); var repository = NTMinerRoot.CreateServerRepository <SysDicData>(isUseJson); repository.Update(entity); VirtualRoot.Happened(new SysDicUpdatedEvent(entity)); }).AddToCollection(root.ContextHandlers); VirtualRoot.Window <RemoveSysDicCommand>("移除系统字典", LogEnum.DevConsole, action: message => { InitOnece(); if (message == null || message.EntityId == Guid.Empty) { throw new ArgumentNullException(); } if (!_dicById.ContainsKey(message.EntityId)) { return; } SysDicData entity = _dicById[message.EntityId]; List <Guid> toRemoves = root.SysDicItemSet.GetSysDicItems(entity.Code).Select(a => a.GetId()).ToList(); foreach (var id in toRemoves) { VirtualRoot.Execute(new RemoveSysDicItemCommand(id)); } _dicById.Remove(entity.Id); if (_dicByCode.ContainsKey(entity.Code)) { _dicByCode.Remove(entity.Code); } var repository = NTMinerRoot.CreateServerRepository <SysDicData>(isUseJson); repository.Remove(entity.Id); VirtualRoot.Happened(new SysDicRemovedEvent(entity)); }).AddToCollection(root.ContextHandlers); }
public UserSet() { VirtualRoot.Window <AddUserCommand>("处理添加用户命令", LogEnum.DevConsole, action: message => { if (!_dicByLoginName.ContainsKey(message.User.LoginName)) { Server.ControlCenterService.AddUserAsync(new UserData { LoginName = message.User.LoginName, Password = message.User.Password, IsEnabled = message.User.IsEnabled, Description = message.User.Description }, (response, exception) => { if (response.IsSuccess()) { UserData entity = new UserData(message.User); _dicByLoginName.Add(message.User.LoginName, entity); VirtualRoot.Happened(new UserAddedEvent(entity)); } else { Write.UserLine(response.ReadMessage(exception), ConsoleColor.Red); } }); } }); VirtualRoot.Window <UpdateUserCommand>("处理修改用户命令", LogEnum.DevConsole, action: message => { if (_dicByLoginName.ContainsKey(message.User.LoginName)) { UserData entity = _dicByLoginName[message.User.LoginName]; UserData oldValue = new UserData(entity); entity.Update(message.User); Server.ControlCenterService.UpdateUserAsync(new UserData { LoginName = message.User.LoginName, Password = message.User.Password, IsEnabled = message.User.IsEnabled, Description = message.User.Description }, (response, exception) => { if (!response.IsSuccess()) { entity.Update(oldValue); VirtualRoot.Happened(new UserUpdatedEvent(entity)); Write.UserLine(response.ReadMessage(exception), ConsoleColor.Red); } }); VirtualRoot.Happened(new UserUpdatedEvent(entity)); } }); VirtualRoot.Window <RemoveUserCommand>("处理删除用户命令", LogEnum.DevConsole, action: message => { if (_dicByLoginName.ContainsKey(message.LoginName)) { UserData entity = _dicByLoginName[message.LoginName]; Server.ControlCenterService.RemoveUserAsync(message.LoginName, (response, exception) => { if (response.IsSuccess()) { _dicByLoginName.Remove(entity.LoginName); VirtualRoot.Happened(new UserRemovedEvent(entity)); } else { Write.UserLine(response.ReadMessage(exception), ConsoleColor.Red); } }); } }); }
public KernelOutputTranslaterSet(INTMinerRoot root, bool isUseJson) { _root = root; _isUseJson = isUseJson; VirtualRoot.Window <AddKernelOutputTranslaterCommand>("添加内核输出翻译器", LogEnum.DevConsole, action: (message) => { InitOnece(); if (message == null || message.Input == null || message.Input.GetId() == Guid.Empty) { throw new ArgumentNullException(); } if (string.IsNullOrEmpty(message.Input.RegexPattern)) { throw new ValidationException("ConsoleTranslater RegexPattern can't be null or empty"); } if (_dicById.ContainsKey(message.Input.GetId())) { return; } KernelOutputTranslaterData entity = new KernelOutputTranslaterData().Update(message.Input); _dicById.Add(entity.Id, entity); if (!_dicByKernelOutputId.ContainsKey(entity.KernelOutputId)) { _dicByKernelOutputId.Add(entity.KernelOutputId, new List <KernelOutputTranslaterData>()); } _dicByKernelOutputId[entity.KernelOutputId].Add(entity); var repository = NTMinerRoot.CreateServerRepository <KernelOutputTranslaterData>(isUseJson); repository.Add(entity); VirtualRoot.Happened(new KernelOutputTranslaterAddedEvent(entity)); }).AddToCollection(root.ContextHandlers); VirtualRoot.Window <UpdateKernelOutputTranslaterCommand>("更新内核输出翻译器", LogEnum.DevConsole, action: (message) => { InitOnece(); if (message == null || message.Input == null || message.Input.GetId() == Guid.Empty) { throw new ArgumentNullException(); } if (string.IsNullOrEmpty(message.Input.RegexPattern)) { throw new ValidationException("ConsoleTranslater RegexPattern can't be null or empty"); } if (!_dicById.ContainsKey(message.Input.GetId())) { return; } KernelOutputTranslaterData entity = _dicById[message.Input.GetId()]; if (ReferenceEquals(entity, message.Input)) { return; } string regexPattern = entity.RegexPattern; string color = entity.Color; entity.Update(message.Input); if (entity.RegexPattern != regexPattern) { _regexDic.Remove(entity); } if (entity.Color != color) { _colorDic.Remove(entity); } _dicByKernelOutputId[entity.KernelOutputId].Sort(new SortNumberComparer()); var repository = NTMinerRoot.CreateServerRepository <KernelOutputTranslaterData>(isUseJson); repository.Update(entity); VirtualRoot.Happened(new KernelOutputTranslaterUpdatedEvent(entity)); }).AddToCollection(root.ContextHandlers); VirtualRoot.Window <RemoveKernelOutputTranslaterCommand>("移除内核输出翻译器", LogEnum.DevConsole, action: (message) => { InitOnece(); if (message == null || message.EntityId == Guid.Empty) { throw new ArgumentNullException(); } if (!_dicById.ContainsKey(message.EntityId)) { return; } KernelOutputTranslaterData entity = _dicById[message.EntityId]; _dicById.Remove(entity.Id); _dicByKernelOutputId[entity.KernelOutputId].Remove(entity); _colorDic.Remove(entity); _regexDic.Remove(entity); _dicByKernelOutputId[entity.KernelOutputId].Sort(new SortNumberComparer()); var repository = NTMinerRoot.CreateServerRepository <KernelOutputTranslaterData>(isUseJson); repository.Remove(entity.Id); VirtualRoot.Happened(new KernelOutputTranslaterRemovedEvent(entity)); }).AddToCollection(root.ContextHandlers); VirtualRoot.On <SysDicItemUpdatedEvent>("LogColor字典项更新后刷新翻译器内存", LogEnum.DevConsole, action: message => { ISysDic dic; if (!_root.SysDicSet.TryGetSysDic("LogColor", out dic)) { return; } if (message.Source.DicId != dic.GetId()) { return; } foreach (var entity in _dicById.Values) { if (entity.Color == message.Source.Code) { _colorDic.Remove(entity); } } }).AddToCollection(root.ContextHandlers); }