public static ITableTemplate CreateAddNew(this ITableTemplate template, Authentication authentication, string columnName, string defaultValue = null, bool isKey = false, string dataType = null, bool?allowNull = null) { var column = template.AddNew(authentication); column.SetName(authentication, columnName); column.SetIsKey(authentication, isKey); if (dataType != null) { column.SetDataType(authentication, dataType); } if (allowNull != null) { column.SetAllowNull(authentication, allowNull.Value); } if (defaultValue != null) { column.SetDefaultValue(authentication, defaultValue); } template.EndNew(authentication, column); return(template); }
public static void AddColumn(this ITableTemplate template, Authentication authentication, string name, string typeName) { var column = template.AddNew(authentication); column.SetName(authentication, name); column.SetDataType(authentication, typeName); template.EndNew(authentication, column); }
public static ITableColumn AddRandomColumn(this ITableTemplate template, Authentication authentication) { var column = template.AddNew(authentication); column.InitializeRandom(authentication); template.EndNew(authentication, column); return(column); }
public static void AddKey(this ITableTemplate template, Authentication authentication, string name, string typeName) { var column = template.AddNew(authentication); column.SetName(authentication, name); column.SetIsKey(authentication, true); column.SetDataType(authentication, typeName); column.SetComment(authentication, string.Format("Key : {0}", typeName)); template.EndNew(authentication, column); }
public static bool EditColumns(ITableTemplate template, Authentication authentication) { var columnCount = template.Dispatcher.Invoke(() => template.Count); var dataTypes = template.Dispatcher.Invoke(() => template.SelectableTypes); var columnList = new List <JsonColumnInfos.ItemInfo>(columnCount); var idToColumn = new Dictionary <Guid, ITableColumn>(columnCount); template.Dispatcher.Invoke(() => { foreach (var item in template) { var column = new JsonColumnInfos.ItemInfo() { ID = Guid.NewGuid(), Name = item.Name, IsKey = item.IsKey, DataType = item.DataType, Comment = item.Comment, IsUnique = item.IsUnique, AutoIncrement = item.AutoIncrement, DefaultValue = item.DefaultValue, Tags = (string)item.Tags, IsReadOnly = item.IsReadOnly, AllowNull = item.AllowNull, }; idToColumn.Add(column.ID, item); columnList.Add(column); } }); var schema = JsonSchemaUtility.CreateSchema(typeof(JsonColumnInfos)); var itemsSchema = schema.Properties[nameof(JsonColumnInfos.Items)]; var itemSchema = itemsSchema.Items.First(); var dataTypeSchema = itemSchema.Properties[nameof(JsonColumnInfos.ItemInfo.DataType)]; dataTypeSchema.SetEnums(dataTypes); var tagSchema = itemSchema.Properties[nameof(JsonColumnInfos.ItemInfo.Tags)]; tagSchema.SetEnums(TagInfoUtility.Names); var columns = new JsonColumnInfos() { Items = columnList.ToArray() }; using (var editor = new JsonEditorHost(columns, schema)) { if (editor.Execute() == false) { return(false); } columns = editor.Read <JsonColumnInfos>(); } template.Dispatcher.Invoke(() => { foreach (var item in idToColumn.Keys.ToArray()) { if (columns.Items.Any(i => i.ID == item) == false) { var column = idToColumn[item]; column.Delete(authentication); idToColumn.Remove(item); } } for (var i = 0; i < columns.Items.Length; i++) { var item = columns.Items[i]; if (item.ID == Guid.Empty) { var column = template.AddNew(authentication); item = InitializeFields(authentication, item, column); template.EndNew(authentication, column); item.ID = Guid.NewGuid(); idToColumn.Add(item.ID, column); columns.Items[i] = item; } else if (idToColumn.ContainsKey(item.ID) == true) { var column = idToColumn[item.ID]; SetFields(authentication, item, column); } else { throw new InvalidOperationException($"{item.ID} is not existed column."); } } for (var i = 0; i < columns.Items.Length; i++) { var item = columns.Items[i]; var column = idToColumn[item.ID]; column.SetIndex(authentication, i); } }); return(true); }
public void EndNew() { template.EndNew(authentication, column); }
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); }