Пример #1
0
        public PoolKernelSet(INTMinerRoot root)
        {
            _root = root;
            _root.ServerContextCmdPath <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.Input));
                }
            });
            _root.ServerContextCmdPath <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(entity));
                }
            });
            _root.ServerContextCmdPath <UpdatePoolKernelCommand>("更新矿池内核", LogEnum.DevConsole,
                                                                 action: (message) => {
                InitOnece();
                if (message == null || message.Input == null || message.Input.GetId() == Guid.Empty)
                {
                    throw new ArgumentNullException();
                }
                if (!_root.PoolSet.Contains(message.Input.PoolId))
                {
                    throw new ValidationException("there is no pool with id" + message.Input.PoolId);
                }
                if (!_dicById.ContainsKey(message.Input.GetId()))
                {
                    return;
                }
                PoolKernelData entity = _dicById[message.Input.GetId()];
                if (ReferenceEquals(entity, message.Input))
                {
                    return;
                }
                entity.Update(message.Input);
                var repository = NTMinerRoot.CreateServerRepository <PoolKernelData>();
                repository.Update(entity);

                VirtualRoot.RaiseEvent(new PoolKernelUpdatedEvent(entity));
            });
        }
Пример #2
0
        public CoinGroupSet(INTMinerRoot root)
        {
            _root = root;
            _root.ServerContextCmdPath <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(entity));
            });
            _root.ServerContextCmdPath <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(entity));
            });
        }
Пример #3
0
        public PoolSet(INTMinerRoot root)
        {
            _root = root;
            _root.ServerContextCmdPath <AddPoolCommand>("添加矿池", LogEnum.DevConsole,
                                                        action: (message) => {
                InitOnece();
                if (message == null || message.Input == null || message.Input.GetId() == Guid.Empty)
                {
                    throw new ArgumentNullException();
                }
                if (!_root.CoinSet.Contains(message.Input.CoinId))
                {
                    throw new ValidationException("there is no coin with id " + message.Input.CoinId);
                }
                if (string.IsNullOrEmpty(message.Input.Server))
                {
                    throw new ValidationException("pool poolurl can't be null or empty");
                }
                if (_dicById.ContainsKey(message.Input.GetId()))
                {
                    return;
                }
                PoolData entity = new PoolData().Update(message.Input);
                _dicById.Add(entity.Id, entity);

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

                VirtualRoot.RaiseEvent(new PoolAddedEvent(entity));

                if (root.CoinSet.TryGetCoin(message.Input.CoinId, out ICoin coin))
                {
                    ICoinKernel[] coinKernels = root.CoinKernelSet.Where(a => a.CoinId == coin.GetId()).ToArray();
                    foreach (ICoinKernel coinKernel in coinKernels)
                    {
                        Guid poolKernelId = Guid.NewGuid();
                        var poolKernel    = new PoolKernelData()
                        {
                            Id       = poolKernelId,
                            Args     = string.Empty,
                            KernelId = coinKernel.KernelId,
                            PoolId   = message.Input.GetId()
                        };
                        VirtualRoot.Execute(new AddPoolKernelCommand(poolKernel));
                    }
                }
            });
            _root.ServerContextCmdPath <UpdatePoolCommand>("更新矿池", LogEnum.DevConsole,
                                                           action: (message) => {
                InitOnece();
                if (message == null || message.Input == null || message.Input.GetId() == Guid.Empty)
                {
                    throw new ArgumentNullException();
                }
                if (!_root.CoinSet.Contains(message.Input.CoinId))
                {
                    throw new ValidationException("there is no coin with id " + message.Input.CoinId);
                }
                if (string.IsNullOrEmpty(message.Input.Server))
                {
                    throw new ValidationException("pool poolurl can't be null or empty");
                }
                if (string.IsNullOrEmpty(message.Input.Name))
                {
                    throw new ValidationException("pool name can't be null or empty");
                }
                if (!_dicById.ContainsKey(message.Input.GetId()))
                {
                    return;
                }
                PoolData entity = _dicById[message.Input.GetId()];
                if (ReferenceEquals(entity, message.Input))
                {
                    return;
                }
                entity.Update(message.Input);
                if (VirtualRoot.IsMinerStudio)
                {
                    Server.PoolService.AddOrUpdatePoolAsync(entity, callback: null);
                }
                else
                {
                    var repository = NTMinerRoot.CreateCompositeRepository <PoolData>();
                    repository.Update(new PoolData().Update(message.Input));
                }

                VirtualRoot.RaiseEvent(new PoolUpdatedEvent(entity));
            });
            _root.ServerContextCmdPath <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(entity));
                Guid[] toRemoves = root.PoolKernelSet.Where(a => a.PoolId == message.EntityId).Select(a => a.GetId()).ToArray();
                foreach (Guid poolKernelId in toRemoves)
                {
                    VirtualRoot.Execute(new RemovePoolKernelCommand(poolKernelId));
                }
            });
            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
                        });
                    }
                }
            });
        }
Пример #4
0
        public PackageSet(INTMinerRoot root)
        {
            _root = root;
            _root.ServerContextCmdPath <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(entity));
            });
            _root.ServerContextCmdPath <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(entity));
            });
            _root.ServerContextCmdPath <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(entity));
            });
        }
Пример #5
0
        public KernelOutputTranslaterSet(INTMinerRoot root)
        {
            _root = root;
            _root.ServerContextCmdPath <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(entity));
            });
            _root.ServerContextCmdPath <UpdateKernelOutputTranslaterCommand>("更新内核输出翻译器", LogEnum.DevConsole,
                                                                             action: (message) => {
                InitOnece();
                if (message == null || message.Input == null || message.Input.GetId() == Guid.Empty)
                {
                    throw new ArgumentNullException();
                }
                if (string.IsNullOrEmpty(message.Input.RegexPattern))
                {
                    throw new ValidationException($"{nameof(message.Input.RegexPattern)} can't be null or empty");
                }
                if (!_dicById.ContainsKey(message.Input.GetId()))
                {
                    return;
                }
                KernelOutputTranslaterData entity = _dicById[message.Input.GetId()];
                if (ReferenceEquals(entity, message.Input))
                {
                    return;
                }
                string regexPattern = entity.RegexPattern;
                string color        = entity.Color;
                entity.Update(message.Input);
                if (entity.Color != color)
                {
                    _colorDic.Remove(entity);
                }
                _dicByKernelOutputId[entity.KernelOutputId].Sort(new SortNumberComparer());
                var repository = NTMinerRoot.CreateServerRepository <KernelOutputTranslaterData>();
                repository.Update(entity);

                VirtualRoot.RaiseEvent(new KernelOutputTranslaterUpdatedEvent(entity));
            });
            _root.ServerContextCmdPath <RemoveKernelOutputTranslaterCommand>("移除内核输出翻译器", LogEnum.DevConsole,
                                                                             action: (message) => {
                InitOnece();
                if (message == null || message.EntityId == Guid.Empty)
                {
                    throw new ArgumentNullException();
                }
                if (!_dicById.ContainsKey(message.EntityId))
                {
                    return;
                }
                KernelOutputTranslaterData entity = _dicById[message.EntityId];
                _dicById.Remove(entity.Id);
                _dicByKernelOutputId[entity.KernelOutputId].Remove(entity);
                _colorDic.Remove(entity);
                _dicByKernelOutputId[entity.KernelOutputId].Sort(new SortNumberComparer());
                var repository = NTMinerRoot.CreateServerRepository <KernelOutputTranslaterData>();
                repository.Remove(entity.Id);

                VirtualRoot.RaiseEvent(new KernelOutputTranslaterRemovedEvent(entity));
            });
            _root.ServerContextEventPath <SysDicItemUpdatedEvent>($"{VirtualRoot.LogColorSysDicCode}字典项更新后刷新翻译器内存", LogEnum.DevConsole,
                                                                  action: message => {
                if (!_root.SysDicSet.TryGetSysDic(VirtualRoot.LogColorSysDicCode, out ISysDic dic))
                {
                    return;
                }
                if (message.Source.DicId != dic.GetId())
                {
                    return;
                }
                foreach (var entity in _dicById.Values)
                {
                    if (entity.Color == message.Source.Code)
                    {
                        _colorDic.Remove(entity);
                    }
                }
            });
        }
Пример #6
0
        public KernelOutputSet(INTMinerRoot root)
        {
            _root = root;
            #region 接线
            _root.ServerContextCmdPath <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(entity));
            });
            _root.ServerContextCmdPath <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(entity));
            });
            _root.ServerContextCmdPath <RemoveKernelOutputCommand>("移除内核输出组", LogEnum.DevConsole,
                                                                   action: (message) => {
                InitOnece();
                if (message == null || message.EntityId == Guid.Empty)
                {
                    throw new ArgumentNullException();
                }
                if (!_dicById.ContainsKey(message.EntityId))
                {
                    return;
                }
                IKernel[] outputUsers = root.KernelSet.Where(a => a.KernelOutputId == message.EntityId).ToArray();
                if (outputUsers.Length != 0)
                {
                    throw new ValidationException($"这些内核在使用该内核输出组,删除前请先解除使用:{string.Join(",", outputUsers.Select(a => a.GetFullName()))}");
                }
                KernelOutputData entity = _dicById[message.EntityId];
                List <Guid> kernelOutputTranslaterIds = root.KernelOutputTranslaterSet.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(entity));
            });
            #endregion
        }
Пример #7
0
        public GroupSet(INTMinerRoot root)
        {
            _root = root;
            _root.ServerContextCmdPath <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(entity));
            });
            _root.ServerContextCmdPath <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(entity));
            });
            _root.ServerContextCmdPath <RemoveGroupCommand>("移除组", LogEnum.DevConsole,
                                                            action: (message) => {
                InitOnece();
                if (message == null || message.EntityId == Guid.Empty)
                {
                    throw new ArgumentNullException();
                }
                if (!_dicById.ContainsKey(message.EntityId))
                {
                    return;
                }
                GroupData entity = _dicById[message.EntityId];
                Guid[] toRemoves = root.CoinGroupSet.GetGroupCoinIds(entity.Id).ToArray();
                foreach (var id in toRemoves)
                {
                    VirtualRoot.Execute(new RemoveCoinGroupCommand(id));
                }
                _dicById.Remove(entity.GetId());
                var repository = NTMinerRoot.CreateServerRepository <GroupData>();
                repository.Remove(message.EntityId);

                VirtualRoot.RaiseEvent(new GroupRemovedEvent(entity));
            });
        }
Пример #8
0
        public FragmentWriterSet(INTMinerRoot root)
        {
            _root = root;
            _root.ServerContextCmdPath <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 = NTMinerRoot.CreateServerRepository <FragmentWriterData>();
                repository.Add(entity);

                VirtualRoot.RaiseEvent(new FragmentWriterAddedEvent(entity));
            });
            _root.ServerContextCmdPath <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.ContainsKey(message.Input.GetId()))
                {
                    return;
                }
                FragmentWriterData entity = _dicById[message.Input.GetId()];
                if (ReferenceEquals(entity, message.Input))
                {
                    return;
                }
                entity.Update(message.Input);
                var repository = NTMinerRoot.CreateServerRepository <FragmentWriterData>();
                repository.Update(entity);

                VirtualRoot.RaiseEvent(new FragmentWriterUpdatedEvent(entity));
            });
            _root.ServerContextCmdPath <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 = NTMinerRoot.CreateServerRepository <FragmentWriterData>();
                repository.Remove(message.EntityId);

                VirtualRoot.RaiseEvent(new FragmentWriterRemovedEvent(entity));
            });
        }
Пример #9
0
        public KernelOutputKeywordSet(INTMinerRoot root)
        {
            _root = root;
            _root.ServerContextCmdPath <AddKernelOutputKeywordCommand>("添加内核输出关键字", LogEnum.DevConsole,
                                                                       action: (message) => {
                InitOnece();
                if (message == null || message.Input == null || message.Input.GetId() == Guid.Empty)
                {
                    throw new ArgumentNullException();
                }
                if (_dicById.ContainsKey(message.Input.GetId()))
                {
                    return;
                }
                if (string.IsNullOrEmpty(message.Input.WorkerMessageType))
                {
                    throw new ValidationException("WorkerMessageType can't be null or empty");
                }
                if (string.IsNullOrEmpty(message.Input.Keyword))
                {
                    throw new ValidationException("Keyword can't be null or empty");
                }
                if (_dicById.Values.Any(a => a.Keyword == message.Input.Keyword && a.Id != message.Input.GetId()))
                {
                    throw new ValidationException($"关键字{message.Input.Keyword}已存在");
                }
                KernelOutputKeywordData entity = new KernelOutputKeywordData().Update(message.Input);
                _dicById.Add(entity.Id, entity);
                var repository = NTMinerRoot.CreateCompositeRepository <KernelOutputKeywordData>();
                repository.Add(entity);

                VirtualRoot.RaiseEvent(new KernelOutputKeywordAddedEvent(entity));
            });
            _root.ServerContextCmdPath <UpdateKernelOutputKeywordCommand>("更新内核输出关键字", LogEnum.DevConsole,
                                                                          action: (message) => {
                InitOnece();
                if (message == null || message.Input == null || message.Input.GetId() == Guid.Empty)
                {
                    throw new ArgumentNullException();
                }
                if (string.IsNullOrEmpty(message.Input.WorkerMessageType))
                {
                    throw new ValidationException("WorkerMessageType can't be null or empty");
                }
                if (string.IsNullOrEmpty(message.Input.Keyword))
                {
                    throw new ValidationException("Keyword can't be null or empty");
                }
                if (!_dicById.ContainsKey(message.Input.GetId()))
                {
                    return;
                }
                if (_dicById.Values.Any(a => a.Keyword == message.Input.Keyword && a.Id != message.Input.GetId()))
                {
                    throw new ValidationException($"关键字{message.Input.Keyword}已存在");
                }
                KernelOutputKeywordData entity = _dicById[message.Input.GetId()];
                if (ReferenceEquals(entity, message.Input))
                {
                    return;
                }
                entity.Update(message.Input);
                var repository = NTMinerRoot.CreateCompositeRepository <KernelOutputKeywordData>();
                repository.Update(entity);

                VirtualRoot.RaiseEvent(new KernelOutputKeywordUpdatedEvent(entity));
            });
            _root.ServerContextCmdPath <RemoveKernelOutputKeywordCommand>("移除内核输出关键字", LogEnum.DevConsole,
                                                                          action: (message) => {
                InitOnece();
                if (message == null || message.EntityId == Guid.Empty)
                {
                    throw new ArgumentNullException();
                }
                if (!_dicById.ContainsKey(message.EntityId))
                {
                    return;
                }
                KernelOutputKeywordData entity = _dicById[message.EntityId];
                _dicById.Remove(entity.GetId());
                var repository = NTMinerRoot.CreateCompositeRepository <KernelOutputKeywordData>();
                repository.Remove(message.EntityId);

                VirtualRoot.RaiseEvent(new KernelOutputKeywordRemovedEvent(entity));
            });
        }
Пример #10
0
        public SysDicItemSet(INTMinerRoot root)
        {
            _root = root;
            _root.ServerContextCmdPath <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(entity));
            });
            _root.ServerContextCmdPath <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(entity));
            });
            _root.ServerContextCmdPath <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(entity));
            });
        }
Пример #11
0
        public CoinKernelSet(INTMinerRoot root)
        {
            _root = root;
            _root.ServerContextCmdPath <AddCoinKernelCommand>("添加币种内核", LogEnum.DevConsole,
                                                              action: (message) => {
                InitOnece();
                if (message == null || message.Input == null || message.Input.GetId() == Guid.Empty)
                {
                    throw new ArgumentNullException();
                }
                if (!_root.CoinSet.Contains(message.Input.CoinId))
                {
                    throw new ValidationException("there is no coin with id" + message.Input.CoinId);
                }
                if (_dicById.ContainsKey(message.Input.GetId()))
                {
                    return;
                }
                if (_dicById.Values.Any(a => a.CoinId == message.Input.CoinId && a.KernelId == message.Input.KernelId))
                {
                    return;
                }
                CoinKernelData entity = new CoinKernelData().Update(message.Input);
                _dicById.Add(entity.Id, entity);
                var repository = NTMinerRoot.CreateServerRepository <CoinKernelData>();
                repository.Add(entity);

                VirtualRoot.RaiseEvent(new CoinKernelAddedEvent(entity));

                ICoin coin;
                if (root.CoinSet.TryGetCoin(message.Input.CoinId, out coin))
                {
                    IPool[] pools = root.PoolSet.Where(a => a.CoinId == coin.GetId()).ToArray();
                    foreach (IPool pool in pools)
                    {
                        Guid poolKernelId = Guid.NewGuid();
                        var poolKernel    = new PoolKernelData()
                        {
                            Id       = poolKernelId,
                            Args     = string.Empty,
                            KernelId = message.Input.KernelId,
                            PoolId   = pool.GetId()
                        };
                        VirtualRoot.Execute(new AddPoolKernelCommand(poolKernel));
                    }
                }
            });
            _root.ServerContextCmdPath <UpdateCoinKernelCommand>("更新币种内核", LogEnum.DevConsole,
                                                                 action: (message) => {
                InitOnece();
                if (message == null || message.Input == null || message.Input.GetId() == Guid.Empty)
                {
                    throw new ArgumentNullException();
                }
                if (!_root.CoinSet.Contains(message.Input.CoinId))
                {
                    throw new ValidationException("there is no coin with id" + message.Input.CoinId);
                }
                if (!_dicById.ContainsKey(message.Input.GetId()))
                {
                    return;
                }
                CoinKernelData entity = _dicById[message.Input.GetId()];
                if (ReferenceEquals(entity, message.Input))
                {
                    return;
                }
                entity.Update(message.Input);
                var repository = NTMinerRoot.CreateServerRepository <CoinKernelData>();
                repository.Update(entity);

                VirtualRoot.RaiseEvent(new CoinKernelUpdatedEvent(entity));
            });
            _root.ServerContextCmdPath <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(entity));
                ICoin coin;
                if (root.CoinSet.TryGetCoin(entity.CoinId, out coin))
                {
                    List <Guid> toRemoves = new List <Guid>();
                    IPool[] pools         = root.PoolSet.Where(a => a.CoinId == coin.GetId()).ToArray();
                    foreach (IPool pool in pools)
                    {
                        foreach (PoolKernelData poolKernel in root.PoolKernelSet.Where(a => a.PoolId == pool.GetId() && a.KernelId == entity.KernelId))
                        {
                            toRemoves.Add(poolKernel.Id);
                        }
                    }
                    foreach (Guid poolKernelId in toRemoves)
                    {
                        VirtualRoot.Execute(new RemovePoolKernelCommand(poolKernelId));
                    }
                }
            });
            _root.ServerContextEventPath <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(entity));
                }
            });
            _root.ServerContextEventPath <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(entity));
                }
            });
        }
Пример #12
0
        public KernelOutputFilterSet(INTMinerRoot root)
        {
            _root = root;
            _root.ServerContextCmdPath <AddKernelOutputFilterCommand>("添加内核输出过滤器", LogEnum.DevConsole,
                                                                      action: (message) => {
                InitOnece();
                if (message == null || message.Input == null || message.Input.GetId() == Guid.Empty)
                {
                    throw new ArgumentNullException();
                }
                if (string.IsNullOrEmpty(message.Input.RegexPattern))
                {
                    throw new ValidationException($"{nameof(message.Input.RegexPattern)} can't be null or empty");
                }
                if (_dicById.ContainsKey(message.Input.GetId()))
                {
                    return;
                }
                KernelOutputFilterData entity = new KernelOutputFilterData().Update(message.Input);
                _dicById.Add(entity.Id, entity);
                if (!_dicByKernelOutputId.ContainsKey(entity.KernelOutputId))
                {
                    _dicByKernelOutputId.Add(entity.KernelOutputId, new List <KernelOutputFilterData>());
                }
                _dicByKernelOutputId[entity.KernelOutputId].Add(entity);
                var repository = NTMinerRoot.CreateServerRepository <KernelOutputFilterData>();
                repository.Add(entity);

                VirtualRoot.RaiseEvent(new KernelOutputFilterAddedEvent(entity));
            });
            _root.ServerContextCmdPath <UpdateKernelOutputFilterCommand>("更新内核输出过滤器", LogEnum.DevConsole,
                                                                         action: (message) => {
                InitOnece();
                if (message == null || message.Input == null || message.Input.GetId() == Guid.Empty)
                {
                    throw new ArgumentNullException();
                }
                if (string.IsNullOrEmpty(message.Input.RegexPattern))
                {
                    throw new ValidationException($"{nameof(message.Input.RegexPattern)} can't be null or empty");
                }
                if (!_dicById.ContainsKey(message.Input.GetId()))
                {
                    return;
                }
                KernelOutputFilterData entity = _dicById[message.Input.GetId()];
                if (ReferenceEquals(entity, message.Input))
                {
                    return;
                }
                entity.Update(message.Input);
                var repository = NTMinerRoot.CreateServerRepository <KernelOutputFilterData>();
                repository.Update(entity);

                VirtualRoot.RaiseEvent(new KernelOutputFilterUpdatedEvent(entity));
            });
            _root.ServerContextCmdPath <RemoveKernelOutputFilterCommand>("移除内核输出过滤器", LogEnum.DevConsole,
                                                                         action: (message) => {
                InitOnece();
                if (message == null || message.EntityId == Guid.Empty)
                {
                    throw new ArgumentNullException();
                }
                if (!_dicById.ContainsKey(message.EntityId))
                {
                    return;
                }
                KernelOutputFilterData entity = _dicById[message.EntityId];
                _dicById.Remove(entity.Id);
                _dicByKernelOutputId[entity.KernelOutputId].Remove(entity);
                var repository = NTMinerRoot.CreateServerRepository <KernelOutputFilterData>();
                repository.Remove(entity.Id);

                VirtualRoot.RaiseEvent(new KernelOutputFilterRemovedEvent(entity));
            });
        }
Пример #13
0
        public KernelSet(INTMinerRoot root)
        {
            _root = root;
            _root.ServerContextCmdPath <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(entity));
            });
            _root.ServerContextCmdPath <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(entity));
            });
            _root.ServerContextCmdPath <RemoveKernelCommand>("移除内核", LogEnum.DevConsole,
                                                             action: message => {
                InitOnece();
                if (message == null || message.EntityId == Guid.Empty)
                {
                    throw new ArgumentNullException();
                }
                if (!_dicById.ContainsKey(message.EntityId))
                {
                    return;
                }
                KernelData entity         = _dicById[message.EntityId];
                List <Guid> coinKernelIds = root.CoinKernelSet.Where(a => a.KernelId == entity.Id).Select(a => a.GetId()).ToList();
                foreach (var coinKernelId in coinKernelIds)
                {
                    VirtualRoot.Execute(new RemoveCoinKernelCommand(coinKernelId));
                }
                _dicById.Remove(entity.Id);
                var repository = NTMinerRoot.CreateServerRepository <KernelData>();
                repository.Remove(entity.Id);

                VirtualRoot.RaiseEvent(new KernelRemovedEvent(entity));
            });
        }
Пример #14
0
        public CoinSet(INTMinerRoot root)
        {
            _root = root;
            _root.ServerContextCmdPath <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(entity));
            });
            _root.ServerContextCmdPath <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.Input));
            });
            _root.ServerContextCmdPath <RemoveCoinCommand>("移除币种", LogEnum.DevConsole,
                                                           action: message => {
                InitOnece();
                if (message == null || message.EntityId == Guid.Empty)
                {
                    throw new ArgumentNullException();
                }
                if (!_dicById.ContainsKey(message.EntityId))
                {
                    return;
                }
                CoinData entity  = _dicById[message.EntityId];
                Guid[] toRemoves = root.PoolSet.Where(a => a.CoinId == entity.Id).Select(a => a.GetId()).ToArray();
                foreach (var id in toRemoves)
                {
                    VirtualRoot.Execute(new RemovePoolCommand(id));
                }
                toRemoves = root.CoinKernelSet.Where(a => a.CoinId == entity.Id).Select(a => a.GetId()).ToArray();
                foreach (var id in toRemoves)
                {
                    VirtualRoot.Execute(new RemoveCoinKernelCommand(id));
                }
                toRemoves = root.MinerProfile.GetWallets().Where(a => a.CoinId == entity.Id).Select(a => a.GetId()).ToArray();
                foreach (var id in toRemoves)
                {
                    VirtualRoot.Execute(new RemoveWalletCommand(id));
                }
                toRemoves = root.CoinGroupSet.Where(a => a.CoinId == entity.Id).Select(a => a.GetId()).ToArray();
                foreach (var id in toRemoves)
                {
                    VirtualRoot.Execute(new RemoveCoinGroupCommand(id));
                }
                _dicById.Remove(entity.Id);
                if (_dicByCode.ContainsKey(entity.Code))
                {
                    _dicByCode.Remove(entity.Code);
                }
                var repository = NTMinerRoot.CreateServerRepository <CoinData>();
                repository.Remove(entity.Id);

                VirtualRoot.RaiseEvent(new CoinRemovedEvent(entity));
            });
        }
Пример #15
0
        public SysDicSet(INTMinerRoot root)
        {
            _root = root;
            _root.ServerContextCmdPath <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(entity));
            });
            _root.ServerContextCmdPath <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(entity));
            });
            _root.ServerContextCmdPath <RemoveSysDicCommand>("移除系统字典", LogEnum.DevConsole,
                                                             action: message => {
                InitOnece();
                if (message == null || message.EntityId == Guid.Empty)
                {
                    throw new ArgumentNullException();
                }
                if (!_dicById.ContainsKey(message.EntityId))
                {
                    return;
                }
                SysDicData entity     = _dicById[message.EntityId];
                List <Guid> toRemoves = root.SysDicItemSet.GetSysDicItems(entity.Code).Select(a => a.GetId()).ToList();
                foreach (var id in toRemoves)
                {
                    VirtualRoot.Execute(new RemoveSysDicItemCommand(id));
                }
                _dicById.Remove(entity.Id);
                if (_dicByCode.ContainsKey(entity.Code))
                {
                    _dicByCode.Remove(entity.Code);
                }
                var repository = NTMinerRoot.CreateServerRepository <SysDicData>();
                repository.Remove(entity.Id);

                VirtualRoot.RaiseEvent(new SysDicRemovedEvent(entity));
            });
        }