public IRunner CreateRunner(RDMPCommandLineOptions command) { if (command.Command == CommandLineActivity.none) { throw new Exception("No command has been set on '" + command.GetType().Name + "'"); } var dleOpts = command as DleOptions; var dqeOpts = command as DqeOptions; var cacheOpts = command as CacheOptions; var listOpts = command as ListOptions; var extractionOpts = command as ExtractionOptions; var releaseOpts = command as ReleaseOptions; var cohortOpts = command as CohortCreationOptions; var packOpts = command as PackOptions; if (dleOpts != null) { return(new DleRunner(dleOpts)); } if (dqeOpts != null) { return(new DqeRunner(dqeOpts)); } if (cacheOpts != null) { return(new CacheRunner(cacheOpts)); } if (listOpts != null) { return(new ListRunner(listOpts)); } if (extractionOpts != null) { return(new ExtractionRunner(extractionOpts)); } if (releaseOpts != null) { return(new ReleaseRunner(releaseOpts)); } if (cohortOpts != null) { return(new CohortCreationRunner(cohortOpts)); } if (packOpts != null) { return(new PackPluginRunner(packOpts)); } throw new Exception("RDMPCommandLineOptions Type '" + command.GetType() + "'"); }
private static void PopulateConnectionStringsFromYamlIfMissing(RDMPCommandLineOptions opts) { var logger = LogManager.GetCurrentClassLogger(); if (!opts.NoConnectionStringsSpecified()) { logger.Info("Connection string options have been specified on command line, yaml config values will be ignored"); return; } string assemblyFolder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); var yaml = Path.Combine(assemblyFolder, "Databases.yaml"); if (File.Exists(yaml)) { try { // Setup the input using (var input = new StreamReader(yaml)) { // Load the stream var yamlStream = new YamlStream(); yamlStream.Load(input); // Examine the stream var mapping = (YamlMappingNode)yamlStream.Documents[0].RootNode; foreach (var entry in mapping.Children) { string key = ((YamlScalarNode)entry.Key).Value; string value = ((YamlScalarNode)entry.Value).Value; try { var prop = typeof(RDMPCommandLineOptions).GetProperty(key); prop.SetValue(opts, value); logger.Info("Setting yaml config value for " + key); } catch (Exception) { logger.Error("Could not set property called " + key); } } } } catch (Exception ex) { logger.Error(ex, "Failed to read yaml file '" + yaml + "'"); } } }
private static int Run(RDMPCommandLineOptions opts) { ImplementationManager.Load <MicrosoftSQLImplementation>(); ImplementationManager.Load <MySqlImplementation>(); ImplementationManager.Load <OracleImplementation>(); ImplementationManager.Load <PostgreSqlImplementation>(); PopulateConnectionStringsFromYamlIfMissing(opts); var listener = new NLogIDataLoadEventListener(false); var checker = new NLogICheckNotifier(true, false); var factory = new RunnerFactory(); opts.DoStartup(GetEnvironmentInfo(), opts.LogStartup ? (ICheckNotifier)checker: new IgnoreAllErrorsCheckNotifier()); //if user wants to run checking chances are they don't want checks to fail becasue of errors logged during startup (MEF shows lots of errors!) if (opts.LogStartup && opts.Command == CommandLineActivity.check) { checker.Worst = LogLevel.Info; } var runner = opts is ConsoleGuiOptions g ? new ConsoleGuiRunner(g): factory.CreateRunner(opts); int runExitCode = runner.Run(opts.GetRepositoryLocator(), listener, checker, new GracefulCancellationToken()); if (opts.Command == CommandLineActivity.check) { checker.OnCheckPerformed(checker.Worst <= LogLevel.Warn ? new CheckEventArgs("Checks Passed", CheckResult.Success) : new CheckEventArgs("Checks Failed", CheckResult.Fail)); } if (runExitCode != 0) { return(runExitCode); } //or if either listener reports error if (listener.Worst >= LogLevel.Error || checker.Worst >= LogLevel.Error) { return(-1); } if (opts.FailOnWarnings && (listener.Worst >= LogLevel.Warn || checker.Worst >= LogLevel.Warn)) { return(1); } return(0); }
public IRunner CreateRunner(RDMPCommandLineOptions command) { if (command.Command == CommandLineActivity.none) { throw new Exception("No command has been set on '" + command.GetType().Name + "'"); } if (command is DleOptions dleOpts) { return(new DleRunner(dleOpts)); } if (command is DqeOptions dqeOpts) { return(new DqeRunner(dqeOpts)); } if (command is CacheOptions cacheOpts) { return(new CacheRunner(cacheOpts)); } if (command is ExtractionOptions extractionOpts) { return(new ExtractionRunner(extractionOpts)); } if (command is ReleaseOptions releaseOpts) { return(new ReleaseRunner(releaseOpts)); } if (command is CohortCreationOptions cohortOpts) { return(new CohortCreationRunner(cohortOpts)); } if (command is PackOptions packOpts) { return(new PackPluginRunner(packOpts)); } if (command is ExecuteCommandOptions executeOpts) { return(new ExecuteCommandRunner(executeOpts)); } throw new Exception("RDMPCommandLineOptions Type '" + command.GetType() + "'"); }
private void PopulateConnectionStringOptions(RDMPCommandLineOptions options) { if (BasicActivator == null) { return; } if (string.IsNullOrWhiteSpace(options.CatalogueConnectionString)) { options.CatalogueConnectionString = _cataTableRepo.ConnectionStringBuilder.ConnectionString; } if (string.IsNullOrWhiteSpace(options.DataExportConnectionString)) { options.DataExportConnectionString = _dataExportTableRepo.ConnectionStringBuilder.ConnectionString; } }
private static int Run(RDMPCommandLineOptions opts) { opts.PopulateConnectionStringsFromYamlIfMissing(); // where RDMP objects are stored var repositoryLocator = opts.GetRepositoryLocator(); if (!CheckRepo(repositoryLocator)) { return(REPO_ERROR); } var listener = new NLogIDataLoadEventListener(false); var checker = new NLogICheckNotifier(true, false); var factory = new RunnerFactory(); opts.DoStartup(GetEnvironmentInfo(), opts.LogStartup ? (ICheckNotifier)checker: new IgnoreAllErrorsCheckNotifier()); //if user wants to run checking chances are they don't want checks to fail becasue of errors logged during startup (MEF shows lots of errors!) if (opts.LogStartup && opts.Command == CommandLineActivity.check) { checker.Worst = LogLevel.Info; } var runner = opts is ConsoleGuiOptions g ? new ConsoleGuiRunner(g): factory.CreateRunner(new ThrowImmediatelyActivator(repositoryLocator, checker), opts); // Let's not worry about global errors during the CreateRunner process // These are mainly UI/GUI and unrelated to the actual process to run if (checker.Worst > LogLevel.Warn) { checker.Worst = LogLevel.Warn; } int runExitCode = runner.Run(repositoryLocator, listener, checker, new GracefulCancellationToken()); if (opts.Command == CommandLineActivity.check) { checker.OnCheckPerformed(checker.Worst <= LogLevel.Warn ? new CheckEventArgs("Checks Passed", CheckResult.Success) : new CheckEventArgs("Checks Failed", CheckResult.Fail)); } if (runExitCode != 0) { return(runExitCode); } //or if either listener reports error if (listener.Worst >= LogLevel.Error || checker.Worst >= LogLevel.Error) { return(-1); } if (opts.FailOnWarnings && (listener.Worst >= LogLevel.Warn || checker.Worst >= LogLevel.Warn)) { return(1); } return(0); }