示例#1
0
        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);
        }
示例#2
0
        private static int Run(PatchDatabaseOptions opts)
        {
            opts.PopulateConnectionStringsFromYamlIfMissing();

            var repo = opts.GetRepositoryLocator();

            if (!CheckRepo(repo))
            {
                return(REPO_ERROR);
            }

            var checker = new NLogICheckNotifier(true, false);

            var  start    = new Startup.Startup(GetEnvironmentInfo(), repo);
            bool badTimes = false;

            start.DatabaseFound += (s, e) => {
                var db = e.Repository.DiscoveredServer.GetCurrentDatabase();

                if (e.Status == Startup.Events.RDMPPlatformDatabaseStatus.RequiresPatching)
                {
                    var mds = new MasterDatabaseScriptExecutor(db);
                    mds.PatchDatabase(e.Patcher, checker, (p) => true, () => opts.BackupDatabase);
                }

                if (e.Status <= Startup.Events.RDMPPlatformDatabaseStatus.Broken)
                {
                    checker.OnCheckPerformed(new CheckEventArgs($"Database {db} had status {e.Status}", CheckResult.Fail));
                    badTimes = true;
                }
            };

            start.DoStartup(new IgnoreAllErrorsCheckNotifier());

            return(badTimes ? -1 :0);
        }
示例#3
0
        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);
        }