Esempio n. 1
0
        private void CoinKernelDataGrid_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            DataGrid dg = (DataGrid)sender;

            if (dg.SelectedItem != null)
            {
                CoinKernelViewModel kernelVm = (CoinKernelViewModel)dg.SelectedItem;
                kernelVm.Edit.Execute(null);
            }
        }
Esempio n. 2
0
 public static void ShowWindow(CoinKernelViewModel coinKernelVm, EnvironmentVariable environmentVariable)
 {
     ContainerWindow.ShowWindow(new ContainerWindowViewModel {
         IsDialogWindow = true,
         CloseVisible   = System.Windows.Visibility.Visible
     }, ucFactory: (window) =>
     {
         EnvironmentVariableEditViewModel vm = new EnvironmentVariableEditViewModel(coinKernelVm, environmentVariable);
         vm.CloseWindow = () => window.Close();
         return(new EnvironmentVariableEdit(vm));
     }, fixedSize: true);
 }
Esempio n. 3
0
 public static void ShowEditWindow(CoinKernelViewModel source)
 {
     ContainerWindow.ShowWindow(new ContainerWindowViewModel {
         IsDialogWindow = true,
         IconName       = "Icon_Kernel",
         CloseVisible   = System.Windows.Visibility.Visible
     }, ucFactory: (window) =>
     {
         CoinKernelViewModel vm = new CoinKernelViewModel(source);
         vm.CloseWindow         = () => window.Close();
         return(new CoinKernelEdit(vm));
     }, fixedSize: true);
 }
 public static void ShowWindow(CoinKernelViewModel coinKernelVm, EnvironmentVariable environmentVariable)
 {
     ContainerWindow.ShowWindow(new ContainerWindowViewModel {
         Title           = "环境变量",
         IsMaskTheParent = true,
         Width           = 500,
         CloseVisible    = System.Windows.Visibility.Visible
     }, ucFactory: (window) =>
     {
         EnvironmentVariableEditViewModel vm = new EnvironmentVariableEditViewModel(coinKernelVm, environmentVariable);
         window.AddCloseWindowOnecePath(vm.Id);
         return(new EnvironmentVariableEdit(vm));
     }, fixedSize: true);
 }
Esempio n. 5
0
 public static void ShowWindow(CoinKernelViewModel coinKernelVm, InputSegmentViewModel segment)
 {
     ContainerWindow.ShowWindow(new ContainerWindowViewModel {
         Title           = "片段",
         IsMaskTheParent = true,
         Width           = 500,
         CloseVisible    = System.Windows.Visibility.Visible
     }, ucFactory: (window) =>
     {
         InputSegmentEditViewModel vm = new InputSegmentEditViewModel(coinKernelVm, segment);
         window.AddCloseWindowOnecePath(vm.Id);
         return(new InputSegmentEdit(vm));
     }, fixedSize: true);
 }
 public static void ShowWindow(CoinKernelViewModel coinKernelVm, InputSegment segment)
 {
     ContainerWindow.ShowWindow(new ContainerWindowViewModel {
         Title          = "片段",
         IsDialogWindow = true,
         CloseVisible   = System.Windows.Visibility.Visible
     }, ucFactory: (window) =>
     {
         InputSegmentEditViewModel vm = new InputSegmentEditViewModel(coinKernelVm, segment)
         {
             CloseWindow = () => window.Close()
         };
         return(new InputSegmentEdit(vm));
     }, fixedSize: true);
 }
Esempio n. 7
0
 public static void ShowWindow(CoinKernelViewModel coinKernelVm, InputSegmentViewModel segment)
 {
     ContainerWindow.ShowWindow(new ContainerWindowViewModel {
         Title           = "片段",
         IsMaskTheParent = true,
         Width           = 500,
         CloseVisible    = System.Windows.Visibility.Visible
     }, ucFactory: (window) =>
     {
         InputSegmentEditViewModel vm = new InputSegmentEditViewModel(coinKernelVm, segment);
         window.AddOnecePath <CloseWindowCommand>("处理关闭窗口命令", LogEnum.DevConsole, action: message => {
             window.Close();
         }, pathId: vm.Id, location: typeof(InputSegmentEdit));
         return(new InputSegmentEdit(vm));
     }, fixedSize: true);
 }
Esempio n. 8
0
 public static void ShowWindow(FormType formType, CoinKernelViewModel source)
 {
     ContainerWindow.ShowWindow(new ContainerWindowViewModel {
         Title           = "币种级参数",
         FormType        = formType,
         Width           = 700,
         IsMaskTheParent = true,
         IconName        = "Icon_Kernel",
         CloseVisible    = Visibility.Visible
     }, ucFactory: (window) =>
     {
         CoinKernelViewModel vm = new CoinKernelViewModel(source);
         window.AddCloseWindowOnecePath(vm.Id);
         return(new CoinKernelEdit(vm));
     }, fixedSize: true);
 }
Esempio n. 9
0
 public static void ShowWindow(FormType formType, CoinKernelViewModel source)
 {
     ContainerWindow.ShowWindow(new ContainerWindowViewModel {
         Title           = "币种级参数",
         FormType        = formType,
         Width           = 700,
         IsMaskTheParent = true,
         IconName        = "Icon_Kernel",
         CloseVisible    = Visibility.Visible
     }, ucFactory: (window) =>
     {
         CoinKernelViewModel vm = new CoinKernelViewModel(source);
         window.AddOnecePath <CloseWindowCommand>("处理关闭窗口命令", LogEnum.DevConsole, action: message => {
             window.Close();
         }, pathId: vm.Id, location: typeof(CoinKernelEdit));
         return(new CoinKernelEdit(vm));
     }, fixedSize: true);
 }
Esempio n. 10
0
 public static void ShowWindow(FormType formType, CoinKernelViewModel source)
 {
     ContainerWindow.ShowWindow(new ContainerWindowViewModel {
         Title          = "币种级参数",
         FormType       = formType,
         Width          = 700,
         IsDialogWindow = true,
         IconName       = "Icon_Kernel",
         CloseVisible   = Visibility.Visible
     }, ucFactory: (window) =>
     {
         CoinKernelViewModel vm = new CoinKernelViewModel(source)
         {
             CloseWindow = () => window.Close()
         };
         return(new CoinKernelEdit(vm));
     }, fixedSize: true);
 }
Esempio n. 11
0
        public static void ShowEditWindow(CoinKernelViewModel source)
        {
            string title;

            if (!DevMode.IsDevMode)
            {
                title = "内核详情";
            }
            else
            {
                if (NTMinerRoot.Current.CoinKernelSet.Contains(source.Id))
                {
                    title = "编辑内核";
                }
                else
                {
                    title = "添加内核";
                }
            }
            ContainerWindow.ShowWindow(new ContainerWindowViewModel {
                Title          = title,
                IsDialogWindow = true,
                IconName       = "Icon_Kernel",
                SaveVisible    = DevMode.IsDevMode ? System.Windows.Visibility.Visible : System.Windows.Visibility.Collapsed,
                CloseVisible   = System.Windows.Visibility.Visible,
                OnOk           = (uc) => {
                    var vm = ((CoinKernelEdit)uc).Vm;
                    if (NTMinerRoot.Current.CoinKernelSet.Contains(source.Id))
                    {
                        Global.Execute(new UpdateCoinKernelCommand(vm));
                    }
                    return(true);
                }
            }, ucFactory: (window) =>
            {
                CoinKernelViewModel vm = new CoinKernelViewModel(source);
                return(new CoinKernelEdit(vm));
            }, fixedSize: true);
        }
Esempio n. 12
0
 public CoinKernelEdit(CoinKernelViewModel vm)
 {
     this.DataContext = vm;
     InitializeComponent();
 }
 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 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();
 }
Esempio n. 15
0
 public CoinKernelEdit(CoinKernelViewModel vm)
 {
     this.DataContext = vm;
     InitializeComponent();
     ResourceDictionarySet.Instance.FillResourceDic(this, this.Resources);
 }
Esempio n. 16
0
            private CoinKernelViewModels()
            {
#if DEBUG
                VirtualRoot.Stopwatch.Restart();
#endif
                On <ServerContextReInitedEvent>("ServerContext刷新后刷新VM内存", LogEnum.DevConsole,
                                                action: message => {
                    _dicById.Clear();
                    Init();
                });
                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.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));
                    }
                });
                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.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 (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.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));
                    }
                });
                Init();
#if DEBUG
                Write.DevWarn($"耗时{VirtualRoot.Stopwatch.ElapsedMilliseconds}毫秒 {this.GetType().Name}.ctor");
#endif
            }
Esempio n. 17
0
 public CoinKernelEditCommand(FormType formType, CoinKernelViewModel source)
 {
     this.FormType = formType;
     this.Source   = source;
 }
Esempio n. 18
0
 public InputSegmentEditCommand(CoinKernelViewModel coinKernelVm, InputSegment segment)
 {
     this.CoinKernelVm = coinKernelVm;
     this.Segment      = segment;
 }
Esempio n. 19
0
 public EnvironmentVariableEditCommand(CoinKernelViewModel coinKernelVm, EnvironmentVariable environmentVariable)
 {
     this.CoinKernelVm        = coinKernelVm;
     this.EnvironmentVariable = environmentVariable;
 }
Esempio n. 20
0
 public bool TryGetCoinKernelVm(Guid id, out CoinKernelViewModel vm)
 {
     return(_dicById.TryGetValue(id, out vm));
 }
Esempio n. 21
0
            private CoinKernelViewModels()
            {
#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.Target);
                    _dicById.Add(message.Target.GetId(), coinKernelVm);
                    OnPropertyChanged(nameof(AllCoinKernels));
                    if (AppContext.Instance.CoinVms.TryGetCoinVm(message.Target.CoinId, out CoinViewModel 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.CoinKernels));
                        kernelVm.OnPropertyChanged(nameof(kernelVm.CoinVms));
                        kernelVm.OnPropertyChanged(nameof(kernelVm.SupportedCoinVms));
                        kernelVm.OnPropertyChanged(nameof(kernelVm.SupportedCoins));
                    }
                }, location: this.GetType());
                AddEventPath <CoinKernelUpdatedEvent>("更新了币种内核后刷新VM内存", LogEnum.DevConsole,
                                                      action: (message) => {
                    CoinKernelViewModel entity = _dicById[message.Target.GetId()];
                    var supportedGpu           = entity.SupportedGpu;
                    Guid dualCoinGroupId       = entity.DualCoinGroupId;
                    entity.Update(message.Target);
                    if (supportedGpu != entity.SupportedGpu)
                    {
                        var coinKernels = AllCoinKernels.Where(a => a.KernelId == entity.Id);
                        foreach (var coinKernel in coinKernels)
                        {
                            if (AppContext.Instance.CoinVms.TryGetCoinVm(coinKernel.CoinId, out CoinViewModel coinVm))
                            {
                                coinVm.OnPropertyChanged(nameof(coinVm.IsSupported));
                                coinVm.OnPropertyChanged(nameof(coinVm.CoinKernels));
                            }
                        }
                        var kernelVm = entity.Kernel;
                        kernelVm.OnPropertyChanged(nameof(kernelVm.CoinKernels));
                    }
                }, location: this.GetType());
                AddEventPath <CoinKernelRemovedEvent>("移除了币种内核后刷新VM内存", LogEnum.DevConsole,
                                                      action: (message) => {
                    if (_dicById.TryGetValue(message.Target.GetId(), out CoinKernelViewModel coinKernelVm))
                    {
                        _dicById.Remove(message.Target.GetId());
                        OnPropertyChanged(nameof(AllCoinKernels));
                        if (AppContext.Instance.CoinVms.TryGetCoinVm(message.Target.CoinId, out CoinViewModel coinVm))
                        {
                            coinVm.OnPropertyChanged(nameof(CoinViewModel.CoinKernel));
                            coinVm.OnPropertyChanged(nameof(CoinViewModel.CoinKernels));
                            coinVm.OnPropertyChanged(nameof(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));
                    }
                }, location: this.GetType());
                Init();
#if DEBUG
                var elapsedMilliseconds = NTStopwatch.Stop();
                if (elapsedMilliseconds.ElapsedMilliseconds > NTStopwatch.ElapsedMilliseconds)
                {
                    Write.DevTimeSpan($"耗时{elapsedMilliseconds} {this.GetType().Name}.ctor");
                }
#endif
            }
Esempio n. 22
0
            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.Target.GetId(), new CoinViewModel(message.Target));
                    AppContext.Instance.MinerProfileVm.OnPropertyChanged(nameof(NTMiner.AppContext.Instance.MinerProfileVm.CoinVm));
                    AllPropertyChanged();
                }, location: this.GetType());
                AddEventPath <CoinRemovedEvent>("移除了币种后刷新VM内存", LogEnum.DevConsole,
                                                action: message => {
                    _dicById.Remove(message.Target.GetId());
                    AppContext.Instance.MinerProfileVm.OnPropertyChanged(nameof(NTMiner.AppContext.Instance.MinerProfileVm.CoinVm));
                    AllPropertyChanged();
                }, location: this.GetType());
                AddEventPath <CoinUpdatedEvent>("更新了币种后刷新VM内存", LogEnum.DevConsole,
                                                action: message => {
                    CoinViewModel coinVm = _dicById[message.Target.GetId()];
                    bool justAsDualCoin  = coinVm.JustAsDualCoin;
                    coinVm.Update(message.Target);
                    coinVm.TestWalletVm.Address = message.Target.TestWallet;
                    coinVm.OnPropertyChanged(nameof(coinVm.Wallets));
                    coinVm.OnPropertyChanged(nameof(coinVm.WalletItems));
                    if (AppContext.Instance.MinerProfileVm.CoinId == message.Target.GetId())
                    {
                        AppContext.Instance.MinerProfileVm.OnPropertyChanged(nameof(NTMiner.AppContext.Instance.MinerProfileVm.CoinVm));
                    }
                    CoinKernelViewModel coinKernelVm = AppContext.Instance.MinerProfileVm.CoinVm.CoinKernel;
                    if (coinKernelVm != null &&
                        coinKernelVm.CoinKernelProfile.SelectedDualCoin != null &&
                        coinKernelVm.CoinKernelProfile.SelectedDualCoin.GetId() == message.Target.GetId())
                    {
                        coinKernelVm.CoinKernelProfile.OnPropertyChanged(nameof(coinKernelVm.CoinKernelProfile.SelectedDualCoin));
                    }
                    if (justAsDualCoin != coinVm.JustAsDualCoin)
                    {
                        OnPropertyChanged(nameof(MainCoins));
                    }
                }, location: this.GetType());
                AddEventPath <CoinIconDownloadedEvent>("下载了币种图标后", LogEnum.DevConsole,
                                                       action: message => {
                    try {
                        if (string.IsNullOrEmpty(message.Target.Icon))
                        {
                            return;
                        }
                        string iconFileFullName = SpecialPath.GetIconFileFullName(message.Target);
                        if (string.IsNullOrEmpty(iconFileFullName) || !File.Exists(iconFileFullName))
                        {
                            return;
                        }
                        if (_dicById.TryGetValue(message.Target.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
            }