Example #1
0
 private KernelInputViewModels()
 {
     Global.Access <KernelInputAddedEvent>(
         Guid.Parse("7BB2CAD5-333F-4BDD-B6FF-3F0AA50724EA"),
         "添加了内核输入后刷新VM内存",
         LogEnum.None,
         action: message => {
         var vm = new KernelInputViewModel(message.Source);
         _dicById.Add(message.Source.GetId(), vm);
         OnPropertyChanged(nameof(AllKernelInputVms));
         OnPropertyChanged(nameof(PleaseSelectVms));
     });
     Global.Access <KernelInputUpdatedEvent>(
         Guid.Parse("A85F4699-F884-43A3-B6F1-3E7CBCA7D7D6"),
         "更新了内核输入后刷新VM内存",
         LogEnum.None,
         action: message => {
         if (_dicById.ContainsKey(message.Source.GetId()))
         {
             var item = _dicById[message.Source.GetId()];
             if (item != null)
             {
                 bool isSupportDualMine = item.IsSupportDualMine;
                 string args            = item.Args;
                 string dualFullArgs    = item.DualFullArgs;
                 item.Update(message.Source);
                 if (args != item.Args || dualFullArgs != item.DualFullArgs)
                 {
                     CoinViewModel coinVm = MinerProfileViewModel.Current.CoinVm;
                     if (coinVm != null && coinVm.CoinKernel != null && coinVm.CoinKernel.Kernel.KernelInputId == item.Id)
                     {
                         Global.Execute(new RefreshArgsAssemblyCommand());
                     }
                 }
                 if (isSupportDualMine != item.IsSupportDualMine)
                 {
                     foreach (var coinKernelVm in CoinKernelViewModels.Current.AllCoinKernels.Where(a => a.KernelId == message.Source.GetId()))
                     {
                         coinKernelVm.OnPropertyChanged(nameof(coinKernelVm.IsSupportDualMine));
                         coinKernelVm.OnPropertyChanged(nameof(coinKernelVm.DualCoinGroup));
                     }
                 }
             }
         }
     });
     Global.Access <KernelInputRemovedEvent>(
         Guid.Parse("4E0CFBAF-443F-4C09-B86B-3DBC7D7AF875"),
         "移除了内核输入后刷新VM内存",
         LogEnum.None,
         action: message => {
         if (_dicById.ContainsKey(message.Source.GetId()))
         {
             _dicById.Remove(message.Source.GetId());
             OnPropertyChanged(nameof(AllKernelInputVms));
             OnPropertyChanged(nameof(PleaseSelectVms));
         }
     });
     foreach (var item in NTMinerRoot.Current.KernelInputSet)
     {
         _dicById.Add(item.GetId(), new KernelInputViewModel(item));
     }
 }
Example #2
0
        private MinerProfileViewModel()
        {
            if (NTMinerRoot.IsInDesignMode)
            {
                return;
            }
            this.CustomTheme = new DelegateCommand(() => {
                LogColor.ShowWindow();
            });
            Global.Access <Per1SecondEvent>(
                Guid.Parse("479A35A1-5A5A-48AF-B184-F1EC568BE181"),
                "挖矿计时秒表",
                LogEnum.None,
                action: message => {
                var mineContext = NTMinerRoot.Current.CurrentMineContext;
                if (mineContext != null)
                {
                    this.MineTimeSpan = DateTime.Now - mineContext.CreatedOn;
                }
                OnPropertyChanged(nameof(MineStatusText));
            });
            Global.Access <MinerProfilePropertyChangedEvent>(
                Guid.Parse("00F1C9F7-ADC8-438D-8B7E-942F6EE5F9A4"),
                "MinerProfile设置变更后刷新VM内存",
                LogEnum.Log,
                action: message => {
                OnPropertyChanged(message.PropertyName);
            });
            Global.Access <MineWorkPropertyChangedEvent>(
                Guid.Parse("7F96F755-E292-4146-9390-75635D150A4B"),
                "MineWork设置变更后刷新VM内存",
                LogEnum.Log,
                action: message => {
                OnPropertyChanged(message.PropertyName);
            });
            Global.Access <MineStartedEvent>(
                Guid.Parse("36B6B69F-37E3-44BE-9CA9-20D6764E7058"),
                "挖矿开始后刷新MinerProfileVM的IsMinig属性",
                LogEnum.None,
                action: message => {
                this.OnPropertyChanged(nameof(this.IsMining));
            });
            Global.Access <MineStopedEvent>(
                Guid.Parse("C4C1308A-1C04-4094-91A2-D11993C626A0"),
                "挖矿停止后刷新MinerProfileVM的IsMinig属性",
                LogEnum.None,
                action: message => {
                this.OnPropertyChanged(nameof(this.IsMining));
            });

            Global.Access <RefreshArgsAssemblyCommand>(
                Guid.Parse("4931C5C3-178F-4867-B615-215F0744C1EB"),
                "刷新参数总成",
                LogEnum.Log,
                action: cmd => {
                this.OnPropertyChanged(nameof(this.ArgsAssembly));
            });
            System.Timers.Timer t = new System.Timers.Timer(100);
            t.Elapsed += (object sender, System.Timers.ElapsedEventArgs e) => {
                if (this._logoRotateTransformAngle > 3600000)
                {
                    this._logoRotateTransformAngle = 0;
                }
                this.LogoRotateTransformAngle += 50;
            };
            Global.Access <MineStartedEvent>(
                Guid.Parse("D8CC83D6-B9B5-4739-BD66-0F772A22BBF8"),
                "挖矿开始后将风扇转起来",
                LogEnum.None,
                action: message => {
                t.Start();
                OnPropertyChanged(nameof(GpuStateColor));
            });
            Global.Access <MineStopedEvent>(
                Guid.Parse("0BB360E4-92A6-4629-861F-B3E4C9BE1203"),
                "挖矿停止后将风扇停转",
                LogEnum.None,
                action: message => {
                t.Stop();
                OnPropertyChanged(nameof(GpuStateColor));
            });
            if (CommandLineArgs.IsWorker)
            {
                Server.ProfileService.GetMineWork(CommandLineArgs.WorkId, mineWorkData => {
                    if (mineWorkData != null)
                    {
                        this.MineWork = mineWorkData;
                    }
                });
            }
        }
Example #3
0
 private CoinGroupViewModels() {
     foreach (var item in NTMinerRoot.Current.CoinGroupSet) {
         CoinGroupViewModel groupVm = new CoinGroupViewModel(item);
         _dicById.Add(item.GetId(), groupVm);
         if (!_listByGroupId.ContainsKey(item.GroupId)) {
             _listByGroupId.Add(item.GroupId, new List<CoinGroupViewModel>());
         }
         _listByGroupId[item.GroupId].Add(groupVm);
     }
     Global.Access<CoinGroupAddedEvent>(
         Guid.Parse("e0476d29-0115-405e-81d1-c7fb65051c83"),
         "添加了币组后调整VM内存",
         LogEnum.Log,
         action: (message) => {
             if (!_dicById.ContainsKey(message.Source.GetId())) {
                 CoinGroupViewModel coinGroupVm = new CoinGroupViewModel(message.Source);
                 _dicById.Add(message.Source.GetId(), coinGroupVm);
                 if (!_listByGroupId.ContainsKey(coinGroupVm.GroupId)) {
                     _listByGroupId.Add(coinGroupVm.GroupId, new List<CoinGroupViewModel>());
                 }
                 _listByGroupId[coinGroupVm.GroupId].Add(coinGroupVm);
                 GroupViewModel groupVm;
                 if (GroupViewModels.Current.TryGetGroupVm(coinGroupVm.GroupId, out groupVm)) {
                     groupVm.OnPropertyChanged(nameof(groupVm.CoinVms));
                     groupVm.OnPropertyChanged(nameof(groupVm.DualCoinVms));
                     groupVm.OnPropertyChanged(nameof(groupVm.CoinGroupVms));
                 }
             }
         });
     Global.Access<CoinGroupUpdatedEvent>(
         Guid.Parse("c600d33a-21e3-45ad-b9b3-cfd5578885f4"),
         "更新了币组后调整VM内存",
         LogEnum.Log,
         action: (message) => {
             if (_dicById.ContainsKey(message.Source.GetId())) {
                 CoinGroupViewModel entity = _dicById[message.Source.GetId()];
                 int sortNumber = entity.SortNumber;
                 entity.Update(message.Source);
                 if (sortNumber != entity.SortNumber) {
                     GroupViewModel groupVm;
                     if (GroupViewModels.Current.TryGetGroupVm(entity.GroupId, out groupVm)) {
                         groupVm.OnPropertyChanged(nameof(groupVm.CoinGroupVms));
                     }
                 }
             }
         });
     Global.Access<CoinGroupRemovedEvent>(
         Guid.Parse("76842ab6-c1a3-4eee-b951-f25be25ec35a"),
         "删除了币组后调整VM内存",
         LogEnum.Log,
         action: (message) => {
             if (_dicById.ContainsKey(message.Source.GetId())) {
                 var entity = _dicById[message.Source.GetId()];
                 _dicById.Remove(message.Source.GetId());
                 if (_listByGroupId.ContainsKey(entity.GroupId)) {
                     _listByGroupId[entity.GroupId].Remove(entity);
                 }
                 GroupViewModel groupVm;
                 if (GroupViewModels.Current.TryGetGroupVm(entity.GroupId, out groupVm)) {
                     groupVm.OnPropertyChanged(nameof(groupVm.CoinVms));
                     groupVm.OnPropertyChanged(nameof(groupVm.DualCoinVms));
                     groupVm.OnPropertyChanged(nameof(groupVm.CoinGroupVms));
                 }
             }
         });
 }
 private KernelOutputTranslaterViewModels()
 {
     foreach (var item in NTMinerRoot.Current.KernelOutputTranslaterSet)
     {
         if (!_dicByKernelId.ContainsKey(item.KernelId))
         {
             _dicByKernelId.Add(item.KernelId, new List <KernelOutputTranslaterViewModel>());
         }
         var vm = new KernelOutputTranslaterViewModel(item);
         _dicByKernelId[item.KernelId].Add(vm);
         _dicById.Add(item.GetId(), vm);
     }
     Global.Access <KernelOutputTranslaterAddedEvent>(
         Guid.Parse("70f5bc18-3536-4306-9af7-256f323c9313"),
         "添加了内核输出翻译器后刷新VM内存",
         LogEnum.None,
         action: message => {
         KernelViewModel kernelVm;
         if (KernelViewModels.Current.TryGetKernelVm(message.Source.KernelId, out kernelVm))
         {
             if (!_dicByKernelId.ContainsKey(message.Source.KernelId))
             {
                 _dicByKernelId.Add(message.Source.KernelId, new List <KernelOutputTranslaterViewModel>());
             }
             var vm = new KernelOutputTranslaterViewModel(message.Source);
             _dicByKernelId[message.Source.KernelId].Add(vm);
             _dicById.Add(message.Source.GetId(), vm);
             kernelVm.OnPropertyChanged(nameof(kernelVm.KernelOutputTranslaters));
         }
     });
     Global.Access <KernelOutputTranslaterUpdatedEvent>(
         Guid.Parse("eef26e4b-af61-436b-9f24-9e128d614598"),
         "更新了内核输出翻译器后刷新VM内存",
         LogEnum.None,
         action: message => {
         if (_dicByKernelId.ContainsKey(message.Source.KernelId))
         {
             var item = _dicByKernelId[message.Source.KernelId].FirstOrDefault(a => a.Id == message.Source.GetId());
             if (item != null)
             {
                 item.Update(message.Source);
             }
         }
     });
     Global.Access <KernelOutputTranslaterRemovedEvent>(
         Guid.Parse("d77c3aaa-be1f-41b2-9e9f-495fa6a076bf"),
         "移除了内核输出翻译器后刷新VM内存",
         LogEnum.None,
         action: message => {
         if (_dicByKernelId.ContainsKey(message.Source.KernelId))
         {
             var item = _dicByKernelId[message.Source.KernelId].FirstOrDefault(a => a.Id == message.Source.GetId());
             if (item != null)
             {
                 _dicByKernelId[message.Source.KernelId].Remove(item);
             }
         }
         if (_dicById.ContainsKey(message.Source.GetId()))
         {
             _dicById.Remove(message.Source.GetId());
         }
         KernelViewModel kernelVm;
         if (KernelViewModels.Current.TryGetKernelVm(message.Source.KernelId, out kernelVm))
         {
             kernelVm.OnPropertyChanged(nameof(kernelVm.KernelOutputTranslaters));
         }
     });
 }
Example #5
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));
         });
     });
     Global.Logger.InfoDebugLine(this.GetType().FullName + "接入总线");
 }
Example #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 + "接入总线");
        }
 private CoinKernelViewModels()
 {
     Global.Access <CoinKernelAddedEvent>(
         Guid.Parse("b3d7280d-3107-4730-a111-f34dd5cf4ede"),
         "添加了币种内核后刷新VM内存",
         LogEnum.Log, action: (message) => {
         var coinKernelVm = new CoinKernelViewModel(message.Source);
         _dicById.Add(message.Source.GetId(), coinKernelVm);
         OnPropertyChanged(nameof(AllCoinKernels));
         CoinViewModel coinVm;
         if (CoinViewModels.Current.TryGetCoinVm(message.Source.CoinId, out coinVm))
         {
             coinVm.OnPropertyChanged(nameof(CoinViewModel.CoinKernel));
             coinVm.OnPropertyChanged(nameof(CoinViewModel.CoinKernels));
             coinVm.OnPropertyChanged(nameof(CoinViewModel.IsSupported));
         }
         coinKernelVm.Kernel.OnPropertyChanged(nameof(coinKernelVm.Kernel.IsSupported));
         coinKernelVm.Kernel.OnPropertyChanged(nameof(coinKernelVm.Kernel.IsNvidiaIconVisible));
         coinKernelVm.Kernel.OnPropertyChanged(nameof(coinKernelVm.Kernel.IsAMDIconVisible));
         coinKernelVm.Kernel.OnPropertyChanged(nameof(coinKernelVm.Kernel.CoinKernels));
         coinKernelVm.Kernel.OnPropertyChanged(nameof(coinKernelVm.Kernel.CoinVms));
         coinKernelVm.Kernel.OnPropertyChanged(nameof(coinKernelVm.Kernel.SupportedCoinVms));
         coinKernelVm.Kernel.OnPropertyChanged(nameof(coinKernelVm.Kernel.SupportedCoins));
     });
     Global.Access <CoinKernelUpdatedEvent>(
         Guid.Parse("48afedd3-5005-46a2-ae23-3f6f99a77683"),
         "更新了币种内核后刷新VM内存",
         LogEnum.Log,
         action: (message) => {
         CoinKernelViewModel entity = _dicById[message.Source.GetId()];
         var supportedGpu           = entity.SupportedGpu;
         Guid dualCoinGroupId       = entity.DualCoinGroupId;
         entity.Update(message.Source);
         if (supportedGpu != entity.SupportedGpu)
         {
             var coinKernels = AllCoinKernels.Where(a => a.KernelId == entity.Id);
             foreach (var coinKernel in coinKernels)
             {
                 CoinViewModel coinVm;
                 if (CoinViewModels.Current.TryGetCoinVm(coinKernel.CoinId, out coinVm))
                 {
                     coinVm.OnPropertyChanged(nameof(coinVm.IsSupported));
                     coinVm.OnPropertyChanged(nameof(coinVm.CoinKernels));
                 }
                 coinKernel.Kernel.OnPropertyChanged(nameof(coinKernel.Kernel.IsSupported));
             }
             entity.Kernel.OnPropertyChanged(nameof(entity.Kernel.IsNvidiaIconVisible));
             entity.Kernel.OnPropertyChanged(nameof(entity.Kernel.IsAMDIconVisible));
             entity.Kernel.OnPropertyChanged(nameof(entity.Kernel.CoinKernels));
         }
         if (dualCoinGroupId != entity.DualCoinGroupId)
         {
             entity.OnPropertyChanged(nameof(entity.DualCoinGroup));
         }
     });
     Global.Access <CoinKernelRemovedEvent>(
         Guid.Parse("0a2937bc-bb9c-4369-92b1-3c41eeb170ce"),
         "移除了币种内核后刷新VM内存",
         LogEnum.Log,
         action: (message) => {
         var coinKernelVm = _dicById[message.Source.GetId()];
         _dicById.Remove(message.Source.GetId());
         OnPropertyChanged(nameof(AllCoinKernels));
         CoinViewModel coinVm;
         if (CoinViewModels.Current.TryGetCoinVm(message.Source.CoinId, out coinVm))
         {
             coinVm.OnPropertyChanged(nameof(CoinViewModel.CoinKernel));
             coinVm.OnPropertyChanged(nameof(CoinViewModel.CoinKernels));
             coinVm.OnPropertyChanged(nameof(CoinViewModel.IsSupported));
         }
         coinKernelVm.Kernel.OnPropertyChanged(nameof(coinKernelVm.Kernel.IsSupported));
         coinKernelVm.Kernel.OnPropertyChanged(nameof(coinKernelVm.Kernel.IsNvidiaIconVisible));
         coinKernelVm.Kernel.OnPropertyChanged(nameof(coinKernelVm.Kernel.IsAMDIconVisible));
         coinKernelVm.Kernel.OnPropertyChanged(nameof(coinKernelVm.Kernel.CoinKernels));
         coinKernelVm.Kernel.OnPropertyChanged(nameof(coinKernelVm.Kernel.CoinVms));
         coinKernelVm.Kernel.OnPropertyChanged(nameof(coinKernelVm.Kernel.SupportedCoinVms));
         coinKernelVm.Kernel.OnPropertyChanged(nameof(coinKernelVm.Kernel.SupportedCoins));
     });
     foreach (var item in NTMinerRoot.Current.CoinKernelSet)
     {
         _dicById.Add(item.GetId(), new CoinKernelViewModel(item));
     }
 }
Example #8
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 + "接入总线");
        }
Example #9
0
        private LangViewItemSet()
        {
            Global.Access <AddLangViewItemCommand>(
                Guid.Parse("07AC4BE6-AB09-48D2-A3D7-8653EE52CC43"),
                "处理添加语言项命令",
                LogEnum.None,
                action: message => {
                if (_dicById.ContainsKey(message.Input.GetId()))
                {
                    return;
                }
                ILang lang;
                if (LangSet.Instance.TryGetLang(message.Input.LangId, out lang))
                {
                    if (!_dicByLangAndView.ContainsKey(message.Input.LangId))
                    {
                        _dicByLangAndView.Add(message.Input.LangId, new Dictionary <string, List <ILangViewItem> >());
                    }
                    var dic = _dicByLangAndView[message.Input.LangId];
                    if (!dic.ContainsKey(message.Input.ViewId))
                    {
                        dic.Add(message.Input.ViewId, new List <ILangViewItem>());
                    }
                    var entity = new LangViewItem().Update(message.Input);
                    dic[message.Input.ViewId].Add(entity);
                    _dicById.Add(message.Input.GetId(), entity);
                    var repository = Repository.CreateLanguageRepository <LangViewItem>();
                    repository.Add(entity);

                    Global.Happened(new LangViewItemAddedEvent(entity));
                }
            });
            Global.Access <UpdateLangViewItemCommand>(
                Guid.Parse("CEC2EFC5-4F92-4226-ADCE-BE36D8968B9E"),
                "处理修改语言项命令",
                LogEnum.None,
                action: message => {
                if (_dicById.ContainsKey(message.Input.GetId()))
                {
                    var entity = _dicById[message.Input.GetId()];
                    entity.Update(message.Input);
                    var repository = Repository.CreateLanguageRepository <LangViewItem>();
                    repository.Update(entity);

                    Global.Happened(new LangViewItemUpdatedEvent(entity));
                }
            });
            Global.Access <RemoveLangViewItemCommand>(
                Guid.Parse("3827E59B-872D-45E6-8512-7EC22E1BE6E3"),
                "处理删除语言项命令",
                LogEnum.None,
                action: message => {
                if (_dicById.ContainsKey(message.EntityId))
                {
                    var entity = _dicById[message.EntityId];
                    _dicById.Remove(message.EntityId);
                    ILang lang;
                    if (LangSet.Instance.TryGetLang(entity.LangId, out lang))
                    {
                        if (_dicByLangAndView.ContainsKey(entity.LangId))
                        {
                            var dic = _dicByLangAndView[entity.LangId];
                            if (dic.ContainsKey(entity.ViewId) && dic[entity.ViewId].Contains(entity))
                            {
                                dic[entity.ViewId].Remove(entity);
                                if (dic[entity.ViewId].Count == 0)
                                {
                                    dic.Remove(entity.ViewId);
                                }
                            }
                            if (_dicByLangAndView.Count == 0)
                            {
                                _dicByLangAndView.Remove(entity.LangId);
                            }
                        }
                    }
                    var repository = Repository.CreateLanguageRepository <LangViewItem>();
                    repository.Remove(entity.Id);

                    Global.Happened(new LangViewItemRemovedEvent(entity));
                }
            });
        }
Example #10
0
        private GpuSpeedViewModels()
        {
            if (Design.IsInDesignMode)
            {
                return;
            }
            this.GpuAllVm = GpuViewModels.Current.FirstOrDefault(a => a.Index == NTMinerRoot.GpuAllId);
            IGpusSpeed gpuSpeeds = NTMinerRoot.Current.GpusSpeed;

            foreach (var item in gpuSpeeds)
            {
                this._list.Add(new GpuSpeedViewModel(item));
            }
            _totalSpeedVm = this._list.FirstOrDefault(a => a.GpuVm.Index == NTMinerRoot.GpuAllId);
            Global.Access <GpuSpeedChangedEvent>(
                Guid.Parse("acb2e5fd-a3ed-4ed6-b8c7-583eafd5e579"),
                "显卡算力变更后刷新VM内存",
                LogEnum.None,
                action: (message) => {
                Guid mainCoinId = NTMinerRoot.Current.MinerProfile.CoinId;
                if (_mainCoinId != mainCoinId)
                {
                    _mainCoinId  = mainCoinId;
                    DateTime now = DateTime.Now;
                    foreach (var item in _list)
                    {
                        item.MainCoinSpeed.Value   = 0;
                        item.MainCoinSpeed.SpeedOn = now;
                        item.DualCoinSpeed.Value   = 0;
                        item.DualCoinSpeed.SpeedOn = now;
                    }
                    IncomeMainCoinPerDay = 0;
                    IncomeDualCoinPerDay = 0;
                }
                int index = message.Source.Gpu.Index;
                GpuSpeedViewModel gpuSpeedVm = _list.FirstOrDefault(a => a.GpuVm.Index == index);
                if (gpuSpeedVm != null)
                {
                    if (message.IsDualSpeed)
                    {
                        gpuSpeedVm.DualCoinSpeed.Update(message.Source.DualCoinSpeed);
                    }
                    else
                    {
                        gpuSpeedVm.MainCoinSpeed.Update(message.Source.MainCoinSpeed);
                    }
                }
                if (index == _totalSpeedVm.GpuVm.Index)
                {
                    IMineContext mineContext = NTMinerRoot.Current.CurrentMineContext;
                    if (mineContext == null)
                    {
                        IncomeMainCoinPerDay = 0;
                        IncomeDualCoinPerDay = 0;
                    }
                    else
                    {
                        if (message.IsDualSpeed)
                        {
                            if (mineContext is IDualMineContext dualMineContext)
                            {
                                IncomeDualCoinPerDay = _totalSpeedVm.DualCoinSpeed.Value * NTMinerRoot.Current.CalcConfigSet.GetIncomePerHashPerDay(dualMineContext.DualCoin);
                            }
                        }
                        else
                        {
                            IncomeMainCoinPerDay = _totalSpeedVm.MainCoinSpeed.Value * NTMinerRoot.Current.CalcConfigSet.GetIncomePerHashPerDay(mineContext.MainCoin);
                        }
                    }
                }
            });
        }
Example #11
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 + "接入总线");
        }
Example #12
0
        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));
            });
            Global.Logger.InfoDebugLine(this.GetType().FullName + "接入总线");
        }
Example #13
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 + "接入总线");
        }
Example #14
0
        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 + "接入总线");
        }
Example #15
0
 private LangViewItemViewModels()
 {
     Global.Access <LangViewItemAddedEvent>(
         Guid.Parse("60FD738F-F260-4EF2-A60A-66B04EC6B243"),
         "添加了语言项后刷新VM内存",
         LogEnum.None,
         action: message => {
         if (_dicById.ContainsKey(message.Source.GetId()))
         {
             return;
         }
         LangViewModel langVm;
         if (LangViewModels.Current.TryGetLangVm(message.Source.LangId, out langVm))
         {
             Dictionary <string, List <LangViewItemViewModel> > dic = null;
             if (!_dicByLangAndView.ContainsKey(langVm))
             {
                 dic = new Dictionary <string, List <LangViewItemViewModel> >();
                 _dicByLangAndView.Add(langVm, dic);
             }
             else
             {
                 dic = _dicByLangAndView[langVm];
             }
             if (!dic.ContainsKey(message.Source.ViewId))
             {
                 dic.Add(message.Source.ViewId, new List <LangViewItemViewModel>());
             }
             var entity = new LangViewItemViewModel(message.Source);
             dic[message.Source.ViewId].Add(entity);
             _dicById.Add(entity.Id, entity);
         }
     });
     Global.Access <LangViewItemUpdatedEvent>(
         Guid.Parse("A4DCFEE0-FA36-4D84-9D98-0D4455BE1EA7"),
         "更新了语言项后刷新VM内存",
         LogEnum.None,
         action: message => {
         LangViewItemViewModel langItemVm;
         if (_dicById.TryGetValue(message.Source.GetId(), out langItemVm))
         {
             langItemVm.Update(message.Source);
         }
     });
     Global.Access <LangViewItemRemovedEvent>(
         Guid.Parse("4AA8EA72-7BD9-45D8-B798-EF505C665572"),
         "删除了语言项后刷新VM内存",
         LogEnum.None,
         action: message => {
         LangViewItemViewModel langItemVm;
         if (_dicById.TryGetValue(message.Source.GetId(), out langItemVm))
         {
             _dicById.Remove(langItemVm.Id);
             LangViewModel langVm;
             if (LangViewModels.Current.TryGetLangVm(langItemVm.LangId, out langVm))
             {
                 if (_dicByLangAndView.ContainsKey(langVm) && _dicByLangAndView[langVm].ContainsKey(langItemVm.ViewId))
                 {
                     _dicByLangAndView[langVm][langItemVm.ViewId].Remove(langItemVm);
                     if (_dicByLangAndView[langVm][langItemVm.ViewId].Count == 0)
                     {
                         _dicByLangAndView[langVm].Remove(langItemVm.ViewId);
                         if (_dicByLangAndView[langVm].Count == 0)
                         {
                             _dicByLangAndView.Remove(langVm);
                         }
                     }
                 }
             }
         }
     });
     foreach (var lang in LangViewModels.Current.LangVms)
     {
         var dic = new Dictionary <string, List <LangViewItemViewModel> >();
         _dicByLangAndView.Add(lang, dic);
         foreach (var item in LangViewItemSet.Instance.GetLangItems(lang.Id))
         {
             if (!dic.ContainsKey(item.Key))
             {
                 List <LangViewItemViewModel> list = item.Value.Select(a => new LangViewItemViewModel(a)).ToList();
                 dic.Add(item.Key, list);
                 foreach (var langViewItemVm in list)
                 {
                     _dicById.Add(langViewItemVm.Id, langViewItemVm);
                 }
             }
         }
     }
 }
Example #16
0
        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 + "接入总线");
        }
Example #17
0
        public KernelInputSet(INTMinerRoot root)
        {
            _root = root;
            Global.Access <AddKernelInputCommand>(
                Guid.Parse("62D0B345-26F8-42BA-B7CD-E547C2B298C9"),
                "添加内核输入组",
                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;
                }
                KernelInputData entity = new KernelInputData().Update(message.Input);
                _dicById.Add(entity.Id, entity);
                var repository = NTMinerRoot.CreateServerRepository <KernelInputData>();
                repository.Add(entity);

                Global.Happened(new KernelInputAddedEvent(entity));
            });
            Global.Access <UpdateKernelInputCommand>(
                Guid.Parse("FED12C08-7BD7-4A8E-BD0B-A19075F4E8C4"),
                "更新内核输入组",
                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("KernelInput name can't be null or empty");
                }
                if (!_dicById.ContainsKey(message.Input.GetId()))
                {
                    return;
                }
                KernelInputData entity = _dicById[message.Input.GetId()];
                entity.Update(message.Input);
                var repository = NTMinerRoot.CreateServerRepository <KernelInputData>();
                repository.Update(entity);

                Global.Happened(new KernelInputUpdatedEvent(entity));
            });
            Global.Access <RemoveKernelInputCommand>(
                Guid.Parse("2227F6B9-5A2A-42AB-8147-05E245E2872F"),
                "移除内核输入组",
                LogEnum.Log,
                action: (message) => {
                InitOnece();
                if (message == null || message.EntityId == Guid.Empty)
                {
                    throw new ArgumentNullException();
                }
                if (!_dicById.ContainsKey(message.EntityId))
                {
                    return;
                }
                KernelInputData entity = _dicById[message.EntityId];
                _dicById.Remove(entity.GetId());
                var repository = NTMinerRoot.CreateServerRepository <KernelInputData>();
                repository.Remove(message.EntityId);

                Global.Happened(new KernelInputRemovedEvent(entity));
            });
            Global.Logger.InfoDebugLine(this.GetType().FullName + "接入总线");
        }
Example #18
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 + "接入总线");
        }
Example #19
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 + "接入总线");
        }
Example #20
0
 private CoinViewModels()
 {
     if (Design.IsInDesignMode)
     {
         return;
     }
     Global.Access <CoinAddedEvent>(
         Guid.Parse("1ee6e72d-d98f-42ab-8732-dcee2e42f4b8"),
         "添加了币种后刷新VM内存",
         LogEnum.Log,
         action: (message) => {
         _dicById.Add(message.Source.GetId(), new CoinViewModel(message.Source));
         MinerProfileViewModel.Current.OnPropertyChanged(nameof(MinerProfileViewModel.Current.CoinVm));
         OnPropertyChanged(nameof(AllCoins));
         OnPropertyChanged(nameof(MainCoins));
         CoinPageViewModel.Current.OnPropertyChanged(nameof(CoinPageViewModel.List));
         OnPropertyChanged(nameof(PleaseSelect));
         OnPropertyChanged(nameof(DualPleaseSelect));
     });
     Global.Access <CoinRemovedEvent>(
         Guid.Parse("6c966862-6dfa-4473-94b5-1133a16180a1"),
         "移除了币种后刷新VM内存",
         LogEnum.Log,
         action: message => {
         _dicById.Remove(message.Source.GetId());
         MinerProfileViewModel.Current.OnPropertyChanged(nameof(MinerProfileViewModel.Current.CoinVm));
         OnPropertyChanged(nameof(AllCoins));
         OnPropertyChanged(nameof(MainCoins));
         CoinPageViewModel.Current.OnPropertyChanged(nameof(CoinPageViewModel.List));
         OnPropertyChanged(nameof(PleaseSelect));
         OnPropertyChanged(nameof(DualPleaseSelect));
     });
     Global.Access <CoinUpdatedEvent>(
         Guid.Parse("114c90e5-6a0a-4aa4-9ba8-5ed603286c51"),
         "更新了币种后刷新VM内存",
         LogEnum.Log,
         action: message => {
         CoinViewModel coinVm = _dicById[message.Source.GetId()];
         bool justAsDualCoin  = coinVm.JustAsDualCoin;
         coinVm.Update(message.Source);
         coinVm.TestWalletVm.Address = message.Source.TestWallet;
         coinVm.OnPropertyChanged(nameof(coinVm.Wallets));
         coinVm.OnPropertyChanged(nameof(coinVm.WalletItems));
         if (MinerProfileViewModel.Current.CoinId == message.Source.GetId())
         {
             MinerProfileViewModel.Current.OnPropertyChanged(nameof(MinerProfileViewModel.Current.CoinVm));
         }
         CoinKernelViewModel coinKernelVm = MinerProfileViewModel.Current.CoinVm.CoinKernel;
         if (coinKernelVm != null &&
             coinKernelVm.CoinKernelProfile.SelectedDualCoin != null &&
             coinKernelVm.CoinKernelProfile.SelectedDualCoin.GetId() == message.Source.GetId())
         {
             coinKernelVm.CoinKernelProfile.OnPropertyChanged(nameof(coinKernelVm.CoinKernelProfile.SelectedDualCoin));
         }
         if (justAsDualCoin != coinVm.JustAsDualCoin)
         {
             OnPropertyChanged(nameof(MainCoins));
         }
     });
     foreach (var item in NTMinerRoot.Current.CoinSet)
     {
         _dicById.Add(item.GetId(), new CoinViewModel(item));
     }
 }
Example #21
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 + "接入总线");
        }
Example #22
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 + "接入总线");
        }
Example #23
0
        public SpeedCharts()
        {
            InitializeComponent();
            ResourceDictionarySet.Instance.FillResourceDic(this, this.Resources);

            if (Design.IsInDesignMode)
            {
                return;
            }
            Guid mainCoinId = NTMinerRoot.Current.MinerProfile.CoinId;
            DelegateHandler <GpuSpeedChangedEvent> gpuSpeedChangedEventHandler = Global.Access <GpuSpeedChangedEvent>(
                Guid.Parse("2cb8adb2-1e7e-433e-8904-ae71d9563c20"),
                "显卡算力变更后刷新算力图界面",
                LogEnum.None,
                action: (message) => {
                Execute.OnUIThread(() => {
                    if (mainCoinId != NTMinerRoot.Current.MinerProfile.CoinId)
                    {
                        mainCoinId = NTMinerRoot.Current.MinerProfile.CoinId;
                        foreach (var speedChartVm in Vm.SpeedChartVms)
                        {
                            SeriesCollection series       = speedChartVm.Series;
                            SeriesCollection seriesShadow = speedChartVm.SeriesShadow;
                            foreach (var item in series)
                            {
                                item.Values.Clear();
                            }
                            foreach (var item in seriesShadow)
                            {
                                item.Values.Clear();
                            }
                        }
                    }
                    IGpuSpeed gpuSpeed = message.Source;
                    int index          = gpuSpeed.Gpu.Index;
                    if (Vm.SpeedChartVms.ContainsKey(index))
                    {
                        SpeedChartViewModel speedChartVm = Vm.SpeedChartVms[index];
                        SeriesCollection series          = speedChartVm.Series;
                        SeriesCollection seriesShadow    = speedChartVm.SeriesShadow;
                        DateTime now = DateTime.Now;
                        if (gpuSpeed.MainCoinSpeed != null && series.Count > 0)
                        {
                            IChartValues chartValues = series[0].Values;
                            chartValues.Add(new MeasureModel()
                            {
                                DateTime = gpuSpeed.MainCoinSpeed.SpeedOn,
                                Value    = gpuSpeed.MainCoinSpeed.Value
                            });
                            if (((MeasureModel)chartValues[0]).DateTime.AddMinutes(NTMinerRoot.Current.SpeedHistoryLengthByMinute) < now)
                            {
                                chartValues.RemoveAt(0);
                            }
                            chartValues = seriesShadow[0].Values;
                            chartValues.Add(new MeasureModel()
                            {
                                DateTime = gpuSpeed.MainCoinSpeed.SpeedOn,
                                Value    = gpuSpeed.MainCoinSpeed.Value
                            });
                            if (((MeasureModel)chartValues[0]).DateTime.AddMinutes(NTMinerRoot.Current.SpeedHistoryLengthByMinute) < now)
                            {
                                chartValues.RemoveAt(0);
                            }
                        }
                        if (gpuSpeed.DualCoinSpeed != null && series.Count > 1)
                        {
                            IChartValues chartValues = series[1].Values;
                            chartValues.Add(new MeasureModel()
                            {
                                DateTime = gpuSpeed.DualCoinSpeed.SpeedOn,
                                Value    = gpuSpeed.DualCoinSpeed.Value
                            });
                            if (((MeasureModel)chartValues[0]).DateTime.AddMinutes(NTMinerRoot.Current.SpeedHistoryLengthByMinute) < now)
                            {
                                chartValues.RemoveAt(0);
                            }
                            chartValues = seriesShadow[1].Values;
                            chartValues.Add(new MeasureModel()
                            {
                                DateTime = gpuSpeed.DualCoinSpeed.SpeedOn,
                                Value    = gpuSpeed.DualCoinSpeed.Value
                            });
                            if (((MeasureModel)chartValues[0]).DateTime.AddMinutes(NTMinerRoot.Current.SpeedHistoryLengthByMinute) < now)
                            {
                                chartValues.RemoveAt(0);
                            }
                        }

                        speedChartVm.SetAxisLimits(now);
                    }
                });
            });

            Vm.ItemsPanelColumns = 1;
            this.Unloaded       += (object sender, RoutedEventArgs e) => {
                Global.UnAccess(gpuSpeedChangedEventHandler);
                foreach (var item in Vm.SpeedChartVms)
                {
                    item.Series       = null;
                    item.SeriesShadow = null;
                    item.AxisX        = null;
                    item.AxisY        = null;
                    item.AxisXShadow  = null;
                    item.AxisYShadow  = null;
                }
                _chartDic.Clear();
            };
            SolidColorBrush White = new SolidColorBrush(Colors.White);

            Vm.PropertyChanged += (object sender, System.ComponentModel.PropertyChangedEventArgs e) => {
                if (e.PropertyName == nameof(Vm.CurrentSpeedChartVm))
                {
                    SpeedChartViewModel currentItem = Vm.CurrentSpeedChartVm;
                    if (currentItem != null)
                    {
                        foreach (var item in _chartDic.Values)
                        {
                            item.Visibility = Visibility.Collapsed;
                        }
                        CartesianChart chart;
                        if (!_chartDic.ContainsKey(currentItem))
                        {
                            chart = new CartesianChart()
                            {
                                DisableAnimations = true,
                                Hoverable         = false,
                                DataTooltip       = null,
                                Background        = White,
                                Padding           = new Thickness(4, 0, 0, 0),
                                Visibility        = Visibility.Visible
                            };
                            chart.Series = currentItem.SeriesShadow;
                            chart.AxisX  = currentItem.AxisXShadow;
                            chart.AxisY  = currentItem.AxisYShadow;
                            _chartDic.Add(currentItem, chart);
                            DetailsGrid.Children.Add(chart);
                        }
                        else
                        {
                            chart            = _chartDic[currentItem];
                            chart.Visibility = Visibility.Visible;
                        }
                    }
                }
            };

            Vm.SetCurrentSpeedChartVm(Vm.SpeedChartVms.FirstOrDefault());

            if (MinerProfileViewModel.Current.CoinVm != null)
            {
                Guid coinId = MinerProfileViewModel.Current.CoinId;
                foreach (var item in NTMinerRoot.Current.GpuSet)
                {
                    List <IGpuSpeed>    gpuSpeedHistory = item.GetGpuSpeedHistory();
                    SpeedChartViewModel speedChartVm    = Vm.SpeedChartVms[item.Index];
                    SeriesCollection    series          = speedChartVm.Series;
                    SeriesCollection    seriesShadow    = speedChartVm.SeriesShadow;
                    DateTime            now             = DateTime.Now;
                    foreach (var gpuSpeed in gpuSpeedHistory)
                    {
                        if (gpuSpeed.MainCoinSpeed != null && series.Count > 0)
                        {
                            series[0].Values.Add(new MeasureModel()
                            {
                                DateTime = gpuSpeed.MainCoinSpeed.SpeedOn,
                                Value    = gpuSpeed.MainCoinSpeed.Value
                            });
                            seriesShadow[0].Values.Add(new MeasureModel()
                            {
                                DateTime = gpuSpeed.MainCoinSpeed.SpeedOn,
                                Value    = gpuSpeed.MainCoinSpeed.Value
                            });
                        }
                        if (gpuSpeed.DualCoinSpeed != null && series.Count > 1)
                        {
                            series[0].Values.Add(new MeasureModel()
                            {
                                DateTime = gpuSpeed.DualCoinSpeed.SpeedOn,
                                Value    = gpuSpeed.DualCoinSpeed.Value
                            });
                            seriesShadow[0].Values.Add(new MeasureModel()
                            {
                                DateTime = gpuSpeed.DualCoinSpeed.SpeedOn,
                                Value    = gpuSpeed.DualCoinSpeed.Value
                            });
                        }
                    }
                    IChartValues values = series[0].Values;
                    if (values.Count > 0 && ((MeasureModel)values[0]).DateTime.AddMinutes(NTMinerRoot.Current.SpeedHistoryLengthByMinute) < now)
                    {
                        series[0].Values.RemoveAt(0);
                    }
                    values = seriesShadow[0].Values;
                    if (values.Count > 0 && ((MeasureModel)values[0]).DateTime.AddMinutes(NTMinerRoot.Current.SpeedHistoryLengthByMinute) < now)
                    {
                        seriesShadow[0].Values.RemoveAt(0);
                    }
                    speedChartVm.SetAxisLimits(now);
                }
            }
        }
Example #24
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));
            });
            Global.Logger.InfoDebugLine(this.GetType().FullName + "接入总线");
        }
Example #25
0
        public KernelOutputSet(INTMinerRoot root)
        {
            _root = root;
            Global.Access <AddKernelOutputCommand>(
                Guid.Parse("142AE86A-C264-40B2-A617-D65E33C7FEE2"),
                "添加内核输出组",
                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;
                }
                KernelOutputData entity = new KernelOutputData().Update(message.Input);
                _dicById.Add(entity.Id, entity);
                var repository = NTMinerRoot.CreateServerRepository <KernelOutputData>();
                repository.Add(entity);

                Global.Happened(new KernelOutputAddedEvent(entity));
            });
            Global.Access <UpdateKernelOutputCommand>(
                Guid.Parse("2A3CAE7E-D0E2-4E4B-B75B-357EB0BE1AA1"),
                "更新内核输出组",
                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("KernelOutput name can't be null or empty");
                }
                if (!_dicById.ContainsKey(message.Input.GetId()))
                {
                    return;
                }
                KernelOutputData entity = _dicById[message.Input.GetId()];
                entity.Update(message.Input);
                var repository = NTMinerRoot.CreateServerRepository <KernelOutputData>();
                repository.Update(entity);

                Global.Happened(new KernelOutputUpdatedEvent(entity));
            });
            Global.Access <RemoveKernelOutputCommand>(
                Guid.Parse("43B565B4-1509-4DC6-9FA4-55D49C79C60A"),
                "移除内核输出组",
                LogEnum.Log,
                action: (message) => {
                InitOnece();
                if (message == null || message.EntityId == Guid.Empty)
                {
                    throw new ArgumentNullException();
                }
                if (!_dicById.ContainsKey(message.EntityId))
                {
                    return;
                }
                IKernel[] outputUsers = root.KernelSet.Where(a => a.KernelOutputId == message.EntityId).ToArray();
                if (outputUsers.Length != 0)
                {
                    throw new ValidationException($"这些内核在使用该内核输出组,删除前请先解除使用:{string.Join(",", outputUsers.Select(a => a.FullName))}");
                }
                KernelOutputData entity               = _dicById[message.EntityId];
                List <Guid> kernelOutputFilterIds     = root.KernelOutputFilterSet.Where(a => a.KernelOutputId == entity.Id).Select(a => a.GetId()).ToList();
                List <Guid> kernelOutputTranslaterIds = root.KernelOutputTranslaterSet.Where(a => a.KernelOutputId == entity.Id).Select(a => a.GetId()).ToList();
                foreach (var kernelOutputFilterId in kernelOutputFilterIds)
                {
                    Global.Execute(new RemoveKernelOutputFilterCommand(kernelOutputFilterId));
                }
                foreach (var kernelOutputTranslaterId in kernelOutputTranslaterIds)
                {
                    Global.Execute(new RemoveKernelOutputTranslaterCommand(kernelOutputTranslaterId));
                }
                _dicById.Remove(entity.GetId());
                var repository = NTMinerRoot.CreateServerRepository <KernelOutputData>();
                repository.Remove(message.EntityId);

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