Beispiel #1
0
 private void Init()
 {
     lock (_locker) {
         if (!_isInited)
         {
             var repository = NTMinerRoot.CreateCompositeRepository <SysDicItemData>(_isUseJson);
             foreach (var item in repository.GetAll())
             {
                 if (!_dicById.ContainsKey(item.GetId()))
                 {
                     _dicById.Add(item.GetId(), item);
                 }
                 if (!_dicByDicId.ContainsKey(item.DicId))
                 {
                     _dicByDicId.Add(item.DicId, new Dictionary <string, SysDicItemData>(StringComparer.OrdinalIgnoreCase));
                 }
                 if (!_dicByDicId[item.DicId].ContainsKey(item.Code))
                 {
                     _dicByDicId[item.DicId].Add(item.Code, item);
                 }
             }
             _isInited = true;
         }
     }
 }
Beispiel #2
0
 private void Init()
 {
     lock (_locker) {
         if (!_isInited)
         {
             var             repository = NTMinerRoot.CreateCompositeRepository <PoolData>();
             List <PoolData> data       = repository.GetAll().ToList();
             if (VirtualRoot.IsMinerStudio)
             {
                 foreach (var item in Server.PoolService.GetPools())
                 {
                     data.Add(item);
                 }
             }
             foreach (var item in data)
             {
                 if (!_dicById.ContainsKey(item.GetId()))
                 {
                     _dicById.Add(item.GetId(), item);
                 }
             }
             _isInited = true;
         }
     }
 }
Beispiel #3
0
 private void Init()
 {
     lock (_locker) {
         if (!_isInited)
         {
             var repository = NTMinerRoot.CreateCompositeRepository <PoolData>();
             foreach (var item in repository.GetAll())
             {
                 if (!_dicById.ContainsKey(item.GetId()))
                 {
                     _dicById.Add(item.GetId(), item);
                 }
             }
             _isInited = true;
         }
     }
 }
Beispiel #4
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
                        });
                    }
                }
            });
        }
Beispiel #5
0
        public SysDicItemSet(INTMinerRoot root, bool isUseJson)
        {
            _root      = root;
            _isUseJson = isUseJson;
            _root.ServerContextWindow <AddSysDicItemCommand>("添加系统字典项", LogEnum.DevConsole,
                                                             action: (message) => {
                InitOnece();
                if (message == null || message.Input == null || message.Input.GetId() == Guid.Empty)
                {
                    throw new ArgumentNullException();
                }
                if (string.IsNullOrEmpty(message.Input.Code))
                {
                    throw new ValidationException("dicitem code can't be null or empty");
                }
                if (_dicById.ContainsKey(message.Input.GetId()))
                {
                    return;
                }
                if (!_dicByDicId.ContainsKey(message.Input.DicId))
                {
                    _dicByDicId.Add(message.Input.DicId, new Dictionary <string, SysDicItemData>(StringComparer.OrdinalIgnoreCase));
                }
                if (_dicByDicId[message.Input.DicId].ContainsKey(message.Input.Code))
                {
                    throw new ValidationException("编码重复");
                }
                SysDicItemData entity = new SysDicItemData().Update(message.Input);
                _dicById.Add(entity.Id, entity);
                _dicByDicId[message.Input.DicId].Add(entity.Code, entity);
                var repository = NTMinerRoot.CreateCompositeRepository <SysDicItemData>(isUseJson);
                repository.Add(entity);

                VirtualRoot.Happened(new SysDicItemAddedEvent(entity));
            });
            _root.ServerContextWindow <UpdateSysDicItemCommand>("更新系统字典项", LogEnum.DevConsole,
                                                                action: (message) => {
                InitOnece();
                if (message == null || message.Input == null || message.Input.GetId() == Guid.Empty)
                {
                    throw new ArgumentNullException();
                }
                if (string.IsNullOrEmpty(message.Input.Code))
                {
                    throw new ValidationException("sysDicItem code can't be null or empty");
                }
                if (!_dicById.ContainsKey(message.Input.GetId()))
                {
                    return;
                }
                SysDicItemData entity = _dicById[message.Input.GetId()];
                if (ReferenceEquals(entity, message.Input))
                {
                    return;
                }
                string oldCode = entity.Code;
                entity.Update(message.Input);
                // 如果编码变更了
                if (oldCode != entity.Code)
                {
                    _dicByDicId[entity.DicId].Remove(oldCode);
                    _dicByDicId[entity.DicId].Add(entity.Code, entity);
                }
                var repository = NTMinerRoot.CreateCompositeRepository <SysDicItemData>(isUseJson);
                repository.Update(entity);

                VirtualRoot.Happened(new SysDicItemUpdatedEvent(entity));
            });
            _root.ServerContextWindow <RemoveSysDicItemCommand>("移除系统字典项", LogEnum.DevConsole,
                                                                action: (message) => {
                InitOnece();
                if (message == null || message.EntityId == Guid.Empty)
                {
                    throw new ArgumentNullException();
                }
                if (!_dicById.ContainsKey(message.EntityId))
                {
                    return;
                }
                SysDicItemData entity = _dicById[message.EntityId];
                _dicById.Remove(entity.Id);
                if (_dicByDicId.ContainsKey(entity.DicId))
                {
                    if (_dicByDicId[entity.DicId].ContainsKey(entity.Code))
                    {
                        _dicByDicId[entity.DicId].Remove(entity.Code);
                    }
                }
                var repository = NTMinerRoot.CreateCompositeRepository <SysDicItemData>(isUseJson);
                repository.Remove(entity.Id);

                VirtualRoot.Happened(new SysDicItemRemovedEvent(entity));
            });
        }
Beispiel #6
0
        public PoolSet(INTMinerRoot root)
        {
            _root = root;
            Global.Access <AddPoolCommand>(
                Guid.Parse("5ee1b14b-4b9e-445f-b6fe-433f6fe44b18"),
                "添加矿池",
                LogEnum.Log,
                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);
                var repository = NTMinerRoot.CreateCompositeRepository <PoolData>();
                repository.Add(entity);

                Global.Happened(new PoolAddedEvent(entity));
            });
            Global.Access <UpdatePoolCommand>(
                Guid.Parse("62d847f6-2b1f-4891-990b-3beb4c1dc5b0"),
                "更新矿池",
                LogEnum.Log,
                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;
                }
                // 组合GlobalDb和ProfileDb,Profile用户无权修改GlobalDb中的数据,否则抛出异常终端流程从而确保GlobalDb中的数据不会被后续的流程修改
                var repository = NTMinerRoot.CreateCompositeRepository <PoolData>();
                repository.Update(new PoolData().Update(message.Input));
                PoolData entity = _dicById[message.Input.GetId()];
                entity.Update(message.Input);

                Global.Happened(new PoolUpdatedEvent(entity));
            });
            Global.Access <RemovePoolCommand>(
                Guid.Parse("c5ce3c6c-78c4-4e76-81e3-2feeac5d5ced"),
                "移除矿池",
                LogEnum.Log,
                action: (message) => {
                InitOnece();
                if (message == null || message.EntityId == Guid.Empty)
                {
                    throw new ArgumentNullException();
                }
                if (!_dicById.ContainsKey(message.EntityId))
                {
                    return;
                }
                // 组合GlobalDb和ProfileDb,Profile用户无权删除GlobalDb中的数据,否则抛出异常终端流程从而确保GlobalDb中的数据不会被后续的流程修改
                var repository = NTMinerRoot.CreateCompositeRepository <PoolData>();
                repository.Remove(message.EntityId);
                PoolData entity = _dicById[message.EntityId];
                _dicById.Remove(entity.GetId());

                Global.Happened(new PoolRemovedEvent(entity));
            });
            Global.Logger.InfoDebugLine(this.GetType().FullName + "接入总线");
        }
        public KernelOutputKeywordSet(INTMinerRoot root, bool isUseJson)
        {
            _root      = root;
            _isUseJson = isUseJson;
            _root.ServerContextWindow <AddKernelOutputKeywordCommand>("添加内核输出关键字", LogEnum.DevConsole,
                                                                      action: (message) => {
                InitOnece();
                if (message == null || message.Input == null || message.Input.GetId() == Guid.Empty)
                {
                    throw new ArgumentNullException();
                }
                if (_dicById.ContainsKey(message.Input.GetId()))
                {
                    return;
                }
                if (string.IsNullOrEmpty(message.Input.Keyword))
                {
                    throw new ValidationException("EventType name can't be null or empty");
                }
                if (_dicById.Values.Any(a => a.Keyword == message.Input.Keyword && a.Id != message.Input.GetId()))
                {
                    throw new ValidationException($"关键字{message.Input.Keyword}已存在");
                }
                KernelOutputKeywordData entity = new KernelOutputKeywordData().Update(message.Input);
                _dicById.Add(entity.Id, entity);
                var repository = NTMinerRoot.CreateCompositeRepository <KernelOutputKeywordData>(isUseJson);
                repository.Add(entity);

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

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

                VirtualRoot.Happened(new KernelOutputKeywordRemovedEvent(entity));
            });
        }
Beispiel #8
0
        public PoolSet(INTMinerRoot root, bool isUseJson)
        {
            _root      = root;
            _isUseJson = isUseJson;
            _root.ServerContextWindow <AddPoolCommand>("添加矿池", LogEnum.DevConsole,
                                                       action: (message) => {
                InitOnece();
                if (message == null || message.Input == null || message.Input.GetId() == Guid.Empty)
                {
                    throw new ArgumentNullException();
                }
                if (!_root.CoinSet.Contains(message.Input.CoinId))
                {
                    throw new ValidationException("there is no coin with id " + message.Input.CoinId);
                }
                if (string.IsNullOrEmpty(message.Input.Server))
                {
                    throw new ValidationException("pool poolurl can't be null or empty");
                }
                if (_dicById.ContainsKey(message.Input.GetId()))
                {
                    return;
                }
                PoolData entity = new PoolData().Update(message.Input);
                _dicById.Add(entity.Id, entity);

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

                VirtualRoot.Happened(new PoolAddedEvent(entity));

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

                VirtualRoot.Happened(new PoolUpdatedEvent(entity));
            });
            _root.ServerContextWindow <RemovePoolCommand>("移除矿池", LogEnum.DevConsole,
                                                          action: (message) => {
                InitOnece();
                if (message == null || message.EntityId == Guid.Empty)
                {
                    throw new ArgumentNullException();
                }
                if (!_dicById.ContainsKey(message.EntityId))
                {
                    return;
                }

                PoolData entity = _dicById[message.EntityId];
                _dicById.Remove(entity.GetId());
                if (VirtualRoot.IsMinerStudio)
                {
                    Server.ControlCenterService.RemovePoolAsync(entity.Id, callback: null);
                }
                else
                {
                    var repository = NTMinerRoot.CreateCompositeRepository <PoolData>(isUseJson);
                    repository.Remove(message.EntityId);
                }
                VirtualRoot.Happened(new PoolRemovedEvent(entity));
                Guid[] toRemoves = root.PoolKernelSet.Where(a => a.PoolId == message.EntityId).Select(a => a.GetId()).ToArray();
                foreach (Guid poolKernelId in toRemoves)
                {
                    VirtualRoot.Execute(new RemovePoolKernelCommand(poolKernelId));
                }
            });
        }
        public WorkerEventTypeSet(INTMinerRoot root, bool isUseJson)
        {
            _root      = root;
            _isUseJson = isUseJson;
            _root.ServerContextWindow <AddWorkerEventTypeCommand>("添加事件类型", LogEnum.DevConsole,
                                                                  action: (message) => {
                InitOnece();
                if (message == null || message.Input == null || message.Input.GetId() == Guid.Empty)
                {
                    throw new ArgumentNullException();
                }
                if (_dicById.ContainsKey(message.Input.GetId()))
                {
                    return;
                }
                if (string.IsNullOrEmpty(message.Input.Name))
                {
                    throw new ValidationException("EventType name can't be null or empty");
                }
                WorkerEventTypeData entity = new WorkerEventTypeData().Update(message.Input);
                _dicById.Add(entity.Id, entity);
                var repository = NTMinerRoot.CreateCompositeRepository <WorkerEventTypeData>(isUseJson);
                repository.Add(entity);

                VirtualRoot.Happened(new WorkerEventTypeAddedEvent((IWorkerEventType)entity));
            });
            _root.ServerContextWindow <UpdateWorkerEventTypeCommand>("更新事件类型", LogEnum.DevConsole,
                                                                     action: (message) => {
                InitOnece();
                if (message == null || message.Input == null || message.Input.GetId() == Guid.Empty)
                {
                    throw new ArgumentNullException();
                }
                if (string.IsNullOrEmpty(message.Input.Name))
                {
                    throw new ValidationException("EventType name can't be null or empty");
                }
                if (!_dicById.ContainsKey(message.Input.GetId()))
                {
                    return;
                }
                WorkerEventTypeData entity = _dicById[message.Input.GetId()];
                if (ReferenceEquals(entity, message.Input))
                {
                    return;
                }
                entity.Update(message.Input);
                var repository = NTMinerRoot.CreateCompositeRepository <WorkerEventTypeData>(isUseJson);
                repository.Update(entity);

                VirtualRoot.Happened(new WorkerEventTypeUpdatedEvent((IWorkerEventType)entity));
            });
            _root.ServerContextWindow <RemoveWorkerEventTypeCommand>("移除事件类型", LogEnum.DevConsole,
                                                                     action: (message) => {
                InitOnece();
                if (message == null || message.EntityId == Guid.Empty)
                {
                    throw new ArgumentNullException();
                }
                if (!_dicById.ContainsKey(message.EntityId))
                {
                    return;
                }
                WorkerEventTypeData entity = _dicById[message.EntityId];
                _dicById.Remove(entity.GetId());
                var repository = NTMinerRoot.CreateCompositeRepository <WorkerEventTypeData>(isUseJson);
                repository.Remove(message.EntityId);

                VirtualRoot.Happened(new WorkerEventTypeRemovedEvent((IWorkerEventType)entity));
            });
        }