Пример #1
0
        private void AddDescriptor(TableDescriptor descriptor)
        {
            var viewModel = descriptor.Host == null?this.CreateInstance(this.authentication, descriptor, this.Owner) : descriptor.Host as TableTreeItemBase;

            viewModel.Parent = this;
            descriptor.Host  = viewModel;
        }
Пример #2
0
 private void RemoveDescriptor(TableDescriptor descriptor)
 {
     foreach (var item in this.Items.ToArray())
     {
         if (item is TableTreeItemBase viewModel && viewModel.Descriptor == descriptor)
         {
             this.Items.Remove(viewModel);
         }
     }
 }
Пример #3
0
        public TableDescriptor(Authentication authentication, ITable table, DescriptorTypes descriptorTypes, object owner)
            : base(authentication, table, descriptorTypes)
        {
            this.table = table;
            this.owner = owner ?? this;
            this.table.Dispatcher.VerifyAccess();
            this.tableInfo      = table.TableInfo;
            this.tableState     = table.TableState;
            this.tableAttribute = TableAttribute.None;
            if (this.table.DerivedTables.Any() == true)
            {
                this.tableAttribute |= TableAttribute.BaseTable;
            }
            if (this.table.TemplatedParent != null)
            {
                this.tableAttribute |= TableAttribute.DerivedTable;
            }
            if (this.table.Parent != null)
            {
                this.tableAttribute |= TableAttribute.HasParent;
            }
            this.lockInfo           = table.LockInfo;
            this.accessInfo         = table.AccessInfo;
            this.accessType         = table.GetAccessType(this.authentication);
            this.templateDescriptor = new TableTemplateDescriptor(authentication, table.Template, descriptorTypes, owner);
            this.contentDescriptor  = new TableContentDescriptor(authentication, table.Content, descriptorTypes, owner);
            this.childsReadonly     = new ReadOnlyObservableCollection <TableDescriptor>(this.childs);
            this.table.ExtendedProperties[this.owner] = this;

            if (this.descriptorTypes.HasFlag(DescriptorTypes.IsSubscriptable) == true)
            {
                this.table.Deleted           += Table_Deleted;
                this.table.LockChanged       += Table_LockChanged;
                this.table.AccessChanged     += Table_AccessChanged;
                this.table.TableInfoChanged  += Table_TableInfoChanged;
                this.table.TableStateChanged += Table_TableStateChanged;
                this.table.DerivedTables.CollectionChanged += DerivedTables_CollectionChanged;
            }

            if (this.descriptorTypes.HasFlag(DescriptorTypes.IsRecursive) == true)
            {
                if (this.descriptorTypes.HasFlag(DescriptorTypes.IsSubscriptable) == true)
                {
                    this.table.Childs.CollectionChanged += Childs_CollectionChanged;
                }

                foreach (var item in this.table.Childs)
                {
                    var descriptor = new TableDescriptor(this.authentication, item, this.descriptorTypes, this.owner);
                    this.childs.Add(descriptor);
                }
            }
        }
Пример #4
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);
                }
            }
        }
Пример #5
0
 protected virtual TableTreeItemBase CreateInstance(Authentication authentication, TableDescriptor descriptor, object owner)
 {
     return(new TableTreeItemBase(authentication, descriptor, owner));
 }
Пример #6
0
        private void Childs_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            switch (e.Action)
            {
            case NotifyCollectionChangedAction.Add:
            {
                var descriptorList = new List <TableDescriptor>(e.NewItems.Count);
                foreach (ITable item in e.NewItems)
                {
                    if (item.ExtendedProperties.ContainsKey(this.owner) == true)
                    {
                        var descriptor = item.ExtendedProperties[this.owner] as TableDescriptor;
                        descriptorList.Add(descriptor);
                    }
                    else
                    {
                        var descriptor = new TableDescriptor(this.authentication, item, this.descriptorTypes, this.owner);
                        descriptorList.Add(descriptor);
                    }
                }
                this.Dispatcher.InvokeAsync(() =>
                    {
                        foreach (var item in descriptorList)
                        {
                            this.childs.Add(item);
                        }
                    });
            }
            break;

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

            case NotifyCollectionChangedAction.Move:
            {
            }
            break;

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