예제 #1
0
        public async Task <SanityCheckResult> Check(Type[] types, BootLog log)
        {
            var result = new SanityCheckResult();

            foreach (var type in types)
            {
                try
                {
                    var check = (ICheckSanity)serviceLocator.GetService(type);
                    var sane  = await check.Probe();

                    result.Add(type, sane);
                    if (sane)
                    {
                        log.Info(Constants.BootComponents.SanityChecks, $"{type.Name} passed.");
                    }
                    else
                    {
                        log.Error(Constants.BootComponents.SanityChecks, $"{type.Name} failed.");
                    }
                }
                catch (Exception)
                {
                    result.Add(type, false);
                    log.Error(Constants.BootComponents.SanityChecks, $"{type.Name} failed significantly.");
                }
            }

            return(result);
        }
예제 #2
0
        public Log4NetLoggingService()
        {
            XmlDocument xmlDoc  = new XmlDocument();
            string      logFile = "logs\root.log";

            if (!string.IsNullOrEmpty(BootLog.LogDir))
            {
                logFile = Path.Combine(BootLog.LogDir, "root.log");
            }
            xmlDoc.LoadXml(
                $@"<log4net>
  <root>
    <level value=""ALL"" />
    <appender-ref ref=""RollingFileAppender"" />
  </root>
  <appender name=""RollingFileAppender"" type =""log4net.Appender.RollingFileAppender"" >
    <filter type=""log4net.Filter.LevelRangeFilter"" >
    </filter>
    <param name=""File"" value =""{logFile}"" />
    <param name=""AppendToFile"" value =""true"" />
    <param name=""MaxSizeRollBackups"" value =""10"" />
    <param name=""MaximumFileSize"" value =""2MB"" />
    <param name=""RollingStyle"" value =""Size"" />
    <param name=""StaticLogFileName"" value =""true"" />
    <layout type=""log4net.Layout.PatternLayout"" >
      <param name=""ConversionPattern"" value =""%d [%t] %-5p %c - %m%n"" />
    </layout>
  </appender>
</log4net>
");
            XmlConfigurator.Configure(xmlDoc.DocumentElement);
            _log = LogManager.GetLogger("global");
            BootLog.Log(this.GetType().FullName + "接入总线");
        }
예제 #3
0
 public MinerProfile(INTMinerRoot root)
 {
     _root = root;
     _data = GetMinerProfileData();
     if (_data == null)
     {
         throw new ValidationException("未获取到MinerProfileData数据,请重试");
     }
     BootLog.Log(this.GetType().FullName + "接入总线");
 }
        internal void RegisterServices(IServiceRegistration[] registrations, BootLog log)
        {
            Container = new Container();
            foreach (var registration in registrations)
            {
                log?.Info("ServiceLocator", $"Loading Services {registration.GetType().Name}");
                registration.RegisterServices(Container);
            }

            Container.Register <IServiceLocator>(() => this, Lifestyle.Singleton);
        }
예제 #5
0
        public CoinGroupSet(INTMinerRoot root)
        {
            _root = root;
            Global.Access <AddCoinGroupCommand>(
                Guid.Parse("2dd8f7e9-c79d-4621-954f-9fc45b0207dd"),
                "添加币组",
                LogEnum.Log,
                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);
                _dicById.Add(entity.Id, entity);
                var repository = NTMinerRoot.CreateServerRepository <CoinGroupData>();
                repository.Add(entity);

                Global.Happened(new CoinGroupAddedEvent(entity));
            });
            Global.Access <RemoveCoinGroupCommand>(
                Guid.Parse("e52874f4-37d8-4d49-a637-5b95aa89367e"),
                "移除币组",
                LogEnum.Log,
                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);

                Global.Happened(new CoinGroupRemovedEvent(entity));
            });
            BootLog.Log(this.GetType().FullName + "接入总线");
        }
예제 #6
0
        public SysDicItemSet(INTMinerRoot root)
        {
            _root = root;
            Global.Access <AddSysDicItemCommand>(
                Guid.Parse("485407c5-ffe0-462d-b05f-a13418307be0"),
                "添加系统字典项",
                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("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 DuplicateCodeException();
                }
                SysDicItemData entity = new SysDicItemData().Update(message.Input);
                _dicById.Add(entity.Id, entity);
                _dicByDicId[message.Input.DicId].Add(entity.Code, entity);
                var repository = NTMinerRoot.CreateServerRepository <SysDicItemData>();
                repository.Add(entity);

                Global.Happened(new SysDicItemAddedEvent(entity));
            });
            Global.Access <UpdateSysDicItemCommand>(
                Guid.Parse("0379df7f-9f34-449a-91b2-4bd32e0c287f"),
                "更新系统字典项",
                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("sysDicItem code can't be null or empty");
                }
                if (!_dicById.ContainsKey(message.Input.GetId()))
                {
                    return;
                }
                SysDicItemData entity = _dicById[message.Input.GetId()];
                entity.Update(message.Input);
                var repository = NTMinerRoot.CreateServerRepository <SysDicItemData>();
                repository.Update(entity);

                Global.Happened(new SysDicItemUpdatedEvent(entity));
            });
            Global.Access <RemoveSysDicItemCommand>(
                Guid.Parse("d0b7b706-2a57-492c-842d-03a4281ecfdf"),
                "移除系统字典项",
                LogEnum.Log,
                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.CreateServerRepository <SysDicItemData>();
                repository.Remove(entity.Id);

                Global.Happened(new SysDicItemRemovedEvent(entity));
            });
            BootLog.Log(this.GetType().FullName + "接入总线");
        }
예제 #7
0
        public KernelOutputTranslaterSet(INTMinerRoot root)
        {
            _root = root;
            Global.Access <AddKernelOutputTranslaterCommand>(
                Guid.Parse("d9da43ad-8fb7-4d6b-a8c7-ac0c1bbc4dd3"),
                "添加内核输出翻译器",
                LogEnum.Log,
                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("ConsoleTranslater 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 (!_dicByKernelId.ContainsKey(entity.KernelId))
                {
                    _dicByKernelId.Add(entity.KernelId, new List <KernelOutputTranslaterData>());
                }
                _dicByKernelId[entity.KernelId].Add(entity);
                var repository = NTMinerRoot.CreateServerRepository <KernelOutputTranslaterData>();
                repository.Add(entity);

                Global.Happened(new KernelOutputTranslaterAddedEvent(entity));
            });
            Global.Access <UpdateKernelOutputTranslaterCommand>(
                Guid.Parse("9e22fc7d-41da-4291-8dde-d8282f81d188"),
                "更新内核输出翻译器",
                LogEnum.Log,
                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("ConsoleTranslater RegexPattern can't be null or empty");
                }
                if (!_dicById.ContainsKey(message.Input.GetId()))
                {
                    return;
                }
                KernelOutputTranslaterData entity = _dicById[message.Input.GetId()];
                string regexPattern = entity.RegexPattern;
                string color        = entity.Color;
                entity.Update(message.Input);
                if (entity.RegexPattern != regexPattern)
                {
                    _regexDic.Remove(entity);
                }
                if (entity.Color != color)
                {
                    _colorDic.Remove(entity);
                }
                _dicByKernelId[entity.KernelId].Sort(new SortNumberComparer());
                var repository = NTMinerRoot.CreateServerRepository <KernelOutputTranslaterData>();
                repository.Update(entity);

                Global.Happened(new KernelOutputTranslaterUpdatedEvent(entity));
            });
            Global.Access <RemoveKernelOutputTranslaterCommand>(
                Guid.Parse("7e76b569-aa52-492a-ae41-f2e0a22ffa9b"),
                "移除内核输出翻译器",
                LogEnum.Log,
                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);
                _dicByKernelId[entity.KernelId].Remove(entity);
                _colorDic.Remove(entity);
                _regexDic.Remove(entity);
                _dicByKernelId[entity.KernelId].Sort(new SortNumberComparer());
                var repository = NTMinerRoot.CreateServerRepository <KernelOutputTranslaterData>();
                repository.Remove(entity.Id);

                Global.Happened(new KernelOutputTranslaterRemovedEvent(entity));
            });
            Global.Access <SysDicItemUpdatedEvent>(
                Guid.Parse("de662262-bd05-4cae-ba6e-843f18541966"),
                "LogColor字典项更新后刷新翻译器内存",
                LogEnum.None,
                action: message => {
                ISysDic dic;
                if (!_root.SysDicSet.TryGetSysDic("LogColor", out dic))
                {
                    return;
                }
                if (message.Source.DicId != dic.GetId())
                {
                    return;
                }
                foreach (var entity in _dicById.Values)
                {
                    if (entity.Color == message.Source.Code)
                    {
                        _colorDic.Remove(entity);
                    }
                }
            });
            BootLog.Log(this.GetType().FullName + "接入总线");
        }
예제 #8
0
 public CoinShareSet(INTMinerRoot root)
 {
     _root = root;
     BootLog.Log(this.GetType().FullName + "接入总线");
 }
예제 #9
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 + "接入总线");
        }
예제 #10
0
파일: GroupSet.cs 프로젝트: TimeYM/ntminer
        public GroupSet(INTMinerRoot root)
        {
            _root = root;
            Global.Access <AddGroupCommand>(
                Guid.Parse("e0c313ff-2550-41f8-9403-8575638c7faf"),
                "添加组",
                LogEnum.Log,
                action: (message) => {
                InitOnece();
                if (message == null || message.Input == null || message.Input.GetId() == Guid.Empty)
                {
                    throw new ArgumentNullException();
                }
                if (_dicById.ContainsKey(message.Input.GetId()))
                {
                    return;
                }
                GroupData entity = new GroupData().Update(message.Input);
                _dicById.Add(entity.Id, entity);
                var repository = NTMinerRoot.CreateServerRepository <GroupData>();
                repository.Add(entity);

                Global.Happened(new GroupAddedEvent(entity));
            });
            Global.Access <UpdateGroupCommand>(
                Guid.Parse("b2d190dd-b60d-41f9-8e93-65902c318a78"),
                "更新组",
                LogEnum.Log,
                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()];
                entity.Update(message.Input);
                var repository = NTMinerRoot.CreateServerRepository <GroupData>();
                repository.Update(new GroupData().Update(message.Input));

                Global.Happened(new GroupUpdatedEvent(entity));
            });
            Global.Access <RemoveGroupCommand>(
                Guid.Parse("7dede0b5-be81-4fc1-bee1-cdeb6afa7b72"),
                "移除组",
                LogEnum.Log,
                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)
                {
                    Global.Execute(new RemoveCoinGroupCommand(id));
                }
                _dicById.Remove(entity.GetId());
                var repository = NTMinerRoot.CreateServerRepository <GroupData>();
                repository.Remove(message.EntityId);

                Global.Happened(new GroupRemovedEvent(entity));
            });
            BootLog.Log(this.GetType().FullName + "接入总线");
        }
예제 #11
0
        public MineWorkSet(INTMinerRoot root)
        {
            _root = root;
            ICoin coin = root.CoinSet.FirstOrDefault();

            Global.Access <AddMineWorkCommand>(
                Guid.Parse("2ce02224-8ddf-4499-9d1d-7439ba5ca2fc"),
                "添加工作",
                LogEnum.Log,
                action: (message) => {
                InitOnece();
                if (message == null || message.Input == null || message.Input.GetId() == Guid.Empty)
                {
                    throw new ArgumentNullException();
                }
                if (_dicById.ContainsKey(message.Input.GetId()))
                {
                    return;
                }
                MineWorkData entity = new MineWorkData().Update(message.Input);
                _dicById.Add(entity.Id, entity);
                Server.ControlCenterService.AddOrUpdateMineWork(entity, isSuccess => {
                    Global.Happened(new MineWorkAddedEvent(entity));
                });
            });
            Global.Access <UpdateMineWorkCommand>(
                Guid.Parse("21140dbe-c9be-48d6-ae92-4d0ebc666a25"),
                "更新工作",
                LogEnum.Log,
                action: (message) => {
                InitOnece();
                if (message == null || message.Input == null || message.Input.GetId() == Guid.Empty)
                {
                    throw new ArgumentNullException();
                }
                if (!_dicById.ContainsKey(message.Input.GetId()))
                {
                    return;
                }
                MineWorkData entity = _dicById[message.Input.GetId()];
                entity.Update(message.Input);
                Server.ControlCenterService.AddOrUpdateMineWork(entity, isSuccess => {
                    Global.Happened(new MineWorkUpdatedEvent(entity));
                });
            });
            Global.Access <RemoveMineWorkCommand>(
                Guid.Parse("cec3ccf4-9700-4e38-b786-8ceefe5209fb"),
                "移除工作",
                LogEnum.Log,
                action: (message) => {
                InitOnece();
                if (message == null || message.EntityId == Guid.Empty)
                {
                    throw new ArgumentNullException();
                }
                if (!_dicById.ContainsKey(message.EntityId))
                {
                    return;
                }
                MineWorkData entity = _dicById[message.EntityId];
                _dicById.Remove(entity.Id);
                Server.ControlCenterService.RemoveMineWork(entity.Id, isSuccess => {
                    Global.Happened(new MineWorkRemovedEvent(entity));
                });
            });
            BootLog.Log(this.GetType().FullName + "接入总线");
        }
예제 #12
0
 public MinerGroupSet(INTMinerRoot root)
 {
     _root = root;
     Global.Access <AddMinerGroupCommand>(
         Guid.Parse("051DE144-1C91-4633-B826-EDFBE951B450"),
         "添加矿工组",
         LogEnum.Log,
         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("minerGroup name can't be null or empty");
         }
         if (_dicById.ContainsKey(message.Input.GetId()))
         {
             return;
         }
         MinerGroupData entity = new MinerGroupData().Update(message.Input);
         _dicById.Add(entity.Id, entity);
         Server.ControlCenterService.AddOrUpdateMinerGroup(entity, response => {
             if (response.IsSuccess())
             {
                 Global.Happened(new MinerGroupAddedEvent(entity));
             }
         });
     });
     Global.Access <UpdateMinerGroupCommand>(
         Guid.Parse("BC6ADC0E-E57C-4313-8C85-D866E2068913"),
         "更新矿工组",
         LogEnum.Log,
         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("minerGroup name can't be null or empty");
         }
         if (!_dicById.ContainsKey(message.Input.GetId()))
         {
             return;
         }
         MinerGroupData entity = _dicById[message.Input.GetId()];
         entity.Update(message.Input);
         Server.ControlCenterService.AddOrUpdateMinerGroup(entity, isSuccess => {
             Global.Happened(new MinerGroupUpdatedEvent(entity));
         });
     });
     Global.Access <RemoveMinerGroupCommand>(
         Guid.Parse("3083F1E6-0932-484E-AD2F-BDEA2790FD44"),
         "移除矿工组",
         LogEnum.Log,
         action: (message) => {
         InitOnece();
         if (message == null || message.EntityId == Guid.Empty)
         {
             throw new ArgumentNullException();
         }
         if (!_dicById.ContainsKey(message.EntityId))
         {
             return;
         }
         MinerGroupData entity = _dicById[message.EntityId];
         _dicById.Remove(entity.Id);
         Server.ControlCenterService.RemoveMinerGroup(entity.Id, isSuccess => {
             Global.Happened(new MinerGroupRemovedEvent(entity));
         });
     });
     BootLog.Log(this.GetType().FullName + "接入总线");
 }
예제 #13
0
        public GpusSpeed(INTMinerRoot root)
        {
            _root = root;
            foreach (var gpu in _root.GpuSet)
            {
                _currentGpuSpeed.Add(gpu.Index, new GpuSpeed(gpu)
                {
                    MainCoinSpeed = new Speed()
                    {
                        Value   = 0,
                        SpeedOn = DateTime.Now
                    },
                    DualCoinSpeed = new Speed()
                    {
                        Value   = 0,
                        SpeedOn = DateTime.Now
                    }
                });
            }
            IGpuSpeed totalGpuSpeed    = this._currentGpuSpeed[NTMinerRoot.Current.GpuAllId];
            var       speedExceptTotal = _currentGpuSpeed.Values.Where(a => a != totalGpuSpeed).ToArray();

            totalGpuSpeed.MainCoinSpeed.Value = speedExceptTotal.Sum(a => a.MainCoinSpeed.Value);
            totalGpuSpeed.DualCoinSpeed.Value = speedExceptTotal.Sum(a => a.DualCoinSpeed.Value);
            foreach (var item in _currentGpuSpeed)
            {
                _gpuSpeedHistory.Add(item.Key, new List <IGpuSpeed>());
            }
            Global.Access <Per10MinuteEvent>(
                Guid.Parse("9A17AE73-34B8-4EBA-BE91-22BBD163A3E8"),
                "周期清除过期的历史算力",
                LogEnum.Console,
                action: message => {
                ClearOutOfDateHistory();
            });

            Global.Access <MineStopedEvent>(
                Guid.Parse("1C79954C-0311-4C94-B001-09B39FC11DC6"),
                "停止挖矿后产生一次0算力",
                LogEnum.Console,
                action: message => {
                var now = DateTime.Now;
                foreach (var gpu in _root.GpuSet)
                {
                    Global.Happened(new GpuSpeedChangedEvent(isDualSpeed: false, gpuSpeed: new GpuSpeed(gpu)
                    {
                        MainCoinSpeed = new Speed {
                            Value   = 0,
                            SpeedOn = now
                        },
                        DualCoinSpeed = new Speed {
                            Value   = 0,
                            SpeedOn = now
                        }
                    }));
                    if (message.MineContext is IDualMineContext dualMineContext)
                    {
                        Global.Happened(new GpuSpeedChangedEvent(isDualSpeed: true, gpuSpeed: new GpuSpeed(gpu)
                        {
                            MainCoinSpeed = new Speed {
                                Value   = 0,
                                SpeedOn = now
                            },
                            DualCoinSpeed = new Speed {
                                Value   = 0,
                                SpeedOn = now
                            }
                        }));
                    }
                }
            });

            Global.Access <MineStartedEvent>(
                Guid.Parse("997bc22f-9bee-4fd6-afe8-eec7eb664daf"),
                "挖矿开始时产生一次0算力0份额",
                LogEnum.Console,
                action: message => {
                var now                = DateTime.Now;
                ICoinShare share       = _root.CoinShareSet.GetOrCreate(message.MineContext.MainCoin.GetId());
                share.AcceptShareCount = 0;
                share.RejectCount      = 0;
                share.ShareOn          = now;
                Global.Happened(new ShareChangedEvent(share));
                foreach (var gpu in _root.GpuSet)
                {
                    Global.Happened(new GpuSpeedChangedEvent(isDualSpeed: false, gpuSpeed: new GpuSpeed(gpu)
                    {
                        MainCoinSpeed = new Speed {
                            Value   = 0,
                            SpeedOn = now
                        },
                        DualCoinSpeed = new Speed {
                            Value   = 0,
                            SpeedOn = now
                        }
                    }));
                }
                if (message.MineContext is IDualMineContext dualMineContext)
                {
                    share = _root.CoinShareSet.GetOrCreate(dualMineContext.DualCoin.GetId());
                    share.AcceptShareCount = 0;
                    share.RejectCount      = 0;
                    share.ShareOn          = now;
                    Global.Happened(new ShareChangedEvent(share));
                    foreach (var gpu in _root.GpuSet)
                    {
                        Global.Happened(new GpuSpeedChangedEvent(isDualSpeed: true, gpuSpeed: new GpuSpeed(gpu)
                        {
                            MainCoinSpeed = new Speed {
                                Value   = 0,
                                SpeedOn = now
                            },
                            DualCoinSpeed = new Speed {
                                Value   = 0,
                                SpeedOn = now
                            }
                        }));
                    }
                }
            });
            BootLog.Log(this.GetType().FullName + "接入总线");
        }
예제 #14
0
 public ObjectJsonSerializer()
 {
     BootLog.Log(this.GetType().FullName + "接入总线");
 }
예제 #15
0
 public CalcConfigSet(INTMinerRoot root)
 {
     _root = root;
     BootLog.Log(this.GetType().FullName + "接入总线");
 }
예제 #16
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));
            });
            BootLog.Log(this.GetType().FullName + "接入总线");
        }
예제 #17
0
 public KernelProfileSet(INTMinerRoot root)
 {
     _root = root;
     BootLog.Log(this.GetType().FullName + "接入总线");
 }
예제 #18
0
        public KernelOutputFilterSet(INTMinerRoot root)
        {
            _root = root;
            Global.Access <AddKernelOutputFilterCommand>(
                Guid.Parse("43c09cc6-456c-4e55-95b1-63b5937c5b11"),
                "添加内核输出过滤器",
                LogEnum.Log,
                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("KernelOutputFilter 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 (!_dicByKernelId.ContainsKey(entity.KernelId))
                {
                    _dicByKernelId.Add(entity.KernelId, new List <KernelOutputFilterData>());
                }
                _dicByKernelId[entity.KernelId].Add(entity);
                var repository = NTMinerRoot.CreateServerRepository <KernelOutputFilterData>();
                repository.Add(entity);

                Global.Happened(new KernelOutputFilterAddedEvent(entity));
            });
            Global.Access <UpdateKernelOutputFilterCommand>(
                Guid.Parse("b449bd25-98d8-4a60-9c75-36a6983c6176"),
                "更新内核输出过滤器",
                LogEnum.Log,
                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("KernelOutputFilter RegexPattern can't be null or empty");
                }
                if (!_dicById.ContainsKey(message.Input.GetId()))
                {
                    return;
                }
                KernelOutputFilterData entity = _dicById[message.Input.GetId()];
                entity.Update(message.Input);
                var repository = NTMinerRoot.CreateServerRepository <KernelOutputFilterData>();
                repository.Update(entity);

                Global.Happened(new KernelOutputFilterUpdatedEvent(entity));
            });
            Global.Access <RemoveKernelOutputFilterCommand>(
                Guid.Parse("11a3a185-3d2e-463e-bd92-94a0db909d32"),
                "移除内核输出过滤器",
                LogEnum.Log,
                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);
                _dicByKernelId[entity.KernelId].Remove(entity);
                var repository = NTMinerRoot.CreateServerRepository <KernelOutputFilterData>();
                repository.Remove(entity.Id);

                Global.Happened(new KernelOutputFilterRemovedEvent(entity));
            });
            BootLog.Log(this.GetType().FullName + "接入总线");
        }
예제 #19
0
        public CoinKernelSet(INTMinerRoot root)
        {
            _root = root;
            Global.Access <AddCoinKernelCommand>(
                Guid.Parse("6345c411-4860-433b-ad5e-3a743bcebfa8"),
                "添加币种内核",
                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 (_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);

                Global.Happened(new CoinKernelAddedEvent(entity));
            });
            Global.Access <UpdateCoinKernelCommand>(
                Guid.Parse("b3dfdf09-f732-4b3b-aeeb-25de7b83d30c"),
                "更新币种内核",
                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 (!_dicById.ContainsKey(message.Input.GetId()))
                {
                    return;
                }
                CoinKernelData entity = _dicById[message.Input.GetId()];
                entity.Update(message.Input);
                var repository = NTMinerRoot.CreateServerRepository <CoinKernelData>();
                repository.Update(entity);

                Global.Happened(new CoinKernelUpdatedEvent(entity));
            });
            Global.Access <RemoveCoinKernelCommand>(
                Guid.Parse("ee34113f-e616-421d-adcc-c2e810723035"),
                "移除币种内核",
                LogEnum.Log,
                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);

                Global.Happened(new CoinKernelRemovedEvent(entity));
            });
            BootLog.Log(this.GetType().FullName + "接入总线");
        }
예제 #20
0
 public SanityCheckProcessorTests()
 {
     log = new BootLog(GetMocked <IClock>());
 }
예제 #21
0
파일: WalletSet.cs 프로젝트: TimeYM/ntminer
        public WalletSet(INTMinerRoot root)
        {
            _root = root;
            Global.Access <AddWalletCommand>(
                Guid.Parse("d050de9d-7356-471b-b9c7-19d685aa770a"),
                "添加钱包",
                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 not coin with id " + message.Input.CoinId);
                }
                if (string.IsNullOrEmpty(message.Input.Address))
                {
                    throw new ValidationException("wallet code and Address can't be null or empty");
                }
                if (_dicById.ContainsKey(message.Input.GetId()))
                {
                    return;
                }
                WalletData entity = new WalletData().Update(message.Input);
                _dicById.Add(entity.Id, entity);
                AddWallet(entity);

                Global.Happened(new WalletAddedEvent(entity));
            });
            Global.Access <UpdateWalletCommand>(
                Guid.Parse("658f0e61-8c86-493f-a147-d66da2ed194d"),
                "更新钱包",
                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 not coin with id " + message.Input.CoinId);
                }
                if (string.IsNullOrEmpty(message.Input.Address))
                {
                    throw new ValidationException("wallet Address can't be null or empty");
                }
                if (string.IsNullOrEmpty(message.Input.Name))
                {
                    throw new ValidationException("wallet name can't be null or empty");
                }
                if (!_dicById.ContainsKey(message.Input.GetId()))
                {
                    return;
                }
                WalletData entity = _dicById[message.Input.GetId()];
                entity.Update(message.Input);
                UpdateWallet(entity);

                Global.Happened(new WalletUpdatedEvent(entity));
            });
            Global.Access <RemoveWalletCommand>(
                Guid.Parse("bd70fe34-7575-43d0-a8e5-d8e9566d8d56"),
                "移除钱包",
                LogEnum.Log,
                action: (message) => {
                InitOnece();
                if (message == null || message.EntityId == Guid.Empty)
                {
                    throw new ArgumentNullException();
                }
                if (!_dicById.ContainsKey(message.EntityId))
                {
                    return;
                }
                WalletData entity = _dicById[message.EntityId];
                _dicById.Remove(entity.GetId());
                RemoveWallet(entity.Id);

                Global.Happened(new WalletRemovedEvent(entity));
            });
            BootLog.Log(this.GetType().FullName + "接入总线");
        }
예제 #22
0
        public SysDicSet(INTMinerRoot root)
        {
            _root = root;
            Global.Access <AddSysDicCommand>(
                Guid.Parse("9353be1f-707f-455f-ade5-07e081141d47"),
                "添加系统字典",
                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("dic code can't be null or empty");
                }
                if (_dicById.ContainsKey(message.Input.GetId()))
                {
                    return;
                }
                if (_dicByCode.ContainsKey(message.Input.Code))
                {
                    throw new DuplicateCodeException();
                }
                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);

                Global.Happened(new SysDicAddedEvent(entity));
            });
            Global.Access <UpdateSysDicCommand>(
                Guid.Parse("b37df2da-ab45-416e-ba58-d703667f300b"),
                "更新系统字典",
                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("sysDic code can't be null or empty");
                }
                if (!_dicById.ContainsKey(message.Input.GetId()))
                {
                    return;
                }
                SysDicData entity = _dicById[message.Input.GetId()];
                entity.Update(message.Input);
                var repository = NTMinerRoot.CreateServerRepository <SysDicData>();
                repository.Update(entity);

                Global.Happened(new SysDicUpdatedEvent(entity));
            });
            Global.Access <RemoveSysDicCommand>(
                Guid.Parse("ac6af880-89a1-47a4-9596-55e33714db45"),
                "移除系统字典",
                LogEnum.Log,
                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)
                {
                    Global.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);

                Global.Happened(new SysDicRemovedEvent(entity));
            });
            BootLog.Log(this.GetType().FullName + "接入总线");
        }
예제 #23
0
파일: KernelSet.cs 프로젝트: TimeYM/ntminer
        public KernelSet(INTMinerRoot root)
        {
            _root = root;
            Global.Access <AddKernelCommand>(
                Guid.Parse("331be370-2d4f-488f-9dd8-3709e3ff63af"),
                "添加内核",
                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("package 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);
                IRepository <KernelData> repository = NTMinerRoot.CreateServerRepository <KernelData>();
                repository.Add(entity);

                Global.Happened(new KernelAddedEvent(entity));
            });
            Global.Access <UpdateKernelCommand>(
                Guid.Parse("f23c801a-afbe-4e59-93c2-3eaecf3c7d8e"),
                "更新内核",
                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("package code can't be null or empty");
                }
                if (!_dicById.ContainsKey(message.Input.GetId()))
                {
                    return;
                }
                KernelData entity = _dicById[message.Input.GetId()];
                entity.Update(message.Input);
                IRepository <KernelData> repository = NTMinerRoot.CreateServerRepository <KernelData>();
                repository.Update(entity);

                Global.Happened(new KernelUpdatedEvent(entity));
            });
            Global.Access <RemoveKernelCommand>(
                Guid.Parse("b90d68ba-2af2-48db-8bf3-5b2795667e8c"),
                "移除内核",
                LogEnum.Log,
                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();
                List <Guid> kernelOutputFilterIds     = root.KernelOutputFilterSet.Where(a => a.KernelId == entity.Id).Select(a => a.GetId()).ToList();
                List <Guid> kernelOutputTranslaterIds = root.KernelOutputTranslaterSet.Where(a => a.KernelId == entity.Id).Select(a => a.GetId()).ToList();
                foreach (var coinKernelId in coinKernelIds)
                {
                    Global.Execute(new RemoveCoinKernelCommand(coinKernelId));
                }
                foreach (var kernelOutputFilterId in kernelOutputFilterIds)
                {
                    Global.Execute(new RemoveKernelOutputFilterCommand(kernelOutputFilterId));
                }
                foreach (var kernelOutputTranslaterId in kernelOutputTranslaterIds)
                {
                    Global.Execute(new RemoveKernelOutputTranslaterCommand(kernelOutputTranslaterId));
                }
                _dicById.Remove(entity.Id);
                IRepository <KernelData> repository = NTMinerRoot.CreateServerRepository <KernelData>();
                repository.Remove(entity.Id);

                Global.Happened(new KernelRemovedEvent(entity));
            });
            BootLog.Log(this.GetType().FullName + "接入总线");
        }
예제 #24
0
 public PackageDownloader(INTMinerRoot root)
 {
     _root = root;
     BootLog.Log(this.GetType().FullName + "接入总线");
 }