private CoinViewModels() { if (WpfUtil.IsInDesignMode) { return; } VirtualRoot.BuildEventPath <ServerContextReInitedEvent>("刷新VM内存", LogEnum.DevConsole, location: this.GetType(), PathPriority.Normal, path: message => { _dicById.Clear(); Init(); }); VirtualRoot.BuildEventPath <ServerContextReInitedEvent>("刷新视图界面", LogEnum.DevConsole, location: this.GetType(), PathPriority.BelowNormal, path: message => { AllPropertyChanged(); }); BuildEventPath <CoinAddedEvent>("刷新VM内存", LogEnum.DevConsole, location: this.GetType(), PathPriority.Normal, path: (message) => { _dicById.Add(message.Source.GetId(), new CoinViewModel(message.Source)); AllPropertyChanged(); }); BuildEventPath <CoinRemovedEvent>("刷新VM内存", LogEnum.DevConsole, location: this.GetType(), PathPriority.Normal, path: message => { _dicById.Remove(message.Source.GetId()); AllPropertyChanged(); }); BuildEventPath <CoinKernelAddedEvent>("刷新币种Vm集的关联内存", LogEnum.DevConsole, this.GetType(), PathPriority.BelowNormal, path: message => { if (_dicById.TryGetValue(message.Source.CoinId, out CoinViewModel coinVm)) { coinVm.OnPropertyChanged(nameof(CoinViewModel.CoinKernel)); coinVm.OnPropertyChanged(nameof(CoinViewModel.CoinKernels)); coinVm.OnPropertyChanged(nameof(CoinViewModel.IsSupported)); } }); BuildEventPath <CoinKernelRemovedEvent>("刷新币种Vm集的关联内存", LogEnum.DevConsole, this.GetType(), PathPriority.BelowNormal, path: message => { if (_dicById.TryGetValue(message.Source.CoinId, out CoinViewModel coinVm)) { coinVm.OnPropertyChanged(nameof(CoinViewModel.CoinKernel)); coinVm.OnPropertyChanged(nameof(CoinViewModel.CoinKernels)); coinVm.OnPropertyChanged(nameof(CoinViewModel.IsSupported)); } }); BuildEventPath <CoinUpdatedEvent>("刷新VM内存", LogEnum.DevConsole, location: this.GetType(), PathPriority.Normal, path: message => { if (_dicById.TryGetValue(message.Source.GetId(), out CoinViewModel vm)) { bool justAsDualCoin = vm.JustAsDualCoin; vm.Update(message.Source); vm.TestWalletVm.Address = message.Source.TestWallet; vm.OnPropertyChanged(nameof(vm.Wallets)); vm.OnPropertyChanged(nameof(vm.WalletItems)); if (MinerProfileVm.CoinId == message.Source.GetId()) { MinerProfileVm.OnPropertyChanged(nameof(MinerProfileVm.CoinVm)); } CoinKernelViewModel coinKernelVm = MinerProfileVm.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 != vm.JustAsDualCoin) { OnPropertyChanged(nameof(MainCoins)); } } }); BuildEventPath <CoinIconDownloadedEvent>("刷新图标", LogEnum.DevConsole, location: this.GetType(), PathPriority.Normal, path: message => { try { if (string.IsNullOrEmpty(message.Source.Icon)) { return; } string iconFileFullName = MinerClientTempPath.GetIconFileFullName(message.Source.Icon); if (string.IsNullOrEmpty(iconFileFullName) || !File.Exists(iconFileFullName)) { return; } if (_dicById.TryGetValue(message.Source.GetId(), out CoinViewModel coinVm)) { try { coinVm.IconImageSource = new Uri(iconFileFullName, UriKind.Absolute).ToString(); } catch (Exception e) { File.Delete(iconFileFullName); Logger.ErrorDebugLine(e); } } } catch (Exception e) { Logger.ErrorDebugLine(e); } }); Init(); }
private CoinViewModels() { #if DEBUG NTStopwatch.Start(); #endif if (WpfUtil.IsInDesignMode) { return; } VirtualRoot.AddEventPath <ServerContextReInitedEvent>("ServerContext刷新后刷新VM内存", LogEnum.DevConsole, action: message => { _dicById.Clear(); Init(); }, location: this.GetType()); VirtualRoot.AddEventPath <ServerContextVmsReInitedEvent>("ServerContext的VM集刷新后刷新视图界面", LogEnum.DevConsole, action: message => { AllPropertyChanged(); }, location: this.GetType()); AddEventPath <CoinAddedEvent>("添加了币种后刷新VM内存", LogEnum.DevConsole, action: (message) => { _dicById.Add(message.Source.GetId(), new CoinViewModel(message.Source)); AllPropertyChanged(); VirtualRoot.RaiseEvent(new CoinVmAddedEvent(message)); }, location: this.GetType()); AddEventPath <CoinRemovedEvent>("移除了币种后刷新VM内存", LogEnum.DevConsole, action: message => { _dicById.Remove(message.Source.GetId()); AllPropertyChanged(); VirtualRoot.RaiseEvent(new CoinVmRemovedEvent(message)); }, location: this.GetType()); AddEventPath <CoinKernelVmAddedEvent>("币种内核Vm集添加了新Vm后刷新币种Vm集的关联内存", LogEnum.DevConsole, action: message => { if (_dicById.TryGetValue(message.Event.Source.CoinId, out CoinViewModel coinVm)) { coinVm.OnPropertyChanged(nameof(CoinViewModel.CoinKernel)); coinVm.OnPropertyChanged(nameof(CoinViewModel.CoinKernels)); coinVm.OnPropertyChanged(nameof(CoinViewModel.IsSupported)); } }, this.GetType()); AddEventPath <CoinKernelVmRemovedEvent>("币种内核Vm集删除了新Vm后刷新币种Vm集的关联内存", LogEnum.DevConsole, action: message => { if (_dicById.TryGetValue(message.Event.Source.CoinId, out CoinViewModel coinVm)) { coinVm.OnPropertyChanged(nameof(CoinViewModel.CoinKernel)); coinVm.OnPropertyChanged(nameof(CoinViewModel.CoinKernels)); coinVm.OnPropertyChanged(nameof(CoinViewModel.IsSupported)); } }, this.GetType()); AddEventPath <CoinUpdatedEvent>("更新了币种后刷新VM内存", LogEnum.DevConsole, action: message => { if (_dicById.TryGetValue(message.Source.GetId(), out CoinViewModel vm)) { bool justAsDualCoin = vm.JustAsDualCoin; vm.Update(message.Source); vm.TestWalletVm.Address = message.Source.TestWallet; vm.OnPropertyChanged(nameof(vm.Wallets)); vm.OnPropertyChanged(nameof(vm.WalletItems)); if (MinerProfileVm.CoinId == message.Source.GetId()) { MinerProfileVm.OnPropertyChanged(nameof(MinerProfileVm.CoinVm)); } CoinKernelViewModel coinKernelVm = MinerProfileVm.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 != vm.JustAsDualCoin) { OnPropertyChanged(nameof(MainCoins)); } } }, location: this.GetType()); AddEventPath <CoinIconDownloadedEvent>("下载了币种图标后", LogEnum.DevConsole, action: message => { try { if (string.IsNullOrEmpty(message.Source.Icon)) { return; } string iconFileFullName = TempPath.GetIconFileFullName(message.Source.Icon); if (string.IsNullOrEmpty(iconFileFullName) || !File.Exists(iconFileFullName)) { return; } if (_dicById.TryGetValue(message.Source.GetId(), out CoinViewModel coinVm)) { try { coinVm.IconImageSource = new Uri(iconFileFullName, UriKind.Absolute).ToString(); } catch (Exception e) { File.Delete(iconFileFullName); Logger.ErrorDebugLine(e); } } } catch (Exception e) { Logger.ErrorDebugLine(e); } }, location: this.GetType()); Init(); #if DEBUG var elapsedMilliseconds = NTStopwatch.Stop(); if (elapsedMilliseconds.ElapsedMilliseconds > NTStopwatch.ElapsedMilliseconds) { Write.DevTimeSpan($"耗时{elapsedMilliseconds} {this.GetType().Name}.ctor"); } #endif }