private static async Task UnlockAsync(Authentication authentication, ITableCategoryDescriptor descriptor, string comment) { if (descriptor.Target is ITableCategory category) { if (category.Dispatcher == null) { return; } try { await category.Dispatcher.InvokeAsync(() => { var lockInfo = category.LockInfo; if (lockInfo.IsLocked == true && lockInfo.IsInherited == false && lockInfo.Comment == comment) { category.Unlock(authentication); } }); } catch (Exception e) { AppMessageBox.ShowError(e); } } else { throw new NotImplementedException(); } }
private static async Task <string> LockAsync(Authentication authentication, ITableCategoryDescriptor descriptor, string comment) { if (descriptor.Target is ITableCategory category) { try { return(await category.Dispatcher.InvokeAsync(() => { if (category.IsLocked == false || category.LockInfo.IsInherited == true) { var lockComment = comment + ":" + Guid.NewGuid(); category.Lock(authentication, lockComment); return lockComment; } return string.Empty; })); } catch (Exception e) { AppMessageBox.ShowError(e); return(null); } } else { throw new NotImplementedException(); } }
public static bool CanNewFolder(Authentication authentication, ITableCategoryDescriptor descriptor) { if (descriptor is IPermissionDescriptor permissionDescriptor) { return(permissionDescriptor.AccessType >= AccessType.Master); } return(false); }
public static async Task <bool> DeleteAsync(Authentication authentication, ITableCategoryDescriptor descriptor) { var dialog = await DeleteTableCategoryViewModel.CreateInstanceAsync(authentication, descriptor); if (dialog != null && await dialog.ShowDialogAsync() == true) { return(true); } return(false); }
public static async Task <bool> MoveAsync(Authentication authentication, ITableCategoryDescriptor descriptor) { var comment = await LockAsync(authentication, descriptor, nameof(ITableCategory.MoveAsync)); if (comment == null) { return(false); } var dialog = await MoveTableCategoryViewModel.CreateInstanceAsync(authentication, descriptor); var dialogResult = await ShowDialogAsync(dialog); await UnlockAsync(authentication, descriptor, comment); return(dialogResult); }
public static async Task <bool> RenameAsync(Authentication authentication, ITableCategoryDescriptor descriptor) { var comment = await LockAsync(authentication, descriptor, nameof(ITableCategory.Rename)); if (comment == null) { return(false); } var dialog = await RenameCategoryViewModel.CreateInstanceAsync(authentication, descriptor); dialog?.ShowDialog(); await UnlockAsync(authentication, descriptor, comment); return(dialog?.DialogResult == true); }
public static Task <NewTableCategoryViewModel> CreateInstanceAsync(Authentication authentication, ITableCategoryDescriptor descriptor) { if (authentication == null) { throw new ArgumentNullException(nameof(authentication)); } if (descriptor == null) { throw new ArgumentNullException(nameof(descriptor)); } if (descriptor.Target is ITableCategory category) { return(category.Dispatcher.InvokeAsync(() => { return new NewTableCategoryViewModel(authentication, category); })); } else { throw new ArgumentException("Invalid Target of Descriptor", nameof(descriptor)); } }
public static async Task <string> NewFolderAsync(Authentication authentication, ITableCategoryDescriptor descriptor) { var dialog = await NewTableCategoryViewModel.CreateInstanceAsync(authentication, descriptor); if (dialog?.ShowDialog() == true) { return(dialog.CategoryName); } return(null); }
public static async Task <bool> DeleteAsync(Authentication authentication, ITableCategoryDescriptor descriptor) { var dialog = await DeleteTableCategoryViewModel.CreateInstanceAsync(authentication, descriptor); return(dialog?.ShowDialog() == true); }
public static Task <ExportViewModel> CreateInstanceAsync(Authentication authentication, ITableCategoryDescriptor descriptor) { if (authentication == null) { throw new ArgumentNullException(nameof(authentication)); } if (descriptor == null) { throw new ArgumentNullException(nameof(descriptor)); } if (descriptor.Target is ITableCategory category && category.GetService(typeof(IDataBase)) is IDataBase dataBase) { return(dataBase.Dispatcher.InvokeAsync(() => { return new ExportViewModel(authentication, dataBase, new string[] { descriptor.Path }); })); }
public static Task <MoveTableCategoryViewModel> CreateInstanceAsync(Authentication authentication, ITableCategoryDescriptor descriptor) { if (authentication == null) { throw new ArgumentNullException(nameof(authentication)); } if (descriptor == null) { throw new ArgumentNullException(nameof(descriptor)); } if (descriptor.Target is ITableCategory category) { return(category.Dispatcher.InvokeAsync(() => { var categories = category.GetService(typeof(ITableCategoryCollection)) as ITableCategoryCollection; var targetPaths = categories.Select(item => item.Path).ToArray(); return new MoveTableCategoryViewModel(authentication, category, targetPaths); })); } else { throw new ArgumentException("Invalid Target of Descriptor", nameof(descriptor)); } }