public PoolKernelSet(INTMinerRoot root, bool isUseJson) { _root = root; _isUseJson = isUseJson; _root.ServerContextWindow <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)); } }); _root.ServerContextWindow <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)); } }); _root.ServerContextWindow <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)); }); }
public CoinGroupSet(INTMinerRoot root, bool isUseJson) { _root = root; _isUseJson = isUseJson; _root.ServerContextWindow <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)); }); _root.ServerContextWindow <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)); }); }
public KernelOutputFilterSet(INTMinerRoot root, bool isUseJson) { _root = root; _isUseJson = isUseJson; _root.ServerContextWindow <AddKernelOutputFilterCommand>("添加内核输出过滤器", 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($"{nameof(message.Input.RegexPattern)} can't be null or empty"); } if (_dicById.ContainsKey(message.Input.GetId())) { return; } KernelOutputFilterData entity = new KernelOutputFilterData().Update(message.Input); _dicById.Add(entity.Id, entity); if (!_dicByKernelOutputId.ContainsKey(entity.KernelOutputId)) { _dicByKernelOutputId.Add(entity.KernelOutputId, new List <KernelOutputFilterData>()); } _dicByKernelOutputId[entity.KernelOutputId].Add(entity); var repository = NTMinerRoot.CreateServerRepository <KernelOutputFilterData>(isUseJson); repository.Add(entity); VirtualRoot.Happened(new KernelOutputFilterAddedEvent(entity)); }); _root.ServerContextWindow <UpdateKernelOutputFilterCommand>("更新内核输出过滤器", 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($"{nameof(message.Input.RegexPattern)} can't be null or empty"); } if (!_dicById.ContainsKey(message.Input.GetId())) { return; } KernelOutputFilterData entity = _dicById[message.Input.GetId()]; if (ReferenceEquals(entity, message.Input)) { return; } entity.Update(message.Input); var repository = NTMinerRoot.CreateServerRepository <KernelOutputFilterData>(isUseJson); repository.Update(entity); VirtualRoot.Happened(new KernelOutputFilterUpdatedEvent(entity)); }); _root.ServerContextWindow <RemoveKernelOutputFilterCommand>("移除内核输出过滤器", LogEnum.DevConsole, action: (message) => { InitOnece(); if (message == null || message.EntityId == Guid.Empty) { throw new ArgumentNullException(); } if (!_dicById.ContainsKey(message.EntityId)) { return; } KernelOutputFilterData entity = _dicById[message.EntityId]; _dicById.Remove(entity.Id); _dicByKernelOutputId[entity.KernelOutputId].Remove(entity); var repository = NTMinerRoot.CreateServerRepository <KernelOutputFilterData>(isUseJson); repository.Remove(entity.Id); VirtualRoot.Happened(new KernelOutputFilterRemovedEvent(entity)); }); }
public CoinKernelSet(INTMinerRoot root) { _root = root; _root.ServerContextWindow <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>(); 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, KernelId = message.Input.KernelId, PoolId = pool.GetId() }; VirtualRoot.Execute(new AddPoolKernelCommand(poolKernel)); } } }); _root.ServerContextWindow <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>(); repository.Update(entity); VirtualRoot.Happened(new CoinKernelUpdatedEvent(entity)); }); _root.ServerContextWindow <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>(); 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)); } } }); _root.ServerContextOn <FileWriterRemovedEvent>("移除文件书写器后移除引用关系", LogEnum.DevConsole, action: message => { var repository = NTMinerRoot.CreateServerRepository <CoinKernelData>(); var entities = _dicById.Values.Where(a => a.FileWriterIds.Contains(message.Source.GetId())).ToArray(); foreach (var entity in entities) { entity.FileWriterIds = new List <Guid>(entity.FileWriterIds.Where(a => a != message.Source.GetId())); repository.Update(entity); VirtualRoot.Happened(new CoinKernelUpdatedEvent(entity)); } }); _root.ServerContextOn <FragmentWriterRemovedEvent>("移除命令行片段书写器后移除引用关系", LogEnum.DevConsole, action: message => { var repository = NTMinerRoot.CreateServerRepository <CoinKernelData>(); var entities = _dicById.Values.Where(a => a.FragmentWriterIds.Contains(message.Source.GetId())).ToArray(); foreach (var entity in entities) { entity.FragmentWriterIds = new List <Guid>(entity.FragmentWriterIds.Where(a => a != message.Source.GetId())); repository.Update(entity); VirtualRoot.Happened(new CoinKernelUpdatedEvent(entity)); } }); }
public SysDicItemSet(INTMinerRoot root, bool isUseJson) { _root = root; _isUseJson = isUseJson; _root.ServerContextWindow <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 ValidationException("编码重复"); } SysDicItemData entity = new SysDicItemData().Update(message.Input); _dicById.Add(entity.Id, entity); _dicByDicId[message.Input.DicId].Add(entity.Code, entity); var repository = NTMinerRoot.CreateCompositeRepository <SysDicItemData>(isUseJson); repository.Add(entity); VirtualRoot.Happened(new SysDicItemAddedEvent(entity)); }); _root.ServerContextWindow <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; } string oldCode = entity.Code; entity.Update(message.Input); // 如果编码变更了 if (oldCode != entity.Code) { _dicByDicId[entity.DicId].Remove(oldCode); _dicByDicId[entity.DicId].Add(entity.Code, entity); } var repository = NTMinerRoot.CreateCompositeRepository <SysDicItemData>(isUseJson); repository.Update(entity); VirtualRoot.Happened(new SysDicItemUpdatedEvent(entity)); }); _root.ServerContextWindow <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.CreateCompositeRepository <SysDicItemData>(isUseJson); repository.Remove(entity.Id); VirtualRoot.Happened(new SysDicItemRemovedEvent(entity)); }); }
public PackageSet(INTMinerRoot root) { _root = root; _root.ServerContextWindow <AddPackageCommand>("添加包", 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($"{nameof(message.Input.Name)} can't be null or empty"); } if (_dicById.Values.Any(a => string.Equals(message.Input.Name, a.Name, StringComparison.OrdinalIgnoreCase))) { throw new ValidationException("包名重复"); } if (_dicById.ContainsKey(message.Input.GetId())) { return; } PackageData entity = new PackageData().Update(message.Input); _dicById.Add(entity.Id, entity); IRepository <PackageData> repository = NTMinerRoot.CreateServerRepository <PackageData>(); repository.Add(entity); VirtualRoot.Happened(new PackageAddedEvent(entity)); }); _root.ServerContextWindow <UpdatePackageCommand>("更新包", 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($"{nameof(message.Input.Name)} can't be null or empty"); } if (!_dicById.ContainsKey(message.Input.GetId())) { return; } if (_dicById.Values.Any(a => a.Id != message.Input.Id && string.Equals(message.Input.Name, a.Name, StringComparison.OrdinalIgnoreCase))) { throw new ValidationException("包名重复"); } PackageData entity = _dicById[message.Input.GetId()]; if (ReferenceEquals(entity, message.Input)) { return; } entity.Update(message.Input); IRepository <PackageData> repository = NTMinerRoot.CreateServerRepository <PackageData>(); repository.Update(entity); VirtualRoot.Happened(new PackageUpdatedEvent(entity)); }); _root.ServerContextWindow <RemovePackageCommand>("移除包", LogEnum.DevConsole, action: message => { InitOnece(); if (message == null || message.EntityId == Guid.Empty) { throw new ArgumentNullException(); } if (!_dicById.ContainsKey(message.EntityId)) { return; } PackageData entity = _dicById[message.EntityId]; _dicById.Remove(entity.Id); IRepository <PackageData> repository = NTMinerRoot.CreateServerRepository <PackageData>(); repository.Remove(entity.Id); VirtualRoot.Happened(new PackageRemovedEvent(entity)); }); }
public GroupSet(INTMinerRoot root, bool isUseJson) { _isUseJson = isUseJson; _root = root; _root.ServerContextWindow <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; } if (string.IsNullOrEmpty(message.Input.Name)) { throw new ValidationException("Group name can't be null or empty"); } 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)); }); _root.ServerContextWindow <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)); }); _root.ServerContextWindow <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)); }); }
public CoinSet(INTMinerRoot root, bool isUseJson) { _root = root; _isUseJson = isUseJson; _root.ServerContextWindow <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 ValidationException("编码重复"); } 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)); }); _root.ServerContextWindow <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)); }); _root.ServerContextWindow <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)); }); }
public KernelOutputKeywordSet(INTMinerRoot root, bool isUseJson) { _root = root; _isUseJson = isUseJson; _root.ServerContextWindow <AddKernelOutputKeywordCommand>("添加内核输出关键字", 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; } if (string.IsNullOrEmpty(message.Input.Keyword)) { throw new ValidationException("EventType name can't be null or empty"); } if (_dicById.Values.Any(a => a.Keyword == message.Input.Keyword && a.Id != message.Input.GetId())) { throw new ValidationException($"关键字{message.Input.Keyword}已存在"); } KernelOutputKeywordData entity = new KernelOutputKeywordData().Update(message.Input); _dicById.Add(entity.Id, entity); var repository = NTMinerRoot.CreateCompositeRepository <KernelOutputKeywordData>(isUseJson); repository.Add(entity); VirtualRoot.Happened(new KernelOutputKeywordAddedEvent(entity)); }); _root.ServerContextWindow <UpdateKernelOutputKeywordCommand>("更新内核输出关键字", LogEnum.DevConsole, action: (message) => { InitOnece(); if (message == null || message.Input == null || message.Input.GetId() == Guid.Empty) { throw new ArgumentNullException(); } if (string.IsNullOrEmpty(message.Input.Keyword)) { throw new ValidationException("EventType name can't be null or empty"); } if (!_dicById.ContainsKey(message.Input.GetId())) { return; } if (_dicById.Values.Any(a => a.Keyword == message.Input.Keyword && a.Id != message.Input.GetId())) { throw new ValidationException($"关键字{message.Input.Keyword}已存在"); } KernelOutputKeywordData entity = _dicById[message.Input.GetId()]; if (ReferenceEquals(entity, message.Input)) { return; } entity.Update(message.Input); var repository = NTMinerRoot.CreateCompositeRepository <KernelOutputKeywordData>(isUseJson); repository.Update(entity); VirtualRoot.Happened(new KernelOutputKeywordUpdatedEvent(entity)); }); _root.ServerContextWindow <RemoveKernelOutputKeywordCommand>("移除内核输出关键字", LogEnum.DevConsole, action: (message) => { InitOnece(); if (message == null || message.EntityId == Guid.Empty) { throw new ArgumentNullException(); } if (!_dicById.ContainsKey(message.EntityId)) { return; } KernelOutputKeywordData entity = _dicById[message.EntityId]; _dicById.Remove(entity.GetId()); var repository = NTMinerRoot.CreateCompositeRepository <KernelOutputKeywordData>(isUseJson); repository.Remove(message.EntityId); VirtualRoot.Happened(new KernelOutputKeywordRemovedEvent(entity)); }); }
public PoolSet(INTMinerRoot root, bool isUseJson) { _root = root; _isUseJson = isUseJson; _root.ServerContextWindow <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 = NTMinerRoot.CreateCompositeRepository <PoolData>(isUseJson); repository.Add(entity); } VirtualRoot.Happened(new PoolAddedEvent(entity)); if (root.CoinSet.TryGetCoin(message.Input.CoinId, out ICoin 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, KernelId = coinKernel.KernelId, PoolId = message.Input.GetId() }; VirtualRoot.Execute(new AddPoolKernelCommand(poolKernel)); } } }); _root.ServerContextWindow <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 = NTMinerRoot.CreateCompositeRepository <PoolData>(isUseJson); repository.Update(new PoolData().Update(message.Input)); } VirtualRoot.Happened(new PoolUpdatedEvent(entity)); }); _root.ServerContextWindow <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 = NTMinerRoot.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)); } }); }
public FileWriterSet(INTMinerRoot root) { _root = root; _root.ServerContextWindow <AddFileWriterCommand>("添加文件书写器", 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; } if (string.IsNullOrEmpty(message.Input.FileUrl) || string.IsNullOrEmpty(message.Input.Body)) { throw new ValidationException("FileWriter name and body can't be null or empty"); } FileWriterData entity = new FileWriterData().Update(message.Input); _dicById.Add(entity.Id, entity); var repository = NTMinerRoot.CreateServerRepository <FileWriterData>(); repository.Add(entity); VirtualRoot.Happened(new FileWriterAddedEvent(entity)); }); _root.ServerContextWindow <UpdateFileWriterCommand>("更新文件书写器", LogEnum.DevConsole, action: (message) => { InitOnece(); if (message == null || message.Input == null || message.Input.GetId() == Guid.Empty) { throw new ArgumentNullException(); } if (string.IsNullOrEmpty(message.Input.FileUrl) || string.IsNullOrEmpty(message.Input.Body)) { throw new ValidationException("FileWriter name and body can't be null or empty"); } if (!_dicById.ContainsKey(message.Input.GetId())) { return; } FileWriterData entity = _dicById[message.Input.GetId()]; if (ReferenceEquals(entity, message.Input)) { return; } entity.Update(message.Input); var repository = NTMinerRoot.CreateServerRepository <FileWriterData>(); repository.Update(entity); VirtualRoot.Happened(new FileWriterUpdatedEvent(entity)); }); _root.ServerContextWindow <RemoveFileWriterCommand>("移除文件书写器", LogEnum.DevConsole, action: (message) => { InitOnece(); if (message == null || message.EntityId == Guid.Empty) { throw new ArgumentNullException(); } if (!_dicById.ContainsKey(message.EntityId)) { return; } FileWriterData entity = _dicById[message.EntityId]; _dicById.Remove(entity.GetId()); var repository = NTMinerRoot.CreateServerRepository <FileWriterData>(); repository.Remove(message.EntityId); VirtualRoot.Happened(new FileWriterRemovedEvent(entity)); }); }
public KernelOutputSet(INTMinerRoot root, bool isUseJson) { _root = root; _isUseJson = isUseJson; _root.ServerContextWindow <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)); }); _root.ServerContextWindow <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)); }); _root.ServerContextWindow <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)); }); }
public KernelOutputTranslaterSet(INTMinerRoot root, bool isUseJson) { _root = root; _isUseJson = isUseJson; _root.ServerContextWindow <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($"{nameof(message.Input.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)); }); _root.ServerContextWindow <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($"{nameof(message.Input.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)); }); _root.ServerContextWindow <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)); }); _root.ServerContextOn <SysDicItemUpdatedEvent>($"{Consts.LogColorDicKey}字典项更新后刷新翻译器内存", LogEnum.DevConsole, action: message => { if (!_root.SysDicSet.TryGetSysDic(Consts.LogColorDicKey, out ISysDic dic)) { return; } if (message.Source.DicId != dic.GetId()) { return; } foreach (var entity in _dicById.Values) { if (entity.Color == message.Source.Code) { _colorDic.Remove(entity); } } }); }
public SysDicSet(INTMinerRoot root, bool isUseJson) { _root = root; _isUseJson = isUseJson; _root.ServerContextWindow <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 ValidationException("编码重复"); } 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)); }); _root.ServerContextWindow <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)); }); _root.ServerContextWindow <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)); }); }
public KernelSet(INTMinerRoot root) { _root = root; _root.ServerContextWindow <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($"{nameof(message.Input.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>(); repository.Add(entity); VirtualRoot.Happened(new KernelAddedEvent(entity)); }); _root.ServerContextWindow <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($"{nameof(message.Input.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>(); repository.Update(entity); VirtualRoot.Happened(new KernelUpdatedEvent(entity)); }); _root.ServerContextWindow <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>(); repository.Remove(entity.Id); VirtualRoot.Happened(new KernelRemovedEvent(entity)); }); }
public WorkerEventTypeSet(INTMinerRoot root, bool isUseJson) { _root = root; _isUseJson = isUseJson; _root.ServerContextWindow <AddWorkerEventTypeCommand>("添加事件类型", 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; } if (string.IsNullOrEmpty(message.Input.Name)) { throw new ValidationException("EventType name can't be null or empty"); } WorkerEventTypeData entity = new WorkerEventTypeData().Update(message.Input); _dicById.Add(entity.Id, entity); var repository = NTMinerRoot.CreateCompositeRepository <WorkerEventTypeData>(isUseJson); repository.Add(entity); VirtualRoot.Happened(new WorkerEventTypeAddedEvent((IWorkerEventType)entity)); }); _root.ServerContextWindow <UpdateWorkerEventTypeCommand>("更新事件类型", 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("EventType name can't be null or empty"); } if (!_dicById.ContainsKey(message.Input.GetId())) { return; } WorkerEventTypeData entity = _dicById[message.Input.GetId()]; if (ReferenceEquals(entity, message.Input)) { return; } entity.Update(message.Input); var repository = NTMinerRoot.CreateCompositeRepository <WorkerEventTypeData>(isUseJson); repository.Update(entity); VirtualRoot.Happened(new WorkerEventTypeUpdatedEvent((IWorkerEventType)entity)); }); _root.ServerContextWindow <RemoveWorkerEventTypeCommand>("移除事件类型", LogEnum.DevConsole, action: (message) => { InitOnece(); if (message == null || message.EntityId == Guid.Empty) { throw new ArgumentNullException(); } if (!_dicById.ContainsKey(message.EntityId)) { return; } WorkerEventTypeData entity = _dicById[message.EntityId]; _dicById.Remove(entity.GetId()); var repository = NTMinerRoot.CreateCompositeRepository <WorkerEventTypeData>(isUseJson); repository.Remove(message.EntityId); VirtualRoot.Happened(new WorkerEventTypeRemovedEvent((IWorkerEventType)entity)); }); }