Esempio n. 1
0
        public async static Task <bool> UnloadAsync(Authentication authentication, IDataBaseDescriptor descriptor)
        {
            if (descriptor.Target is IDataBase dataBase)
            {
                try
                {
                    if (descriptor.AuthenticationInfos.Any() == true && await AppMessageBox.ShowProceedAsync(Resources.Message_VerifyToCloseDataBase) == false)
                    {
                        return(false);
                    }
                    await dataBase.UnloadAsync(authentication);

                    return(true);
                }
                catch (Exception e)
                {
                    await AppMessageBox.ShowErrorAsync(e);

                    return(false);
                }
            }
            else
            {
                throw new NotImplementedException();
            }
        }
Esempio n. 2
0
        public async static Task <bool> DeleteAsync(Authentication authentication, IDataBaseDescriptor descriptor)
        {
            if (descriptor.Target is IDataBase dataBase)
            {
                if (await new DeleteViewModel().ShowDialogAsync() != true)
                {
                    return(false);
                }

                try
                {
                    await dataBase.DeleteAsync(authentication);

                    await AppMessageBox.ShowAsync(Resources.Message_Deleted);

                    return(true);
                }
                catch (Exception e)
                {
                    await AppMessageBox.ShowErrorAsync(e);

                    return(false);
                }
            }
            else
            {
                throw new NotImplementedException();
            }
        }
Esempio n. 3
0
 public static bool CanViewLog(Authentication authentication, IDataBaseDescriptor descriptor)
 {
     if (descriptor is IPermissionDescriptor permissionDescriptor)
     {
         return(permissionDescriptor.AccessType >= AccessType.Guest);
     }
     return(false);
 }
Esempio n. 4
0
 public static bool CanDelete(Authentication authentication, IDataBaseDescriptor descriptor)
 {
     if (DataBaseDescriptorUtility.IsLoaded(authentication, descriptor) == true)
     {
         return(false);
     }
     return(authentication.Authority == Authority.Admin);
 }
Esempio n. 5
0
        public async static Task <string> RenameAsync(Authentication authentication, IDataBaseDescriptor descriptor)
        {
            var dialog = await RenameDataBaseViewModel.CreateInstanceAsync(authentication, descriptor);

            if (await dialog?.ShowDialogAsync() == true)
            {
                return(dialog.NewName);
            }
            return(null);
        }
Esempio n. 6
0
 public static bool CanLoad(Authentication authentication, IDataBaseDescriptor descriptor)
 {
     if (DataBaseDescriptorUtility.IsLoaded(authentication, descriptor) == true)
     {
         return(false);
     }
     if (descriptor is IAccessibleDescriptor accessibleDescriptor)
     {
         return(AccessibleDescriptorUtility.IsPrivate(authentication, accessibleDescriptor) == false && authentication.Authority == Authority.Admin);
     }
     return(authentication.Authority == Authority.Admin);
 }
Esempio n. 7
0
 public static bool CanUnload(Authentication authentication, IDataBaseDescriptor descriptor)
 {
     if (DataBaseDescriptorUtility.IsLoaded(authentication, descriptor) == false)
     {
         return(false);
     }
     if (descriptor is IPermissionDescriptor permissionDescriptor)
     {
         return(permissionDescriptor.AccessType >= AccessType.Owner);
     }
     return(authentication.Authority == Authority.Admin);
 }
Esempio n. 8
0
 public static bool IsLoaded(Authentication authentication, IDataBaseDescriptor descriptor)
 {
     if (descriptor == null)
     {
         throw new ArgumentNullException(nameof(descriptor));
     }
     if (authentication == null)
     {
         return(false);
     }
     return(descriptor.DataBaseState.HasFlag(DataBaseState.IsLoaded));
 }
        public override void SelectObject(object obj)
        {
            if (this.notifyObject != null)
            {
                this.notifyObject.PropertyChanged -= NotifyObject_PropertyChanged;
            }

            this.descriptor   = obj as IDataBaseDescriptor;
            this.notifyObject = obj as INotifyPropertyChanged;
            this.SyncUsers(this.descriptor == null ? new AuthenticationInfo[] { } : this.descriptor.AuthenticationInfos);

            if (this.notifyObject != null)
            {
                this.notifyObject.PropertyChanged += NotifyObject_PropertyChanged;
            }
        }
Esempio n. 10
0
        public async static Task <bool> LoadAsync(Authentication authentication, IDataBaseDescriptor descriptor)
        {
            if (descriptor.Target is IDataBase dataBase)
            {
                try
                {
                    await dataBase.Dispatcher.InvokeAsync(() => dataBase.Load(authentication));

                    return(true);
                }
                catch (Exception e)
                {
                    AppMessageBox.ShowError(e);
                    return(false);
                }
            }
            else
            {
                throw new NotImplementedException();
            }
        }
Esempio n. 11
0
 public override void SelectObject(object obj)
 {
     this.descriptor = obj as IDataBaseDescriptor;
     if (this.descriptor != null)
     {
         foreach (var item in this.domains)
         {
             item.IsVisible = this.descriptor.DataBaseID == item.DomainInfo.DataBaseID;
         }
     }
     else
     {
         foreach (var item in this.domains)
         {
             item.IsVisible = false;
         }
     }
     this.SelectedDomain = null;
     this.NotifyOfPropertyChange(nameof(this.IsVisible));
     this.NotifyOfPropertyChange(nameof(this.SelectedObject));
 }
Esempio n. 12
0
        public static Task <RenameDataBaseViewModel> CreateInstanceAsync(Authentication authentication, IDataBaseDescriptor descriptor)
        {
            if (authentication == null)
            {
                throw new ArgumentNullException(nameof(authentication));
            }
            if (descriptor == null)
            {
                throw new ArgumentNullException(nameof(descriptor));
            }

            if (descriptor.Target is IDataBase dataBase)
            {
                return(dataBase.Dispatcher.InvokeAsync(() =>
                {
                    return new RenameDataBaseViewModel(authentication, dataBase);
                }));
            }
            else
            {
                throw new ArgumentException("Invalid Target of Descriptor", nameof(descriptor));
            }
        }
Esempio n. 13
0
 public override void SelectObject(object obj)
 {
     this.Detach();
     this.descriptor = obj as IDataBaseDescriptor;
     this.Attach();
 }
Esempio n. 14
0
 public DataBaseDescriptor(Authentication authentication, IDataBaseDescriptor descriptor, bool isSubscriptable, object owner)
     : base(authentication, descriptor.Target, descriptor, isSubscriptable)
 {
     this.dataBase = descriptor.Target;
     this.owner    = owner ?? this;
 }
Esempio n. 15
0
        public static async Task <LogViewModel> ShowDialogAsync(Authentication authentication, IDataBaseDescriptor descriptor)
        {
            if (authentication == null)
            {
                throw new ArgumentNullException(nameof(authentication));
            }
            if (descriptor == null)
            {
                throw new ArgumentNullException(nameof(descriptor));
            }

            if (descriptor.Target is IDataBase dataBase)
            {
                try
                {
                    var dialog = await dataBase.Dispatcher.InvokeAsync(() => new LogViewModel(authentication, dataBase));

                    if (dialog.ShowDialog() == true)
                    {
                        return(dialog);
                    }
                    return(null);
                }
                catch (Exception e)
                {
                    CremaLog.Error(e);
                    return(null);
                }
            }
            throw new NotImplementedException();
        }
Esempio n. 16
0
 public DataBaseItemViewModel(Authentication authentication, IDataBaseDescriptor descriptor, object owner)
     : base(authentication, new DataBaseDescriptor(authentication, descriptor, false, owner), owner)
 {
 }
Esempio n. 17
0
        public async static Task <bool> CopyAsync(Authentication authentication, IDataBaseDescriptor descriptor)
        {
            var dialog = await CopyDataBaseViewModel.CreateInstanceAsync(authentication, descriptor);

            return(await dialog?.ShowDialogAsync() == true);
        }
Esempio n. 18
0
 public static async Task <bool> ViewLogAsync(Authentication authentication, IDataBaseDescriptor descriptor)
 {
     return(await LogViewModel.ShowDialogAsync(authentication, descriptor) != null);
 }
Esempio n. 19
0
 public static bool CanCopy(Authentication authentication, IDataBaseDescriptor descriptor)
 {
     return(authentication.Authority == Authority.Admin);
 }