private PoolViewModels()
            {
                if (WpfUtil.IsInDesignMode)
                {
                    return;
                }
#if DEBUG
                NTStopwatch.Start();
#endif
                VirtualRoot.AddEventPath <ServerContextReInitedEvent>("ServerContext刷新后刷新VM内存", LogEnum.DevConsole,
                                                                      action: message => {
                    _dicById.Clear();
                    Init();
                }, location: this.GetType());
                VirtualRoot.AddEventPath <ServerContextVmsReInitedEvent>("ServerContext的VM集刷新后刷新视图界面", LogEnum.DevConsole,
                                                                         action: message => {
                    OnPropertyChanged(nameof(AllPools));
                }, location: this.GetType());
                AddEventPath <PoolAddedEvent>("添加矿池后刷新VM内存", LogEnum.DevConsole,
                                              action: (message) => {
                    _dicById.Add(message.Source.GetId(), new PoolViewModel(message.Source));
                    OnPropertyChanged(nameof(AllPools));
                    if (CoinVms.TryGetCoinVm(message.Source.CoinId, out CoinViewModel coinVm))
                    {
                        coinVm.CoinProfile?.OnPropertyChanged(nameof(CoinProfileViewModel.MainCoinPool));
                        coinVm.CoinProfile?.OnPropertyChanged(nameof(CoinProfileViewModel.DualCoinPool));
                        coinVm.OnPropertyChanged(nameof(CoinViewModel.Pools));
                        coinVm.OnPropertyChanged(nameof(CoinViewModel.OptionPools));
                    }
                }, location: this.GetType());
                AddEventPath <PoolRemovedEvent>("删除矿池后刷新VM内存", LogEnum.DevConsole,
                                                action: (message) => {
                    _dicById.Remove(message.Source.GetId());
                    OnPropertyChanged(nameof(AllPools));
                    if (CoinVms.TryGetCoinVm(message.Source.CoinId, out CoinViewModel coinVm))
                    {
                        coinVm.CoinProfile?.OnPropertyChanged(nameof(CoinProfileViewModel.MainCoinPool));
                        coinVm.CoinProfile?.OnPropertyChanged(nameof(CoinProfileViewModel.DualCoinPool));
                        coinVm.OnPropertyChanged(nameof(CoinViewModel.Pools));
                        coinVm.OnPropertyChanged(nameof(CoinViewModel.OptionPools));
                    }
                }, location: this.GetType());
                AddEventPath <PoolUpdatedEvent>("更新矿池后刷新VM内存", LogEnum.DevConsole,
                                                action: (message) => {
                    if (_dicById.TryGetValue(message.Source.GetId(), out PoolViewModel vm))
                    {
                        vm.Update(message.Source);
                    }
                }, location: this.GetType());
                Init();
#if DEBUG
                var elapsedMilliseconds = NTStopwatch.Stop();
                if (elapsedMilliseconds.ElapsedMilliseconds > NTStopwatch.ElapsedMilliseconds)
                {
                    Write.DevTimeSpan($"耗时{elapsedMilliseconds} {this.GetType().Name}.ctor");
                }
#endif
            }
            private WalletViewModels()
            {
                if (WpfUtil.IsInDesignMode)
                {
                    return;
                }
#if DEBUG
                NTStopwatch.Start();
#endif
                VirtualRoot.AddEventPath <LocalContextReInitedEvent>("LocalContext刷新后刷新钱包Vm内存", LogEnum.None,
                                                                     action: message => {
                    _dicById.Clear();
                    Init();
                }, location: this.GetType());
                AddEventPath <WalletAddedEvent>("添加了钱包后调整VM内存", LogEnum.DevConsole,
                                                action: (message) => {
                    _dicById.Add(message.Source.GetId(), new WalletViewModel(message.Source));
                    OnPropertyChanged(nameof(WalletList));
                    if (CoinVms.TryGetCoinVm(message.Source.CoinId, out CoinViewModel coin))
                    {
                        coin.OnPropertyChanged(nameof(CoinViewModel.Wallets));
                        coin.OnPropertyChanged(nameof(CoinViewModel.WalletItems));
                        coin.CoinKernel?.CoinKernelProfile?.SelectedDualCoin?.OnPropertyChanged(nameof(CoinViewModel.Wallets));
                    }
                    VirtualRoot.RaiseEvent(new WalletVmAddedEvent(message));
                }, location: this.GetType());
                AddEventPath <WalletRemovedEvent>("删除了钱包后调整VM内存", LogEnum.DevConsole,
                                                  action: (message) => {
                    _dicById.Remove(message.Source.GetId());
                    OnPropertyChanged(nameof(WalletList));
                    if (CoinVms.TryGetCoinVm(message.Source.CoinId, out CoinViewModel coin))
                    {
                        coin.OnPropertyChanged(nameof(CoinViewModel.Wallets));
                        coin.OnPropertyChanged(nameof(CoinViewModel.WalletItems));
                        coin.CoinProfile?.OnPropertyChanged(nameof(CoinProfileViewModel.SelectedWallet));
                        coin.CoinKernel?.CoinKernelProfile?.SelectedDualCoin?.OnPropertyChanged(nameof(CoinViewModel.Wallets));
                    }
                    VirtualRoot.RaiseEvent(new WalletVmRemovedEvent(message));
                }, location: this.GetType());
                AddEventPath <WalletUpdatedEvent>("更新了钱包后调整VM内存", LogEnum.DevConsole,
                                                  action: (message) => {
                    if (_dicById.TryGetValue(message.Source.GetId(), out WalletViewModel vm))
                    {
                        vm.Update(message.Source);
                    }
                }, location: this.GetType());
                Init();
#if DEBUG
                var elapsedMilliseconds = NTStopwatch.Stop();
                if (elapsedMilliseconds.ElapsedMilliseconds > NTStopwatch.ElapsedMilliseconds)
                {
                    Write.DevTimeSpan($"耗时{elapsedMilliseconds} {this.GetType().Name}.ctor");
                }
#endif
            }
Beispiel #3
0
 private PoolViewModels()
 {
     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(AllPools));
     }, location: this.GetType());
     BuildEventPath <PoolAddedEvent>("刷新VM内存", LogEnum.DevConsole,
                                     path: (message) => {
         _dicById.Add(message.Source.GetId(), new PoolViewModel(message.Source));
         OnPropertyChanged(nameof(AllPools));
         if (CoinVms.TryGetCoinVm(message.Source.CoinId, out CoinViewModel coinVm))
         {
             coinVm.CoinProfile?.OnPropertyChanged(nameof(CoinProfileViewModel.MainCoinPool));
             coinVm.CoinProfile?.OnPropertyChanged(nameof(CoinProfileViewModel.DualCoinPool));
             coinVm.OnPropertyChanged(nameof(CoinViewModel.Pools));
             coinVm.OnPropertyChanged(nameof(CoinViewModel.OptionPools));
         }
     }, location: this.GetType());
     BuildEventPath <PoolRemovedEvent>("刷新VM内存", LogEnum.DevConsole,
                                       path: (message) => {
         _dicById.Remove(message.Source.GetId());
         OnPropertyChanged(nameof(AllPools));
         if (CoinVms.TryGetCoinVm(message.Source.CoinId, out CoinViewModel coinVm))
         {
             coinVm.CoinProfile?.OnPropertyChanged(nameof(CoinProfileViewModel.MainCoinPool));
             coinVm.CoinProfile?.OnPropertyChanged(nameof(CoinProfileViewModel.DualCoinPool));
             coinVm.OnPropertyChanged(nameof(CoinViewModel.Pools));
             coinVm.OnPropertyChanged(nameof(CoinViewModel.OptionPools));
         }
     }, location: this.GetType());
     BuildEventPath <PoolUpdatedEvent>("刷新VM内存", LogEnum.DevConsole,
                                       path: (message) => {
         if (_dicById.TryGetValue(message.Source.GetId(), out PoolViewModel vm))
         {
             vm.Update(message.Source);
         }
     }, location: this.GetType());
     Init();
 }
 private WalletViewModels()
 {
     if (WpfUtil.IsInDesignMode)
     {
         return;
     }
     VirtualRoot.AddEventPath <LocalContextReInitedEvent>("LocalContext刷新后刷新钱包Vm内存", LogEnum.None,
                                                          action: message => {
         _dicById.Clear();
         Init();
     }, location: this.GetType());
     AddEventPath <WalletAddedEvent>("添加了钱包后调整VM内存", LogEnum.DevConsole,
                                     action: (message) => {
         _dicById.Add(message.Source.GetId(), new WalletViewModel(message.Source));
         OnPropertyChanged(nameof(WalletList));
         if (CoinVms.TryGetCoinVm(message.Source.CoinId, out CoinViewModel coin))
         {
             coin.OnPropertyChanged(nameof(CoinViewModel.Wallets));
             coin.OnPropertyChanged(nameof(CoinViewModel.WalletItems));
             coin.CoinKernel?.CoinKernelProfile?.SelectedDualCoin?.OnPropertyChanged(nameof(CoinViewModel.Wallets));
         }
         VirtualRoot.RaiseEvent(new WalletVmAddedEvent(message));
     }, location: this.GetType());
     AddEventPath <WalletRemovedEvent>("删除了钱包后调整VM内存", LogEnum.DevConsole,
                                       action: (message) => {
         _dicById.Remove(message.Source.GetId());
         OnPropertyChanged(nameof(WalletList));
         if (CoinVms.TryGetCoinVm(message.Source.CoinId, out CoinViewModel coin))
         {
             coin.OnPropertyChanged(nameof(CoinViewModel.Wallets));
             coin.OnPropertyChanged(nameof(CoinViewModel.WalletItems));
             coin.CoinProfile?.OnPropertyChanged(nameof(CoinProfileViewModel.SelectedWallet));
             coin.CoinKernel?.CoinKernelProfile?.SelectedDualCoin?.OnPropertyChanged(nameof(CoinViewModel.Wallets));
         }
         VirtualRoot.RaiseEvent(new WalletVmRemovedEvent(message));
     }, location: this.GetType());
     AddEventPath <WalletUpdatedEvent>("更新了钱包后调整VM内存", LogEnum.DevConsole,
                                       action: (message) => {
         if (_dicById.TryGetValue(message.Source.GetId(), out WalletViewModel vm))
         {
             vm.Update(message.Source);
         }
     }, location: this.GetType());
     Init();
 }
 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();
 }
            private CoinKernelViewModels()
            {
                if (WpfUtil.IsInDesignMode)
                {
                    return;
                }
#if DEBUG
                NTStopwatch.Start();
#endif
                VirtualRoot.AddEventPath <ServerContextReInitedEvent>("ServerContext刷新后刷新VM内存", LogEnum.DevConsole,
                                                                      action: message => {
                    _dicById.Clear();
                    Init();
                }, location: this.GetType());
                VirtualRoot.AddEventPath <ServerContextVmsReInitedEvent>("ServerContext的VM集刷新后刷新视图界面", LogEnum.DevConsole,
                                                                         action: message => {
                    OnPropertyChanged(nameof(AllCoinKernels));
                }, location: this.GetType());
                AddEventPath <CoinKernelAddedEvent>("添加了币种内核后刷新VM内存", LogEnum.DevConsole,
                                                    action: (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());
                AddEventPath <CoinKernelUpdatedEvent>("更新了币种内核后刷新VM内存", LogEnum.DevConsole,
                                                      action: (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());
                AddEventPath <CoinKernelRemovedEvent>("移除了币种内核后刷新VM内存", LogEnum.DevConsole,
                                                      action: (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();
#if DEBUG
                var elapsedMilliseconds = NTStopwatch.Stop();
                if (elapsedMilliseconds.ElapsedMilliseconds > NTStopwatch.ElapsedMilliseconds)
                {
                    Write.DevTimeSpan($"耗时{elapsedMilliseconds} {this.GetType().Name}.ctor");
                }
#endif
            }