Exemple #1
0
 private void Init()
 {
     VirtualRoot.On <KernelOutputTranslaterAddedEvent>("添加了内核输出翻译器后刷新VM内存", LogEnum.DevConsole,
                                                       action: message => {
         KernelOutputViewModel kernelOutputVm;
         if (KernelOutputViewModels.Current.TryGetKernelOutputVm(message.Source.KernelOutputId, out kernelOutputVm))
         {
             if (!_dicByKernelOutputId.ContainsKey(message.Source.KernelOutputId))
             {
                 _dicByKernelOutputId.Add(message.Source.KernelOutputId, new List <KernelOutputTranslaterViewModel>());
             }
             var vm = new KernelOutputTranslaterViewModel(message.Source);
             _dicByKernelOutputId[message.Source.KernelOutputId].Add(vm);
             _dicById.Add(message.Source.GetId(), vm);
             kernelOutputVm.OnPropertyChanged(nameof(kernelOutputVm.KernelOutputTranslaters));
         }
     }).AddToCollection(NTMinerRoot.Current.ContextHandlers);
     VirtualRoot.On <KernelOutputTranslaterUpdatedEvent>("更新了内核输出翻译器后刷新VM内存", LogEnum.DevConsole,
                                                         action: message => {
         if (_dicByKernelOutputId.ContainsKey(message.Source.KernelOutputId))
         {
             var item = _dicByKernelOutputId[message.Source.KernelOutputId].FirstOrDefault(a => a.Id == message.Source.GetId());
             if (item != null)
             {
                 item.Update(message.Source);
             }
         }
     }).AddToCollection(NTMinerRoot.Current.ContextHandlers);
     VirtualRoot.On <KernelOutputTranslaterRemovedEvent>("移除了内核输出翻译器后刷新VM内存", LogEnum.DevConsole,
                                                         action: message => {
         if (_dicByKernelOutputId.ContainsKey(message.Source.KernelOutputId))
         {
             var item = _dicByKernelOutputId[message.Source.KernelOutputId].FirstOrDefault(a => a.Id == message.Source.GetId());
             if (item != null)
             {
                 _dicByKernelOutputId[message.Source.KernelOutputId].Remove(item);
             }
         }
         if (_dicById.ContainsKey(message.Source.GetId()))
         {
             _dicById.Remove(message.Source.GetId());
         }
         KernelOutputViewModel kernelOutputVm;
         if (KernelOutputViewModels.Current.TryGetKernelOutputVm(message.Source.KernelOutputId, out kernelOutputVm))
         {
             kernelOutputVm.OnPropertyChanged(nameof(kernelOutputVm.KernelOutputTranslaters));
         }
     }).AddToCollection(NTMinerRoot.Current.ContextHandlers);
     foreach (var item in NTMinerRoot.Current.KernelOutputTranslaterSet)
     {
         if (!_dicByKernelOutputId.ContainsKey(item.KernelOutputId))
         {
             _dicByKernelOutputId.Add(item.KernelOutputId, new List <KernelOutputTranslaterViewModel>());
         }
         var vm = new KernelOutputTranslaterViewModel(item);
         _dicByKernelOutputId[item.KernelOutputId].Add(vm);
         _dicById.Add(item.GetId(), vm);
     }
 }
 public KernelOutputTranslaterViewModel(Guid id)
 {
     _id       = id;
     this.Edit = new DelegateCommand(() => {
         KernelOutputTranslaterEdit.ShowEditWindow(this);
     });
     this.Remove = new DelegateCommand(() => {
         if (this.Id == Guid.Empty)
         {
             return;
         }
         DialogWindow.ShowDialog(message: $"您确定删除{this.RegexPattern}内核输出翻译器吗?", title: "确认", onYes: () => {
             Global.Execute(new RemoveKernelOutputTranslaterCommand(this.Id));
         }, icon: "Icon_Confirm");
     });
     this.SortUp = new DelegateCommand(() => {
         KernelOutputTranslaterViewModel upOne = KernelOutputTranslaterViewModels.Current.GetListByKernelId(this.KernelId).OrderByDescending(a => a.SortNumber).FirstOrDefault(a => a.SortNumber < this.SortNumber);
         if (upOne != null)
         {
             int sortNumber   = upOne.SortNumber;
             upOne.SortNumber = this.SortNumber;
             Global.Execute(new UpdateKernelOutputTranslaterCommand(upOne));
             this.SortNumber = sortNumber;
             Global.Execute(new UpdateKernelOutputTranslaterCommand(this));
             KernelOutputTranslaterViewModels.Current.OnPropertyChanged(nameof(KernelOutputTranslaterViewModels.AllKernelOutputTranslaterVms));
             if (KernelViewModels.Current.TryGetKernelVm(this.KernelId, out KernelViewModel kernelVm))
             {
                 kernelVm.OnPropertyChanged(nameof(kernelVm.KernelOutputTranslaters));
             }
         }
     });
     this.SortDown = new DelegateCommand(() => {
         KernelOutputTranslaterViewModel nextOne = KernelOutputTranslaterViewModels.Current.GetListByKernelId(this.KernelId).OrderBy(a => a.SortNumber).FirstOrDefault(a => a.SortNumber > this.SortNumber);
         if (nextOne != null)
         {
             int sortNumber     = nextOne.SortNumber;
             nextOne.SortNumber = this.SortNumber;
             Global.Execute(new UpdateKernelOutputTranslaterCommand(nextOne));
             this.SortNumber = sortNumber;
             Global.Execute(new UpdateKernelOutputTranslaterCommand(this));
             KernelOutputTranslaterViewModels.Current.OnPropertyChanged(nameof(KernelOutputTranslaterViewModels.AllKernelOutputTranslaterVms));
             if (KernelViewModels.Current.TryGetKernelVm(this.KernelId, out KernelViewModel kernelVm))
             {
                 kernelVm.OnPropertyChanged(nameof(kernelVm.KernelOutputTranslaters));
             }
         }
     });
 }
Exemple #3
0
 public KernelOutputTranslaterViewModel(Guid id)
 {
     _id       = id;
     this.Save = new DelegateCommand(() => {
         int sortNumber = this.SortNumber;
         if (NTMinerRoot.Current.KernelOutputTranslaterSet.Contains(this.Id))
         {
             VirtualRoot.Execute(new UpdateKernelOutputTranslaterCommand(this));
         }
         else
         {
             VirtualRoot.Execute(new AddKernelOutputTranslaterCommand(this));
         }
         if (sortNumber != this.SortNumber)
         {
             if (KernelOutputViewModels.Current.TryGetKernelOutputVm(this.KernelOutputId, out KernelOutputViewModel kernelOutputVm))
             {
                 kernelOutputVm.OnPropertyChanged(nameof(kernelOutputVm.KernelOutputTranslaters));
             }
         }
         CloseWindow?.Invoke();
     });
     this.Edit = new DelegateCommand <FormType?>((formType) => {
         KernelOutputTranslaterEdit.ShowWindow(formType ?? FormType.Edit, this);
     });
     this.Remove = new DelegateCommand(() => {
         if (this.Id == Guid.Empty)
         {
             return;
         }
         DialogWindow.ShowDialog(message: $"您确定删除{this.RegexPattern}内核输出翻译器吗?", title: "确认", onYes: () => {
             VirtualRoot.Execute(new RemoveKernelOutputTranslaterCommand(this.Id));
         }, icon: IconConst.IconConfirm);
     });
     this.SortUp = new DelegateCommand(() => {
         KernelOutputTranslaterViewModel upOne = KernelOutputTranslaterViewModels.Current.GetListByKernelId(this.KernelOutputId).OrderByDescending(a => a.SortNumber).FirstOrDefault(a => a.SortNumber < this.SortNumber);
         if (upOne != null)
         {
             int sortNumber   = upOne.SortNumber;
             upOne.SortNumber = this.SortNumber;
             VirtualRoot.Execute(new UpdateKernelOutputTranslaterCommand(upOne));
             this.SortNumber = sortNumber;
             VirtualRoot.Execute(new UpdateKernelOutputTranslaterCommand(this));
             KernelOutputTranslaterViewModels.Current.OnPropertyChanged(nameof(KernelOutputTranslaterViewModels.AllKernelOutputTranslaterVms));
             if (KernelOutputViewModels.Current.TryGetKernelOutputVm(this.KernelOutputId, out KernelOutputViewModel kernelOutputVm))
             {
                 kernelOutputVm.OnPropertyChanged(nameof(kernelOutputVm.KernelOutputTranslaters));
             }
         }
     });
     this.SortDown = new DelegateCommand(() => {
         KernelOutputTranslaterViewModel nextOne = KernelOutputTranslaterViewModels.Current.GetListByKernelId(this.KernelOutputId).OrderBy(a => a.SortNumber).FirstOrDefault(a => a.SortNumber > this.SortNumber);
         if (nextOne != null)
         {
             int sortNumber     = nextOne.SortNumber;
             nextOne.SortNumber = this.SortNumber;
             VirtualRoot.Execute(new UpdateKernelOutputTranslaterCommand(nextOne));
             this.SortNumber = sortNumber;
             VirtualRoot.Execute(new UpdateKernelOutputTranslaterCommand(this));
             KernelOutputTranslaterViewModels.Current.OnPropertyChanged(nameof(KernelOutputTranslaterViewModels.AllKernelOutputTranslaterVms));
             if (KernelOutputViewModels.Current.TryGetKernelOutputVm(this.KernelOutputId, out KernelOutputViewModel kernelOutputVm))
             {
                 kernelOutputVm.OnPropertyChanged(nameof(kernelOutputVm.KernelOutputTranslaters));
             }
         }
     });
 }
 public KernelOutputTranslaterViewModel(Guid id)
 {
     _id       = id;
     this.Save = new DelegateCommand(() => {
         int sortNumber = this.SortNumber;
         if (NTMinerRoot.Instance.KernelOutputTranslaterSet.Contains(this.Id))
         {
             VirtualRoot.Execute(new UpdateKernelOutputTranslaterCommand(this));
         }
         else
         {
             VirtualRoot.Execute(new AddKernelOutputTranslaterCommand(this));
         }
         if (sortNumber != this.SortNumber)
         {
             if (AppContext.Instance.KernelOutputVms.TryGetKernelOutputVm(this.KernelOutputId, out KernelOutputViewModel kernelOutputVm))
             {
                 kernelOutputVm.OnPropertyChanged(nameof(kernelOutputVm.KernelOutputTranslaters));
             }
         }
         CloseWindow?.Invoke();
     });
     this.Edit = new DelegateCommand <FormType?>((formType) => {
         VirtualRoot.Execute(new KernelOutputTranslaterEditCommand(formType ?? FormType.Edit, this));
     });
     this.Remove = new DelegateCommand(() => {
         if (this.Id == Guid.Empty)
         {
             return;
         }
         this.ShowDialog(new DialogWindowViewModel(message: $"您确定删除{this.RegexPattern}内核输出翻译器吗?", title: "确认", onYes: () => {
             VirtualRoot.Execute(new RemoveKernelOutputTranslaterCommand(this.Id));
         }));
     });
     this.SortUp = new DelegateCommand(() => {
         KernelOutputTranslaterViewModel upOne = AppContext.Instance.KernelOutputTranslaterVms.GetUpOne(this.KernelOutputId, this.SortNumber);
         if (upOne != null)
         {
             int sortNumber   = upOne.SortNumber;
             upOne.SortNumber = this.SortNumber;
             VirtualRoot.Execute(new UpdateKernelOutputTranslaterCommand(upOne));
             this.SortNumber = sortNumber;
             VirtualRoot.Execute(new UpdateKernelOutputTranslaterCommand(this));
             AppContext.Instance.KernelOutputTranslaterVms.OnPropertyChanged(nameof(AppContext.KernelOutputTranslaterViewModels.AllKernelOutputTranslaterVms));
             if (AppContext.Instance.KernelOutputVms.TryGetKernelOutputVm(this.KernelOutputId, out KernelOutputViewModel kernelOutputVm))
             {
                 kernelOutputVm.OnPropertyChanged(nameof(kernelOutputVm.KernelOutputTranslaters));
             }
         }
     });
     this.SortDown = new DelegateCommand(() => {
         KernelOutputTranslaterViewModel nextOne = AppContext.Instance.KernelOutputTranslaterVms.GetNextOne(this.KernelOutputId, this.SortNumber);
         if (nextOne != null)
         {
             int sortNumber     = nextOne.SortNumber;
             nextOne.SortNumber = this.SortNumber;
             VirtualRoot.Execute(new UpdateKernelOutputTranslaterCommand(nextOne));
             this.SortNumber = sortNumber;
             VirtualRoot.Execute(new UpdateKernelOutputTranslaterCommand(this));
             AppContext.Instance.KernelOutputTranslaterVms.OnPropertyChanged(nameof(AppContext.KernelOutputTranslaterViewModels.AllKernelOutputTranslaterVms));
             if (AppContext.Instance.KernelOutputVms.TryGetKernelOutputVm(this.KernelOutputId, out KernelOutputViewModel kernelOutputVm))
             {
                 kernelOutputVm.OnPropertyChanged(nameof(kernelOutputVm.KernelOutputTranslaters));
             }
         }
     });
 }
Exemple #5
0
 public KernelOutputTranslaterViewModel(Guid id, Guid kernelOutputId, int sortNumber)
 {
     _id             = id;
     _kernelOutputId = kernelOutputId;
     _sortNumber     = sortNumber;
     _isPre          = true;// 在UI上将IsPre属性视为只读的选中状态的复选框
     this.Save       = new DelegateCommand(() => {
         int oldSortNumber = this.SortNumber;
         if (NTMinerContext.Instance.ServerContext.KernelOutputTranslaterSet.Contains(this.Id))
         {
             VirtualRoot.Execute(new UpdateKernelOutputTranslaterCommand(this));
         }
         else
         {
             VirtualRoot.Execute(new AddKernelOutputTranslaterCommand(this));
         }
         if (oldSortNumber != this.SortNumber)
         {
             if (AppRoot.KernelOutputVms.TryGetKernelOutputVm(this.KernelOutputId, out KernelOutputViewModel kernelOutputVm))
             {
                 kernelOutputVm.OnPropertyChanged(nameof(kernelOutputVm.KernelOutputTranslaters));
             }
         }
         VirtualRoot.Execute(new CloseWindowCommand(this.Id));
     });
     this.Edit = new DelegateCommand <FormType?>((formType) => {
         VirtualRoot.Execute(new EditKernelOutputTranslaterCommand(formType ?? FormType.Edit, this));
     });
     this.Remove = new DelegateCommand(() => {
         if (this.Id == Guid.Empty)
         {
             return;
         }
         this.ShowSoftDialog(new DialogWindowViewModel(message: $"您确定删除{this.RegexPattern}内核输出翻译器吗?", title: "确认", onYes: () => {
             VirtualRoot.Execute(new RemoveKernelOutputTranslaterCommand(this.Id));
         }));
     });
     this.SortUp = new DelegateCommand(() => {
         KernelOutputTranslaterViewModel upOne = AppRoot.KernelOutputTranslaterVms.GetListByKernelOutputId(this.KernelOutputId).GetUpOne(this.SortNumber);
         if (upOne != null)
         {
             int oldSortNumber = upOne.SortNumber;
             upOne.SortNumber  = this.SortNumber;
             VirtualRoot.Execute(new UpdateKernelOutputTranslaterCommand(upOne));
             this.SortNumber = oldSortNumber;
             VirtualRoot.Execute(new UpdateKernelOutputTranslaterCommand(this));
             AppRoot.KernelOutputTranslaterVms.OnPropertyChanged(nameof(AppRoot.KernelOutputTranslaterViewModels.AllKernelOutputTranslaterVms));
             if (AppRoot.KernelOutputVms.TryGetKernelOutputVm(this.KernelOutputId, out KernelOutputViewModel kernelOutputVm))
             {
                 kernelOutputVm.OnPropertyChanged(nameof(kernelOutputVm.KernelOutputTranslaters));
             }
         }
     });
     this.SortDown = new DelegateCommand(() => {
         KernelOutputTranslaterViewModel nextOne = AppRoot.KernelOutputTranslaterVms.GetListByKernelOutputId(this.KernelOutputId).GetNextOne(this.SortNumber);
         if (nextOne != null)
         {
             int oldSortNumber  = nextOne.SortNumber;
             nextOne.SortNumber = this.SortNumber;
             VirtualRoot.Execute(new UpdateKernelOutputTranslaterCommand(nextOne));
             this.SortNumber = oldSortNumber;
             VirtualRoot.Execute(new UpdateKernelOutputTranslaterCommand(this));
             AppRoot.KernelOutputTranslaterVms.OnPropertyChanged(nameof(AppRoot.KernelOutputTranslaterViewModels.AllKernelOutputTranslaterVms));
             if (AppRoot.KernelOutputVms.TryGetKernelOutputVm(this.KernelOutputId, out KernelOutputViewModel kernelOutputVm))
             {
                 kernelOutputVm.OnPropertyChanged(nameof(kernelOutputVm.KernelOutputTranslaters));
             }
         }
     });
 }
 private KernelOutputTranslaterViewModels()
 {
     foreach (var item in NTMinerRoot.Current.KernelOutputTranslaterSet)
     {
         if (!_dicByKernelId.ContainsKey(item.KernelId))
         {
             _dicByKernelId.Add(item.KernelId, new List <KernelOutputTranslaterViewModel>());
         }
         var vm = new KernelOutputTranslaterViewModel(item);
         _dicByKernelId[item.KernelId].Add(vm);
         _dicById.Add(item.GetId(), vm);
     }
     Global.Access <KernelOutputTranslaterAddedEvent>(
         Guid.Parse("70f5bc18-3536-4306-9af7-256f323c9313"),
         "添加了内核输出翻译器后刷新VM内存",
         LogEnum.None,
         action: message => {
         KernelViewModel kernelVm;
         if (KernelViewModels.Current.TryGetKernelVm(message.Source.KernelId, out kernelVm))
         {
             if (!_dicByKernelId.ContainsKey(message.Source.KernelId))
             {
                 _dicByKernelId.Add(message.Source.KernelId, new List <KernelOutputTranslaterViewModel>());
             }
             var vm = new KernelOutputTranslaterViewModel(message.Source);
             _dicByKernelId[message.Source.KernelId].Add(vm);
             _dicById.Add(message.Source.GetId(), vm);
             kernelVm.OnPropertyChanged(nameof(kernelVm.KernelOutputTranslaters));
         }
     });
     Global.Access <KernelOutputTranslaterUpdatedEvent>(
         Guid.Parse("eef26e4b-af61-436b-9f24-9e128d614598"),
         "更新了内核输出翻译器后刷新VM内存",
         LogEnum.None,
         action: message => {
         if (_dicByKernelId.ContainsKey(message.Source.KernelId))
         {
             var item = _dicByKernelId[message.Source.KernelId].FirstOrDefault(a => a.Id == message.Source.GetId());
             if (item != null)
             {
                 item.Update(message.Source);
             }
         }
     });
     Global.Access <KernelOutputTranslaterRemovedEvent>(
         Guid.Parse("d77c3aaa-be1f-41b2-9e9f-495fa6a076bf"),
         "移除了内核输出翻译器后刷新VM内存",
         LogEnum.None,
         action: message => {
         if (_dicByKernelId.ContainsKey(message.Source.KernelId))
         {
             var item = _dicByKernelId[message.Source.KernelId].FirstOrDefault(a => a.Id == message.Source.GetId());
             if (item != null)
             {
                 _dicByKernelId[message.Source.KernelId].Remove(item);
             }
         }
         if (_dicById.ContainsKey(message.Source.GetId()))
         {
             _dicById.Remove(message.Source.GetId());
         }
         KernelViewModel kernelVm;
         if (KernelViewModels.Current.TryGetKernelVm(message.Source.KernelId, out kernelVm))
         {
             kernelVm.OnPropertyChanged(nameof(kernelVm.KernelOutputTranslaters));
         }
     });
 }