public void Delete(IUserCategory category, TaskContext context) { category.Dispatcher.Invoke(() => { if (category.Parent == null) { return; } if (Verify() == false) { return; } category.Delete(context.Authentication); context.Complete(category); }); bool Verify() { if (context.AllowException == true) { return(true); } if (category.Parent == null) { return(false); } if (EnumerableUtility.Descendants <IUserItem, IUser>(category as IUserItem, item => item.Childs).Any() == true) { return(false); } return(true); } }
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); }
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 <IUser> GenerateUserAsync(this IUserCategory userCategory, Authentication authentication) { var authorities = new Authority[] { Authority.Admin, Authority.Member, Authority.Guest }; var authority = authorities.Random(); return(GenerateUserAsync(userCategory, authentication, authority)); }
public void AddNewCategory(IUserCategory category, TaskContext context) { category.Dispatcher.Invoke(() => { var categoryName = RandomUtility.NextIdentifier(); category.AddNewCategory(context.Authentication, categoryName); }); }
public UserCategoryDescriptor(Authentication authentication, IUserCategoryDescriptor descriptor, bool isSubscriptable, object owner) : base(authentication, descriptor.Target, descriptor, isSubscriptable) { this.category = descriptor.Target; this.owner = owner ?? this; this.usersReadonly = new ReadOnlyObservableCollection <UserDescriptor>(this.users); this.categoriesReadonly = new ReadOnlyObservableCollection <UserCategoryDescriptor>(this.categories); }
private void Category_Deleted(object sender, EventArgs e) { this.category = null; this.Dispatcher.InvokeAsync(() => { this.OnDisposed(EventArgs.Empty); }); }
public static Task <string> GenerateNewCategoryNameAsync(this IUserCategory userCategory, string name) { return(userCategory.Dispatcher.InvokeAsync(() => { var names = userCategory.Categories.Select(item => item.Name); return NameUtility.GenerateNewName(name, names); })); }
private NewUserViewModel(Authentication authentication, IUserCategory category) { this.authentication = authentication; this.authentication.Expired += Authentication_Expired; this.category = category; this.category.Dispatcher.VerifyAccess(); this.DisplayName = Resources.Title_NewUser; }
private MoveUserCategoryViewModel(Authentication authentication, IUserCategory category, string[] targetPaths) : base(category.Path, targetPaths) { this.authentication = authentication; this.authentication.Expired += Authentication_Expired; this.category = category; this.category.Dispatcher.VerifyAccess(); this.DisplayName = Resources.Title_MoveUserFolder; }
public async Task AddNewUserAsync(IUserCategory category, TaskContext context) { var authentication = context.Authentication; var index = RandomUtility.Next(int.MaxValue); var authority = RandomUtility.NextEnum <Authority>(); var userID = $"{authority.ToString().ToLower()}_bot_{index}"; var userName = "******" + index; await category.AddNewUserAsync(authentication, userID, ToSecureString("1111"), userName, authority); }
private DeleteUserCategoryViewModel(Authentication authentication, IUserCategory category) { this.authentication = authentication; this.authentication.Expired += Authentication_Expired; this.category = category; this.category.Dispatcher.VerifyAccess(); this.Target = category.Path; this.DisplayName = Resources.Title_DeleteUserFolder; }
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 AddNewUser(IUserCategory category, TaskContext context) { category.Dispatcher.Invoke(() => { var index = RandomUtility.Next(int.MaxValue); var authority = RandomUtility.NextEnum <Authority>(); var userID = $"{authority.ToString().ToLower()}_bot_{index}"; var userName = "******" + index; category.AddNewUser(context.Authentication, userID, ToSecureString("1111"), userName, authority); }); }
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); } } } }
public void Rename(IUserCategory category, TaskContext context) { category.Dispatcher.Invoke(() => { if (category.Parent == null) { return; } var categoryName = RandomUtility.NextIdentifier(); category.Rename(context.Authentication, categoryName); }); }
public static void ClassInit(TestContext context) { app = new CremaBootstrapper(); app.Initialize(context, nameof(IUserCategory_DispatcherTest)); cremaHost = app.GetService(typeof(ICremaHost)) as ICremaHost; cremaHost.Dispatcher.Invoke(() => { authentication = cremaHost.Start(); userContext = cremaHost.GetService(typeof(IUserContext)) as IUserContext; }); category = userContext.Dispatcher.Invoke(() => userContext.Categories.Random()); }
public async Task RenameAsync(IUserCategory category, TaskContext context) { var authentication = context.Authentication; var categoryName = RandomUtility.NextIdentifier(); if (context.AllowException == false) { if (await category.Dispatcher.InvokeAsync(() => category.Parent) == null) { return; } } await category.RenameAsync(authentication, categoryName); }
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); } } }
private static bool CanMove(IUserCategory userCategory, IUserCategory parentCategory) { if (userCategory.Parent == null) { return(false); } if (userCategory.Parent.Path == parentCategory.Path) { return(false); } if (parentCategory.Categories.ContainsKey(userCategory.Name) == true) { return(false); } return(parentCategory.Path.StartsWith(userCategory.Path) == false); }
public async Task DeleteAsync(IUserCategory category, TaskContext context) { var authentication = context.Authentication; if (context.AllowException == false) { if (await category.Dispatcher.InvokeAsync(() => category.Parent) == null) { return; } if (await category.Dispatcher.InvokeAsync(() => EnumerableUtility.Descendants <IUserItem, IUser>(category as IUserItem, item => item.Childs).Any()) == true) { return; } } await category.DeleteAsync(authentication); context.Complete(category); }
public UserCategoryDescriptor(Authentication authentication, IUserCategory category, DescriptorTypes descriptorTypes, object owner) : base(authentication, category, descriptorTypes) { this.category = category; this.owner = owner ?? this; this.category.Dispatcher.VerifyAccess(); this.categoryName = category.Name; this.categoryPath = category.Path; this.usersReadonly = new ReadOnlyObservableCollection <UserDescriptor>(this.users); this.categoriesReadonly = new ReadOnlyObservableCollection <UserCategoryDescriptor>(this.categories); if (this.descriptorTypes.HasFlag(DescriptorTypes.IsSubscriptable) == true) { this.category.Renamed += Category_Renamed; this.category.Moved += Category_Moved; this.category.Deleted += Category_Deleted; } if (this.descriptorTypes.HasFlag(DescriptorTypes.IsRecursive) == true) { if (this.descriptorTypes.HasFlag(DescriptorTypes.IsSubscriptable) == true) { this.category.Users.CollectionChanged += Users_CollectionChanged; this.category.Categories.CollectionChanged += Categories_CollectionChanged; } foreach (var item in this.category.Categories) { var descriptor = new UserCategoryDescriptor(this.authentication, item, this.descriptorTypes, this.owner); item.ExtendedProperties[this.owner] = descriptor; this.categories.Add(descriptor); } foreach (var item in this.category.Users) { var descriptor = new UserDescriptor(this.authentication, item, this.descriptorTypes, this.owner); item.ExtendedProperties[this.owner] = descriptor; this.users.Add(descriptor); } } }
private bool PredicateFunc(IUserCategory userCategory) { if (this.HasParent == true && userCategory.Parent == null) { return(false); } if (this.HasCategories == true && userCategory.Categories.Any() == false) { return(false); } if (this.HasUsers == true && userCategory.Users.Any() == false) { return(false); } if (this.IsLeaf == true && (userCategory.Categories.Any() == true || userCategory.Users.Any() == true)) { return(false); } if (this.ExcludedCategories != null && this.ExcludedCategories.Contains(userCategory) == true) { return(false); } if (this.ExcludedItems != null && this.ExcludedItems.Contains(userCategory as IUserItem) == true) { return(false); } if (this.CategoryToMove != null && CanMove(this.CategoryToMove, userCategory) == false) { return(false); } if (this.UserToMove != null && CanMove(this.UserToMove, userCategory.Path) == false) { return(false); } if (this.Predicate != null && this.Predicate(userCategory) == false) { return(false); } return(true); }
private static bool DefaultPredicate(IUserCategory _) => true;
public UserCategoryTreeViewItemViewModel(Authentication authentication, IUserCategory category, object owner) : this(authentication, new UserCategoryDescriptor(authentication, category, DescriptorTypes.All, owner), owner) { }
public BotVkApi(IFriendCategory friends, IUserCategory users) { Friends = friends ?? throw new ArgumentNullException(paramName: nameof(friends)); Users = users ?? throw new ArgumentNullException(paramName: nameof(users)); }
public static async Task <IUserCategory> GenerateUserCategoryAsync(this IUserCategory userCategory, Authentication authentication) { var name = await userCategory.GenerateNewCategoryNameAsync(); return(await userCategory.AddNewCategoryAsync(authentication, name)); }
public UserCategoryTreeItemBase(Authentication authentication, IUserCategory category, bool isSubscriptable, object owner) : this(authentication, new UserCategoryDescriptor(authentication, category, isSubscriptable == true ? DescriptorTypes.All : DescriptorTypes.IsRecursive, owner), owner) { }
public static Task <string> GenerateNewCategoryNameAsync(this IUserCategory userCategory) { return(GenerateNewCategoryNameAsync(userCategory, "NewCategory")); }