Beispiel #1
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);
     }
 }
Beispiel #2
0
 private static async Task SetFieldsAsync(Authentication authentication, JsonColumnInfos.ItemInfo item, ITableColumn column)
 {
     if (column.Name != item.Name)
     {
         await column.SetNameAsync(authentication, item.Name);
     }
     if (column.DataType != item.DataType)
     {
         await column.SetDataTypeAsync(authentication, item.DataType);
     }
     if (column.Comment != item.Comment)
     {
         await column.SetCommentAsync(authentication, item.Comment);
     }
     if (column.Tags != (TagInfo)item.Tags)
     {
         await column.SetTagsAsync(authentication, (TagInfo)item.Tags);
     }
     if (column.IsReadOnly != item.IsReadOnly)
     {
         await column.SetIsReadOnlyAsync(authentication, item.IsReadOnly);
     }
     if (column.IsUnique != item.IsUnique)
     {
         await column.SetIsUniqueAsync(authentication, item.IsUnique);
     }
     if (column.AutoIncrement != item.AutoIncrement)
     {
         await column.SetAutoIncrementAsync(authentication, item.AutoIncrement);
     }
     if (column.DefaultValue != item.DefaultValue)
     {
         await column.SetDefaultValueAsync(authentication, item.DefaultValue);
     }
     if (column.AllowNull != !item.DisallowNull)
     {
         await column.SetAllowNullAsync(authentication, !item.DisallowNull);
     }
 }
Beispiel #3
0
        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);
        }
Beispiel #4
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);
 }
Beispiel #5
0
        private static async Task <JsonColumnInfos.ItemInfo> InitializeFieldsAsync(Authentication authentication, JsonColumnInfos.ItemInfo item, ITableColumn column)
        {
            await column.SetNameAsync(authentication, item.Name);

            await column.SetDataTypeAsync(authentication, item.DataType);

            await column.SetCommentAsync(authentication, item.Comment);

            await column.SetTagsAsync(authentication, (TagInfo)item.Tags);

            await column.SetIsReadOnlyAsync(authentication, item.IsReadOnly);

            await column.SetIsUniqueAsync(authentication, item.IsUnique);

            await column.SetAutoIncrementAsync(authentication, item.AutoIncrement);

            await column.SetDefaultValueAsync(authentication, item.DefaultValue);

            await column.SetAllowNullAsync(authentication, !item.DisallowNull);

            return(item);
        }