/// <summary> /// Entry point of console app. /// </summary> static int Main(string[] args) { int exitCode = 0; bool loadedFiles = false; try { StartLogging(); if (ParseArguments(args)) { if (_DeleteFlag) { Database.SetInitializer<EntityDataModel>(new DropCreateDatabaseInitializer()); } else if (_InitFlag) { Database.SetInitializer<EntityDataModel>(new CreateDatabaseInitializer()); } else if (_UpgradeFlag) { var configuration = new Configuration(); var migrator = new DbMigrator(configuration); migrator.Update(); Logger.InfoFormat("Upgraded database."); Database.SetInitializer<EntityDataModel>(null); } else { Database.SetInitializer<EntityDataModel>(null); } DbContextWrapper dbContext = new DbContextWrapper(); if (!String.IsNullOrEmpty(_IlcdDirName)) { if (Directory.Exists(_IlcdDirName)) { IlcdImporter ilcdImporter = new IlcdImporter(); ilcdImporter.LoadAll(_IlcdDirName, _IlcdSourceName, dbContext, File.Exists(_PrivateFileName)); Logger.InfoFormat("Loaded ILCD archive from {0}.", _IlcdDirName); loadedFiles = true; } else { Logger.ErrorFormat("ILCD folder, {0}, does not exist.", _IlcdDirName); exitCode = 1; } } if (_CsvFlag) { if (Directory.Exists(_DataRoot)) { CsvImporter.LoadAll(_DataRoot, dbContext); Logger.InfoFormat("Loaded CSV folders under {0}.", _DataRoot); loadedFiles = true; } else { Logger.ErrorFormat("Data Root folder, {0}, does not exist.", _DataRoot); exitCode = 1; } } if (loadedFiles) { Program.Logger.InfoFormat("Update LCIA Flow reference..."); dbContext.UpdateLciaFlowID(); } } } catch (Exception e) { Logger.FatalFormat("Unexpected Exception: {0}", e.Message); for (var ie = e.InnerException; ie != null; ie = ie.InnerException) { Program.Logger.FatalFormat("Inner exception: {0}", ie.Message); } Console.Write(e.ToString()); exitCode = 1; } finally { StopLogging(); } return exitCode; }