コード例 #1
0
        private AccessViewModel(Authentication authentication, IAccessible accessible, UserCategoryTreeViewItemViewModel userItem)
        {
            this.accessible = accessible;
            if (accessible is IDispatcherObject dispatcherObject)
            {
                this.dispatcher = dispatcherObject.Dispatcher;
                this.dispatcher.VerifyAccess();
                this.accessInfo = accessible.AccessInfo;
            }
            else
            {
                this.dispatcher = base.Dispatcher;
                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.UserID, 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;
        }
コード例 #2
0
        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)
            {
                var dispatcher = accessible is IDispatcherObject dispatcherObject ? dispatcherObject.Dispatcher : Application.Current.Dispatcher;
                return(await dispatcher.InvokeAsync(() =>
                {
                    return new AccessViewModel(authentication, accessible, userItem);
                }));
            }
            throw new NotImplementedException();
        }