private async Task MoveUserCategoryAsync(Authentication authentication, IUserCategory sourceCategory, string destPath) { var destObject = await this.GetObjectAsync(destPath); //var dataBase = sourceCategory.GetService(typeof(IDataBase)) as IDataBase; var users = sourceCategory.GetService(typeof(IUserCollection)) as IUserCollection; //if (destPath.DataBaseName != dataBase.Name) // throw new InvalidOperationException($"cannot move to : {destPath}"); //if (destPath.Context != CremaSchema.UserDirectory) // throw new InvalidOperationException($"cannot move to : {destPath}"); if (destObject is IUser) { throw new InvalidOperationException($"cannot move to : {destPath}"); } if (destObject is IUserCategory destCategory) { if (sourceCategory.Parent != destCategory) { await sourceCategory.MoveAsync(authentication, destCategory.Path); } } else { if (NameValidator.VerifyCategoryPath(destPath) == true) { throw new InvalidOperationException($"cannot move to : {destPath}"); } var itemName = new ItemName(destPath); var categories = sourceCategory.GetService(typeof(IUserCategoryCollection)) as IUserCategoryCollection; if (await categories.ContainsAsync(itemName.CategoryPath) == false) { throw new InvalidOperationException($"cannot move to : {destPath}"); } if (sourceCategory.Name != itemName.Name && await users.ContainsAsync(itemName.Name) == true) { throw new InvalidOperationException($"cannot move to : {destPath}"); } if (sourceCategory.Parent.Path != itemName.CategoryPath) { await sourceCategory.MoveAsync(authentication, itemName.CategoryPath); } if (sourceCategory.Name != itemName.Name) { await sourceCategory.RenameAsync(authentication, itemName.Name); } } }
public async Task MoveAsync(IUserCategory category, TaskContext context) { var authentication = context.Authentication; var categories = category.GetService(typeof(IUserCategoryCollection)) as IUserCategoryCollection; var categoryPath = await categories.Dispatcher.InvokeAsync(() => categories.Random().Path); if (context.AllowException == false) { if (await category.Dispatcher.InvokeAsync(() => category.Parent) == null) { return; } if (await category.Dispatcher.InvokeAsync(() => categoryPath.StartsWith(category.Path)) == true) { return; } if (await category.Dispatcher.InvokeAsync(() => category.Path == categoryPath)) { return; } if (await category.Dispatcher.InvokeAsync(() => category.Parent.Path == categoryPath)) { return; } } await category.MoveAsync(authentication, categoryPath); }