public static async Task InitializeRandomAsync(this ITableColumn tableColumn, Authentication authentication) { var template = tableColumn.Template; var table = tableColumn.Template.Target; if (RandomUtility.Within(75) == true) { await tableColumn.SetDataTypeAsync(authentication, CremaDataTypeUtility.GetBaseTypeNames().Random(item => item != typeof(bool).GetTypeName())); } else { await tableColumn.SetDataTypeAsync(authentication, template.SelectableTypes.Random()); } if (template.Count == 0) { await tableColumn.SetIsKeyAsync(authentication, true); } else if (RandomUtility.Within(10) && tableColumn.DataType != typeof(bool).GetTypeName()) { await tableColumn.SetIsKeyAsync(authentication, true); await tableColumn.SetIsUniqueAsync(authentication, RandomUtility.Within(75)); } if (RandomUtility.Within(25) && tableColumn.DataType != typeof(bool).GetTypeName()) { var unique = RandomUtility.Within(75); if (unique != false || template.PrimaryKey.Count() != 1) { await tableColumn.SetIsUniqueAsync(authentication, unique); } } if (RandomUtility.Within(25) == true) { await tableColumn.SetCommentAsync(authentication, RandomUtility.NextString()); } if (RandomUtility.Within(25) == true) { await tableColumn.SetDefaultValueAsync(authentication, await tableColumn.GetRandomStringAsync()); } if (CremaDataTypeUtility.CanUseAutoIncrement(tableColumn.DataType) == true && tableColumn.DefaultValue == null) { await tableColumn.SetAutoIncrementAsync(authentication, RandomUtility.NextBoolean()); } if (RandomUtility.Within(5) == true) { await tableColumn.SetIsReadOnlyAsync(authentication, true); } }
public static async Task GenerateStandardChildAsync(this ITable table, Authentication authentication) { var typeCollection = table.GetService(typeof(ITypeCollection)) as ITypeCollection; var types1 = typeCollection.Select(item => item.Name).ToArray(); var types2 = CremaDataTypeUtility.GetBaseTypeNames(); var allTypes = types1.Concat(types2); var allKeyTypes = types1.Concat(types2).Where(item => item != typeof(bool).GetTypeName()); var prefixes = new string[] { "SingleKey", "DoubleKey", "TripleKey", "QuadraKey", }; for (int i = 0; i < prefixes.Length; i++) { var query = allKeyTypes.Permutations(i + 1); var keys = query.Random(); var columns = allTypes.Except(keys); await table.GenerateStandardChildAsync(authentication, "Child_" + prefixes[i], keys, columns); } }
public static bool CreateColumn(this CremaDataTable dataTable) { var columnName = RandomUtility.NextIdentifier(); if (dataTable.Columns.Contains(columnName) == true) { return(false); } var column = dataTable.Columns.Add(columnName); if (dataTable.PrimaryKey.Any() == false) { column.IsKey = true; } else if (RandomUtility.Within(10)) { column.IsKey = true; column.Unique = RandomUtility.Within(75); } if (RandomUtility.Within(75) == true) { column.DataType = CremaDataTypeUtility.GetType(CremaDataTypeUtility.GetBaseTypeNames().Random()); } else if (dataTable.DataSet.Types.Any()) { column.CremaType = dataTable.DataSet.Types.Random(); } if (RandomUtility.Within(25) == true) { column.Comment = RandomUtility.NextString(); } if (CremaDataTypeUtility.CanUseAutoIncrement(column.DataType) == true) { column.AutoIncrement = RandomUtility.NextBoolean(); } return(true); }
public void SetDataType(ITableColumn column, TaskContext context) { column.Dispatcher.Invoke(() => { var template = column.Template; if (RandomUtility.Within(75) == true) { var dataType = CremaDataTypeUtility.GetBaseTypeNames().Random(); if (Verify(dataType) == false) { return; } column.SetDataType(context.Authentication, dataType); } else { var dataType = template.SelectableTypes.Random(); if (Verify(dataType) == false) { return; } column.SetDataType(context.Authentication, dataType); } }); bool Verify(string dataType) { if (context.AllowException == true) { return(true); } if (column.AutoIncrement == true && CremaDataTypeUtility.CanUseAutoIncrement(column.DataType) == false) { return(false); } return(true); } }
public async Task SetDataTypeAsync(ITableColumn column, TaskContext context) { var authentication = context.Authentication; var template = column.Template; if (RandomUtility.Within(75) == true) { var dataType = CremaDataTypeUtility.GetBaseTypeNames().Random(); if (Verify(dataType) == false) { return; } await column.SetDataTypeAsync(authentication, dataType); } else { var dataType = template.SelectableTypes.Random(); if (Verify(dataType) == false) { return; } await column.SetDataTypeAsync(authentication, dataType); } bool Verify(string dataType) { if (context.AllowException == true) { return(true); } if (column.AutoIncrement == true && CremaDataTypeUtility.CanUseAutoIncrement(column.DataType) == false) { return(false); } return(true); } }
public TypeNamesDescriptionAttribute() : base(string.Join(", ", CremaDataTypeUtility.GetBaseTypeNames()) + " or typePath(e.g., /categoryPath/typeName)") { }
public static bool CreateColumn(this ITableTemplate template, Authentication authentication) { var columnName = RandomUtility.NextIdentifier(); if (template.Contains(columnName) == true) { return(false); } var column = template.AddNew(authentication); column.SetName(authentication, columnName); if (template.PrimaryKey.Any() == false) { column.SetIsKey(authentication, true); } else if (template.Count == 0 && RandomUtility.Within(10)) { column.SetIsKey(authentication, true); column.SetIsUnique(authentication, RandomUtility.Within(75)); } if (RandomUtility.Within(75) == true) { column.SetTags(authentication, TagInfo.All); } else { column.SetTags(authentication, tags.Random()); } if (RandomUtility.Within(75) == true) { column.SetDataType(authentication, CremaDataTypeUtility.GetBaseTypeNames().Random()); } else { column.SetDataType(authentication, template.SelectableTypes.Random()); } if (RandomUtility.Within(25) == true) { column.SetComment(authentication, RandomUtility.NextString()); } if (CremaDataTypeUtility.CanUseAutoIncrement(column.DataType) == true) { column.SetAutoIncrement(authentication, RandomUtility.NextBoolean()); } try { template.EndNew(authentication, column); } catch { return(false); } return(true); }
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); } } } } }