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);
                        }
                    }
                }
            }
        }
Esempio n. 2
0
        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);
                    }
                }
            }
        }