コード例 #1
0
        public static bool CanLock(Authentication authentication, ILockableDescriptor descriptor)
        {
            if (descriptor.LockInfo.IsLocked == true && descriptor.LockInfo.IsInherited == false)
            {
                return(false);
            }

            return(authentication.Authority == Authority.Admin || authentication.Authority == Authority.Member);
        }
コード例 #2
0
        public static bool CanUnlock(Authentication authentication, ILockableDescriptor descriptor)
        {
            if (descriptor.LockInfo.IsLocked == false || descriptor.LockInfo.IsInherited == true)
            {
                return(false);
            }

            return(descriptor.LockInfo.IsOwner(authentication.ID) == true);
        }
コード例 #3
0
        public static async Task <bool> UnlockAsync(Authentication authentication, ILockableDescriptor descriptor)
        {
            if (descriptor.Target is ILockable lockable)
            {
                var dispatcher = lockable is IDispatcherObject dispatcherObject ? dispatcherObject.Dispatcher : Application.Current.Dispatcher;
                try
                {
                    await dispatcher.InvokeAsync(() => lockable.Unlock(authentication));

                    return(true);
                }
                catch (Exception e)
                {
                    AppMessageBox.ShowError(e);
                    return(false);
                }
            }
            else
            {
                throw new NotImplementedException();
            }
        }
コード例 #4
0
        public static async Task <bool> UnlockAsync(Authentication authentication, ILockableDescriptor descriptor)
        {
            if (descriptor.Target is ILockable lockable)
            {
                try
                {
                    await lockable.UnlockAsync(authentication);

                    return(true);
                }
                catch (Exception e)
                {
                    await AppMessageBox.ShowErrorAsync(e);

                    return(false);
                }
            }
            else
            {
                throw new NotImplementedException();
            }
        }
コード例 #5
0
 public override void SelectObject(object obj)
 {
     this.Detach();
     this.descriptor = obj as ILockableDescriptor;
     this.Attach();
 }
コード例 #6
0
        public static async Task <bool> LockAsync(Authentication authentication, ILockableDescriptor descriptor)
        {
            var dialog = await LockLockableViewModel.CreateInstanceAsync(authentication, descriptor);

            return(dialog?.ShowDialog() == true);
        }
コード例 #7
0
 public static bool IsLockInherited(Authentication authentication, ILockableDescriptor descriptor)
 {
     return(descriptor.LockInfo.IsInherited);
 }
コード例 #8
0
 public static bool IsLockOwner(Authentication authentication, ILockableDescriptor descriptor)
 {
     return(descriptor.LockInfo.IsOwner(authentication.ID));
 }
コード例 #9
0
        public static async Task <LockLockableViewModel> CreateInstanceAsync(Authentication authentication, ILockableDescriptor descriptor)
        {
            if (authentication == null)
            {
                throw new ArgumentNullException(nameof(authentication));
            }
            if (descriptor == null)
            {
                throw new ArgumentNullException(nameof(descriptor));
            }

            if (descriptor.Target is ILockable lockable)
            {
                var dispatcher = lockable is IDispatcherObject dispatcherObject ? dispatcherObject.Dispatcher : Application.Current.Dispatcher;
                return(await dispatcher.InvokeAsync(() =>
                {
                    return new LockLockableViewModel(authentication, lockable);
                }));
            }
            else
            {
                throw new ArgumentException("Invalid Target of Descriptor", nameof(descriptor));
            }
        }
コード例 #10
0
        public static async Task <LockLockableViewModel> CreateInstanceAsync(Authentication authentication, ILockableDescriptor descriptor)
        {
            if (authentication == null)
            {
                throw new ArgumentNullException(nameof(authentication));
            }
            if (descriptor == null)
            {
                throw new ArgumentNullException(nameof(descriptor));
            }

            if (descriptor.Target is ILockable lockable && lockable is IDispatcherObject dispatcherObject)
            {
                return(await dispatcherObject.Dispatcher.InvokeAsync(() =>
                {
                    return new LockLockableViewModel(authentication, lockable);
                }));
            }