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 = context.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 = context.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.TryGetValue(message.Input.GetId(), out PoolKernelData entity)) { return; } if (ReferenceEquals(entity, message.Input)) { return; } entity.Update(message.Input); var repository = context.CreateServerRepository <PoolKernelData>(); repository.Update(entity); VirtualRoot.RaiseEvent(new PoolKernelUpdatedEvent(message.MessageId, entity)); }, location: this.GetType()); }
private void Init() { lock (_locker) { if (!_isInited) { var repository = _context.CreateServerRepository <KernelOutputTranslaterData>(); foreach (var item in repository.GetAll()) { if (!_dicById.ContainsKey(item.GetId())) { _dicById.Add(item.GetId(), item); } if (!_dicByKernelOutputId.ContainsKey(item.KernelOutputId)) { _dicByKernelOutputId.Add(item.KernelOutputId, new List <KernelOutputTranslaterData>()); } if (_dicByKernelOutputId[item.KernelOutputId].All(a => a.GetId() != item.GetId())) { _dicByKernelOutputId[item.KernelOutputId].Add(item); } } foreach (var item in _dicByKernelOutputId.Values) { item.Sort(new SortNumberComparer()); } _isInited = true; } } }
protected override void Init() { var repository = _context.CreateServerRepository <PoolKernelData>(); List <PoolKernelData> list = repository.GetAll().ToList(); foreach (IPool pool in _context.PoolSet.AsEnumerable().ToArray()) { foreach (ICoinKernel coinKernel in _context.CoinKernelSet.AsEnumerable().Where(a => a.CoinId == pool.CoinId).ToArray()) { PoolKernelData poolKernel = list.FirstOrDefault(a => a.PoolId == pool.GetId() && a.KernelId == coinKernel.KernelId); if (poolKernel != null) { _dicById.Add(poolKernel.GetId(), poolKernel); } else { Guid poolKernelId = Guid.NewGuid(); _dicById.Add(poolKernelId, new PoolKernelData() { Id = poolKernelId, Args = string.Empty, KernelId = coinKernel.KernelId, PoolId = pool.GetId() }); } } } }
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()); }
protected override void Init() { var repository = _context.CreateServerRepository <CoinKernelData>(); foreach (var item in repository.GetAll()) { if (!_dicById.ContainsKey(item.GetId())) { _dicById.Add(item.GetId(), item); } } }
// 填充空间 private void Init() { lock (_locker) { if (!_isInited) { var repository = _context.CreateServerRepository <KernelOutputData>(); foreach (var item in repository.GetAll()) { if (!_dicById.ContainsKey(item.GetId())) { _dicById.Add(item.GetId(), item); } } _isInited = true; } } }
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 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 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 KernelInputSet(IServerContext context) { _context = 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 = context.CreateServerRepository <KernelInputData>(); repository.Add(entity); VirtualRoot.RaiseEvent(new KernelInputAddedEvent(message.MessageId, 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.TryGetValue(message.Input.GetId(), out KernelInputData entity)) { return; } if (ReferenceEquals(entity, message.Input)) { return; } entity.Update(message.Input); var repository = context.CreateServerRepository <KernelInputData>(); repository.Update(entity); VirtualRoot.RaiseEvent(new KernelInputUpdatedEvent(message.MessageId, 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 = context.CreateServerRepository <KernelInputData>(); repository.Remove(message.EntityId); VirtualRoot.RaiseEvent(new KernelInputRemovedEvent(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 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 GroupSet(IServerContext context) { _context = 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 = context.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.TryGetValue(message.Input.GetId(), out GroupData entity)) { return; } if (ReferenceEquals(entity, message.Input)) { return; } entity.Update(message.Input); var repository = context.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 = context.CreateServerRepository <GroupData>(); repository.Remove(message.EntityId); VirtualRoot.RaiseEvent(new GroupRemovedEvent(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 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()); }