Пример #1
0
        public CoinSet(IServerContext context)
        {
            _context = context;
            context.AddCmdPath <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 = context.CreateServerRepository <CoinData>();
                repository.Add(entity);

                VirtualRoot.RaiseEvent(new CoinAddedEvent(message.MessageId, entity));
            }, location: this.GetType());
            context.AddCmdPath <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.TryGetValue(message.Input.GetId(), out CoinData entity))
                {
                    return;
                }
                if (ReferenceEquals(entity, message.Input))
                {
                    return;
                }
                entity.Update(message.Input);
                var repository = context.CreateServerRepository <CoinData>();
                repository.Update(entity);

                VirtualRoot.RaiseEvent(new CoinUpdatedEvent(message.MessageId, message.Input));
            }, location: this.GetType());
            context.AddCmdPath <RemoveCoinCommand>("移除币种", LogEnum.DevConsole,
                                                   action: message => {
                InitOnece();
                if (message == null || message.EntityId == Guid.Empty)
                {
                    throw new ArgumentNullException();
                }
                if (!_dicById.ContainsKey(message.EntityId))
                {
                    return;
                }
                CoinData entity  = _dicById[message.EntityId];
                Guid[] toRemoves = context.PoolSet.AsEnumerable().Where(a => a.CoinId == entity.Id).Select(a => a.GetId()).ToArray();
                foreach (var id in toRemoves)
                {
                    VirtualRoot.Execute(new RemovePoolCommand(id));
                }
                toRemoves = context.CoinKernelSet.AsEnumerable().Where(a => a.CoinId == entity.Id).Select(a => a.GetId()).ToArray();
                foreach (var id in toRemoves)
                {
                    VirtualRoot.Execute(new RemoveCoinKernelCommand(id));
                }
                toRemoves = NTMinerContext.Instance.MinerProfile.GetWallets().Where(a => a.CoinId == entity.Id).Select(a => a.GetId()).ToArray();
                foreach (var id in toRemoves)
                {
                    VirtualRoot.Execute(new RemoveWalletCommand(id));
                }
                toRemoves = context.CoinGroupSet.AsEnumerable().Where(a => a.CoinId == entity.Id).Select(a => a.GetId()).ToArray();
                foreach (var id in toRemoves)
                {
                    VirtualRoot.Execute(new RemoveCoinGroupCommand(id));
                }
                _dicById.Remove(entity.Id);
                if (_dicByCode.ContainsKey(entity.Code))
                {
                    _dicByCode.Remove(entity.Code);
                }
                var repository = context.CreateServerRepository <CoinData>();
                repository.Remove(entity.Id);

                VirtualRoot.RaiseEvent(new CoinRemovedEvent(message.MessageId, entity));
            }, location: this.GetType());
        }
Пример #2
0
        public CoinSet(INTMinerRoot root)
        {
            _root = root;
            Global.Access <AddCoinCommand>(Guid.Parse("4CF438BB-7B59-4C56-AB8C-D01312848450"), "添加币种", LogEnum.Log, 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 DuplicateCodeException();
                }
                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);

                Global.Happened(new CoinAddedEvent(entity));
            });
            Global.Access <UpdateCoinCommand>(Guid.Parse("86EAEA27-7B7C-4A12-8F22-8F1422C6A489"), "更新币种", LogEnum.Log, 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()];
                entity.Update(message.Input);
                var repository = NTMinerRoot.CreateServerRepository <CoinData>();
                repository.Update(entity);

                Global.Happened(new CoinUpdatedEvent(message.Input));
            });
            Global.Access <RemoveCoinCommand>(Guid.Parse("9BB00186-9647-48D1-BF7B-4281A3FF317C"), "移除币种", LogEnum.Log, 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)
                {
                    Global.Execute(new RemovePoolCommand(id));
                }
                toRemoves = root.CoinKernelSet.Where(a => a.CoinId == entity.Id).Select(a => a.GetId()).ToArray();
                foreach (var id in toRemoves)
                {
                    Global.Execute(new RemoveCoinKernelCommand(id));
                }
                toRemoves = root.WalletSet.Where(a => a.CoinId == entity.Id).Select(a => a.GetId()).ToArray();
                foreach (var id in toRemoves)
                {
                    Global.Execute(new RemoveWalletCommand(id));
                }
                _dicById.Remove(entity.Id);
                if (_dicByCode.ContainsKey(entity.Code))
                {
                    _dicByCode.Remove(entity.Code);
                }
                var repository = NTMinerRoot.CreateServerRepository <CoinData>();
                repository.Remove(entity.Id);

                Global.Happened(new CoinRemovedEvent(entity));
            });
            BootLog.Log(this.GetType().FullName + "接入总线");
        }
Пример #3
0
        public CoinSet(INTMinerRoot root, bool isUseJson)
        {
            _root      = root;
            _isUseJson = isUseJson;
            _root.ServerContextWindow <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>(isUseJson);
                repository.Add(entity);

                VirtualRoot.Happened(new CoinAddedEvent(entity));
            });
            _root.ServerContextWindow <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>(isUseJson);
                repository.Update(entity);

                VirtualRoot.Happened(new CoinUpdatedEvent(message.Input));
            });
            _root.ServerContextWindow <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>(isUseJson);
                repository.Remove(entity.Id);

                VirtualRoot.Happened(new CoinRemovedEvent(entity));
            });
        }
Пример #4
0
        public CoinSet(IServerContext context)
        {
            _context = context;
            context.AddCmdPath <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 = context.CreateServerRepository <CoinData>();
                repository.Add(entity);

                VirtualRoot.RaiseEvent(new CoinAddedEvent(message.MessageId, entity));
            }, location: this.GetType());
            context.AddCmdPath <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.TryGetValue(message.Input.GetId(), out CoinData entity))
                {
                    return;
                }
                if (ReferenceEquals(entity, message.Input))
                {
                    return;
                }
                bool isMinGpuMemoryGbChanged = entity.MinGpuMemoryGb != message.Input.MinGpuMemoryGb;
                entity.Update(message.Input);
                if (isMinGpuMemoryGbChanged && entity.Code == "ETH" &&
                    NTMinerContext.Instance.ServerContext.SysDicItemSet.TryGetDicItem(NTKeyword.ThisSystemSysDicCode, NTKeyword.OsVmPerGpuSysDicItemCode, out ISysDicItem dicItem))
                {
                    VirtualRoot.Execute(new UpdateSysDicItemCommand(new SysDicItemData {
                        Code        = dicItem.Code,
                        Description = dicItem.Description,
                        DicId       = dicItem.DicId,
                        Id          = dicItem.GetId(),
                        SortNumber  = dicItem.SortNumber,
                        Value       = message.Input.MinGpuMemoryGb.ToString()
                    }));
                }
                var repository = context.CreateServerRepository <CoinData>();
                repository.Update(entity);

                VirtualRoot.RaiseEvent(new CoinUpdatedEvent(message.MessageId, message.Input));
            }, location: this.GetType());
            context.AddCmdPath <RemoveCoinCommand>(LogEnum.DevConsole,
                                                   action: message => {
                InitOnece();
                if (message == null || message.EntityId == Guid.Empty)
                {
                    throw new ArgumentNullException();
                }
                if (!_dicById.ContainsKey(message.EntityId))
                {
                    return;
                }
                CoinData entity  = _dicById[message.EntityId];
                Guid[] toRemoves = context.PoolSet.AsEnumerable().Where(a => a.CoinId == entity.Id).Select(a => a.GetId()).ToArray();
                foreach (var id in toRemoves)
                {
                    VirtualRoot.Execute(new RemovePoolCommand(id));
                }
                toRemoves = context.CoinKernelSet.AsEnumerable().Where(a => a.CoinId == entity.Id).Select(a => a.GetId()).ToArray();
                foreach (var id in toRemoves)
                {
                    VirtualRoot.Execute(new RemoveCoinKernelCommand(id));
                }
                toRemoves = NTMinerContext.Instance.MinerProfile.GetWallets().Where(a => a.CoinId == entity.Id).Select(a => a.GetId()).ToArray();
                foreach (var id in toRemoves)
                {
                    VirtualRoot.Execute(new RemoveWalletCommand(id));
                }
                toRemoves = context.CoinGroupSet.AsEnumerable().Where(a => a.CoinId == entity.Id).Select(a => a.GetId()).ToArray();
                foreach (var id in toRemoves)
                {
                    VirtualRoot.Execute(new RemoveCoinGroupCommand(id));
                }
                _dicById.Remove(entity.Id);
                if (_dicByCode.ContainsKey(entity.Code))
                {
                    _dicByCode.Remove(entity.Code);
                }
                var repository = context.CreateServerRepository <CoinData>();
                repository.Remove(entity.Id);

                VirtualRoot.RaiseEvent(new CoinRemovedEvent(message.MessageId, entity));
            }, location: this.GetType());
        }