Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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();
            }
        }
Exemplo n.º 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();
            }
        }
Exemplo n.º 5
0
 public override void SelectObject(object obj)
 {
     this.Detach();
     this.descriptor = obj as ILockableDescriptor;
     this.Attach();
 }
Exemplo n.º 6
0
        public static async Task <bool> LockAsync(Authentication authentication, ILockableDescriptor descriptor)
        {
            var dialog = await LockLockableViewModel.CreateInstanceAsync(authentication, descriptor);

            return(dialog?.ShowDialog() == true);
        }
Exemplo n.º 7
0
 public static bool IsLockInherited(Authentication authentication, ILockableDescriptor descriptor)
 {
     return(descriptor.LockInfo.IsInherited);
 }
Exemplo n.º 8
0
 public static bool IsLockOwner(Authentication authentication, ILockableDescriptor descriptor)
 {
     return(descriptor.LockInfo.IsOwner(authentication.ID));
 }
Exemplo n.º 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));
            }
        }
Exemplo n.º 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);
                }));
            }