public UserCategoryDescriptor(Authentication authentication, IUserCategory 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.usersReadonly      = new ReadOnlyObservableCollection <UserDescriptor>(this.users);
            this.categoriesReadonly = new ReadOnlyObservableCollection <UserCategoryDescriptor>(this.categories);

            if (this.descriptorTypes.HasFlag(DescriptorTypes.IsSubscriptable) == true)
            {
                this.category.Renamed += Category_Renamed;
                this.category.Moved   += Category_Moved;
                this.category.Deleted += Category_Deleted;
            }

            if (this.descriptorTypes.HasFlag(DescriptorTypes.IsRecursive) == true)
            {
                if (this.descriptorTypes.HasFlag(DescriptorTypes.IsSubscriptable) == true)
                {
                    this.category.Users.CollectionChanged      += Users_CollectionChanged;
                    this.category.Categories.CollectionChanged += Categories_CollectionChanged;
                }

                foreach (var item in this.category.Categories)
                {
                    var descriptor = new UserCategoryDescriptor(this.authentication, item, this.descriptorTypes, this.owner);
                    item.ExtendedProperties[this.owner] = descriptor;
                    this.categories.Add(descriptor);
                }

                foreach (var item in this.category.Users)
                {
                    var descriptor = new UserDescriptor(this.authentication, item, this.descriptorTypes, this.owner);
                    item.ExtendedProperties[this.owner] = descriptor;
                    this.users.Add(descriptor);
                }
            }
        }
        private void Categories_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            switch (e.Action)
            {
            case NotifyCollectionChangedAction.Add:
            {
                var descriptorList = new List <UserCategoryDescriptor>(e.NewItems.Count);
                foreach (IUserCategory item in e.NewItems)
                {
                    if (item.ExtendedProperties.ContainsKey(this.owner) == true)
                    {
                        var descriptor = item.ExtendedProperties[this.owner] as UserCategoryDescriptor;
                        descriptorList.Add(descriptor);
                    }
                    else
                    {
                        var descriptor = new UserCategoryDescriptor(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 <UserCategoryDescriptor>(e.OldItems.Count);
                foreach (IUserCategory item in e.OldItems)
                {
                    var descriptor = item.ExtendedProperties[this.owner] as UserCategoryDescriptor;
                    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;
            }
        }