private static void DoReverseEngineer(
CommandLineOptions options,
DashingSettings dashingSettings,
ReverseEngineerSettings reverseEngineerSettings,
ConnectionStringSettings connectionString)
{
// overwrite the path with the default if necessary
if (string.IsNullOrEmpty(options.Location))
{
options.Location = dashingSettings.DefaultSavePath;
}
// if it is still empty, ...
if (string.IsNullOrEmpty(options.Location) && options.ReverseEngineer)
{
throw new CatchyException("You must specify a location for generated files to be saved");
}
// require a generated namespace
if (string.IsNullOrEmpty(reverseEngineerSettings.GeneratedNamespace))
{
throw new CatchyException("You must specify a GeneratedNamespace in the Project ini file");
}
DatabaseSchema schema;
var engineer = new Engineer(reverseEngineerSettings.ExtraPluralizationWords);
var databaseReader = new DatabaseReader(connectionString.ConnectionString, connectionString.ProviderName);
schema = databaseReader.ReadAll();
var maps = engineer.ReverseEngineer(
schema,
new DialectFactory().Create(connectionString.ToSystem()),
reverseEngineerSettings.GetTablesToIgnore(),
consoleAnswerProvider,
true);
var reverseEngineer = new ModelGenerator();
var sources = reverseEngineer.GenerateFiles(maps, schema, reverseEngineerSettings.GeneratedNamespace, consoleAnswerProvider);
foreach (var source in sources)
{
File.WriteAllText(options.Location + "\\" + source.Key + ".cs", source.Value);
}
}