Ejemplo n.º 1
0
        private void AddDescriptor(UserDescriptor descriptor)
        {
            var viewModel = descriptor.Host == null?this.CreateInstance(this.authentication, descriptor, this.Owner) : descriptor.Host as UserTreeItemBase;

            viewModel.Parent = this;
            descriptor.Host  = viewModel;
        }
Ejemplo n.º 2
0
 private void RemoveDescriptor(UserDescriptor descriptor)
 {
     foreach (var item in this.Items.ToArray())
     {
         if (item is UserTreeItemBase viewModel && viewModel.Descriptor == descriptor)
         {
             this.Items.Remove(viewModel);
         }
     }
 }
Ejemplo n.º 3
0
        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);
                }
            }
        }
Ejemplo n.º 4
0
 protected virtual UserTreeItemBase CreateInstance(Authentication authentication, UserDescriptor descriptor, object owner)
 {
     return(new UserTreeItemBase(authentication, descriptor, owner));
 }
Ejemplo n.º 5
0
        private void Users_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            switch (e.Action)
            {
            case NotifyCollectionChangedAction.Add:
            {
                var descriptorList = new List <UserDescriptor>(e.NewItems.Count);
                foreach (IUser item in e.NewItems)
                {
                    if (item.ExtendedProperties.ContainsKey(this.owner) == true)
                    {
                        var descriptor = item.ExtendedProperties[this.owner] as UserDescriptor;
                        descriptorList.Add(descriptor);
                    }
                    else
                    {
                        var descriptor = new UserDescriptor(this.authentication, item, this.descriptorTypes, this.owner);
                        item.ExtendedProperties[this.owner] = descriptor;
                        descriptorList.Add(descriptor);
                    }
                }
                this.Dispatcher.InvokeAsync(() =>
                    {
                        foreach (var item in descriptorList)
                        {
                            this.users.Add(item);
                        }
                    });
            }
            break;

            case NotifyCollectionChangedAction.Remove:
            {
                var descriptorList = new List <UserDescriptor>(e.OldItems.Count);
                foreach (IUser item in e.OldItems)
                {
                    var descriptor = item.ExtendedProperties[this.owner] as UserDescriptor;
                    descriptorList.Add(descriptor);
                }
                this.Dispatcher.InvokeAsync(() =>
                    {
                        foreach (var item in descriptorList)
                        {
                            this.users.Remove(item);
                        }
                    });
            }
            break;

            case NotifyCollectionChangedAction.Move:
            {
            }
            break;

            case NotifyCollectionChangedAction.Reset:
            {
                this.Dispatcher.InvokeAsync(() =>
                    {
                        this.categories.Clear();
                        this.users.Clear();
                    });
            }
            break;
            }
        }