Ejemplo n.º 1
0
 private CoinKernelViewModels()
 {
     if (WpfUtil.IsInDesignMode)
     {
         return;
     }
     VirtualRoot.BuildEventPath <ServerContextReInitedEvent>("刷新VM内存", LogEnum.DevConsole,
                                                             path: message => {
         _dicById.Clear();
         Init();
     }, location: this.GetType());
     VirtualRoot.BuildEventPath <ServerContextReInitedEventHandledEvent>("刷新视图界面", LogEnum.DevConsole,
                                                                         path: message => {
         OnPropertyChanged(nameof(AllCoinKernels));
     }, location: this.GetType());
     BuildEventPath <CoinKernelAddedEvent>("刷新VM内存", LogEnum.DevConsole,
                                           path: (message) => {
         var coinKernelVm = new CoinKernelViewModel(message.Source);
         _dicById.Add(message.Source.GetId(), coinKernelVm);
         OnPropertyChanged(nameof(AllCoinKernels));
         var kernelVm = coinKernelVm.Kernel;
         if (kernelVm != null)
         {
             kernelVm.OnPropertyChanged(nameof(kernelVm.CoinKernels));
             kernelVm.OnPropertyChanged(nameof(kernelVm.CoinVms));
             kernelVm.OnPropertyChanged(nameof(kernelVm.SupportedCoinVms));
             kernelVm.OnPropertyChanged(nameof(kernelVm.SupportedCoins));
         }
         VirtualRoot.RaiseEvent(new CoinKernelVmAddedEvent(message));
     }, location: this.GetType());
     BuildEventPath <CoinKernelUpdatedEvent>("刷新VM内存", LogEnum.DevConsole,
                                             path: (message) => {
         if (_dicById.TryGetValue(message.Source.GetId(), out CoinKernelViewModel vm))
         {
             var supportedGpu     = vm.SupportedGpu;
             Guid dualCoinGroupId = vm.DualCoinGroupId;
             vm.Update(message.Source);
             if (supportedGpu != vm.SupportedGpu)
             {
                 var coinKernels = AllCoinKernels.Where(a => a.KernelId == vm.Id);
                 foreach (var coinKernel in coinKernels)
                 {
                     if (CoinVms.TryGetCoinVm(coinKernel.CoinId, out CoinViewModel coinVm))
                     {
                         coinVm.OnPropertyChanged(nameof(coinVm.IsSupported));
                         coinVm.OnPropertyChanged(nameof(coinVm.CoinKernels));
                     }
                 }
                 var kernelVm = vm.Kernel;
                 kernelVm.OnPropertyChanged(nameof(kernelVm.CoinKernels));
             }
         }
     }, location: this.GetType());
     BuildEventPath <CoinKernelRemovedEvent>("刷新VM内存", LogEnum.DevConsole,
                                             path: (message) => {
         if (_dicById.TryGetValue(message.Source.GetId(), out CoinKernelViewModel coinKernelVm))
         {
             _dicById.Remove(message.Source.GetId());
             OnPropertyChanged(nameof(AllCoinKernels));
             var kernelVm = coinKernelVm.Kernel;
             kernelVm.OnPropertyChanged(nameof(kernelVm.CoinKernels));
             kernelVm.OnPropertyChanged(nameof(kernelVm.CoinVms));
             kernelVm.OnPropertyChanged(nameof(kernelVm.SupportedCoinVms));
             kernelVm.OnPropertyChanged(nameof(kernelVm.SupportedCoins));
             VirtualRoot.RaiseEvent(new CoinKernelVmRemovedEvent(message));
         }
     }, location: this.GetType());
     Init();
 }
Ejemplo n.º 2
0
            private CoinKernelViewModels()
            {
#if DEBUG
                VirtualRoot.Stopwatch.Restart();
#endif
                VirtualRoot.On <ServerContextReInitedEvent>("ServerContext刷新后刷新VM内存", LogEnum.DevConsole,
                                                            action: message => {
                    _dicById.Clear();
                    Init();
                });
                VirtualRoot.On <ServerContextVmsReInitedEvent>("ServerContext的VM集刷新后刷新视图界面", LogEnum.DevConsole,
                                                               action: message => {
                    OnPropertyChanged(nameof(AllCoinKernels));
                });
                On <CoinKernelAddedEvent>("添加了币种内核后刷新VM内存", LogEnum.DevConsole,
                                          action: (message) => {
                    var coinKernelVm = new CoinKernelViewModel(message.Source);
                    _dicById.Add(message.Source.GetId(), coinKernelVm);
                    OnPropertyChanged(nameof(AllCoinKernels));
                    CoinViewModel coinVm;
                    if (AppContext.Instance.CoinVms.TryGetCoinVm((Guid)message.Source.CoinId, out coinVm))
                    {
                        coinVm.OnPropertyChanged(nameof(CoinViewModel.CoinKernel));
                        coinVm.OnPropertyChanged(nameof(CoinViewModel.CoinKernels));
                        coinVm.OnPropertyChanged(nameof(NTMiner.Vms.CoinViewModel.IsSupported));
                    }
                    var kernelVm = coinKernelVm.Kernel;
                    if (kernelVm != null)
                    {
                        kernelVm.OnPropertyChanged(nameof(kernelVm.CoinKernels));
                        kernelVm.OnPropertyChanged(nameof(kernelVm.CoinVms));
                        kernelVm.OnPropertyChanged(nameof(kernelVm.SupportedCoinVms));
                        kernelVm.OnPropertyChanged(nameof(kernelVm.SupportedCoins));
                    }
                });
                On <CoinKernelUpdatedEvent>("更新了币种内核后刷新VM内存", LogEnum.DevConsole,
                                            action: (message) => {
                    CoinKernelViewModel entity = _dicById[message.Source.GetId()];
                    var supportedGpu           = entity.SupportedGpu;
                    int sortNumber             = entity.SortNumber;
                    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 (AppContext.Instance.CoinVms.TryGetCoinVm(coinKernel.CoinId, out coinVm))
                            {
                                coinVm.OnPropertyChanged(nameof(coinVm.IsSupported));
                                coinVm.OnPropertyChanged(nameof(coinVm.CoinKernels));
                            }
                        }
                        var kernelVm = entity.Kernel;
                        kernelVm.OnPropertyChanged(nameof(kernelVm.CoinKernels));
                    }
                    if (dualCoinGroupId != entity.DualCoinGroupId)
                    {
                        entity.OnPropertyChanged(nameof(entity.DualCoinGroup));
                    }
                    if (sortNumber != entity.SortNumber)
                    {
                        CoinViewModel coinVm;
                        if (AppContext.Instance.CoinVms.TryGetCoinVm(entity.CoinId, out coinVm))
                        {
                            coinVm.OnPropertyChanged(nameof(coinVm.CoinKernels));
                        }
                    }
                });
                On <CoinKernelRemovedEvent>("移除了币种内核后刷新VM内存", LogEnum.DevConsole,
                                            action: (message) => {
                    CoinKernelViewModel coinKernelVm;
                    if (_dicById.TryGetValue(message.Source.GetId(), out coinKernelVm))
                    {
                        _dicById.Remove(message.Source.GetId());
                        OnPropertyChanged(nameof(AllCoinKernels));
                        CoinViewModel coinVm;
                        if (AppContext.Instance.CoinVms.TryGetCoinVm((Guid)message.Source.CoinId, out coinVm))
                        {
                            coinVm.OnPropertyChanged(nameof(CoinViewModel.CoinKernel));
                            coinVm.OnPropertyChanged(nameof(CoinViewModel.CoinKernels));
                            coinVm.OnPropertyChanged(nameof(NTMiner.Vms.CoinViewModel.IsSupported));
                        }
                        var kernelVm = coinKernelVm.Kernel;
                        kernelVm.OnPropertyChanged(nameof(kernelVm.CoinKernels));
                        kernelVm.OnPropertyChanged(nameof(kernelVm.CoinVms));
                        kernelVm.OnPropertyChanged(nameof(kernelVm.SupportedCoinVms));
                        kernelVm.OnPropertyChanged(nameof(kernelVm.SupportedCoins));
                    }
                });
                Init();
#if DEBUG
                Write.DevWarn($"耗时{VirtualRoot.Stopwatch.ElapsedMilliseconds}毫秒 {this.GetType().Name}.ctor");
#endif
            }
Ejemplo n.º 3
0
 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));
     }
 }
Ejemplo n.º 4
0
 private void Init()
 {
     VirtualRoot.On <CoinKernelAddedEvent>("添加了币种内核后刷新VM内存", LogEnum.DevConsole,
                                           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));
         }
         var kernelVm = coinKernelVm.Kernel;
         if (kernelVm != null)
         {
             kernelVm.OnPropertyChanged(nameof(kernelVm.IsNvidiaIconVisible));
             kernelVm.OnPropertyChanged(nameof(kernelVm.IsAMDIconVisible));
             kernelVm.OnPropertyChanged(nameof(kernelVm.CoinKernels));
             kernelVm.OnPropertyChanged(nameof(kernelVm.CoinVms));
             kernelVm.OnPropertyChanged(nameof(kernelVm.SupportedCoinVms));
             kernelVm.OnPropertyChanged(nameof(kernelVm.SupportedCoins));
         }
     }).AddToCollection(NTMinerRoot.Current.ContextHandlers);
     VirtualRoot.On <CoinKernelUpdatedEvent>("更新了币种内核后刷新VM内存", LogEnum.DevConsole,
                                             action: (message) => {
         CoinKernelViewModel entity = _dicById[message.Source.GetId()];
         var supportedGpu           = entity.SupportedGpu;
         int sortNumber             = entity.SortNumber;
         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));
                 }
             }
             var kernelVm = entity.Kernel;
             kernelVm.OnPropertyChanged(nameof(kernelVm.IsNvidiaIconVisible));
             kernelVm.OnPropertyChanged(nameof(kernelVm.IsAMDIconVisible));
             kernelVm.OnPropertyChanged(nameof(kernelVm.CoinKernels));
         }
         if (dualCoinGroupId != entity.DualCoinGroupId)
         {
             entity.OnPropertyChanged(nameof(entity.DualCoinGroup));
         }
         if (sortNumber != entity.SortNumber)
         {
             CoinViewModel coinVm;
             if (CoinViewModels.Current.TryGetCoinVm(entity.CoinId, out coinVm))
             {
                 coinVm.OnPropertyChanged(nameof(coinVm.CoinKernels));
             }
         }
     }).AddToCollection(NTMinerRoot.Current.ContextHandlers);
     VirtualRoot.On <CoinKernelRemovedEvent>("移除了币种内核后刷新VM内存", LogEnum.DevConsole,
                                             action: (message) => {
         CoinKernelViewModel coinKernelVm;
         if (_dicById.TryGetValue(message.Source.GetId(), out coinKernelVm))
         {
             _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));
             }
             var kernelVm = coinKernelVm.Kernel;
             kernelVm.OnPropertyChanged(nameof(kernelVm.IsNvidiaIconVisible));
             kernelVm.OnPropertyChanged(nameof(kernelVm.IsAMDIconVisible));
             kernelVm.OnPropertyChanged(nameof(kernelVm.CoinKernels));
             kernelVm.OnPropertyChanged(nameof(kernelVm.CoinVms));
             kernelVm.OnPropertyChanged(nameof(kernelVm.SupportedCoinVms));
             kernelVm.OnPropertyChanged(nameof(kernelVm.SupportedCoins));
         }
     }).AddToCollection(NTMinerRoot.Current.ContextHandlers);
     foreach (var item in NTMinerRoot.Current.CoinKernelSet)
     {
         _dicById.Add(item.GetId(), new CoinKernelViewModel(item));
     }
 }