Exemplo n.º 1
0
 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));
 }
Exemplo n.º 2
0
 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));
 }
Exemplo n.º 3
0
 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);
 }
Exemplo n.º 4
0
        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);
            }
        }
Exemplo n.º 5
0
 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);
 }
Exemplo n.º 6
0
 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);
 }
Exemplo n.º 7
0
        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();
            }
        }
Exemplo n.º 8
0
        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));
            }
        }
Exemplo n.º 9
0
        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();
            }
        }
Exemplo n.º 10
0
        public static async Task <bool> KickAsync(Authentication authentication, IDomainUserDescriptor descriptor)
        {
            var dialog = await KickEditorViewModel.CreateInstanceAsync(authentication, descriptor);

            return(dialog?.ShowDialog() == true);
        }
Exemplo n.º 11
0
 public DomainUserListItemBase(Authentication authentication, IDomainUserDescriptor descriptor, bool IsSubscriptable, object owner)
     : base(authentication, new DomainUserDescriptor(authentication, descriptor, IsSubscriptable == true ? DescriptorTypes.All : DescriptorTypes.IsRecursive, owner), owner)
 {
 }