コード例 #1
0
 private SysDicItemViewModels()
 {
     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 => {
         AllPropertyChanged();
     }, location: this.GetType());
     BuildEventPath <SysDicItemAddedEvent>("调整VM内存", LogEnum.DevConsole,
                                           path: (message) => {
         if (!_dicById.ContainsKey(message.Source.GetId()))
         {
             _dicById.Add(message.Source.GetId(), new SysDicItemViewModel(message.Source));
             AllPropertyChanged();
             if (SysDicVms.TryGetSysDicVm(message.Source.DicId, out SysDicViewModel sysDicVm))
             {
                 sysDicVm.OnPropertyChanged(nameof(sysDicVm.SysDicItems));
                 sysDicVm.OnPropertyChanged(nameof(sysDicVm.SysDicItemsSelect));
             }
         }
     }, location: this.GetType());
     BuildEventPath <SysDicItemUpdatedEvent>("调整VM内存", LogEnum.DevConsole,
                                             path: (message) => {
         if (_dicById.TryGetValue(message.Source.GetId(), out SysDicItemViewModel vm))
         {
             int sortNumber = vm.SortNumber;
             vm.Update(message.Source);
             if (sortNumber != vm.SortNumber)
             {
                 if (SysDicVms.TryGetSysDicVm(vm.DicId, out SysDicViewModel sysDicVm))
                 {
                     sysDicVm.OnPropertyChanged(nameof(sysDicVm.SysDicItems));
                     sysDicVm.OnPropertyChanged(nameof(sysDicVm.SysDicItemsSelect));
                 }
             }
         }
     }, location: this.GetType());
     BuildEventPath <SysDicItemRemovedEvent>("调整VM内存", LogEnum.DevConsole,
                                             path: (message) => {
         _dicById.Remove(message.Source.GetId());
         AllPropertyChanged();
         if (SysDicVms.TryGetSysDicVm(message.Source.DicId, out SysDicViewModel sysDicVm))
         {
             sysDicVm.OnPropertyChanged(nameof(sysDicVm.SysDicItems));
             sysDicVm.OnPropertyChanged(nameof(sysDicVm.SysDicItemsSelect));
         }
     }, location: this.GetType());
     Init();
 }
コード例 #2
0
            private SysDicItemViewModels()
            {
                if (WpfUtil.IsInDesignMode)
                {
                    return;
                }
#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 => {
                    OnPropertyChangeds();
                }, location: this.GetType());
                AddEventPath <SysDicItemAddedEvent>("添加了系统字典项后调整VM内存", LogEnum.DevConsole,
                                                    action: (message) => {
                    if (!_dicById.ContainsKey(message.Source.GetId()))
                    {
                        _dicById.Add(message.Source.GetId(), new SysDicItemViewModel(message.Source));
                        OnPropertyChangeds();
                        if (SysDicVms.TryGetSysDicVm(message.Source.DicId, out SysDicViewModel sysDicVm))
                        {
                            sysDicVm.OnPropertyChanged(nameof(sysDicVm.SysDicItems));
                            sysDicVm.OnPropertyChanged(nameof(sysDicVm.SysDicItemsSelect));
                        }
                    }
                }, location: this.GetType());
                AddEventPath <SysDicItemUpdatedEvent>("更新了系统字典项后调整VM内存", LogEnum.DevConsole,
                                                      action: (message) => {
                    if (_dicById.TryGetValue(message.Source.GetId(), out SysDicItemViewModel vm))
                    {
                        int sortNumber = vm.SortNumber;
                        vm.Update(message.Source);
                        if (sortNumber != vm.SortNumber)
                        {
                            if (SysDicVms.TryGetSysDicVm(vm.DicId, out SysDicViewModel sysDicVm))
                            {
                                sysDicVm.OnPropertyChanged(nameof(sysDicVm.SysDicItems));
                                sysDicVm.OnPropertyChanged(nameof(sysDicVm.SysDicItemsSelect));
                            }
                        }
                    }
                }, location: this.GetType());
                AddEventPath <SysDicItemRemovedEvent>("删除了系统字典项后调整VM内存", LogEnum.DevConsole,
                                                      action: (message) => {
                    _dicById.Remove(message.Source.GetId());
                    OnPropertyChangeds();
                    if (SysDicVms.TryGetSysDicVm(message.Source.DicId, out SysDicViewModel sysDicVm))
                    {
                        sysDicVm.OnPropertyChanged(nameof(sysDicVm.SysDicItems));
                        sysDicVm.OnPropertyChanged(nameof(sysDicVm.SysDicItemsSelect));
                    }
                }, location: this.GetType());
                Init();
#if DEBUG
                var elapsedMilliseconds = NTStopwatch.Stop();
                if (elapsedMilliseconds.ElapsedMilliseconds > NTStopwatch.ElapsedMilliseconds)
                {
                    Write.DevTimeSpan($"耗时{elapsedMilliseconds} {this.GetType().Name}.ctor");
                }
#endif
            }