private async Task MoveTypeCategoryAsync(Authentication authentication, ITypeCategory sourceCategory, string newPath) { var destPath = new DataBasePath(newPath); var destObject = await this.GetObjectAsync(authentication, destPath.Path); var dataBase = sourceCategory.GetService(typeof(IDataBase)) as IDataBase; var types = sourceCategory.GetService(typeof(ITypeCollection)) as ITypeCollection; if (destPath.DataBaseName != dataBase.Name) { throw new InvalidOperationException($"cannot move to : {destPath}"); } if (destPath.Context != CremaSchema.TypeDirectory) { throw new InvalidOperationException($"cannot move to : {destPath}"); } if (destObject is IType) { throw new InvalidOperationException($"cannot move to : {destPath}"); } using (await UsingDataBase.SetAsync(dataBase, authentication)) { if (destObject is ITypeCategory destCategory) { if (sourceCategory.Parent != destCategory) { await sourceCategory.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 = sourceCategory.GetService(typeof(ITypeCategoryCollection)) as ITypeCategoryCollection; if (await categories.ContainsAsync(itemName.CategoryPath) == false) { throw new InvalidOperationException($"cannot move to : {destPath}"); } if (sourceCategory.Name != itemName.Name && await types.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 static Task <MoveTypeCategoryViewModel> CreateInstanceAsync(Authentication authentication, ITypeCategoryDescriptor descriptor) { if (authentication == null) { throw new ArgumentNullException(nameof(authentication)); } if (descriptor == null) { throw new ArgumentNullException(nameof(descriptor)); } if (descriptor.Target is ITypeCategory category) { return(category.Dispatcher.InvokeAsync(() => { var categories = category.GetService(typeof(ITypeCategoryCollection)) as ITypeCategoryCollection; var targetPaths = categories.Select(item => item.Path).ToArray(); return new MoveTypeCategoryViewModel(authentication, category, targetPaths); })); } else { throw new ArgumentException("Invalid Target of Descriptor", nameof(descriptor)); } }
public NewTypeViewModel(Authentication authentication, ITypeCategory category, ITypeTemplate template) : base(authentication, template, true) { this.Category = category; this.typeCollection = category.GetService(typeof(ITypeCollection)) as ITypeCollection; this.DisplayName = Resources.Title_NewType; }
public async Task RemoveAccessMemberAsync(ITypeCategory category, TaskContext context) { var authentication = context.Authentication; if (context.AllowException == false) { if (category.Parent == null) { return; } if (category.IsPrivate == false) { return; } } var userContext = category.GetService(typeof(IUserContext)) as IUserContext; var memberID = await userContext.Dispatcher.InvokeAsync(() => userContext.Select(item => item.Path).Random()); if (NameValidator.VerifyItemPath(memberID) == true) { await category.RemoveAccessMemberAsync(authentication, new ItemName(memberID).Name); } else { await category.RemoveAccessMemberAsync(authentication, memberID); } }
public static async Task GenerateStandardFlagsAsync(this ITypeCategory category, Authentication authentication) { var types = category.GetService(typeof(ITypeCollection)) as ITypeCollection; var typeNames = await types.Dispatcher.InvokeAsync(() => types.Select(item => item.Name).ToArray()); var newName = NameUtility.GenerateNewName("Flag", typeNames); var template = await category.AddNewTypeAsync(authentication); await template.SetTypeNameAsync(authentication, newName); await template.SetIsFlagAsync(authentication, true); await template.SetCommentAsync(authentication, "Standard Flag"); await template.AddMemberAsync(authentication, "None", 0, "None Value"); await template.AddMemberAsync(authentication, "A", 1, "A Value"); await template.AddMemberAsync(authentication, "B", 2, "B Value"); await template.AddMemberAsync(authentication, "C", 4, "C Value"); await template.AddMemberAsync(authentication, "D", 8, "D Value"); await template.AddMemberAsync(authentication, "AC", 1 | 4, "AC Value"); await template.AddMemberAsync(authentication, "ABC", 1 | 2 | 4, "AC Value"); await template.AddMemberAsync(authentication, "BD", 2 | 8, "AC Value"); await template.AddMemberAsync(authentication, "All", 1 | 2 | 4 | 8, "All Value"); await template.EndEditAsync(authentication); }
public void Move(ITypeCategory category, TaskContext context) { category.Dispatcher.Invoke(() => { var categories = category.GetService(typeof(ITypeCategoryCollection)) as ITypeCategoryCollection; 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 (category.Parent == null || category.Path == categoryPath) { return(false); } return(true); } }
public async Task MoveAsync(ITypeCategory category, TaskContext context) { var authentication = context.Authentication; var categories = category.GetService(typeof(ITypeCategoryCollection)) as ITypeCategoryCollection; var categoryPath = await categories.Dispatcher.InvokeAsync(() => categories.Random().Path); if (context.AllowException == false) { if (await VerifyAsync() == false) { return; } } await category.MoveAsync(authentication, categoryPath); async Task <bool> VerifyAsync() { if ((await category.GetAllTypesAsync(item => item.TypeState != TypeState.None)).Any() == true) { return(false); } if ((await category.GetAllUsingTablesAsync(item => item.TableState != TableState.None)).Any() == true) { return(false); } return(await category.Dispatcher.InvokeAsync(() => { if (category.Parent == null) { return false; } if (category.Parent.Path == categoryPath) { return false; } if (category.Path == categoryPath) { return false; } if (categoryPath.StartsWith(category.Path) == true) { return false; } if (category.VerifyAccessType(authentication, AccessType.Master) == false) { return false; } return true; })); } }
public static void MoveTest(this ITypeCategory category, Authentication authentication) { Assert.AreNotEqual(null, category.Parent); var categories = category.GetService(typeof(ITypeCategoryCollection)) as ITypeCategoryCollection; var descendants = EnumerableUtility.Descendants(category, item => item.Categories); var target = categories.Random(item => descendants.Contains(item) == false && item != category && item != category.Parent); if (target == null) { Assert.Inconclusive(); } category.Move(authentication, target.Path); }
public static async Task <IType> GenerateTypeAsync(this ITypeCategory typeCategory, Authentication authentication, bool isFlag) { var typeCollection = typeCategory.GetService(typeof(ITypeCollection)) as ITypeCollection; var newName = await typeCollection.GenerateNewTypeNameAsync("type"); var template = await typeCategory.AddNewTypeAsync(authentication); await template.SetTypeNameAsync(authentication, newName); await template.SetIsFlagAsync(authentication, isFlag); await template.AddRandomMembersAsync(authentication); await template.EndEditAsync(authentication); return(template.Type); }
public void RemoveAccessMember(ITypeCategory category, TaskContext context) { category.Dispatcher.Invoke(() => { if (category.Parent == null) { return; } var userContext = category.GetService(typeof(IUserContext)) as IUserContext; var memberID = userContext.Dispatcher.Invoke(() => userContext.Select(item => item.Path).Random()); if (Verify() == false) { return; } if (NameValidator.VerifyItemPath(memberID) == true) { category.RemoveAccessMember(context.Authentication, new ItemName(memberID).Name); } else { category.RemoveAccessMember(context.Authentication, memberID); } }); bool Verify() { if (context.AllowException == true) { return(true); } if (category.IsPrivate == false) { return(false); } return(true); } }
public void GetService() { Console.Write(category.GetService(typeof(ICremaHost))); }
private void MoveTypeCategory(Authentication authentication, ITypeCategory sourceCategory, string newPath) { var destPath = new DataBasePath(newPath); var destObject = this.GetObject(authentication, destPath.Path); this.CremaHost.Dispatcher.Invoke(MoveTypeCategory); void MoveTypeCategory() { var dataBase = sourceCategory.GetService(typeof(IDataBase)) as IDataBase; var types = sourceCategory.GetService(typeof(ITypeCollection)) as ITypeCollection; if (destPath.DataBaseName != dataBase.Name) { throw new InvalidOperationException($"cannot move to : {destPath}"); } if (destPath.Context != CremaSchema.TypeDirectory) { throw new InvalidOperationException($"cannot move to : {destPath}"); } if (destObject is IType) { throw new InvalidOperationException($"cannot move to : {destPath}"); } using (DataBaseUsing.Set(dataBase, authentication)) { if (destObject is ITypeCategory destCategory) { if (sourceCategory.Parent != destCategory) { sourceCategory.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 = sourceCategory.GetService(typeof(ITypeCategoryCollection)) as ITypeCategoryCollection; if (categories.Contains(itemName.CategoryPath) == false) { throw new InvalidOperationException($"cannot move to : {destPath}"); } if (sourceCategory.Name != itemName.Name && types.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); } } } } }