示例#1
0
 public void ManageSchema(SchemaDefinition schema)
 {
     CurrentSchema = schema;
 }
示例#2
0
        public SchemaDefinition Extract(SchemaManager schemaManager)
        {
            SchemaDefinition result = new SchemaDefinition {
                Name = GetSchemaName()
            };

            schemaManager.CurrentSchema = result;

            // GetTableNames
            GetTableNames().Each(tableName =>
            {
                FireEvent(ProcessingTable, new SchemaExtractorEventArgs {
                    Table = tableName
                });

                FireEvent(ClassNameFormatting, new SchemaExtractorEventArgs {
                    Table = tableName
                });
                string className = GetClassName(tableName);
                NameMap.Set(new TableNameToClassName {
                    TableName = tableName, ClassName = className
                });
                FireEvent(ClassNameFormatted, new SchemaExtractorEventArgs {
                    Table = tableName
                });

                schemaManager.AddTable(tableName, className);//  add each table
                // GetColumnNames
                GetColumnNames(tableName).Each(columnName =>
                {
                    FireEvent(ProcessingColumn, new SchemaExtractorEventArgs {
                        Column = columnName
                    });
                    //  add each column;
                    schemaManager.AddColumn(tableName, CreateColumn(tableName, columnName));
                    FireEvent(ProcessingColumnComplete, new SchemaExtractorEventArgs {
                        Column = columnName
                    });
                });

                string keyColumnName = GetKeyColumnName(tableName);
                if (!string.IsNullOrEmpty(keyColumnName))
                {
                    schemaManager.SetKeyColumn(tableName, keyColumnName);
                }

                FireEvent(ProcessingTableComplete, new SchemaExtractorEventArgs {
                    Table = tableName
                });
            });

            // GetForeignKeyColumns
            GetForeignKeyColumns().Each(fk =>
            {
                FireEvent(ProcessingForeignKey, new SchemaExtractorEventArgs {
                    ForeignKeyColumn = fk
                });
                //  set each foreignkey
                schemaManager.SetForeignKey(fk.ReferencedTable, fk.TableName, fk.Name, GetKeyColumnName(fk.ReferencedTable), NameFormatter);
                FireEvent(ProcessingForeignComplete, new SchemaExtractorEventArgs {
                    ForeignKeyColumn = fk
                });
            });

            NameMap.Save(Path.Combine(RuntimeSettings.AppDataFolder, "{0}_NameMap.json"._Format(schemaManager.CurrentSchema.Name)));
            SetClassNamesOnColumns(schemaManager);
            return(result);
        }
示例#3
0
 public SchemaManager(SchemaDefinition schema)
     : this()
 {
     this.ManageSchema(schema);
 }