Exemplo n.º 1
0
        public PoolKernelSet(INTMinerRoot root, bool isUseJson)
        {
            _root      = root;
            _isUseJson = isUseJson;
            VirtualRoot.Window <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>(isUseJson);
                    repository.Add(entity);
                    VirtualRoot.Happened(new PoolKernelAddedEvent(message.Input));
                }
            }).AddToCollection(root.ContextHandlers);
            VirtualRoot.Window <RemovePoolKernelCommand>("处理移除矿池级内核命令", LogEnum.DevConsole,
                                                         action: message => {
                if (_dicById.ContainsKey(message.EntityId))
                {
                    var entity = _dicById[message.EntityId];
                    _dicById.Remove(message.EntityId);
                    var repository = NTMinerRoot.CreateServerRepository <PoolKernelData>(isUseJson);
                    repository.Remove(message.EntityId);
                    VirtualRoot.Happened(new PoolKernelRemovedEvent(entity));
                }
            }).AddToCollection(root.ContextHandlers);
            VirtualRoot.Window <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>(isUseJson);
                repository.Update(entity);

                VirtualRoot.Happened(new PoolKernelUpdatedEvent(entity));
            }).AddToCollection(root.ContextHandlers);
        }
Exemplo n.º 2
0
        public PoolKernelSet(IServerContext context)
        {
            _context = context;
            _context.AddCmdPath <AddPoolKernelCommand>("处理添加矿池级内核命令", LogEnum.DevConsole,
                                                       action: message => {
                if (!_dicById.ContainsKey(message.Input.GetId()))
                {
                    var entity = new PoolKernelData().Update(message.Input);
                    _dicById.Add(message.Input.GetId(), entity);
                    var repository = NTMinerRoot.CreateServerRepository <PoolKernelData>();
                    repository.Add(entity);
                    VirtualRoot.RaiseEvent(new PoolKernelAddedEvent(message.MessageId, message.Input));
                }
            }, location: this.GetType());
            _context.AddCmdPath <RemovePoolKernelCommand>("处理移除矿池级内核命令", LogEnum.DevConsole,
                                                          action: message => {
                if (_dicById.ContainsKey(message.EntityId))
                {
                    var entity = _dicById[message.EntityId];
                    _dicById.Remove(message.EntityId);
                    var repository = NTMinerRoot.CreateServerRepository <PoolKernelData>();
                    repository.Remove(message.EntityId);
                    VirtualRoot.RaiseEvent(new PoolKernelRemovedEvent(message.MessageId, entity));
                }
            }, location: this.GetType());
            _context.AddCmdPath <UpdatePoolKernelCommand>("更新矿池内核", LogEnum.DevConsole,
                                                          action: (message) => {
                InitOnece();
                if (message == null || message.Input == null || message.Input.GetId() == Guid.Empty)
                {
                    throw new ArgumentNullException();
                }
                if (!_context.PoolSet.Contains(message.Input.PoolId))
                {
                    throw new ValidationException("there is no pool with id" + message.Input.PoolId);
                }
                if (!_dicById.ContainsKey(message.Input.GetId()))
                {
                    return;
                }
                PoolKernelData entity = _dicById[message.Input.GetId()];
                if (ReferenceEquals(entity, message.Input))
                {
                    return;
                }
                entity.Update(message.Input);
                var repository = NTMinerRoot.CreateServerRepository <PoolKernelData>();
                repository.Update(entity);

                VirtualRoot.RaiseEvent(new PoolKernelUpdatedEvent(message.MessageId, entity));
            }, location: this.GetType());
        }
Exemplo n.º 3
0
        public PoolKernelSet(INTMinerRoot root)
        {
            _root = root;
            Global.Access <CoinKernelAddedEvent>(
                Guid.Parse("F39019DF-21F7-40EF-9233-4F7E8291FF39"),
                "新添了币种内核后刷新矿池内核内存",
                LogEnum.Log,
                action: (message) => {
                ICoin coin;
                if (root.CoinSet.TryGetCoin(message.Source.CoinId, out coin))
                {
                    IPool[] pools = root.PoolSet.Where(a => a.CoinId == coin.GetId()).ToArray();
                    foreach (IPool pool in pools)
                    {
                        Guid poolKernelId = Guid.NewGuid();
                        var entity        = new PoolKernelData()
                        {
                            Id          = poolKernelId,
                            Args        = string.Empty,
                            Description = string.Empty,
                            KernelId    = message.Source.KernelId,
                            PoolId      = pool.GetId()
                        };
                        _dicById.Add(poolKernelId, entity);
                        Global.Happened(new PoolKernelAddedEvent(entity));
                    }
                }
            });
            Global.Access <CoinKernelRemovedEvent>(
                Guid.Parse("3FD6D2B4-4C8F-4C81-8E15-2FBA4E730AF7"),
                "移除了币种内核后刷新矿池内核内存",
                LogEnum.Log,
                action: (message) => {
                ICoin coin;
                if (root.CoinSet.TryGetCoin(message.Source.CoinId, out coin))
                {
                    var repository        = NTMinerRoot.CreateServerRepository <PoolKernelData>();
                    List <Guid> toRemoves = new List <Guid>();
                    IPool[] pools         = root.PoolSet.Where(a => a.CoinId == coin.GetId()).ToArray();
                    foreach (IPool pool in pools)
                    {
                        foreach (PoolKernelData poolKernelVm in _dicById.Values.Where(a => a.PoolId == pool.GetId() && a.KernelId == message.Source.KernelId))
                        {
                            toRemoves.Add(poolKernelVm.Id);
                        }
                    }
                    foreach (Guid poolKernelId in toRemoves)
                    {
                        var entity = _dicById[poolKernelId];
                        _dicById.Remove(poolKernelId);
                        repository.Remove(entity.Id);
                        Global.Happened(new PoolKernelRemovedEvent(entity));
                    }
                }
            });
            Global.Access <PoolAddedEvent>(
                Guid.Parse("CDDC4FD4-DC93-4CD3-B814-5A3A99228AB0"),
                "新添了矿池后刷新矿池内核内存",
                LogEnum.Log,
                action: (message) => {
                ICoin coin;
                if (root.CoinSet.TryGetCoin(message.Source.CoinId, out coin))
                {
                    ICoinKernel[] coinKernels = root.CoinKernelSet.Where(a => a.CoinId == coin.GetId()).ToArray();
                    foreach (ICoinKernel coinKernel in coinKernels)
                    {
                        Guid poolKernelId = Guid.NewGuid();
                        var entity        = new PoolKernelData()
                        {
                            Id          = poolKernelId,
                            Args        = string.Empty,
                            Description = string.Empty,
                            KernelId    = coinKernel.KernelId,
                            PoolId      = message.Source.GetId()
                        };
                        _dicById.Add(poolKernelId, entity);
                        Global.Happened(new PoolKernelAddedEvent(entity));
                    }
                }
            });
            Global.Access <PoolRemovedEvent>(
                Guid.Parse("F4B99EAE-2532-4DAC-8D49-2D6A51530722"),
                "移除了矿池后刷新矿池内核内存",
                LogEnum.Log,
                action: (message) => {
                var repository   = NTMinerRoot.CreateServerRepository <PoolKernelData>();
                Guid[] toRemoves = _dicById.Values.Where(a => a.PoolId == message.Source.GetId()).Select(a => a.Id).ToArray();
                foreach (Guid poolKernelId in toRemoves)
                {
                    var entity = _dicById[poolKernelId];
                    _dicById.Remove(poolKernelId);
                    repository.Remove(entity.Id);
                    Global.Happened(new PoolKernelRemovedEvent(entity));
                }
            });
            Global.Access <UpdatePoolKernelCommand>(
                Guid.Parse("08843B3B-3F82-45D2-8B45-6B24F397A326"),
                "更新矿池内核",
                LogEnum.Log,
                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()];
                entity.Update(message.Input);
                var repository = NTMinerRoot.CreateServerRepository <PoolKernelData>();
                repository.Update(entity);

                Global.Happened(new PoolKernelUpdatedEvent(entity));
            });
            Global.Logger.InfoDebugLine(this.GetType().FullName + "接入总线");
        }