private AccessViewModel(Authentication authentication, IAccessible accessible, UserCategoryTreeViewItemViewModel userItem) { this.Accessible = accessible; if (accessible is IDispatcherObject dispatcherObject) { this.accessInfo = dispatcherObject.Dispatcher.Invoke(() => accessible.AccessInfo); } else { this.accessInfo = accessible.AccessInfo; } this.Authentication = authentication; this.path = userItem.Path; this.userItems = EnumerableUtility.FamilyTree <TreeViewItemViewModel>(userItem, item => item.Items).ToArray(); foreach (var item in this.userItems.Where(i => i is UserCategoryTreeViewItemViewModel)) { item.IsExpanded = true; } foreach (var item in this.accessInfo.Members) { this.ItemsSource.Add(new AccessItemViewModel(this, item.ID, item.AccessType)); } this.ItemsSource.CollectionChanged += (s, e) => this.NotifyOfPropertyChange(nameof(this.CanAdd)); this.accessType = AccessType.Master; #if DEBUG this.comment = "access test"; #endif this.DisplayName = Resources.Title_SettingAuthority; }
public static async Task <AccessViewModel> CreateInstanceAsync(Authentication authentication, IAccessibleDescriptor descriptor, UserCategoryTreeViewItemViewModel userItem) { if (authentication == null) { throw new ArgumentNullException(nameof(authentication)); } if (descriptor == null) { throw new ArgumentNullException(nameof(descriptor)); } if (userItem == null) { throw new ArgumentNullException(nameof(userItem)); } if (descriptor.Target is IAccessible accessible && accessible is IDispatcherObject dispatcherObject) { return(await dispatcherObject.Dispatcher.InvokeAsync(() => { return new AccessViewModel(authentication, accessible, userItem); })); } throw new NotImplementedException(); }