/// <summary> /// Initializes a new instance of the <see cref="TableDefinition" /> class. /// </summary> /// <param name="owner">The schema that owns the table.</param> /// <param name="datasource"></param> /// <param name="name">The name of the table.</param> /// <param name="configuration"></param> public TableDefinition(string datasource, string name, string owner, ActiveMapCodeGenConfigurationSection configuration) { Argument.Assert.IsNotNull(name, nameof(name)); Argument.Assert.IsNotNull(owner, nameof(owner)); Datasource = datasource; Name = name; Owner = owner; this.configuration = configuration; SetTableProperties(); }
/// <summary> /// Initializes a new instance of the <see cref="TableDefinition"/> class. /// </summary> /// <param name="owner">The schema that owns the table.</param> /// <param name="datasource"></param> /// <param name="name">The name of the table.</param> /// <param name="configuration"></param> public TableDefinition(string datasource, string name, string owner, ActiveMapCodeGenConfigurationSection configuration) { Argument.Assert.IsNotNull(name, Argument.Names.name); Argument.Assert.IsNotNull(owner, Argument.Names.schema); this.datasource = datasource; this.name = name; this.owner = owner; this.configuration = configuration; SetTableProperties(); }
public CodeGenSession(string configurationFilePath) { if (configurationFilePath == null) { Configuration = new ActiveMapCodeGenConfigurationSection(); return; } Argument.Assert.IsNotNullOrEmpty(configurationFilePath, "configurationFilePath"); ExeConfigurationFileMap map = new ExeConfigurationFileMap(); map.ExeConfigFilename = GetConfigFilePath(configurationFilePath); System.Configuration.Configuration config = ConfigurationManager.OpenMappedExeConfiguration(map, ConfigurationUserLevel.None); Configuration = (ActiveMapCodeGenConfigurationSection)config.GetSection("activeMapCodeGenConfiguration"); if (Configuration == null) { throw new ConfigurationErrorsException("Could not load the configuration section 'activeMapCodeGenConfiguration'."); } }
private TableDefinitionCollection FetchTableList(string connectionString, ActiveMapCodeGenConfigurationSection configuration) { TableDefinitionCollection tableList = new TableDefinitionCollection(configuration); string sql = SqlScript.SqlTableColumns + SqlSeperator + Environment.NewLine + SqlScript.SqlConstraints + SqlSeperator + Environment.NewLine + SqlScript.SqlForeignKeys; using (SqlConnection connection = (SqlConnection)FetchConnection(connectionString)) { connection.Open(); using (SqlCommand command = new SqlCommand(sql, connection)) using (IDataReader reader = command.ExecuteReader()) { PopulateTableInfo(tableList, reader, configuration); reader.NextResult(); UpdateColumnConstraints(tableList, reader); reader.NextResult(); UpdateForeignKeyColumns(tableList, reader); return(tableList); } } }
// TODO: Standardize the order of data source, schema, table, column parameters to methods. /// <summary> /// Initializes a new instance of the <see cref="TableDefinition"/> class. /// </summary> /// <param name="datasource"></param> /// <param name="name">The name of the table.</param> /// <param name="configuration"></param> public TableDefinition(string datasource, string name, ActiveMapCodeGenConfigurationSection configuration) : this(datasource, name, DefaultOwner, configuration) { }
protected SchemaDefinitionCollection(ActiveMapCodeGenConfigurationSection configuration) { this.configuration = configuration; }
public ProcedureParameterDefinition(ActiveMapCodeGenConfigurationSection configuration) { this.configuration = configuration; }
public TableColumnDefinition(ActiveMapCodeGenConfigurationSection configuration) { this.configuration = configuration; }
public DatabaseSchema FetchDatabaseSchema(string connectionString, ActiveMapCodeGenConfigurationSection configuration) { return(new DatabaseSchema(FetchTableList(connectionString, configuration), FetchProcedureList(connectionString, configuration))); }
private static void PopulateProcedureInfo(IWriteEnumerable <ProcedureDefinition> procedureList, IDataReader reader, ActiveMapCodeGenConfigurationSection configuration) { ProcedureDefinition procedureDefinition = null; string lastOwner = null; string lastTable = null; while (reader.Read()) { string newOwner = reader.GetString(0); string newProcedure = reader.GetString(1); if (procedureDefinition == null || (newOwner != lastOwner || newProcedure != lastTable)) { procedureDefinition = new ProcedureDefinition(newProcedure, newOwner); procedureList.Add(procedureDefinition); } ProcedureParameterDefinition parameterDefinition = new ProcedureParameterDefinition(configuration) { Name = reader.GetString(2), Position = Convert.ToInt32(reader[3]), ParameterType = GetParameterType(reader.GetString(4)), IsResult = reader.GetString(5) == SchemaValue.Yes, MaxLength = reader.IsDBNull(7) ? 0 : reader.GetInt32(7) }; parameterDefinition.DbType = GetDbType(reader.GetString(6), parameterDefinition.MaxLength); procedureDefinition.Parameters.Add(parameterDefinition); lastOwner = procedureDefinition.Owner; lastTable = procedureDefinition.Name; } }
private static void PopulateTableInfo(IWriteEnumerable <TableDefinition> tableList, IDataReader reader, ActiveMapCodeGenConfigurationSection configuration) { TableDefinition tableInfo = null; string lastOwner = null; string lastTable = null; while (reader.Read()) { string newOwner = reader.GetString(0); string newTable = reader.GetString(1); if (newTable.StartsWith("sys", StringComparison.OrdinalIgnoreCase) || newTable.StartsWith("dt", StringComparison.OrdinalIgnoreCase)) { continue; } if (tableInfo == null || (newOwner != lastOwner || newTable != lastTable)) { // TODO: Implement data source name usage // TODO: Separate Views from Tables tableInfo = new TableDefinition(null, newTable, newOwner, configuration) { IsReadOnly = reader.GetString(2) != SchemaValue.BaseTable }; tableList.Add(tableInfo); } TableColumnDefinition columnInfo = new TableColumnDefinition(configuration) { Name = reader.GetString(3), IsNullable = reader.GetString(4) == SchemaValue.Yes, MaxLength = reader.IsDBNull(6) ? 0 : reader.GetInt32(6), IsComputed = reader.GetInt32(7) == 1, IsIdentity = reader.GetInt32(8) == 1, Ordinal = Convert.ToInt32(reader[9]), Description = Convert.ToString(reader[10]), DefaultValue = Convert.ToString(reader[11]) }; columnInfo.DbType = GetDbType(reader.GetString(5), columnInfo.MaxLength); tableInfo.Columns.Add(columnInfo); lastOwner = tableInfo.Owner; lastTable = tableInfo.Name; } }
private ProcedureDefinitionCollection FetchProcedureList(string connectionString, ActiveMapCodeGenConfigurationSection configuration) { ProcedureDefinitionCollection procedureDefinitionCollection = new ProcedureDefinitionCollection(configuration); string sql = SqlScript.SqlSPParameters; using (SqlConnection connection = (SqlConnection)FetchConnection(connectionString)) { connection.Open(); using (SqlCommand command = new SqlCommand(sql, connection)) using (IDataReader reader = command.ExecuteReader()) { PopulateProcedureInfo(procedureDefinitionCollection, reader, configuration); return(procedureDefinitionCollection); } } }
public ProcedureDefinitionCollection(ActiveMapCodeGenConfigurationSection configuration) : base(configuration) { }
public TableColumnDefinitionCollection(TableDefinition parentTable, ActiveMapCodeGenConfigurationSection configuration) { ParentTable = parentTable; this.configuration = configuration; }
public CodeGenSession() { configuration = (ActiveMapCodeGenConfigurationSection)ConfigurationManager.GetSection("activeMapCodeGenConfiguration"); }