Esempio n. 1
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 + "接入总线");
        }
Esempio n. 2
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
                        });
                    }
                }
            });
        }
Esempio n. 3
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 = 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 = 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 = 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));
                }
            });
        }