public static bool CanWrite(Authentication authentication, IDomainUserDescriptor descriptor) { if (authentication == null) { throw new ArgumentNullException(nameof(authentication)); } if (descriptor == null) { throw new ArgumentNullException(nameof(descriptor)); } return(descriptor.DomainUserInfo.AccessType.HasFlag(DomainAccessType.ReadWrite)); }
public static bool IsOwner(Authentication authentication, IDomainUserDescriptor descriptor) { if (authentication == null) { throw new ArgumentNullException(nameof(authentication)); } if (descriptor == null) { throw new ArgumentNullException(nameof(descriptor)); } return(descriptor.DomainUserState.HasFlag(DomainUserState.IsOwner)); }
public static bool IsAdmin(Authentication authentication, IDomainUserDescriptor descriptor) { if (authentication == null) { throw new ArgumentNullException(nameof(authentication)); } if (descriptor == null) { throw new ArgumentNullException(nameof(descriptor)); } return(authentication.Authority == Authority.Admin); }
public DomainUserDescriptor(Authentication authentication, IDomainUserDescriptor descriptor, DescriptorTypes descriptorTypes, object owner) : base(authentication, descriptor.Target, descriptorTypes) { this.domainUser = descriptor.Target; this.owner = owner ?? this; this.domainUser.Dispatcher.VerifyAccess(); this.domainUserInfo = domainUser.DomainUserInfo; this.domainUserState = domainUser.DomainUserState; if (this.descriptorTypes.HasFlag(DescriptorTypes.IsSubscriptable) == true && descriptor is INotifyPropertyChanged obj) { obj.PropertyChanged += Descriptor_PropertyChanged; this.disposeAction = new Action(() => obj.PropertyChanged -= Descriptor_PropertyChanged); } }
public static bool CanKick(Authentication authentication, IDomainUserDescriptor descriptor) { if (authentication == null) { throw new ArgumentNullException(nameof(authentication)); } if (descriptor == null) { throw new ArgumentNullException(nameof(descriptor)); } if (DomainUserDescriptorUtility.IsOwner(authentication, descriptor) == true) { return(false); } return(authentication.Authority == Authority.Admin); }
public static bool CanSendMessage(Authentication authentication, IDomainUserDescriptor descriptor) { if (authentication == null) { throw new ArgumentNullException(nameof(authentication)); } if (descriptor == null) { throw new ArgumentNullException(nameof(descriptor)); } if (DomainUserDescriptorUtility.IsOnline(authentication, descriptor) == false) { return(false); } return(authentication.ID != descriptor.DomainUserInfo.UserID); }
public static async Task <bool> SetOwnerAsync(Authentication authentication, IDomainUserDescriptor descriptor) { if (descriptor.Target is IDomainUser domainUser) { try { await domainUser.Dispatcher.InvokeAsync(() => domainUser.SetOwner(authentication)); return(true); } catch (Exception e) { AppMessageBox.ShowError(e); return(false); } } else { throw new NotImplementedException(); } }
public static Task <KickEditorViewModel> CreateInstanceAsync(Authentication authentication, IDomainUserDescriptor descriptor) { if (authentication == null) { throw new ArgumentNullException(nameof(authentication)); } if (descriptor == null) { throw new ArgumentNullException(nameof(descriptor)); } if (descriptor.Target is IDomainUser domainUser) { return(domainUser.Dispatcher.InvokeAsync(() => { return new KickEditorViewModel(authentication, domainUser); })); } else { throw new ArgumentException("Invalid Target of Descriptor", nameof(descriptor)); } }
public static async Task <bool> SendMessageAsync(Authentication authentication, IDomainUserDescriptor descriptor) { if (descriptor.Target is IDomainUser domainUser) { if (domainUser.GetService(typeof(IUserContext)) is IUserContext userContext) { var user = await userContext.Dispatcher.InvokeAsync(() => userContext.Users[descriptor.DomainUserInfo.UserID]); var dialog = await user.Dispatcher.InvokeAsync(() => new SendMessageViewModel(authentication, user)); return(dialog?.ShowDialog() == true); } return(false); } else { throw new NotImplementedException(); } }
public static async Task <bool> KickAsync(Authentication authentication, IDomainUserDescriptor descriptor) { var dialog = await KickEditorViewModel.CreateInstanceAsync(authentication, descriptor); return(dialog?.ShowDialog() == true); }
public DomainUserListItemBase(Authentication authentication, IDomainUserDescriptor descriptor, bool IsSubscriptable, object owner) : base(authentication, new DomainUserDescriptor(authentication, descriptor, IsSubscriptable == true ? DescriptorTypes.All : DescriptorTypes.IsRecursive, owner), owner) { }