示例#1
0
        public PoolKernelSet(IServerContext context)
        {
            _context = context;
            _context.BuildCmdPath <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.Id, message.Input));
                }
            });
            _context.BuildCmdPath <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.Id, entity));
                }
            });
            _context.BuildCmdPath <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.Id, entity));
            });
        }
示例#2
0
        public CoinGroupSet(IServerContext context)
        {
            context.BuildCmdPath <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>();
                repository.Add(entity);

                VirtualRoot.RaiseEvent(new CoinGroupAddedEvent(message.Id, entity));
            });
            context.BuildCmdPath <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>();
                repository.Remove(message.EntityId);

                VirtualRoot.RaiseEvent(new CoinGroupRemovedEvent(message.Id, entity));
            });
        }
示例#3
0
        public FileWriterSet(IServerContext context)
        {
            context.BuildCmdPath <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.RaiseEvent(new FileWriterAddedEvent(message.Id, entity));
            });
            context.BuildCmdPath <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.RaiseEvent(new FileWriterUpdatedEvent(message.Id, entity));
            });
            context.BuildCmdPath <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.RaiseEvent(new FileWriterRemovedEvent(message.Id, entity));
            });
        }
示例#4
0
        public CoinKernelSet(IServerContext context)
        {
            context.BuildCmdPath <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 = NTMinerRoot.CreateServerRepository <CoinKernelData>();
                repository.Add(entity);

                VirtualRoot.RaiseEvent(new CoinKernelAddedEvent(message.Id, 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));
                    }
                }
            });
            context.BuildCmdPath <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.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.RaiseEvent(new CoinKernelUpdatedEvent(message.Id, entity));
            });
            context.BuildCmdPath <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.RaiseEvent(new CoinKernelRemovedEvent(message.Id, 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))
                        {
                            toRemoves.Add(poolKernel.Id);
                        }
                    }
                    foreach (Guid poolKernelId in toRemoves)
                    {
                        VirtualRoot.Execute(new RemovePoolKernelCommand(poolKernelId));
                    }
                }
            });
            context.BuildEventPath <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.RaiseEvent(new CoinKernelUpdatedEvent(message.Id, entity));
                }
            });
            context.BuildEventPath <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.RaiseEvent(new CoinKernelUpdatedEvent(message.Id, entity));
                }
            });
        }
        public KernelOutputTranslaterSet(IServerContext context)
        {
            context.BuildCmdPath <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>();
                repository.Add(entity);

                VirtualRoot.RaiseEvent(new KernelOutputTranslaterAddedEvent(message.Id, entity));
            });
            context.BuildCmdPath <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;
                entity.Update(message.Input);
                _dicByKernelOutputId[entity.KernelOutputId].Sort(new SortNumberComparer());
                var repository = NTMinerRoot.CreateServerRepository <KernelOutputTranslaterData>();
                repository.Update(entity);

                VirtualRoot.RaiseEvent(new KernelOutputTranslaterUpdatedEvent(message.Id, entity));
            });
            context.BuildCmdPath <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 = NTMinerRoot.CreateServerRepository <KernelOutputTranslaterData>();
                repository.Remove(entity.Id);

                VirtualRoot.RaiseEvent(new KernelOutputTranslaterRemovedEvent(message.Id, entity));
            });
        }
示例#6
0
        public SysDicSet(IServerContext context)
        {
            context.BuildCmdPath <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>();
                repository.Add(entity);

                VirtualRoot.RaiseEvent(new SysDicAddedEvent(message.Id, entity));
            });
            context.BuildCmdPath <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>();
                repository.Update(entity);

                VirtualRoot.RaiseEvent(new SysDicUpdatedEvent(message.Id, entity));
            });
            context.BuildCmdPath <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 = NTMinerRoot.CreateServerRepository <SysDicData>();
                repository.Remove(entity.Id);

                VirtualRoot.RaiseEvent(new SysDicRemovedEvent(message.Id, entity));
            });
        }
示例#7
0
        public KernelOutputSet(IServerContext context)
        {
            #region 接线
            context.BuildCmdPath <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>();
                repository.Add(entity);

                VirtualRoot.RaiseEvent(new KernelOutputAddedEvent(message.Id, entity));
            });
            context.BuildCmdPath <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.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>();
                repository.Update(entity);

                VirtualRoot.RaiseEvent(new KernelOutputUpdatedEvent(message.Id, entity));
            });
            context.BuildCmdPath <RemoveKernelOutputCommand>("移除内核输出组", LogEnum.DevConsole,
                                                             action: (message) => {
                InitOnece();
                if (message == null || message.EntityId == Guid.Empty)
                {
                    throw new ArgumentNullException();
                }
                if (!_dicById.ContainsKey(message.EntityId))
                {
                    return;
                }
                IKernel[] outputUsers = context.KernelSet.AsEnumerable().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> 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 = NTMinerRoot.CreateServerRepository <KernelOutputData>();
                repository.Remove(message.EntityId);

                VirtualRoot.RaiseEvent(new KernelOutputRemovedEvent(message.Id, entity));
            });
            #endregion
        }
示例#8
0
        public CoinSet(IServerContext context)
        {
            context.BuildCmdPath <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>();
                repository.Add(entity);

                VirtualRoot.RaiseEvent(new CoinAddedEvent(message.Id, entity));
            });
            context.BuildCmdPath <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>();
                repository.Update(entity);

                VirtualRoot.RaiseEvent(new CoinUpdatedEvent(message.Id, message.Input));
            });
            context.BuildCmdPath <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 = NTMinerRoot.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 = NTMinerRoot.CreateServerRepository <CoinData>();
                repository.Remove(entity.Id);

                VirtualRoot.RaiseEvent(new CoinRemovedEvent(message.Id, entity));
            });
        }
示例#9
0
        public KernelInputSet(IServerContext context)
        {
            context.BuildCmdPath <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));
            });
            context.BuildCmdPath <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));
            });
            context.BuildCmdPath <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));
            });
        }
示例#10
0
        public KernelSet(IServerContext context)
        {
            context.BuildCmdPath <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 = NTMinerRoot.CreateServerRepository <KernelData>();
                repository.Add(entity);

                VirtualRoot.RaiseEvent(new KernelAddedEvent(message.Id, entity));
            });
            context.BuildCmdPath <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);
                var repository = NTMinerRoot.CreateServerRepository <KernelData>();
                repository.Update(entity);

                VirtualRoot.RaiseEvent(new KernelUpdatedEvent(message.Id, entity));
            });
            context.BuildCmdPath <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 = NTMinerRoot.CreateServerRepository <KernelData>();
                repository.Remove(entity.Id);

                VirtualRoot.RaiseEvent(new KernelRemovedEvent(message.Id, entity));
            });
        }
示例#11
0
        public SysDicItemSet(IServerContext context)
        {
            _context = context;
            _context.BuildCmdPath <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>();
                repository.Add(entity);

                VirtualRoot.RaiseEvent(new SysDicItemAddedEvent(message.Id, entity));
            });
            _context.BuildCmdPath <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>();
                repository.Update(entity);

                VirtualRoot.RaiseEvent(new SysDicItemUpdatedEvent(message.Id, entity));
            });
            _context.BuildCmdPath <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>();
                repository.Remove(entity.Id);

                VirtualRoot.RaiseEvent(new SysDicItemRemovedEvent(message.Id, entity));
            });
        }
示例#12
0
        public PoolSet(IServerContext context)
        {
            context.BuildCmdPath <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);

                if (VirtualRoot.IsMinerStudio)
                {
                    Server.PoolService.AddOrUpdatePoolAsync(entity, callback: null);
                }
                else
                {
                    var repository = NTMinerRoot.CreateCompositeRepository <PoolData>();
                    repository.Add(entity);
                }

                VirtualRoot.RaiseEvent(new PoolAddedEvent(message.Id, 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));
                    }
                }
            });
            context.BuildCmdPath <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.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.PoolService.AddOrUpdatePoolAsync(entity, callback: null);
                }
                else
                {
                    var repository = NTMinerRoot.CreateCompositeRepository <PoolData>();
                    repository.Update(new PoolData().Update(message.Input));
                }

                VirtualRoot.RaiseEvent(new PoolUpdatedEvent(message.Id, entity));
            });
            context.BuildCmdPath <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.PoolService.RemovePoolAsync(entity.Id, callback: null);
                }
                else
                {
                    var repository = NTMinerRoot.CreateCompositeRepository <PoolData>();
                    repository.Remove(message.EntityId);
                }
                VirtualRoot.RaiseEvent(new PoolRemovedEvent(message.Id, 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));
                }
            });
            VirtualRoot.BuildEventPath <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
                        });
                    }
                }
            });
        }
示例#13
0
        public GroupSet(IServerContext context)
        {
            context.BuildCmdPath <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.Id, entity));
            });
            context.BuildCmdPath <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.Id, entity));
            });
            context.BuildCmdPath <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.Id, entity));
            });
        }
示例#14
0
        public PackageSet(IServerContext context)
        {
            context.BuildCmdPath <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 = NTMinerRoot.CreateServerRepository <PackageData>();
                repository.Add(entity);

                VirtualRoot.RaiseEvent(new PackageAddedEvent(message.Id, entity));
            });
            context.BuildCmdPath <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);
                var repository = NTMinerRoot.CreateServerRepository <PackageData>();
                repository.Update(entity);

                VirtualRoot.RaiseEvent(new PackageUpdatedEvent(message.Id, entity));
            });
            context.BuildCmdPath <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 = NTMinerRoot.CreateServerRepository <PackageData>();
                repository.Remove(entity.Id);

                VirtualRoot.RaiseEvent(new PackageRemovedEvent(message.Id, entity));
            });
        }