Пример #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);
                }));
            }