Exemplo n.º 1
0
        public static void InitializeRandom(this ITableColumn tableColumn, Authentication authentication)
        {
            var template = tableColumn.Template;
            var table    = tableColumn.Template.Table;

            if (RandomUtility.Within(75) == true)
            {
                tableColumn.SetDataType(authentication, CremaDataTypeUtility.GetBaseTypeNames().Random(item => item != typeof(bool).GetTypeName()));
            }
            else
            {
                tableColumn.SetDataType(authentication, template.SelectableTypes.Random());
            }

            if (template.Count == 0)
            {
                tableColumn.SetIsKey(authentication, true);
            }
            else if (RandomUtility.Within(10) && tableColumn.DataType != typeof(bool).GetTypeName())
            {
                tableColumn.SetIsKey(authentication, true);
                tableColumn.SetIsUnique(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)
                {
                    tableColumn.SetIsUnique(authentication, unique);
                }
            }

            if (RandomUtility.Within(25) == true)
            {
                tableColumn.SetComment(authentication, RandomUtility.NextString());
            }

            if (RandomUtility.Within(25) == true)
            {
                tableColumn.SetDefaultValue(authentication, tableColumn.GetRandomString());
            }

            if (CremaDataTypeUtility.CanUseAutoIncrement(tableColumn.DataType) == true && tableColumn.DefaultValue == null)
            {
                tableColumn.SetAutoIncrement(authentication, RandomUtility.NextBoolean());
            }

            if (RandomUtility.Within(5) == true)
            {
                tableColumn.SetIsReadOnly(authentication, true);
            }
        }
Exemplo n.º 2
0
 private static JsonColumnInfos.ItemInfo InitializeFields(Authentication authentication, JsonColumnInfos.ItemInfo item, ITableColumn column)
 {
     column.SetName(authentication, item.Name);
     column.SetDataType(authentication, item.DataType);
     column.SetComment(authentication, item.Comment);
     column.SetTags(authentication, (TagInfo)item.Tags);
     column.SetIsReadOnly(authentication, item.IsReadOnly);
     column.SetIsUnique(authentication, item.IsUnique);
     column.SetAutoIncrement(authentication, item.AutoIncrement);
     column.SetDefaultValue(authentication, item.DefaultValue);
     column.SetAllowNull(authentication, item.AllowNull);
     return(item);
 }
Exemplo n.º 3
0
        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);
            }
        }
Exemplo n.º 4
0
 private static void SetFields(Authentication authentication, JsonColumnInfos.ItemInfo item, ITableColumn column)
 {
     if (column.Name != item.Name)
     {
         column.SetName(authentication, item.Name);
     }
     if (column.DataType != item.DataType)
     {
         column.SetDataType(authentication, item.DataType);
     }
     if (column.Comment != item.Comment)
     {
         column.SetComment(authentication, item.Comment);
     }
     if (column.Tags != (TagInfo)item.Tags)
     {
         column.SetTags(authentication, (TagInfo)item.Tags);
     }
     if (column.IsReadOnly != item.IsReadOnly)
     {
         column.SetIsReadOnly(authentication, item.IsReadOnly);
     }
     if (column.IsUnique != item.IsUnique)
     {
         column.SetIsUnique(authentication, item.IsUnique);
     }
     if (column.AutoIncrement != item.AutoIncrement)
     {
         column.SetAutoIncrement(authentication, item.AutoIncrement);
     }
     if (column.DefaultValue != item.DefaultValue)
     {
         column.SetDefaultValue(authentication, item.DefaultValue);
     }
     if (column.AllowNull != item.AllowNull)
     {
         column.SetAllowNull(authentication, item.AllowNull);
     }
 }
Exemplo n.º 5
0
 public void SetDataType()
 {
     column.SetDataType(authentication, string.Empty);
 }