public static async Task <ITable> AddRandomChildTableAsync(this ITableContext tableContext, Authentication authentication, DataBaseSettings settings) { var tableCollection = tableContext.GetService(typeof(ITableCollection)) as ITableCollection; var table = await tableCollection.GetRandomTableAsync(item => item.TemplatedParent == null && item.Parent == null); return(await table.AddRandomChildTableAsync(authentication, settings)); }
public static async Task <ITable[]> AddRandomDerivedTableAsync(this ITableContext tableContext, Authentication authentication) { var tableCategoryCollection = tableContext.GetService(typeof(ITableCategoryCollection)) as ITableCategoryCollection; var category = await tableCategoryCollection.GetRandomTableCategoryAsync(); return(await AddRandomDerivedTableAsync(category, authentication)); }
public static async Task <ITable> AddRandomTableAsync(this ITableContext tableContext, Authentication authentication, DataBaseSettings settings) { var tableCategoryCollection = tableContext.GetService(typeof(ITableCategoryCollection)) as ITableCategoryCollection; var category = await tableCategoryCollection.GetRandomTableCategoryAsync(); return(await AddRandomTableAsync(category, authentication, settings)); }
public static async Task <bool> GenerateCategoryAsync(this ITableContext tableContext, Authentication authentication) { var tableCategoryCollection = tableContext.GetService(typeof(ITableCategoryCollection)) as ITableCategoryCollection; var categoryName = RandomUtility.NextIdentifier(); var category = RandomUtility.Within(50) == true ? tableCategoryCollection.Root : await tableCategoryCollection.GetRandomTableCategoryAsync(); if (category.VerifyAccessType(authentication, AccessType.Master) == false) { return(false); } if (GetLevel(category, (i) => i.Parent) > 4) { return(false); } if (category.Categories.ContainsKey(categoryName) == true) { return(false); } await category.AddNewCategoryAsync(authentication, categoryName); return(true); }
public static Task <ITableCategory[]> GetTableCategoriesAsync(this ITableContext tableContext) { if (tableContext.GetService(typeof(ITableCategoryCollection)) is ITableCategoryCollection tableCategoryCollection) { return(tableCategoryCollection.GetCategoriesAsync()); } throw new NotImplementedException(); }
public static Task <ITableCategory> GetTableCategoryAsync(this ITableContext tableContext, string categoryPath) { if (tableContext.GetService(typeof(ITableCategoryCollection)) is ITableCategoryCollection tableCategoryCollection) { return(tableCategoryCollection.GetCategoryAsync(categoryPath)); } throw new NotImplementedException(); }
public static Task <ITable> GetTableAsync(this ITableContext tableContext, string tableName) { if (tableContext.GetService(typeof(ITableCollection)) is ITableCollection tableCollection) { return(tableCollection.GetTableAsync(tableName)); } throw new NotImplementedException(); }
public static async Task <ITableItem> GenerateAsync(this ITableContext tableContext, Authentication authentication) { if (RandomUtility.Within(25) == true) { if (tableContext.GetService(typeof(ITableCategoryCollection)) is ITableCategoryCollection tableCategoryCollection) { return((await tableCategoryCollection.GenerateCategoryAsync(authentication)) as ITableItem); } } else { if (tableContext.GetService(typeof(ITableCollection)) is ITableCollection tableCollection) { return((await tableCollection.GenerateTableAsync(authentication)) as ITableItem); } } throw new NotImplementedException(); }
public static async Task AddRandomTablesAsync(this ITableContext tableContext, Authentication authentication, DataBaseSettings settings) { var minCount = settings.TableContext.MinTableCount; var maxCount = settings.TableContext.MaxTableCount; var count = RandomUtility.Next(minCount, maxCount); var tableCollection = tableContext.GetService(typeof(ITableCollection)) as ITableCollection; while (await tableCollection.GetCountAsync() < count) { await AddRandomTableAsync(tableContext, authentication, settings); } }
public static async Task <ITableCategory> AddRandomCategoryAsync(this ITableContext tableContext, Authentication authentication) { if (tableContext.GetService(typeof(ITableCategoryCollection)) is ITableCategoryCollection tableCategoryCollection) { var category = RandomUtility.Within(33) == true ? tableCategoryCollection.Root : await tableCategoryCollection.GetRandomTableCategoryAsync(); if (GetLevel(category, (i) => i.Parent) > 4) { return(null); } return(await category.AddRandomCategoryAsync(authentication)); } else { throw new NotImplementedException(); } }
public static async Task AddRandomChildTablesAsync(this ITableContext tableContext, Authentication authentication, DataBaseSettings settings) { var minCount = settings.TableContext.MinChildTableCount; var maxCount = settings.TableContext.MaxChildTableCount; var count = RandomUtility.Next(minCount, maxCount); while (await GetChildTableCountAsync() < count) { await AddRandomChildTableAsync(tableContext, authentication, settings); } Task <int> GetChildTableCountAsync() { var tableCollection = tableContext.GetService(typeof(ITableCollection)) as ITableCollection; return(tableCollection.Dispatcher.InvokeAsync(() => { return tableCollection.Where(item => item.Parent != null && item.TemplatedParent == null).Count(); })); } }
public void GetService() { Console.Write(tableContext.GetService(typeof(ICremaHost))); }
public static async Task GenerateStandardAsync(this ITableContext context, Authentication authentication) { var typeCollection = context.GetService(typeof(ITypeCollection)) as ITypeCollection; var tableCategoryCollection = context.GetService(typeof(ITableCategoryCollection)) as ITableCategoryCollection; var root = tableCategoryCollection.Root; var types = await typeCollection.GetTypesAsync(); var typeNames = types.Select(item => item.Name); var baseTypeNames = CremaDataTypeUtility.GetBaseTypeNames(); var allTypes = typeNames.Concat(baseTypeNames); var allKeyTypes = typeNames.Concat(baseTypeNames).Where(item => item != typeof(bool).GetTypeName()); { var category = await root.AddNewCategoryAsync(authentication, "SingleKey"); foreach (var item in allTypes) { var table = await category.GenerateStandardTableAsync(authentication, "SingleKey", EnumerableUtility.AsEnumerable(item), allTypes.Where(i => i != item)); if (table == null) { continue; } await table.GenerateStandardChildAsync(authentication); await table.GenerateStandardContentAsync(authentication); } var category1 = await root.AddNewCategoryAsync(authentication, "SingleKeyRefs"); { foreach (var item in category.Tables) { var tables = await item.InheritAsync(authentication, "Ref_" + item.Name, category1.Path, false); foreach (var i in tables) { await i.GenerateStandardContentAsync(authentication); } } } } { var category = await root.AddNewCategoryAsync(authentication, "DoubleKey"); var query = allKeyTypes.Permutations(2); for (int i = 0; i < allTypes.Count(); i++) { var keys = query.Random(); var columns = allTypes.Except(keys); var table = await category.GenerateStandardTableAsync(authentication, "DoubleKey", keys, columns); if (table == null) { continue; } await table.GenerateStandardChildAsync(authentication); await table.GenerateStandardContentAsync(authentication); } var category1 = await root.AddNewCategoryAsync(authentication, "DoubleKeyRefs"); { foreach (var item in category.Tables) { var tables = await item.InheritAsync(authentication, "Ref_" + item.Name, category1.Path, false); foreach (var i in tables) { await i.GenerateStandardContentAsync(authentication); } } } } { var category = await root.AddNewCategoryAsync(authentication, "TripleKey"); var query = allKeyTypes.Permutations(3); for (int i = 0; i < allTypes.Count(); i++) { var keys = query.Random(); var columns = allTypes.Except(keys); var table = await category.GenerateStandardTableAsync(authentication, "TripleKey", keys, columns); if (table == null) { continue; } await table.GenerateStandardChildAsync(authentication); await table.GenerateStandardContentAsync(authentication); } var category1 = await root.AddNewCategoryAsync(authentication, "TripleKeyRefs"); { foreach (var item in category.Tables) { var tables = await item.InheritAsync(authentication, "Ref_" + item.Name, category1.Path, false); foreach (var i in tables) { await i.GenerateStandardContentAsync(authentication); } } } } { var category = await root.AddNewCategoryAsync(authentication, "QuadraKey"); var query = allKeyTypes.Permutations(4); for (int i = 0; i < allTypes.Count(); i++) { var keys = query.Random(); var columns = allTypes.Except(keys); var table = await category.GenerateStandardTableAsync(authentication, "QuadraKey", keys, columns); if (table == null) { continue; } await table.GenerateStandardChildAsync(authentication); await table.GenerateStandardContentAsync(authentication); } var category1 = await root.AddNewCategoryAsync(authentication, "QuadraKeyRefs"); { foreach (var item in category.Tables) { var tables = await item.InheritAsync(authentication, "Ref_" + item.Name, category1.Path, false); foreach (var i in tables) { await i.GenerateStandardContentAsync(authentication); } } } } }
public static void GenerateStandard(this ITableContext context, Authentication authentication) { var typeContext = context.GetService(typeof(ITypeContext)) as ITypeContext; var root = context.Root; var types1 = typeContext.Types.Select(item => item.Name).ToArray(); var types2 = CremaTypeUtility.GetBaseTypes(); var allTypes = types1.Concat(types2); var allKeyTypes = types1.Concat(types2).Where(item => item != typeof(bool).GetTypeName()); { var category = root.AddNewCategory(authentication, "SingleKey"); foreach (var item in allTypes) { var table = category.GenerateStandardTable(authentication, "SingleKey", EnumerableUtility.AsEnumerable(item), allTypes.Where(i => i != item)); if (table == null) { continue; } table.GenerateStandardChild(authentication); table.GenerateStandardContent(authentication); } var category1 = root.AddNewCategory(authentication, "SingleKeyRefs"); { foreach (var item in category.Tables) { var table1 = item.Inherit(authentication, "Ref_" + item.Name, category1.Path, false); table1.GenerateStandardContent(authentication); } } } { var category = root.AddNewCategory(authentication, "DoubleKey"); var query = allKeyTypes.Permutations(2); for (int i = 0; i < allTypes.Count(); i++) { var keys = query.Random(); var columns = allTypes.Except(keys); var table = category.GenerateStandardTable(authentication, "DoubleKey", keys, columns); if (table == null) { continue; } table.GenerateStandardChild(authentication); table.GenerateStandardContent(authentication); } var category1 = root.AddNewCategory(authentication, "DoubleKeyRefs"); { foreach (var item in category.Tables) { var table1 = item.Inherit(authentication, "Ref_" + item.Name, category1.Path, false); table1.GenerateStandardContent(authentication); } } } { var category = root.AddNewCategory(authentication, "TripleKey"); var query = allKeyTypes.Permutations(3); for (int i = 0; i < allTypes.Count(); i++) { var keys = query.Random(); var columns = allTypes.Except(keys); var table = category.GenerateStandardTable(authentication, "TripleKey", keys, columns); if (table == null) { continue; } table.GenerateStandardChild(authentication); table.GenerateStandardContent(authentication); } var category1 = root.AddNewCategory(authentication, "TripleKeyRefs"); { foreach (var item in category.Tables) { var table1 = item.Inherit(authentication, "Ref_" + item.Name, category1.Path, false); table1.GenerateStandardContent(authentication); } } } { var category = root.AddNewCategory(authentication, "QuadraKey"); var query = allKeyTypes.Permutations(4); for (int i = 0; i < allTypes.Count(); i++) { var keys = query.Random(); var columns = allTypes.Except(keys); var table = category.GenerateStandardTable(authentication, "QuadraKey", keys, columns); if (table == null) { continue; } table.GenerateStandardChild(authentication); table.GenerateStandardContent(authentication); } var category1 = root.AddNewCategory(authentication, "QuadraKeyRefs"); { foreach (var item in category.Tables) { var table1 = item.Inherit(authentication, "Ref_" + item.Name, category1.Path, false); table1.GenerateStandardContent(authentication); } } } }