Example #1
0
 private static SchemaDefinition ExtractSchema(string connectionName, string filePath)
 {
     ISchemaExtractor extractor = Incubator.Default.Get<ISchemaExtractor>(new SQLiteSchemaExtractor(DataProvider.Current.GetSysDatabase(connectionName)));
     SchemaDefinition schema = extractor.Extract();
     schema.Save(filePath);
     return schema;
 }
Example #2
0
        private static SchemaDefinition ExtractSchema(string connectionName, string filePath)
        {
            ISchemaExtractor extractor = Incubator.Default.Get <ISchemaExtractor>(new MsSqlSmoSchemaExtractor(connectionName));
            SchemaDefinition schema    = extractor.Extract();

            schema.Save(filePath);
            return(schema);
        }
        /// <summary>
        /// Create a new Project
        /// </summary>
        private void CreateNewProject()
        {
            DriverDlg dlg = new DriverDlg();

            if (dlg.ShowDialog(this) == DialogResult.OK)
            {
                Driver driver = DriverFactory.GetDriver(dlg.Connection);

                this.CurrentProject.Database.Connection.DataSource     = driver.ConnectionInfo.Database;
                this.CurrentProject.Database.Connection.InitialCatalog = driver.ConnectionInfo.Database;
                this.CurrentProject.Database.Connection.UserID         = driver.ConnectionInfo.User;
                this.CurrentProject.Database.Connection.Password       = driver.ConnectionInfo.Password;
                this.CurrentProject.Caption = driver.ConnectionInfo.Database;
                this.CurrentProject.Name    = driver.ConnectionInfo.Database;

                ISchemaExtractor extractor = driver.CreateExtractor();//new MSSQL2000SchemaExtractor(driver, this.CurrentProject);
                foreach (KeyValuePair <string, ISchemaExtractor.EntityModel> table in extractor.GetAllTables())
                {
                    TableInfo tableModel = new TableInfo(this.CurrentProject.Database);
                    tableModel.Caption = table.Value.TableName.Replace("_", " ");
                    tableModel.Name    = table.Value.TableName;
                    tableModel.Schema  = table.Value.TableSchema;
                    this.CurrentProject.Database.Tables.Add(tableModel);
                }

                foreach (KeyValuePair <string, ISchemaExtractor.EntityModel> view in extractor.GetAllViews())
                {
                    ViewInfo tableModel = new ViewInfo(this.CurrentProject.Database);
                    tableModel.Caption = view.Value.TableName.Replace("_", " ");
                    tableModel.Name    = view.Value.TableName;
                    tableModel.Schema  = view.Value.TableSchema;
                    this.CurrentProject.Database.Views.Add(tableModel);
                }

                foreach (KeyValuePair <string, ISchemaExtractor.ColumnModel> col in extractor.GetColumns())
                {
                    EntityInfo entity = this.CurrentProject.Database.Tables.Find(e => e.Name == col.Value.TableName);
                    if (entity == null)
                    {
                        entity = this.CurrentProject.Database.Views.Find(e => e.Name == col.Value.TableName);
                    }

                    if (entity == null)
                    {
                        continue;
                    }

                    ColumnInfo column = new ColumnInfo(entity);
                    column.Caption      = col.Value.ColumnName.Replace("_", " ");
                    column.IsForeignKey = false;
                    column.IsIdentity   = col.Value.IsIdentity;
                    column.IsPrimaryKey = false;
                    column.IsRequire    = !col.Value.Nullable;
                    column.Length       = col.Value.Length;
                    column.Name         = col.Value.ColumnName;
                    column.Precision    = col.Value.Precision;
                    //column.Referenced = col.Value.r;
                    //column.Referencing;
                    column.Scale   = col.Value.Scale;
                    column.SqlType = col.Value.DataType;
                    entity.Columns.Add(column);
                }

                foreach (KeyValuePair <string, ISchemaExtractor.PrimaryKeyModel> col in extractor.GetAllPrimaryKeys())
                {
                    EntityInfo entity = this.CurrentProject.Database.Tables.Find(e => e.Name == col.Value.TableName);
                    if (entity == null)
                    {
                        continue;
                    }
                    ColumnInfo columnInfo = entity.Columns.Find(e => e.Name == col.Value.ColumnName);
                    if (columnInfo == null)
                    {
                        continue;
                    }
                    columnInfo.IsPrimaryKey = true;
                }

                foreach (KeyValuePair <string, ISchemaExtractor.ForgeinKeyModel> col in extractor.GetAllForeignKeys())
                {
                    EntityInfo entity = this.CurrentProject.Database.Tables.Find(e => e.Name == col.Value.TableName);
                    if (entity == null)
                    {
                        continue;
                    }
                    ColumnInfo columnInfo = entity.Columns.Find(e => e.Name == col.Value.ColumnName);
                    if (columnInfo == null)
                    {
                        continue;
                    }

                    ForeignKeyConstraint constraint = new ForeignKeyConstraint(columnInfo);
                    constraint.Name                 = col.Value.ConstraintName;
                    constraint.RelatedKey           = col.Value.ReferencingColumnName;
                    constraint.RelatedTableName     = col.Value.ReferecingTableName;
                    columnInfo.IsForeignKey         = true;
                    columnInfo.ForeignKeyConstraint = constraint;
                }



                DisplayProperties(null);

                BuildUITreeFromProject();
                BuildDatabaseTreeFromProject();

                SetControls(true);
            }
            dlg.Dispose();
        }