Example #1
0
 private void Init()
 {
     VirtualRoot.On <GroupAddedEvent>("添加了组后调整VM内存", LogEnum.DevConsole,
                                      action: (message) => {
         if (!_dicById.ContainsKey(message.Source.GetId()))
         {
             GroupViewModel groupVm = new GroupViewModel(message.Source);
             _dicById.Add(message.Source.GetId(), groupVm);
             OnPropertyChangeds();
         }
     }).AddToCollection(NTMinerRoot.Current.ContextHandlers);
     VirtualRoot.On <GroupUpdatedEvent>("更新了组后调整VM内存", LogEnum.DevConsole,
                                        action: (message) => {
         if (_dicById.ContainsKey(message.Source.GetId()))
         {
             GroupViewModel entity = _dicById[message.Source.GetId()];
             int sortNumber        = entity.SortNumber;
             entity.Update(message.Source);
             if (sortNumber != entity.SortNumber)
             {
                 this.OnPropertyChanged(nameof(List));
                 OnPropertyChanged(nameof(SelectionOptions));
             }
         }
     }).AddToCollection(NTMinerRoot.Current.ContextHandlers);
     VirtualRoot.On <GroupRemovedEvent>("删除了组后调整VM内存", LogEnum.DevConsole,
                                        action: (message) => {
         _dicById.Remove(message.Source.GetId());
         OnPropertyChangeds();
     }).AddToCollection(NTMinerRoot.Current.ContextHandlers);
     foreach (var item in NTMinerRoot.Current.GroupSet)
     {
         GroupViewModel groupVm = new GroupViewModel(item);
         _dicById.Add(item.GetId(), groupVm);
     }
 }
Example #2
0
 public GroupViewModel(Guid id)
 {
     _id       = id;
     this.Save = new DelegateCommand(() => {
         if (this.Id == Guid.Empty)
         {
             return;
         }
         if (NTMinerRoot.Instance.GroupSet.Contains(this.Id))
         {
             VirtualRoot.Execute(new UpdateGroupCommand(this));
         }
         else
         {
             VirtualRoot.Execute(new AddGroupCommand(this));
         }
         CloseWindow?.Invoke();
     });
     this.Edit = new DelegateCommand <FormType?>((formType) => {
         if (this.Id == Guid.Empty)
         {
             return;
         }
         VirtualRoot.Execute(new GroupEditCommand(formType ?? FormType.Edit, this));
     });
     this.Remove = new DelegateCommand(() => {
         if (this.Id == Guid.Empty)
         {
             return;
         }
         this.ShowDialog(new DialogWindowViewModel(message: $"您确定删除{this.Name}组吗?", title: "确认", onYes: () => {
             VirtualRoot.Execute(new RemoveGroupCommand(this.Id));
         }));
     });
     this.SortUp = new DelegateCommand(() => {
         GroupViewModel upOne = AppContext.Instance.GroupVms.GetUpOne(this.SortNumber);
         if (upOne != null)
         {
             int sortNumber   = upOne.SortNumber;
             upOne.SortNumber = this.SortNumber;
             VirtualRoot.Execute(new UpdateGroupCommand(upOne));
             this.SortNumber = sortNumber;
             VirtualRoot.Execute(new UpdateGroupCommand(this));
             AppContext.Instance.GroupVms.OnPropertyChanged(nameof(AppContext.GroupViewModels.List));
         }
     });
     this.SortDown = new DelegateCommand(() => {
         GroupViewModel nextOne = AppContext.Instance.GroupVms.GetNextOne(this.SortNumber);
         if (nextOne != null)
         {
             int sortNumber     = nextOne.SortNumber;
             nextOne.SortNumber = this.SortNumber;
             VirtualRoot.Execute(new UpdateGroupCommand(nextOne));
             this.SortNumber = sortNumber;
             VirtualRoot.Execute(new UpdateGroupCommand(this));
             AppContext.Instance.GroupVms.OnPropertyChanged(nameof(AppContext.GroupViewModels.List));
         }
     });
     this.AddCoinGroup = new DelegateCommand <CoinViewModel>((coinVm) => {
         if (coinVm == null)
         {
             return;
         }
         var coinGroupVms = AppContext.Instance.CoinGroupVms.GetCoinGroupsByGroupId(this.Id);
         int sortNumber   = coinGroupVms.Count == 0 ? 1 : coinGroupVms.Count + 1;
         CoinGroupViewModel coinGroupVm = new CoinGroupViewModel(Guid.NewGuid())
         {
             CoinId     = coinVm.Id,
             GroupId    = this.Id,
             SortNumber = sortNumber
         };
         VirtualRoot.Execute(new AddCoinGroupCommand(coinGroupVm));
     });
 }
Example #3
0
 public GroupViewModel(Guid id)
 {
     _id       = id;
     this.Save = new DelegateCommand(() => {
         if (NTMinerRoot.Current.GroupSet.Contains(this.Id))
         {
             Global.Execute(new UpdateGroupCommand(this));
         }
         else
         {
             Global.Execute(new AddGroupCommand(this));
         }
         CloseWindow?.Invoke();
     });
     this.Edit = new DelegateCommand(() => {
         GroupEdit.ShowEditWindow(this);
     });
     this.Remove = new DelegateCommand(() => {
         if (this.Id == Guid.Empty)
         {
             return;
         }
         DialogWindow.ShowDialog(message: $"您确定删除{this.Name}组吗?", title: "确认", onYes: () => {
             Global.Execute(new RemoveGroupCommand(this.Id));
         }, icon: "Icon_Confirm");
     });
     this.SortUp = new DelegateCommand(() => {
         GroupViewModel upOne = GroupViewModels.Current.List.OrderByDescending(a => a.SortNumber).FirstOrDefault(a => a.SortNumber < this.SortNumber);
         if (upOne != null)
         {
             int sortNumber   = upOne.SortNumber;
             upOne.SortNumber = this.SortNumber;
             Global.Execute(new UpdateGroupCommand(upOne));
             this.SortNumber = sortNumber;
             Global.Execute(new UpdateGroupCommand(this));
             GroupViewModels.Current.OnPropertyChanged(nameof(GroupViewModels.List));
         }
     });
     this.SortDown = new DelegateCommand(() => {
         GroupViewModel nextOne = GroupViewModels.Current.List.OrderBy(a => a.SortNumber).FirstOrDefault(a => a.SortNumber > this.SortNumber);
         if (nextOne != null)
         {
             int sortNumber     = nextOne.SortNumber;
             nextOne.SortNumber = this.SortNumber;
             Global.Execute(new UpdateGroupCommand(nextOne));
             this.SortNumber = sortNumber;
             Global.Execute(new UpdateGroupCommand(this));
             GroupViewModels.Current.OnPropertyChanged(nameof(GroupViewModels.List));
         }
     });
     this.AddCoinGroup = new DelegateCommand <CoinViewModel>((coinVm) => {
         if (coinVm == null)
         {
             return;
         }
         var coinGroupVms = CoinGroupViewModels.Current.GetCoinGroupsByGroupId(this.Id);
         int sortNumber   = coinGroupVms.Count == 0 ? 1 : coinGroupVms.Count + 1;
         CoinGroupViewModel coinGroupVm = new CoinGroupViewModel(Guid.NewGuid())
         {
             CoinId     = coinVm.Id,
             GroupId    = this.Id,
             SortNumber = sortNumber
         };
         Global.Execute(new AddCoinGroupCommand(coinGroupVm));
     });
 }
Example #4
0
 public bool TryGetGroupVm(Guid groupId, out GroupViewModel groupVm)
 {
     return(_dicById.TryGetValue(groupId, out groupVm));
 }