Example #1
0
 private MinerGroupViewModels()
 {
     if (WpfUtil.IsInDesignMode)
     {
         return;
     }
     foreach (var item in NTMinerContext.MinerStudioContext.MinerGroupSet.AsEnumerable().ToArray())
     {
         if (!_dicById.ContainsKey(item.Id))
         {
             _dicById.Add(item.Id, new MinerGroupViewModel(item));
         }
     }
     AppRoot.BuildEventPath <MinerGroupSetInitedEvent>("矿工组集初始化后初始化Vm内存", LogEnum.DevConsole, this.GetType(), PathPriority.Normal, path: message => {
         _dicById.Clear();
         foreach (var item in NTMinerContext.MinerStudioContext.MinerGroupSet.AsEnumerable().ToArray())
         {
             if (!_dicById.ContainsKey(item.Id))
             {
                 _dicById.Add(item.Id, new MinerGroupViewModel(item));
             }
         }
         this.OnPropertyChangeds();
         MinerClientsWindowViewModel.Instance.RefreshMinerClientsSelectedMinerGroup(MinerClientsWindowViewModel.Instance.MinerClients.ToArray());
     });
     this.Add = new DelegateCommand(() => {
         new MinerGroupViewModel(Guid.NewGuid()).Edit.Execute(FormType.Add);
     });
     AppRoot.BuildEventPath <MinerGroupAddedEvent>("添加矿机分组后刷新VM内存", LogEnum.DevConsole, location: this.GetType(), PathPriority.Normal,
                                                   path: message => {
         if (!_dicById.TryGetValue(message.Source.GetId(), out MinerGroupViewModel vm))
         {
             vm = new MinerGroupViewModel(message.Source);
             _dicById.Add(message.Source.GetId(), vm);
             OnPropertyChangeds();
             MinerClientsWindowVm.OnPropertyChanged(nameof(MinerClientsWindowViewModel.SelectedMinerGroup));
         }
     });
     AppRoot.BuildEventPath <MinerGroupUpdatedEvent>("添加矿机分组后刷新VM内存", LogEnum.DevConsole, location: this.GetType(), PathPriority.Normal,
                                                     path: message => {
         if (_dicById.TryGetValue(message.Source.GetId(), out MinerGroupViewModel vm))
         {
             vm.Update(message.Source);
         }
     });
     AppRoot.BuildEventPath <MinerGroupRemovedEvent>("移除了矿机组后刷新Vm内容", LogEnum.DevConsole, this.GetType(), PathPriority.Normal, path: message => {
         if (_dicById.TryGetValue(message.Source.Id, out MinerGroupViewModel vm))
         {
             _dicById.Remove(vm.Id);
             OnPropertyChangeds();
             MinerClientsWindowVm.OnPropertyChanged(nameof(MinerClientsWindowViewModel.SelectedMinerGroup));
         }
     });
 }
Example #2
0
            private MinerGroupViewModels()
            {
#if DEBUG
                NTStopwatch.Start();
#endif
                if (WpfUtil.IsInDesignMode)
                {
                    return;
                }
                foreach (var item in NTMinerContext.Instance.MinerStudioContext.MinerGroupSet.AsEnumerable())
                {
                    if (!_dicById.ContainsKey(item.Id))
                    {
                        _dicById.Add(item.Id, new MinerGroupViewModel(item));
                    }
                }
                AppRoot.AddEventPath <MinerGroupSetInitedEvent>("矿工组集初始化后初始化Vm内存", LogEnum.DevConsole, action: message => {
                    foreach (var item in NTMinerContext.Instance.MinerStudioContext.MinerGroupSet.AsEnumerable())
                    {
                        if (!_dicById.ContainsKey(item.Id))
                        {
                            _dicById.Add(item.Id, new MinerGroupViewModel(item));
                        }
                    }
                    this.OnPropertyChangeds();
                    MinerClientsWindowViewModel.Instance.RefreshMinerClientsSelectedMinerGroup(MinerClientsWindowViewModel.Instance.MinerClients.ToArray());
                }, this.GetType());
                this.Add = new DelegateCommand(() => {
                    new MinerGroupViewModel(Guid.NewGuid()).Edit.Execute(FormType.Add);
                });
                AppRoot.AddEventPath <MinerGroupAddedEvent>("添加矿机分组后刷新VM内存", LogEnum.DevConsole,
                                                            action: message => {
                    if (!_dicById.TryGetValue(message.Source.GetId(), out MinerGroupViewModel vm))
                    {
                        vm = new MinerGroupViewModel(message.Source);
                        _dicById.Add(message.Source.GetId(), vm);
                        OnPropertyChangeds();
                        MinerClientsWindowVm.OnPropertyChanged(nameof(MinerClientsWindowViewModel.SelectedMinerGroup));
                    }
                }, location: this.GetType());
                AppRoot.AddEventPath <MinerGroupUpdatedEvent>("添加矿机分组后刷新VM内存", LogEnum.DevConsole,
                                                              action: message => {
                    if (_dicById.TryGetValue(message.Source.GetId(), out MinerGroupViewModel vm))
                    {
                        vm.Update(message.Source);
                    }
                }, location: this.GetType());
                AppRoot.AddEventPath <MinerGroupRemovedEvent>("移除了矿机组后刷新Vm内容", LogEnum.DevConsole, action: message => {
                    if (_dicById.TryGetValue(message.Source.Id, out MinerGroupViewModel vm))
                    {
                        _dicById.Remove(vm.Id);
                        OnPropertyChangeds();
                        MinerClientsWindowVm.OnPropertyChanged(nameof(MinerClientsWindowViewModel.SelectedMinerGroup));
                    }
                }, this.GetType());
#if DEBUG
                var elapsedMilliseconds = NTStopwatch.Stop();
                if (elapsedMilliseconds.ElapsedMilliseconds > NTStopwatch.ElapsedMilliseconds)
                {
                    Write.DevTimeSpan($"耗时{elapsedMilliseconds} {this.GetType().Name}.ctor");
                }
#endif
            }