private void MoveUserCategory(Authentication authentication, IUserCategory sourceCategory, string destPath) { var destObject = this.GetObject(destPath); this.UserContext.Dispatcher.Invoke(MoveUserCategory); void MoveUserCategory() { //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) { sourceCategory.Move(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 (categories.Contains(itemName.CategoryPath) == false) { throw new InvalidOperationException($"cannot move to : {destPath}"); } if (sourceCategory.Name != itemName.Name && users.Contains(itemName.Name) == true) { throw new InvalidOperationException($"cannot move to : {destPath}"); } if (sourceCategory.Parent.Path != itemName.CategoryPath) { sourceCategory.Move(authentication, itemName.CategoryPath); } if (sourceCategory.Name != itemName.Name) { sourceCategory.Rename(authentication, itemName.Name); } } } }
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 void Move(IUserCategory category, TaskContext context) { category.Dispatcher.Invoke(() => { if (category.Parent == null) { return; } var categories = category.GetService(typeof(IUserCategoryCollection)) as IUserCategoryCollection; var categoryPath = categories.Random().Path; if (Verify(categoryPath) == false) { return; } category.Move(context.Authentication, categoryPath); }); bool Verify(string categoryPath) { if (context.AllowException == true) { return(true); } if (categoryPath.StartsWith(category.Path) == true) { return(false); } if (category.Path == categoryPath) { return(false); } return(true); } }
public static Task <MoveUserCategoryViewModel> CreateInstanceAsync(Authentication authentication, IUserCategoryDescriptor descriptor) { if (authentication == null) { throw new ArgumentNullException(nameof(authentication)); } if (descriptor == null) { throw new ArgumentNullException(nameof(descriptor)); } if (descriptor.Target is IUserCategory category) { return(category.Dispatcher.InvokeAsync(() => { var categories = category.GetService(typeof(IUserCategoryCollection)) as IUserCategoryCollection; var targetPaths = categories.Select(item => item.Path).ToArray(); return new MoveUserCategoryViewModel(authentication, category, targetPaths); })); } else { throw new ArgumentException("Invalid Target of Descriptor", nameof(descriptor)); } }
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); }
private RenameCategoryViewModel(Authentication authentication, IUserCategory category) : base(category.Name) { this.authentication = authentication; this.authentication.Expired += Authentication_Expired; this.category = category; this.category.Dispatcher.VerifyAccess(); this.userContext = category.GetService(typeof(IUserContext)) as IUserContext; this.DisplayName = Resources.Title_RenameUserFolder; }
public static async Task <IUser> GenerateUserAsync(this IUserCategory userCategory, Authentication authentication, Authority authority) { var userCollection = userCategory.GetService(typeof(IUserCollection)) as IUserCollection; var newID = await userCollection.GenerateNewUserIDAsync("user"); var newName = newID.Replace("user", $"{authority}User"); var password = authority.ToString().ToLower().ToSecureString(); return(await userCategory.AddNewUserAsync(authentication, newID, password, newName, authority)); }
public void GetService() { Console.Write(category.GetService(typeof(ICremaHost))); }