public PoolKernelSet(IServerContext context) { _context = context; _context.AddCmdPath <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>(); repository.Add(entity); VirtualRoot.RaiseEvent(new PoolKernelAddedEvent(message.MessageId, message.Input)); } }, location: this.GetType()); _context.AddCmdPath <RemovePoolKernelCommand>("处理移除矿池级内核命令", LogEnum.DevConsole, action: message => { if (_dicById.ContainsKey(message.EntityId)) { var entity = _dicById[message.EntityId]; _dicById.Remove(message.EntityId); var repository = NTMinerRoot.CreateServerRepository <PoolKernelData>(); repository.Remove(message.EntityId); VirtualRoot.RaiseEvent(new PoolKernelRemovedEvent(message.MessageId, entity)); } }, location: this.GetType()); _context.AddCmdPath <UpdatePoolKernelCommand>("更新矿池内核", LogEnum.DevConsole, action: (message) => { InitOnece(); if (message == null || message.Input == null || message.Input.GetId() == Guid.Empty) { throw new ArgumentNullException(); } if (!_context.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>(); repository.Update(entity); VirtualRoot.RaiseEvent(new PoolKernelUpdatedEvent(message.MessageId, entity)); }, location: this.GetType()); }
public CoinGroupSet(IServerContext context) { _context = context; context.AddCmdPath <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 = context.CreateServerRepository <CoinGroupData>(); repository.Add(entity); VirtualRoot.RaiseEvent(new CoinGroupAddedEvent(message.MessageId, entity)); }, location: this.GetType()); context.AddCmdPath <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 = context.CreateServerRepository <CoinGroupData>(); repository.Remove(message.EntityId); VirtualRoot.RaiseEvent(new CoinGroupRemovedEvent(message.MessageId, entity)); }, location: this.GetType()); }
public KernelOutputSet(IServerContext context) { _context = context; #region 接线 context.AddCmdPath <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 = context.CreateServerRepository <KernelOutputData>(); repository.Add(entity); VirtualRoot.RaiseEvent(new KernelOutputAddedEvent(message.MessageId, entity)); }, location: this.GetType()); context.AddCmdPath <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($"{nameof(message.Input.Name)} can't be null or empty"); } if (!_dicById.TryGetValue(message.Input.GetId(), out KernelOutputData entity)) { return; } if (ReferenceEquals(entity, message.Input)) { return; } entity.Update(message.Input); var repository = context.CreateServerRepository <KernelOutputData>(); repository.Update(entity); VirtualRoot.RaiseEvent(new KernelOutputUpdatedEvent(message.MessageId, entity)); }, location: this.GetType()); context.AddCmdPath <RemoveKernelOutputCommand>("移除内核输出组", LogEnum.DevConsole, action: (message) => { InitOnece(); if (message == null || message.EntityId == Guid.Empty) { throw new ArgumentNullException(); } if (!_dicById.ContainsKey(message.EntityId)) { return; } IKernel[] outputUses = context.KernelSet.AsEnumerable().Where(a => a.KernelOutputId == message.EntityId).ToArray(); if (outputUses.Length != 0) { throw new ValidationException($"这些内核在使用该内核输出组,删除前请先解除使用:{string.Join(",", outputUses.Select(a => a.GetFullName()))}"); } KernelOutputData entity = _dicById[message.EntityId]; List <Guid> kernelOutputTranslaterIds = context.KernelOutputTranslaterSet.AsEnumerable().Where(a => a.KernelOutputId == entity.Id).Select(a => a.GetId()).ToList(); foreach (var kernelOutputTranslaterId in kernelOutputTranslaterIds) { VirtualRoot.Execute(new RemoveKernelOutputTranslaterCommand(kernelOutputTranslaterId)); } _dicById.Remove(entity.GetId()); var repository = context.CreateServerRepository <KernelOutputData>(); repository.Remove(message.EntityId); VirtualRoot.RaiseEvent(new KernelOutputRemovedEvent(message.MessageId, entity)); }, location: this.GetType()); #endregion }
public SysDicSet(IServerContext context) { _context = context; context.AddCmdPath <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 = context.CreateServerRepository <SysDicData>(); repository.Add(entity); VirtualRoot.RaiseEvent(new SysDicAddedEvent(message.MessageId, entity)); }, location: this.GetType()); context.AddCmdPath <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.TryGetValue(message.Input.GetId(), out SysDicData entity)) { return; } if (ReferenceEquals(entity, message.Input)) { return; } entity.Update(message.Input); var repository = context.CreateServerRepository <SysDicData>(); repository.Update(entity); VirtualRoot.RaiseEvent(new SysDicUpdatedEvent(message.MessageId, entity)); }, location: this.GetType()); context.AddCmdPath <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 = context.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 = context.CreateServerRepository <SysDicData>(); repository.Remove(entity.Id); VirtualRoot.RaiseEvent(new SysDicRemovedEvent(message.MessageId, entity)); }, location: this.GetType()); }
public SysDicItemSet(IServerContext context) { _context = context; _context.AddCmdPath <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 = context.CreateCompositeRepository <SysDicItemData>(); repository.Add(entity); VirtualRoot.RaiseEvent(new SysDicItemAddedEvent(message.MessageId, entity)); }, location: this.GetType()); _context.AddCmdPath <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.TryGetValue(message.Input.GetId(), out SysDicItemData entity)) { return; } 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 = context.CreateCompositeRepository <SysDicItemData>(); repository.Update(entity); VirtualRoot.RaiseEvent(new SysDicItemUpdatedEvent(message.MessageId, entity)); }, location: this.GetType()); _context.AddCmdPath <RemoveSysDicItemCommand>("移除系统字典项", LogEnum.DevConsole, action: (message) => { InitOnece(); if (message == null || message.EntityId == Guid.Empty) { throw new ArgumentNullException(); } if (!_dicById.TryGetValue(message.EntityId, out SysDicItemData entity) || !_context.SysDicSet.TryGetSysDic(entity.DicId, out ISysDic sysDic)) { return; } bool isKernelBrand = sysDic.Code == NTKeyword.KernelBrandSysDicCode; bool isPoolBrand = sysDic.Code == NTKeyword.PoolBrandSysDicCode; bool isAlgo = sysDic.Code == NTKeyword.AlgoSysDicCode; // TODO:如果是内核品牌、矿池品牌、算法 _dicById.Remove(entity.Id); if (_dicByDicId.TryGetValue(entity.DicId, out Dictionary <string, SysDicItemData> dicItemDic)) { dicItemDic.Remove(entity.Code); } var repository = context.CreateCompositeRepository <SysDicItemData>(); repository.Remove(entity.Id); VirtualRoot.RaiseEvent(new SysDicItemRemovedEvent(message.MessageId, entity)); }, location: this.GetType()); }
public CoinKernelSet(IServerContext context) { _context = context; context.AddCmdPath <AddCoinKernelCommand>(LogEnum.DevConsole, action: (message) => { InitOnece(); if (message == null || message.Input == null || message.Input.GetId() == Guid.Empty) { throw new ArgumentNullException(); } if (!context.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 = context.CreateServerRepository <CoinKernelData>(); repository.Add(entity); VirtualRoot.RaiseEvent(new CoinKernelAddedEvent(message.MessageId, entity)); if (context.CoinSet.TryGetCoin(message.Input.CoinId, out ICoin coin)) { IPool[] pools = context.PoolSet.AsEnumerable().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)); } } }, location: this.GetType()); context.AddCmdPath <UpdateCoinKernelCommand>(LogEnum.DevConsole, action: (message) => { InitOnece(); if (message == null || message.Input == null || message.Input.GetId() == Guid.Empty) { throw new ArgumentNullException(); } if (!context.CoinSet.Contains(message.Input.CoinId)) { throw new ValidationException("there is no coin with id" + message.Input.CoinId); } if (!_dicById.TryGetValue(message.Input.GetId(), out CoinKernelData entity)) { return; } if (ReferenceEquals(entity, message.Input)) { return; } entity.Update(message.Input); var repository = context.CreateServerRepository <CoinKernelData>(); repository.Update(entity); VirtualRoot.RaiseEvent(new CoinKernelUpdatedEvent(message.MessageId, entity)); }, location: this.GetType()); context.AddCmdPath <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 = context.CreateServerRepository <CoinKernelData>(); repository.Remove(entity.Id); VirtualRoot.RaiseEvent(new CoinKernelRemovedEvent(message.MessageId, entity)); if (context.CoinSet.TryGetCoin(entity.CoinId, out ICoin coin)) { List <Guid> toRemoves = new List <Guid>(); IPool[] pools = context.PoolSet.AsEnumerable().Where(a => a.CoinId == coin.GetId()).ToArray(); foreach (IPool pool in pools) { foreach (PoolKernelData poolKernel in context.PoolKernelSet.AsEnumerable().Where(a => a.PoolId == pool.GetId() && a.KernelId == entity.KernelId).ToArray()) { toRemoves.Add(poolKernel.Id); } } foreach (Guid poolKernelId in toRemoves) { VirtualRoot.Execute(new RemovePoolKernelCommand(poolKernelId)); } } }, location: this.GetType()); context.AddEventPath <FileWriterRemovedEvent>("移除文件书写器后移除引用关系", LogEnum.DevConsole, action: message => { var repository = context.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.RaiseEvent(new CoinKernelUpdatedEvent(message.MessageId, entity)); } }, location: this.GetType()); context.AddEventPath <FragmentWriterRemovedEvent>("移除命令行片段书写器后移除引用关系", LogEnum.DevConsole, action: message => { var repository = context.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.RaiseEvent(new CoinKernelUpdatedEvent(message.MessageId, entity)); } }, location: this.GetType()); }
public KernelInputSet(IServerContext context) { context.AddCmdPath <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>(); repository.Add(entity); VirtualRoot.RaiseEvent(new KernelInputAddedEvent(message.Id, entity)); }, location: this.GetType()); context.AddCmdPath <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($"{nameof(message.Input.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>(); repository.Update(entity); VirtualRoot.RaiseEvent(new KernelInputUpdatedEvent(message.Id, entity)); }, location: this.GetType()); context.AddCmdPath <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>(); repository.Remove(message.EntityId); VirtualRoot.RaiseEvent(new KernelInputRemovedEvent(message.Id, entity)); }, location: this.GetType()); }
public FragmentWriterSet(IServerContext context) { _context = context; context.AddCmdPath <AddFragmentWriterCommand>("添加命令行片段书写器", 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.Body)) { throw new ValidationException("FragmentWriter body can't be null or empty"); } FragmentWriterData entity = new FragmentWriterData().Update(message.Input); _dicById.Add(entity.Id, entity); var repository = context.CreateServerRepository <FragmentWriterData>(); repository.Add(entity); VirtualRoot.RaiseEvent(new FragmentWriterAddedEvent(message.MessageId, entity)); }, location: this.GetType()); context.AddCmdPath <UpdateFragmentWriterCommand>("更新命令行片段书写器", LogEnum.DevConsole, action: (message) => { InitOnece(); if (message == null || message.Input == null || message.Input.GetId() == Guid.Empty) { throw new ArgumentNullException(); } if (string.IsNullOrEmpty(message.Input.Body)) { throw new ValidationException("FragmentWriter body can't be null or empty"); } if (!_dicById.TryGetValue(message.Input.GetId(), out FragmentWriterData entity)) { return; } if (ReferenceEquals(entity, message.Input)) { return; } entity.Update(message.Input); var repository = context.CreateServerRepository <FragmentWriterData>(); repository.Update(entity); VirtualRoot.RaiseEvent(new FragmentWriterUpdatedEvent(message.MessageId, entity)); }, location: this.GetType()); context.AddCmdPath <RemoveFragmentWriterCommand>("移除组", LogEnum.DevConsole, action: (message) => { InitOnece(); if (message == null || message.EntityId == Guid.Empty) { throw new ArgumentNullException(); } if (!_dicById.ContainsKey(message.EntityId)) { return; } FragmentWriterData entity = _dicById[message.EntityId]; _dicById.Remove(entity.GetId()); var repository = context.CreateServerRepository <FragmentWriterData>(); repository.Remove(message.EntityId); VirtualRoot.RaiseEvent(new FragmentWriterRemovedEvent(message.MessageId, entity)); }, location: this.GetType()); }
public CoinSet(IServerContext context) { _context = context; context.AddCmdPath <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 = context.CreateServerRepository <CoinData>(); repository.Add(entity); VirtualRoot.RaiseEvent(new CoinAddedEvent(message.MessageId, entity)); }, location: this.GetType()); context.AddCmdPath <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.TryGetValue(message.Input.GetId(), out CoinData entity)) { return; } if (ReferenceEquals(entity, message.Input)) { return; } entity.Update(message.Input); var repository = context.CreateServerRepository <CoinData>(); repository.Update(entity); VirtualRoot.RaiseEvent(new CoinUpdatedEvent(message.MessageId, message.Input)); }, location: this.GetType()); context.AddCmdPath <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 = context.PoolSet.AsEnumerable().Where(a => a.CoinId == entity.Id).Select(a => a.GetId()).ToArray(); foreach (var id in toRemoves) { VirtualRoot.Execute(new RemovePoolCommand(id)); } toRemoves = context.CoinKernelSet.AsEnumerable().Where(a => a.CoinId == entity.Id).Select(a => a.GetId()).ToArray(); foreach (var id in toRemoves) { VirtualRoot.Execute(new RemoveCoinKernelCommand(id)); } toRemoves = NTMinerContext.Instance.MinerProfile.GetWallets().Where(a => a.CoinId == entity.Id).Select(a => a.GetId()).ToArray(); foreach (var id in toRemoves) { VirtualRoot.Execute(new RemoveWalletCommand(id)); } toRemoves = context.CoinGroupSet.AsEnumerable().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 = context.CreateServerRepository <CoinData>(); repository.Remove(entity.Id); VirtualRoot.RaiseEvent(new CoinRemovedEvent(message.MessageId, entity)); }, location: this.GetType()); }
public KernelSet(IServerContext context) { _context = context; context.AddCmdPath <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); var repository = context.CreateServerRepository <KernelData>(); repository.Add(entity); VirtualRoot.RaiseEvent(new KernelAddedEvent(message.MessageId, entity)); }, location: this.GetType()); context.AddCmdPath <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.TryGetValue(message.Input.GetId(), out KernelData entity)) { return; } if (ReferenceEquals(entity, message.Input)) { return; } entity.Update(message.Input); var repository = context.CreateServerRepository <KernelData>(); repository.Update(entity); VirtualRoot.RaiseEvent(new KernelUpdatedEvent(message.MessageId, entity)); }, location: this.GetType()); context.AddCmdPath <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 = context.CoinKernelSet.AsEnumerable().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); var repository = context.CreateServerRepository <KernelData>(); repository.Remove(entity.Id); VirtualRoot.RaiseEvent(new KernelRemovedEvent(message.MessageId, entity)); }, location: this.GetType()); }
public KernelOutputTranslaterSet(IServerContext context) { _context = context; context.AddCmdPath <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 = context.CreateServerRepository <KernelOutputTranslaterData>(); repository.Add(entity); VirtualRoot.RaiseEvent(new KernelOutputTranslaterAddedEvent(message.MessageId, entity)); }, location: this.GetType()); context.AddCmdPath <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.TryGetValue(message.Input.GetId(), out KernelOutputTranslaterData entity)) { return; } if (ReferenceEquals(entity, message.Input)) { return; } string regexPattern = entity.RegexPattern; entity.Update(message.Input); _dicByKernelOutputId[entity.KernelOutputId].Sort(new SortNumberComparer()); var repository = context.CreateServerRepository <KernelOutputTranslaterData>(); repository.Update(entity); VirtualRoot.RaiseEvent(new KernelOutputTranslaterUpdatedEvent(message.MessageId, entity)); }, location: this.GetType()); context.AddCmdPath <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); _dicByKernelOutputId[entity.KernelOutputId].Sort(new SortNumberComparer()); var repository = context.CreateServerRepository <KernelOutputTranslaterData>(); repository.Remove(entity.Id); VirtualRoot.RaiseEvent(new KernelOutputTranslaterRemovedEvent(message.MessageId, entity)); }, location: this.GetType()); }
public GroupSet(IServerContext context) { context.AddCmdPath <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>(); repository.Add(entity); VirtualRoot.RaiseEvent(new GroupAddedEvent(message.MessageId, entity)); }, location: this.GetType()); context.AddCmdPath <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>(); repository.Update(entity); VirtualRoot.RaiseEvent(new GroupUpdatedEvent(message.MessageId, entity)); }, location: this.GetType()); context.AddCmdPath <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 = context.CoinGroupSet.GetGroupCoinIds(entity.Id).ToArray(); foreach (var id in toRemoves) { VirtualRoot.Execute(new RemoveCoinGroupCommand(id)); } _dicById.Remove(entity.GetId()); var repository = NTMinerRoot.CreateServerRepository <GroupData>(); repository.Remove(message.EntityId); VirtualRoot.RaiseEvent(new GroupRemovedEvent(message.MessageId, entity)); }, location: this.GetType()); }
public PoolSet(IServerContext context) { _context = context; context.AddCmdPath <AddPoolCommand>(LogEnum.DevConsole, action: (message) => { InitOnece(); if (message == null || message.Input == null || message.Input.GetId() == Guid.Empty) { throw new ArgumentNullException(); } if (!context.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); var repository = context.CreateCompositeRepository <PoolData>(); repository.Add(entity); VirtualRoot.RaiseEvent(new PoolAddedEvent(message.MessageId, entity)); if (context.CoinSet.TryGetCoin(message.Input.CoinId, out ICoin coin)) { ICoinKernel[] coinKernels = context.CoinKernelSet.AsEnumerable().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)); } } }, location: this.GetType()); context.AddCmdPath <UpdatePoolCommand>(LogEnum.DevConsole, action: (message) => { InitOnece(); if (message == null || message.Input == null || message.Input.GetId() == Guid.Empty) { throw new ArgumentNullException(); } if (!context.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.TryGetValue(message.Input.GetId(), out PoolData entity)) { return; } if (ReferenceEquals(entity, message.Input)) { return; } entity.Update(message.Input); var repository = context.CreateCompositeRepository <PoolData>(); repository.Update(new PoolData().Update(message.Input)); VirtualRoot.RaiseEvent(new PoolUpdatedEvent(message.MessageId, entity)); }, location: this.GetType()); context.AddCmdPath <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()); var repository = context.CreateCompositeRepository <PoolData>(); repository.Remove(message.EntityId); VirtualRoot.RaiseEvent(new PoolRemovedEvent(message.MessageId, entity)); Guid[] toRemoves = context.PoolKernelSet.AsEnumerable().Where(a => a.PoolId == message.EntityId).Select(a => a.GetId()).ToArray(); foreach (Guid poolKernelId in toRemoves) { VirtualRoot.Execute(new RemovePoolKernelCommand(poolKernelId)); } }, location: this.GetType()); context.AddEventPath <PoolDelayPickedEvent>("提取了矿池延时后记录进内存", LogEnum.DevConsole, action: message => { if (message.IsDual) { if (_poolDelayById.TryGetValue(message.PoolId, out PoolDelay poolDelay)) { poolDelay.DualCoinPoolDelayText = message.PoolDelayText; } else { _poolDelayById.Add(message.PoolId, new PoolDelay { MainCoinPoolDelayText = string.Empty, DualCoinPoolDelayText = message.PoolDelayText }); } } else { if (_poolDelayById.TryGetValue(message.PoolId, out PoolDelay poolDelay)) { poolDelay.MainCoinPoolDelayText = message.PoolDelayText; } else { _poolDelayById.Add(message.PoolId, new PoolDelay { MainCoinPoolDelayText = message.PoolDelayText, DualCoinPoolDelayText = string.Empty }); } } }, location: this.GetType()); }
public PackageSet(IServerContext context) { _context = context; context.AddCmdPath <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); var repository = context.CreateServerRepository <PackageData>(); repository.Add(entity); VirtualRoot.RaiseEvent(new PackageAddedEvent(message.MessageId, entity)); }, location: this.GetType()); context.AddCmdPath <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.TryGetValue(message.Input.GetId(), out PackageData entity)) { return; } if (_dicById.Values.Any(a => a.Id != message.Input.Id && string.Equals(message.Input.Name, a.Name, StringComparison.OrdinalIgnoreCase))) { throw new ValidationException("包名重复"); } if (ReferenceEquals(entity, message.Input)) { return; } entity.Update(message.Input); var repository = context.CreateServerRepository <PackageData>(); repository.Update(entity); VirtualRoot.RaiseEvent(new PackageUpdatedEvent(message.MessageId, entity)); }, location: this.GetType()); context.AddCmdPath <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); var repository = context.CreateServerRepository <PackageData>(); repository.Remove(entity.Id); VirtualRoot.RaiseEvent(new PackageRemovedEvent(message.MessageId, entity)); }, location: this.GetType()); }
public SysDicItemSet(IServerContext context) { _context = context; _context.AddCmdPath <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 = context.CreateCompositeRepository <SysDicItemData>(); repository.Add(entity); VirtualRoot.RaiseEvent(new SysDicItemAddedEvent(message.MessageId, entity)); }, location: this.GetType()); _context.AddCmdPath <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.TryGetValue(message.Input.GetId(), out SysDicItemData entity)) { return; } 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 = context.CreateCompositeRepository <SysDicItemData>(); repository.Update(entity); VirtualRoot.RaiseEvent(new SysDicItemUpdatedEvent(message.MessageId, entity)); }, location: this.GetType()); _context.AddCmdPath <RemoveSysDicItemCommand>(LogEnum.DevConsole, action: (message) => { InitOnece(); if (message == null || message.EntityId == Guid.Empty) { throw new ArgumentNullException(); } if (!_dicById.TryGetValue(message.EntityId, out SysDicItemData entity) || !_context.SysDicSet.TryGetSysDic(entity.DicId, out ISysDic sysDic)) { return; } switch (sysDic.Code) { case NTKeyword.KernelBrandSysDicCode: if (NTMinerContext.Instance.ServerContext.KernelSet.AsEnumerable().Any(a => a.BrandId == message.EntityId)) { VirtualRoot.Out.ShowWarn("该内核品牌字典项关联有内核品牌不能删除,请先解除关联"); return; } break; case NTKeyword.PoolBrandSysDicCode: if (NTMinerContext.Instance.ServerContext.PoolSet.AsEnumerable().Any(a => a.BrandId == message.EntityId)) { VirtualRoot.Out.ShowWarn("该矿池品牌字典项关联有矿池品牌不能删除,请先解除关联"); return; } break; case NTKeyword.AlgoSysDicCode: if (NTMinerContext.Instance.ServerContext.PackageSet.AsEnumerable().Any(a => a.AlgoIds.Contains(message.EntityId))) { VirtualRoot.Out.ShowWarn("该算法字典项关联有内核不能删除,请先解除关联"); return; } break; default: break; } _dicById.Remove(entity.Id); if (_dicByDicId.TryGetValue(entity.DicId, out Dictionary <string, SysDicItemData> dicItemDic)) { dicItemDic.Remove(entity.Code); } var repository = context.CreateCompositeRepository <SysDicItemData>(); repository.Remove(entity.Id); VirtualRoot.RaiseEvent(new SysDicItemRemovedEvent(message.MessageId, entity)); }, location: this.GetType()); }
public CoinSet(IServerContext context) { _context = context; context.AddCmdPath <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 = context.CreateServerRepository <CoinData>(); repository.Add(entity); VirtualRoot.RaiseEvent(new CoinAddedEvent(message.MessageId, entity)); }, location: this.GetType()); context.AddCmdPath <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.TryGetValue(message.Input.GetId(), out CoinData entity)) { return; } if (ReferenceEquals(entity, message.Input)) { return; } bool isMinGpuMemoryGbChanged = entity.MinGpuMemoryGb != message.Input.MinGpuMemoryGb; entity.Update(message.Input); if (isMinGpuMemoryGbChanged && entity.Code == "ETH" && NTMinerContext.Instance.ServerContext.SysDicItemSet.TryGetDicItem(NTKeyword.ThisSystemSysDicCode, NTKeyword.OsVmPerGpuSysDicItemCode, out ISysDicItem dicItem)) { VirtualRoot.Execute(new UpdateSysDicItemCommand(new SysDicItemData { Code = dicItem.Code, Description = dicItem.Description, DicId = dicItem.DicId, Id = dicItem.GetId(), SortNumber = dicItem.SortNumber, Value = message.Input.MinGpuMemoryGb.ToString() })); } var repository = context.CreateServerRepository <CoinData>(); repository.Update(entity); VirtualRoot.RaiseEvent(new CoinUpdatedEvent(message.MessageId, message.Input)); }, location: this.GetType()); context.AddCmdPath <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 = context.PoolSet.AsEnumerable().Where(a => a.CoinId == entity.Id).Select(a => a.GetId()).ToArray(); foreach (var id in toRemoves) { VirtualRoot.Execute(new RemovePoolCommand(id)); } toRemoves = context.CoinKernelSet.AsEnumerable().Where(a => a.CoinId == entity.Id).Select(a => a.GetId()).ToArray(); foreach (var id in toRemoves) { VirtualRoot.Execute(new RemoveCoinKernelCommand(id)); } toRemoves = NTMinerContext.Instance.MinerProfile.GetWallets().Where(a => a.CoinId == entity.Id).Select(a => a.GetId()).ToArray(); foreach (var id in toRemoves) { VirtualRoot.Execute(new RemoveWalletCommand(id)); } toRemoves = context.CoinGroupSet.AsEnumerable().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 = context.CreateServerRepository <CoinData>(); repository.Remove(entity.Id); VirtualRoot.RaiseEvent(new CoinRemovedEvent(message.MessageId, entity)); }, location: this.GetType()); }