/// <summary>
        /// 处理外键。
        /// </summary>
        /// <param name="tables"></param>
        /// <param name="foreignKeys"></param>
        private void ProcessForeignKeys(List <Table> tables, List <Schema.ForeignKey> foreignKeys)
        {
            foreach (var sfk in foreignKeys)
            {
                if (Processor.IsCancellationRequested())
                {
                    break;
                }

                var pkTable = tables.FirstOrDefault(s => s.Name.Equals(sfk.PKTable, StringComparison.CurrentCultureIgnoreCase));
                var fkTable = tables.FirstOrDefault(s => s.Name.Equals(sfk.TableName, StringComparison.CurrentCultureIgnoreCase));
                if (pkTable != null && fkTable != null)
                {
                    var pkColumn = pkTable.Columns.FirstOrDefault(s => s.Name.Equals(sfk.PKColumn, StringComparison.CurrentCultureIgnoreCase));
                    var fkColumn = fkTable.Columns.FirstOrDefault(s => s.Name.Equals(sfk.ColumnName, StringComparison.CurrentCultureIgnoreCase));

                    if (pkColumn != null && fkColumn != null)
                    {
                        var fk = SchemaExtensionManager.Build <Reference>(pkTable, pkColumn, fkTable, fkColumn);
                        fk.Name = sfk.Name;
                        fkColumn.BindForeignKey(fk);
                    }
                }
            }
        }
        private IEnumerable <Column> ConvertSchemaColumns(Table table, IEnumerable <Schema.Column> columns, List <Schema.DataType> dbTypes, string providerName)
        {
            foreach (var c in columns)
            {
                if (Processor.IsCancellationRequested())
                {
                    yield break;
                }

                var column = SchemaExtensionManager.Build <Column>(table);

                column.Name          = c.Name;
                column.AutoIncrement = c.Autoincrement;
                column.Description   = c.Description ?? string.Empty;
                column.IsNullable    = c.IsNullable;
                column.DataType      = c.DataType;
                column.Length        = c.Length;
                column.Scale         = c.NumericScale;
                column.Precision     = c.NumericPrecision;
                column.IsPrimaryKey  = c.IsPrimaryKey;
                column.DbType        = ConvertDbType(column, dbTypes, providerName);

                InitializerUnity.Initialize(column);

                yield return(column);
            }
        }
Esempio n. 3
0
 private void InitInsertMenus()
 {
     InitMenuFields(mnuTableFields, SchemaExtensionManager.GetPropertyMaps <Table>());
     InitMenuFields(mnuColumnFields, SchemaExtensionManager.GetPropertyMaps <Column>());
     InitMenuFields(mnuReferFields, SchemaExtensionManager.GetPropertyMaps <Reference>());
     InitMenuFields(mnuProfileFields, ProfileExtensionManager.GetPropertyMaps());
 }
Esempio n. 4
0
        private IEnumerable <Table> ConvertSchemaTables(IEnumerable <Schema.Table> tables, IEnumerable <Schema.View> views)
        {
            var index = 0;

            foreach (var t in tables)
            {
                var table = SchemaExtensionManager.Build <Table>();
                table.Name        = t.Name;
                table.Description = t.Description ?? string.Empty;
                table.Index       = ++index;

                InitializerUnity.Initialize(table);

                yield return(table);
            }

            foreach (var v in views)
            {
                var table = SchemaExtensionManager.Build <Table>(true);
                table.Name        = v.Name;
                table.Description = v.Description ?? string.Empty;
                table.Index       = ++index;

                InitializerUnity.Initialize(table);

                yield return(table);
            }
        }
Esempio n. 5
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.ThreadException += Application_ThreadException;
            Util.ClearTempFiles();

            SchemaExtensionManager.Initialize();
            ProfileExtensionManager.Initialize();
            Application.Run(new frmMain());
        }
        private IEnumerable <Table> ConvertSchemaTables(IEnumerable <Schema.Table> tables)
        {
            foreach (var t in tables)
            {
                if (t.Type.ToUpper().Contains("SYS"))
                {
                    continue;
                }

                var table = SchemaExtensionManager.Build <Table>();
                table.Name        = t.Name;
                table.Description = t.Description ?? string.Empty;

                InitializerUnity.Initialize(table);

                yield return(table);
            }
        }
Esempio n. 7
0
        private static ProxyType BuildSchemaProxyType(List <string> assemblyList)
        {
            var proxyType = new ProxyType();
            var fileName  = Util.GenerateTempFileName();

            assemblyList.Add(fileName);
            var assemblyBuilder = new DynamicAssemblyBuilder("__Schema_Proxy", fileName);

            var tableTypeBuilder     = assemblyBuilder.DefineType("Table", baseType: typeof(MarshalByRefObject));
            var columnTypeBuilder    = assemblyBuilder.DefineType("Column", baseType: typeof(MarshalByRefObject));
            var referenceTypeBuilder = assemblyBuilder.DefineType("Reference", baseType: typeof(MarshalByRefObject));

            tableTypeBuilder.ImplementInterface(typeof(_IIdentity));
            columnTypeBuilder.ImplementInterface(typeof(_IIdentity));
            referenceTypeBuilder.ImplementInterface(typeof(_IIdentity));

            proxyType.TableType     = tableTypeBuilder.UnderlyingSystemType;
            proxyType.ColumnType    = columnTypeBuilder.UnderlyingSystemType;
            proxyType.ReferenceType = referenceTypeBuilder.UnderlyingSystemType;

            //定义Table代理类的属性
            foreach (var property in SchemaExtensionManager.GetWrapType <Table>().GetProperties(BindingFlags.Public | BindingFlags.Instance))
            {
                var propertyType = Replace(property.PropertyType, proxyType);
                tableTypeBuilder.DefineProperty(property.Name, propertyType).DefineGetSetMethods();
            }

            //定义Table代理类的属性
            foreach (var property in SchemaExtensionManager.GetWrapType <Column>().GetProperties(BindingFlags.Public | BindingFlags.Instance))
            {
                var propertyType = Replace(property.PropertyType, proxyType);
                columnTypeBuilder.DefineProperty(property.Name, propertyType).DefineGetSetMethods();
            }

            //定义Table代理类的属性
            foreach (var property in SchemaExtensionManager.GetWrapType <Reference>().GetProperties(BindingFlags.Public | BindingFlags.Instance))
            {
                var propertyType = Replace(property.PropertyType, proxyType);
                referenceTypeBuilder.DefineProperty(property.Name, propertyType).DefineGetSetMethods();
            }

            assemblyBuilder.Save();
            return(proxyType);
        }
Esempio n. 8
0
        public Table ParseTable(PdmTable table)
        {
            var node      = doc.SelectSingleNode(table.Uri, nms);
            var ndColumns = node.SelectNodes("c:Columns/o:Column", nms);
            var newtable  = SchemaExtensionManager.Build <Table>();

            var pkRootNode = node.SelectSingleNode("c:PrimaryKey/o:Key", nms);
            var pkRefId    = pkRootNode == null ? string.Empty : pkRootNode.Attributes["Ref"].InnerText;

            newtable.Name        = table.Name;
            newtable.Description = table.Description;

            foreach (XmlNode child in ndColumns)
            {
                var id          = child.Attributes["Id"].InnerText;
                var nameNode    = child.SelectSingleNode("a:Name", nms);
                var codeNode    = child.SelectSingleNode("a:Code", nms);
                var descNode    = child.SelectSingleNode("a:Comment", nms);
                var dtNode      = child.SelectSingleNode("a:DataType", nms);
                var lngNode     = child.SelectSingleNode("a:Length", nms);
                var mandNode    = child.SelectSingleNode("a:Column.Mandatory", nms);
                var idenNode    = child.SelectSingleNode("a:Identity", nms);
                var defaultNode = child.SelectSingleNode("a:DefaultValue", nms);
                var column      = SchemaExtensionManager.Build <Column>(newtable);
                column.Name = codeNode.InnerText;

                if (descNode != null && !string.IsNullOrEmpty(descNode.InnerText) &&
                    nameNode.InnerText != descNode.InnerText)
                {
                    column.Description = descNode.InnerText;
                }
                else
                {
                    column.Description = nameNode.InnerText;
                }

                if (dtNode != null)
                {
                    ParseDbTypeAndPrecision(dtNode.InnerText, column);
                    column.DbType = DbTypeManager.GetDbType(databaseType, column.DataType);
                }

                if (lngNode != null)
                {
                    column.Length = lngNode.InnerText.To <long>();
                }

                if (mandNode == null)
                {
                    column.IsNullable = true;
                }

                if (idenNode != null)
                {
                    column.AutoIncrement = idenNode.InnerText == "1";
                }

                if (defaultNode != null)
                {
                    column.DefaultValue = defaultNode.InnerText;
                }

                if (!string.IsNullOrEmpty(pkRefId))
                {
                    var pkNode = node.SelectSingleNode("c:Keys/o:Key[@Id='" + pkRefId + "']/c:Key.Columns/o:Column[@Ref='" + id + "']", nms);
                    if (pkNode != null)
                    {
                        column.IsPrimaryKey = true;
                    }
                }

                InitializerUnity.Initialize(column);
                newtable.Columns.Add(column);
            }

            InitializerUnity.Initialize(newtable);
            return(newtable);
        }