Exemplo n.º 1
0
        public TableCategoryDescriptor(Authentication authentication, ITableCategory 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.accessInfo   = category.AccessInfo;
            this.lockInfo     = category.LockInfo;
            this.accessType   = category.GetAccessType(authentication);

            this.tablesReadonly     = new ReadOnlyObservableCollection <TableDescriptor>(this.tables);
            this.categoriesReadonly = new ReadOnlyObservableCollection <TableCategoryDescriptor>(this.categories);

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

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

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

                foreach (var item in this.category.Tables)
                {
                    if (item.Parent != null)
                    {
                        continue;
                    }
                    var descriptor = new TableDescriptor(this.authentication, item, this.descriptorTypes, this.owner);
                    item.ExtendedProperties[this.owner] = descriptor;
                    this.tables.Add(descriptor);
                }
            }
        }
Exemplo n.º 2
0
        private void Categories_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            switch (e.Action)
            {
            case NotifyCollectionChangedAction.Add:
            {
                var descriptorList = new List <TableCategoryDescriptor>(e.NewItems.Count);
                foreach (ITableCategory item in e.NewItems)
                {
                    if (item.ExtendedProperties.ContainsKey(this.owner) == true)
                    {
                        var descriptor = item.ExtendedProperties[this.owner] as TableCategoryDescriptor;
                        descriptorList.Add(descriptor);
                    }
                    else
                    {
                        var descriptor = new TableCategoryDescriptor(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 <TableCategoryDescriptor>(e.OldItems.Count);
                foreach (ITableCategory item in e.OldItems)
                {
                    var descriptor = item.ExtendedProperties[this.owner] as TableCategoryDescriptor;
                    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;
            }
        }