コード例 #1
0
        public static void OnDBSchemaChanged(DBSchemaItem item, DDLType type)
        {
            if (type == DDLType.Default ||
                !item.Containers.Any() ||
                item.Schema == null ||
                !item.Schema.Containers.Any() ||
                item.Schema.IsSynchronizing)
            {
                return;
            }
            if (item is IDBTableContent tabled)
            {
                if (tabled.Table is IDBVirtualTable || !tabled.Table.Containers.Any())
                {
                    return;
                }
                if (item is DBColumn column && column.ColumnType != DBColumnTypes.Default)
                {
                    return;
                }
            }
            DBSchemaChange change = null;

            var list = Changes.Select(DBSchemaChangeItemInvoker, CompareType.Equal, item).ToList();

            if (list.Count > 0)
            {
                change = list[0];
                if (change.Change != type)
                {
                    if (change.Change == DDLType.Create && type == DDLType.Alter)
                    {
                        return;
                    }
                    change = null;
                }
            }

            if (change == null)
            {
                change = new DBSchemaChange()
                {
                    Item = item, Change = type
                };
                Changes.Add(change);
            }
            DBSchemaChanged?.Invoke(item, new DBSchemaChangedArgs {
                Item = item, Type = type
            });
        }
コード例 #2
0
        public void Deserialize(string file, DBSchemaItem selectedItem)
        {
            var item = Serialization.Deserialize(file);

            if (item is DBTable table)
            {
                DBSchema schema = selectedItem.Schema;

                if (schema.Tables.Contains(table.Name))
                {
                    schema.Tables.Remove(table.Name);
                }
                schema.Tables.Add(table);
            }
            else if (item is DBSchema schema)
            {
                if (Contains(schema.Name))
                {
                    schema.Name = schema.Name + "1";
                }
                Add((DBSchema)item);
            }
            else if (item is DBColumn column)
            {
                if (selectedItem is DBTable sTable)
                {
                    sTable.Columns.Add((DBColumn)item);
                }
            }
            else if (item is SelectableList <DBSchemaItem> list)
            {
                foreach (var element in list)
                {
                    if (element is DBColumn && selectedItem is DBTable)
                    {
                        ((DBTable)selectedItem).Columns.Add((DBColumn)element);
                    }
                    else if (element is DBTable && selectedItem is DBSchema)
                    {
                        ((DBSchema)selectedItem).Tables.Add((DBTable)element);
                    }
                }
            }
        }