private void Init()
 {
     VirtualRoot.On <CoinGroupAddedEvent>("添加了币组后调整VM内存", LogEnum.DevConsole,
                                          action: (message) => {
         if (!_dicById.ContainsKey(message.Source.GetId()))
         {
             CoinGroupViewModel coinGroupVm = new CoinGroupViewModel(message.Source);
             _dicById.Add(message.Source.GetId(), coinGroupVm);
             if (!_listByGroupId.ContainsKey(coinGroupVm.GroupId))
             {
                 _listByGroupId.Add(coinGroupVm.GroupId, new List <CoinGroupViewModel>());
             }
             _listByGroupId[coinGroupVm.GroupId].Add(coinGroupVm);
             OnGroupPropertyChanged(coinGroupVm.GroupId);
         }
     }).AddToCollection(NTMinerRoot.Current.ContextHandlers);
     VirtualRoot.On <CoinGroupUpdatedEvent>("更新了币组后调整VM内存", LogEnum.DevConsole,
                                            action: (message) => {
         if (_dicById.ContainsKey(message.Source.GetId()))
         {
             CoinGroupViewModel entity = _dicById[message.Source.GetId()];
             int sortNumber            = entity.SortNumber;
             entity.Update(message.Source);
             if (sortNumber != entity.SortNumber)
             {
                 GroupViewModel groupVm;
                 if (GroupViewModels.Current.TryGetGroupVm(entity.GroupId, out groupVm))
                 {
                     groupVm.OnPropertyChanged(nameof(groupVm.CoinGroupVms));
                 }
             }
         }
     }).AddToCollection(NTMinerRoot.Current.ContextHandlers);
     VirtualRoot.On <CoinGroupRemovedEvent>("删除了币组后调整VM内存", LogEnum.DevConsole,
                                            action: (message) => {
         if (_dicById.ContainsKey(message.Source.GetId()))
         {
             var entity = _dicById[message.Source.GetId()];
             _dicById.Remove(message.Source.GetId());
             if (_listByGroupId.ContainsKey(entity.GroupId))
             {
                 _listByGroupId[entity.GroupId].Remove(entity);
             }
             OnGroupPropertyChanged(entity.GroupId);
         }
     }).AddToCollection(NTMinerRoot.Current.ContextHandlers);
     foreach (var item in NTMinerRoot.Current.CoinGroupSet)
     {
         CoinGroupViewModel groupVm = new CoinGroupViewModel(item);
         _dicById.Add(item.GetId(), groupVm);
         if (!_listByGroupId.ContainsKey(item.GroupId))
         {
             _listByGroupId.Add(item.GroupId, new List <CoinGroupViewModel>());
         }
         _listByGroupId[item.GroupId].Add(groupVm);
     }
 }
Example #2
0
 public GroupViewModel(Guid id)
 {
     _id       = id;
     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) => {
         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));
     });
 }
 public CoinGroupViewModel(Guid id)
 {
     _id         = id;
     this.Remove = new DelegateCommand(() => {
         if (this.Id == Guid.Empty)
         {
             return;
         }
         DialogWindow.ShowDialog(message: $"您确定删除{CoinVm.Code}吗?", title: "确认", onYes: () => {
             VirtualRoot.Execute(new RemoveCoinGroupCommand(this.Id));
         }, icon: IconConst.IconConfirm);
     });
     this.SortUp = new DelegateCommand(() => {
         CoinGroupViewModel upOne = CoinGroupViewModels.Current.GetCoinGroupsByGroupId(this.GroupId).OrderByDescending(a => a.SortNumber).FirstOrDefault(a => a.SortNumber < this.SortNumber);
         if (upOne != null)
         {
             int sortNumber   = upOne.SortNumber;
             upOne.SortNumber = this.SortNumber;
             VirtualRoot.Execute(new UpdateCoinGroupCommand(upOne));
             this.SortNumber = sortNumber;
             VirtualRoot.Execute(new UpdateCoinGroupCommand(this));
             GroupViewModel groupVm;
             if (GroupViewModels.Current.TryGetGroupVm(this.GroupId, out groupVm))
             {
                 groupVm.OnPropertyChanged(nameof(groupVm.CoinGroupVms));
             }
         }
     });
     this.SortDown = new DelegateCommand(() => {
         CoinGroupViewModel nextOne = CoinGroupViewModels.Current.GetCoinGroupsByGroupId(this.GroupId).OrderBy(a => a.SortNumber).FirstOrDefault(a => a.SortNumber > this.SortNumber);
         if (nextOne != null)
         {
             int sortNumber     = nextOne.SortNumber;
             nextOne.SortNumber = this.SortNumber;
             VirtualRoot.Execute(new UpdateCoinGroupCommand(nextOne));
             this.SortNumber = sortNumber;
             VirtualRoot.Execute(new UpdateCoinGroupCommand(this));
             GroupViewModel groupVm;
             if (GroupViewModels.Current.TryGetGroupVm(this.GroupId, out groupVm))
             {
                 groupVm.OnPropertyChanged(nameof(groupVm.CoinGroupVms));
             }
         }
     });
 }
Example #4
0
 public CoinGroupViewModel(Guid id)
 {
     _id         = id;
     this.Remove = new DelegateCommand(() => {
         if (this.Id == Guid.Empty)
         {
             return;
         }
         this.ShowDialog(message: $"您确定删除{CoinVm.Code}吗?", title: "确认", onYes: () => {
             VirtualRoot.Execute(new RemoveCoinGroupCommand(this.Id));
         }, icon: IconConst.IconConfirm);
     });
     this.SortUp = new DelegateCommand(() => {
         CoinGroupViewModel upOne = AppContext.Instance.CoinGroupVms.GetUpOne(this.GroupId, this.SortNumber);
         if (upOne != null)
         {
             int sortNumber   = upOne.SortNumber;
             upOne.SortNumber = this.SortNumber;
             VirtualRoot.Execute(new UpdateCoinGroupCommand(upOne));
             this.SortNumber = sortNumber;
             VirtualRoot.Execute(new UpdateCoinGroupCommand(this));
             GroupViewModel groupVm;
             if (AppContext.Instance.GroupVms.TryGetGroupVm(this.GroupId, out groupVm))
             {
                 groupVm.OnPropertyChanged(nameof(groupVm.CoinGroupVms));
             }
         }
     });
     this.SortDown = new DelegateCommand(() => {
         CoinGroupViewModel nextOne = AppContext.Instance.CoinGroupVms.GetNextOne(this.GroupId, this.SortNumber);
         if (nextOne != null)
         {
             int sortNumber     = nextOne.SortNumber;
             nextOne.SortNumber = this.SortNumber;
             VirtualRoot.Execute(new UpdateCoinGroupCommand(nextOne));
             this.SortNumber = sortNumber;
             VirtualRoot.Execute(new UpdateCoinGroupCommand(this));
             GroupViewModel groupVm;
             if (AppContext.Instance.GroupVms.TryGetGroupVm(this.GroupId, out groupVm))
             {
                 groupVm.OnPropertyChanged(nameof(groupVm.CoinGroupVms));
             }
         }
     });
 }
Example #5
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));
     });
 }
 public bool TryGetGroupVm(Guid coinGroupId, out CoinGroupViewModel groupVm)
 {
     return(_dicById.TryGetValue(coinGroupId, out groupVm));
 }
Example #7
0
 private CoinGroupViewModels() {
     foreach (var item in NTMinerRoot.Current.CoinGroupSet) {
         CoinGroupViewModel groupVm = new CoinGroupViewModel(item);
         _dicById.Add(item.GetId(), groupVm);
         if (!_listByGroupId.ContainsKey(item.GroupId)) {
             _listByGroupId.Add(item.GroupId, new List<CoinGroupViewModel>());
         }
         _listByGroupId[item.GroupId].Add(groupVm);
     }
     Global.Access<CoinGroupAddedEvent>(
         Guid.Parse("e0476d29-0115-405e-81d1-c7fb65051c83"),
         "添加了币组后调整VM内存",
         LogEnum.Log,
         action: (message) => {
             if (!_dicById.ContainsKey(message.Source.GetId())) {
                 CoinGroupViewModel coinGroupVm = new CoinGroupViewModel(message.Source);
                 _dicById.Add(message.Source.GetId(), coinGroupVm);
                 if (!_listByGroupId.ContainsKey(coinGroupVm.GroupId)) {
                     _listByGroupId.Add(coinGroupVm.GroupId, new List<CoinGroupViewModel>());
                 }
                 _listByGroupId[coinGroupVm.GroupId].Add(coinGroupVm);
                 GroupViewModel groupVm;
                 if (GroupViewModels.Current.TryGetGroupVm(coinGroupVm.GroupId, out groupVm)) {
                     groupVm.OnPropertyChanged(nameof(groupVm.CoinVms));
                     groupVm.OnPropertyChanged(nameof(groupVm.DualCoinVms));
                     groupVm.OnPropertyChanged(nameof(groupVm.CoinGroupVms));
                 }
             }
         });
     Global.Access<CoinGroupUpdatedEvent>(
         Guid.Parse("c600d33a-21e3-45ad-b9b3-cfd5578885f4"),
         "更新了币组后调整VM内存",
         LogEnum.Log,
         action: (message) => {
             if (_dicById.ContainsKey(message.Source.GetId())) {
                 CoinGroupViewModel entity = _dicById[message.Source.GetId()];
                 int sortNumber = entity.SortNumber;
                 entity.Update(message.Source);
                 if (sortNumber != entity.SortNumber) {
                     GroupViewModel groupVm;
                     if (GroupViewModels.Current.TryGetGroupVm(entity.GroupId, out groupVm)) {
                         groupVm.OnPropertyChanged(nameof(groupVm.CoinGroupVms));
                     }
                 }
             }
         });
     Global.Access<CoinGroupRemovedEvent>(
         Guid.Parse("76842ab6-c1a3-4eee-b951-f25be25ec35a"),
         "删除了币组后调整VM内存",
         LogEnum.Log,
         action: (message) => {
             if (_dicById.ContainsKey(message.Source.GetId())) {
                 var entity = _dicById[message.Source.GetId()];
                 _dicById.Remove(message.Source.GetId());
                 if (_listByGroupId.ContainsKey(entity.GroupId)) {
                     _listByGroupId[entity.GroupId].Remove(entity);
                 }
                 GroupViewModel groupVm;
                 if (GroupViewModels.Current.TryGetGroupVm(entity.GroupId, out groupVm)) {
                     groupVm.OnPropertyChanged(nameof(groupVm.CoinVms));
                     groupVm.OnPropertyChanged(nameof(groupVm.DualCoinVms));
                     groupVm.OnPropertyChanged(nameof(groupVm.CoinGroupVms));
                 }
             }
         });
 }
Example #8
0
 public GroupViewModel(Guid id)
 {
     _id       = id;
     this.Save = new DelegateCommand(() => {
         if (this.Id == Guid.Empty)
         {
             return;
         }
         if (NTMinerRoot.Current.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;
         }
         GroupEdit.ShowWindow(formType ?? FormType.Edit, this);
     });
     this.Remove = new DelegateCommand(() => {
         if (this.Id == Guid.Empty)
         {
             return;
         }
         DialogWindow.ShowDialog(message: $"您确定删除{this.Name}组吗?", title: "确认", onYes: () => {
             VirtualRoot.Execute(new RemoveGroupCommand(this.Id));
         }, icon: IconConst.IconConfirm);
     });
     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;
             VirtualRoot.Execute(new UpdateGroupCommand(upOne));
             this.SortNumber = sortNumber;
             VirtualRoot.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;
             VirtualRoot.Execute(new UpdateGroupCommand(nextOne));
             this.SortNumber = sortNumber;
             VirtualRoot.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
         };
         VirtualRoot.Execute(new AddCoinGroupCommand(coinGroupVm));
     });
 }