public async Task NewTableAsync(ITableCategory category, TaskContext context) { var authentication = context.Authentication; var template = await category.AddNewTableAsync(authentication); context.Push(template); }
public static async Task <ITable> GenerateStandardTableAsync(this ITableCategory category, Authentication authentication, string prefix, IEnumerable <string> keyTypes, IEnumerable <string> columnTypes) { var tables = category.GetService(typeof(ITableCollection)) as ITableCollection; var tableName = string.Join("_", EnumerableUtility.Friends(prefix, keyTypes)); if (tables.Contains(tableName) == true) { return(null); } var template = await category.AddNewTableAsync(authentication); await template.SetTableNameAsync(authentication, tableName); foreach (var item in keyTypes) { await template.AddKeyAsync(authentication, item, item); } foreach (var item in columnTypes) { await template.AddColumnAsync(authentication, item, item); } try { await template.EndEditAsync(authentication); return(template.Target as ITable); } catch { await template.CancelEditAsync(authentication); return(null); } //var table = template.Table; //var content = table.Content; //content.BeginEdit(authentication); //content.EnterEdit(authentication); //try //{ // content.GenerateRowsAsync(authentication, RandomUtility.Next(10, 1000)); // content.LeaveEdit(authentication); // content.EndEdit(authentication); //} //catch //{ // content.CancelEdit(authentication); //} //return table; }
public static async Task <ITable> GenerateTableAsync(this ITableCategory tableCategory, Authentication authentication, params string[] typeNames) { var tableCollection = tableCategory.GetService(typeof(ITableCollection)) as ITableCollection; var newName = await tableCollection.GenerateNewTableNameAsync("table"); var template = await tableCategory.AddNewTableAsync(authentication); await template.SetTableNameAsync(authentication, newName); foreach (var item in typeNames) { var columnName = await template.GenerateNewColumnNameAsync(); var comment = RandomUtility.NextString(); await template.AddColumnAsync(authentication, columnName, item, comment); } await template.AddRandomColumnsAsync(authentication); await template.EndEditAsync(authentication); return(template.Target as ITable); throw new NotImplementedException(); }
public static async Task <ITable> AddRandomTableAsync(this ITableCategory category, Authentication authentication, DataBaseSettings settings) { var template = await category.AddNewTableAsync(authentication); await template.InitializeRandomAsync(authentication); await template.EndEditAsync(authentication); if (template.Target is ITable[] tables) { foreach (var item in tables) { var minCount = settings.TableContext.MinRowCount; var maxCount = settings.TableContext.MaxRowCount; var count = RandomUtility.Next(minCount, maxCount); await item.AddRandomRowsAsync(authentication, count); } return(tables.First()); } else { throw new NotImplementedException(); } }