public DomainCategoryDescriptor(Authentication authentication, IDomainCategory category, DescriptorTypes descriptorTypes, object owner) : base(authentication, category, descriptorTypes) { this.category = category; this.owner = owner ?? this; this.category.Dispatcher.VerifyAccess(); this.categoryName = category.Name; this.categoryPath = category.Path; this.domainsReadonly = new ReadOnlyObservableCollection <DomainDescriptor>(this.domains); this.categoriesReadonly = new ReadOnlyObservableCollection <DomainCategoryDescriptor>(this.categories); if (this.descriptorTypes.HasFlag(DescriptorTypes.IsSubscriptable) == true) { this.category.Renamed += Category_Renamed; } if (this.descriptorTypes.HasFlag(DescriptorTypes.IsRecursive) == true) { if (this.descriptorTypes.HasFlag(DescriptorTypes.IsSubscriptable) == true) { this.category.Domains.CollectionChanged += Domains_CollectionChanged; this.category.Categories.CollectionChanged += Categories_CollectionChanged; } foreach (var item in this.category.Categories) { var descriptor = new DomainCategoryDescriptor(this.authentication, item, this.descriptorTypes, this.owner); item.ExtendedProperties[this.owner] = descriptor; this.categories.Add(descriptor); } foreach (var item in this.category.Domains) { var descriptor = new DomainDescriptor(this.authentication, item, this.descriptorTypes, this.owner); item.ExtendedProperties[this.owner] = descriptor; this.domains.Add(descriptor); } } if (this.category.GetService(typeof(IDataBase)) is IDataBase dataBase) { this.isActivated = dataBase.IsLoaded; if (this.descriptorTypes.HasFlag(DescriptorTypes.IsSubscriptable) == true) { dataBase.Loaded += DataBase_Loaded; dataBase.Unloaded += DataBase_Unloaded; } } }
private void Categories_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e) { switch (e.Action) { case NotifyCollectionChangedAction.Add: { var descriptorList = new List <DomainCategoryDescriptor>(e.NewItems.Count); foreach (IDomainCategory item in e.NewItems) { if (item.ExtendedProperties.ContainsKey(this.owner) == true) { var descriptor = item.ExtendedProperties[this.owner] as DomainCategoryDescriptor; descriptorList.Add(descriptor); } else { var descriptor = new DomainCategoryDescriptor(this.authentication, item, this.descriptorTypes, this.owner); item.ExtendedProperties[this.owner] = descriptor; descriptorList.Add(descriptor); } } this.Dispatcher.InvokeAsync(() => { foreach (var item in descriptorList) { this.categories.Add(item); } }); } break; case NotifyCollectionChangedAction.Remove: { var descriptorList = new List <DomainCategoryDescriptor>(e.OldItems.Count); foreach (IDomainCategory item in e.OldItems) { var descriptor = item.ExtendedProperties[this.owner] as DomainCategoryDescriptor; descriptorList.Add(descriptor); } this.Dispatcher.InvokeAsync(() => { foreach (var item in descriptorList) { this.categories.Remove(item); } }); } break; case NotifyCollectionChangedAction.Move: { } break; case NotifyCollectionChangedAction.Reset: { this.Dispatcher.InvokeAsync(() => { this.categories.Clear(); }); } break; } }