static int Main(string[] args) { var app = new CommandLineApplication(); app.HelpOption(); CommandOption <string> connectionStringArgument = app.Option <string>("-c|--connection=<CONNECTION_STRING>", "Required: A connectionstring for the database to seed", CommandOptionType.SingleValue); CommandOption <string> ucommerceConnectionStringArgument = app.Option <string>("-u|--ucommerce-connection=<CONNECTION_STRING>", "The connectionstring used by Ucommerce when different from the CMS database", CommandOptionType.SingleOrNoValue); CommandOption <DbSizeOption> sizeArgument = app.Option <DbSizeOption>("-s|--size=<SIZE>", "The size of the database, either 'huge', 'large' or 'medium'. Default is 'huge'.", CommandOptionType.SingleOrNoValue); CommandOption <bool> verboseArgument = app.Option <bool>("-v|--verbose", "Verbose output", CommandOptionType.NoValue); CommandOption <bool> noCmsArgument = app.Option <bool>("-n|--no-cms", "Exclude CMS specific tables (Umbraco)", CommandOptionType.NoValue); CommandOption <string> jsonFilePath = app.Option <string>("-i|--input-json-file", "Define database dimensions in a json file. See the example file 'example-db-size.json'.", CommandOptionType.SingleOrNoValue); app.OnExecute(() => { var cmsConnectionString = connectionStringArgument.Value(); var ucommerceConnectionString = ucommerceConnectionStringArgument.Value(); if (string.IsNullOrWhiteSpace(cmsConnectionString)) { app.ShowHelp(); return(1); } if (string.IsNullOrEmpty(ucommerceConnectionString)) { ucommerceConnectionString = cmsConnectionString; } DbSizeOption dbSize = sizeArgument.HasValue() ? sizeArgument.ParsedValue : DbSizeOption.Huge; return(new Seeder(cmsConnectionString, ucommerceConnectionString, dbSize, verboseArgument.HasValue(), noCmsArgument.HasValue(), jsonFilePath.Value()).Run()); }); return(app.Execute(args)); }
public Seeder(string cmsConnectionString, string ucommerceConnectionString, DbSizeOption dbSize, bool verbose, bool excludeCmsTables, string useJsonDbSizePath) { _cmsConnectionString = cmsConnectionString; _ucommerceConnectionString = ucommerceConnectionString; _verbose = verbose; _excludeCmsTables = excludeCmsTables; if (useJsonDbSizePath != null) { if (!File.Exists(useJsonDbSizePath)) { throw new ArgumentException($"Can not find file {useJsonDbSizePath}"); } Console.WriteLine($"Using {useJsonDbSizePath} for database size."); _dbSize = JsonConvert.DeserializeObject <DatabaseSize>(File.ReadAllText(useJsonDbSizePath)); } else { switch (dbSize) { case DbSizeOption.Huge: _dbSize = DatabaseSize.Huge; break; case DbSizeOption.Large: _dbSize = DatabaseSize.Large; break; case DbSizeOption.Medium: _dbSize = DatabaseSize.Medium; break; case DbSizeOption.TinyForTesting: _dbSize = DatabaseSize.TinyForTesting; break; case DbSizeOption.Dev: _dbSize = DatabaseSize.Developer; break; default: throw new ArgumentException($"Unknown DbSizeOption value {dbSize}"); } } }