protected override void OnDelete(Authentication authentication, string path) { var target = this.GetObject(authentication, path); this.CremaHost.Dispatcher.Invoke(Delete); void Delete() { if (target is IDataBase) { var dataBase = target as IDataBase; dataBase.Delete(authentication); } else if (target is ITableItem tableItem) { var dataBase = tableItem.GetService(typeof(IDataBase)) as IDataBase; using (DataBaseUsing.Set(dataBase, authentication)) { tableItem.Delete(authentication); } } else if (target is ITypeItem typeItem) { var dataBase = typeItem.GetService(typeof(IDataBase)) as IDataBase; using (DataBaseUsing.Set(dataBase, authentication)) { typeItem.Delete(authentication); } } else { throw new InvalidOperationException(); } } }
protected override void OnCreate(Authentication authentication, string path, string name) { var target = this.GetObject(authentication, path); if (target is ITableCategory tableCategory) { this.CremaHost.Dispatcher.Invoke(() => { var dataBase = tableCategory.GetService(typeof(IDataBase)) as IDataBase; using (DataBaseUsing.Set(dataBase, authentication)) { tableCategory.AddNewCategory(authentication, name); } }); } else if (target is ITypeCategory typeCategory) { this.CremaHost.Dispatcher.Invoke(() => { var dataBase = typeCategory.GetService(typeof(IDataBase)) as IDataBase; using (DataBaseUsing.Set(dataBase, authentication)) { typeCategory.AddNewCategory(authentication, name); } }); } else if (path == PathUtility.Separator) { var comment = this.CommandContext.ReadString("comment:"); this.CremaHost.Dispatcher.Invoke(() => { this.CremaHost.DataBases.AddNewDataBase(authentication, name, comment); }); } else { var dataBasePath = new DataBasePath(path); if (dataBasePath.Context == string.Empty) { throw new PermissionDeniedException(); } throw new CategoryNotFoundException(path); } }
private void MoveTable(Authentication authentication, ITable sourceTable, string newPath) { var destPath = new DataBasePath(newPath); var destObject = this.GetObject(authentication, destPath.Path); this.CremaHost.Dispatcher.Invoke(MoveTable); void MoveTable() { 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 (DataBaseUsing.Set(dataBase, authentication)) { if (destObject is ITableCategory destCategory) { if (sourceTable.Category != destCategory) { sourceTable.Move(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 (categories.Contains(itemName.CategoryPath) == false) { throw new InvalidOperationException($"cannot move to : {destPath}"); } if (sourceTable.Name != itemName.Name && tables.Contains(itemName.Name) == true) { throw new InvalidOperationException($"cannot move to : {destPath}"); } if (sourceTable.Category.Path != itemName.CategoryPath) { sourceTable.Move(authentication, itemName.CategoryPath); } if (sourceTable.Name != itemName.Name) { sourceTable.Rename(authentication, itemName.Name); } } } }; }