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); }
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); }
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(); } }
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(); } }
public override void SelectObject(object obj) { this.Detach(); this.descriptor = obj as ILockableDescriptor; this.Attach(); }
public static async Task <bool> LockAsync(Authentication authentication, ILockableDescriptor descriptor) { var dialog = await LockLockableViewModel.CreateInstanceAsync(authentication, descriptor); return(dialog?.ShowDialog() == true); }
public static bool IsLockInherited(Authentication authentication, ILockableDescriptor descriptor) { return(descriptor.LockInfo.IsInherited); }
public static bool IsLockOwner(Authentication authentication, ILockableDescriptor descriptor) { return(descriptor.LockInfo.IsOwner(authentication.ID)); }
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)); } }
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); })); }