protected override async Task OnCreateAsync(Authentication authentication, string path, string name) { var target = await this.GetObjectAsync(authentication, path); if (target is ITableCategory tableCategory) { var dataBase = tableCategory.GetService(typeof(IDataBase)) as IDataBase; using (await UsingDataBase.SetAsync(dataBase, authentication)) { await tableCategory.AddNewCategoryAsync(authentication, name); } } else if (target is ITypeCategory typeCategory) { var dataBase = typeCategory.GetService(typeof(IDataBase)) as IDataBase; using (await UsingDataBase.SetAsync(dataBase, authentication)) { await typeCategory.AddNewCategoryAsync(authentication, name); } } else if (path == PathUtility.Separator) { var comment = this.CommandContext.ReadString("comment:"); await this.DataBaseContext.AddNewDataBaseAsync(authentication, name, comment); } else { var dataBasePath = new DataBasePath(path); if (dataBasePath.Context == string.Empty) { throw new PermissionDeniedException(); } throw new CategoryNotFoundException(path); } }
private async Task MoveTableAsync(Authentication authentication, ITable sourceTable, string newPath) { var destPath = new DataBasePath(newPath); var destObject = await this.GetObjectAsync(authentication, destPath.Path); var dataBase = sourceTable.GetService(typeof(IDataBase)) as IDataBase; var tables = sourceTable.GetService(typeof(ITableCollection)) as ITableCollection; if (destPath.DataBaseName != dataBase.Name) { throw new InvalidOperationException($"cannot move to : {destPath}"); } if (destPath.Context != CremaSchema.TableDirectory) { throw new InvalidOperationException($"cannot move to : {destPath}"); } if (destObject is ITable) { throw new InvalidOperationException($"cannot move to : {destPath}"); } using (await UsingDataBase.SetAsync(dataBase, authentication)) { if (destObject is ITableCategory destCategory) { if (sourceTable.Category != destCategory) { await sourceTable.MoveAsync(authentication, destCategory.Path); } } else { if (NameValidator.VerifyCategoryPath(destPath.ItemPath) == true) { throw new InvalidOperationException($"cannot move to : {destPath}"); } var itemName = new ItemName(destPath.ItemPath); var categories = sourceTable.GetService(typeof(ITableCategoryCollection)) as ITableCategoryCollection; if (await categories.ContainsAsync(itemName.CategoryPath) == false) { throw new InvalidOperationException($"cannot move to : {destPath}"); } if (sourceTable.Name != itemName.Name && await tables.ContainsAsync(itemName.Name) == true) { throw new InvalidOperationException($"cannot move to : {destPath}"); } if (sourceTable.Category.Path != itemName.CategoryPath) { await sourceTable.MoveAsync(authentication, itemName.CategoryPath); } if (sourceTable.Name != itemName.Name) { await sourceTable.RenameAsync(authentication, itemName.Name); } } } }
private string GetCurrentDirectory() { if (this.CommandContext.Drive is DataBasesConsoleDrive root) { var dataBasePath = new DataBasePath(this.CommandContext.Path); if (dataBasePath.ItemPath != string.Empty) { return(dataBasePath.ItemPath); } } return(PathUtility.Separator); }
protected override async Task OnSetPathAsync(Authentication authentication, string path) { var dataBaseName = this.DataBaseName; var dataBasePath = new DataBasePath(path); if (dataBaseName != string.Empty && dataBasePath.DataBaseName != dataBaseName) { var dataBase = this.DataBaseContext.Dispatcher.Invoke(() => this.DataBaseContext[dataBaseName]); await dataBase.Dispatcher.InvokeAsync(() => { dataBase.Unloaded -= DataBase_Unloaded; }); if (dataBase.IsLoaded == true) { await dataBase.LeaveAsync(authentication); } } if (dataBasePath.DataBaseName != string.Empty && dataBasePath.DataBaseName != dataBaseName) { var dataBase = this.DataBaseContext.Dispatcher.Invoke(() => this.DataBaseContext[dataBasePath.DataBaseName]); if (dataBase.IsLoaded == false) { await dataBase.LoadAsync(authentication); } await dataBase.EnterAsync(authentication); await dataBase.Dispatcher.InvokeAsync(() => { dataBase.Unloaded += DataBase_Unloaded; }); } this.dataBasePath = dataBasePath; }
void IPartImportsSatisfiedNotification.OnImportsSatisfied() { this.CremaHost.Closed += (s, e) => this.dataBasePath = null; }
public override async Task <object> GetObjectAsync(Authentication authentication, string path) { var dataBasePath = new DataBasePath(path); if (dataBasePath.DataBaseName == string.Empty) { return(null); } var dataBase = this.DataBaseContext[dataBasePath.DataBaseName]; if (dataBase == null) { throw new DataBaseNotFoundException(dataBasePath.DataBaseName); } if (dataBasePath.Context == string.Empty) { return(dataBase); } if (dataBasePath.ItemPath == string.Empty) { return(null); } if (dataBase.IsLoaded == false) { await dataBase.LoadAsync(authentication); } var tableContext = dataBase.GetService(typeof(ITableContext)) as ITableContext; var typeContext = dataBase.GetService(typeof(ITypeContext)) as ITypeContext; if (dataBasePath.Context == CremaSchema.TableDirectory) { if (NameValidator.VerifyCategoryPath(dataBasePath.ItemPath) == true) { return(tableContext[dataBasePath.ItemPath]); } var item = tableContext[dataBasePath.ItemPath + PathUtility.Separator]; if (item != null) { return(item); } return(tableContext[dataBasePath.ItemPath]); } else if (dataBasePath.Context == CremaSchema.TypeDirectory) { if (NameValidator.VerifyCategoryPath(dataBasePath.ItemPath) == true) { return(typeContext[dataBasePath.ItemPath]); } var item = typeContext[dataBasePath.ItemPath + PathUtility.Separator]; if (item != null) { return(item); } return(typeContext[dataBasePath.ItemPath]); } else { return(null); } }