Пример #1
0
        private IAnnouncer InitInnerAnnouncer()
        {
            var sw            = new StreamWriter(GetOutputFileName());
            var fileAnnouncer = _executeAgainstMsSql ? new TextWriterWithGoAnnouncer(sw) : new TextWriterAnnouncer(sw);

            fileAnnouncer.ShowElapsedTime = false;
            fileAnnouncer.ShowSql         = true;

            var announcer = new CompositeAnnouncer(_consoleAnnouncer, fileAnnouncer);

            _streamWriter = sw;
            return(announcer);
        }
 private void ExecuteMigrations(string outputTo)
 {
     using (var sw = new StreamWriter(outputTo))
     {
         var fileAnnouncer = ExecutingAgainstMsSql ?
                             new TextWriterWithGoAnnouncer(sw) :
                             new TextWriterAnnouncer(sw);
         fileAnnouncer.ShowElapsedTime    = false;
         fileAnnouncer.ShowSql            = true;
         consoleAnnouncer.ShowElapsedTime = verbose;
         consoleAnnouncer.ShowSql         = verbose;
         var announcer = new CompositeAnnouncer(consoleAnnouncer, fileAnnouncer);
         ExecuteMigrations(announcer);
     }
 }
Пример #3
0
        private void ExecuteMigrations(string outputTo)
        {
            using (var sw = new StreamWriter(outputTo))
            {
                var fileAnnouncer = new TextWriterAnnouncer(sw)
                {
                    ShowElapsedTime = false,
                    ShowSql         = true
                };
                consoleAnnouncer.ShowElapsedTime = Verbose;
                consoleAnnouncer.ShowSql         = Verbose;

                var announcer = new CompositeAnnouncer(consoleAnnouncer, fileAnnouncer);

                ExecuteMigrations(announcer);
            }
        }
Пример #4
0
        protected TaskExecutor MakeTask(string task, string migrationsNamespace, Action <RunnerContext> configureContext = null)
        {
            var consoleAnnouncer = new TextWriterAnnouncer(TestContext.Out);
            var debugAnnouncer   = new TextWriterAnnouncer(msg => Debug.WriteLine(msg));
            var announcer        = new CompositeAnnouncer(consoleAnnouncer, debugAnnouncer);
            var runnerContext    = new RunnerContext(announcer)
            {
                Database   = "Firebird",
                Connection = ConnectionString,
                Targets    = new[] { Assembly.GetExecutingAssembly().Location },
                Namespace  = migrationsNamespace,
                Task       = task
            };

            configureContext?.Invoke(runnerContext);
            return(new TaskExecutor(runnerContext));
        }
        private TaskExecutor MakeTask(string task, string migrationsNamespace, Action<RunnerContext> configureContext = null)
        {
            var consoleAnnouncer = new TextWriterAnnouncer(TestContext.Out)
            {
                ShowSql = true
            };
            var debugAnnouncer = new TextWriterAnnouncer(msg => Debug.WriteLine(msg));
            var announcer = new CompositeAnnouncer(consoleAnnouncer, debugAnnouncer);
            var runnerContext = new RunnerContext(announcer)
            {
                Database = "SqlServer2016",
                Connection = IntegrationTestOptions.SqlServer2016.ConnectionString,
                Targets = new[] { Assembly.GetExecutingAssembly().Location },
                Namespace = migrationsNamespace,
                Task = task
            };

            configureContext?.Invoke(runnerContext);
            return new TaskExecutor(runnerContext);
        }
Пример #6
0
        public override bool Execute()
        {
            if (string.IsNullOrEmpty(databaseType))
            {
                Log.LogError("You must specific a database type. i.e. mysql or sqlserver");
                return(false);
            }

            if (string.IsNullOrEmpty(migrationAssembly))
            {
                Log.LogError("You must specific a migration assembly");
                return(false);
            }

            IAnnouncer announcer = new ConsoleAnnouncer
            {
                ShowElapsedTime = Verbose,
                ShowSql         = Verbose
            };

            StreamWriter outputWriter = null;

            if (Output)
            {
                if (string.IsNullOrEmpty(OutputFilename))
                {
                    OutputFilename = Path.GetFileName(Target) + ".sql";
                }

                outputWriter = new StreamWriter(OutputFilename);
                var fileAnnouncer = new TextWriterAnnouncer(outputWriter)
                {
                    ShowElapsedTime = false,
                    ShowSql         = true
                };

                announcer = new CompositeAnnouncer(announcer, fileAnnouncer);
            }

            Log.LogMessage(MessageImportance.Low, "Creating Context");

            var runnerContext = new RunnerContext(announcer)
            {
                ApplicationContext         = ApplicationContext,
                Database                   = databaseType,
                Connection                 = Connection,
                ConnectionStringConfigPath = ConnectionStringConfigPath,
                Target           = Target,
                PreviewOnly      = PreviewOnly,
                Namespace        = Namespace,
                Task             = Task,
                Version          = Version,
                Steps            = Steps,
                WorkingDirectory = WorkingDirectory,
                Profile          = Profile,
                Tags             = Tags.ToTags(),
                Timeout          = Timeout
            };

            Log.LogMessage(MessageImportance.Low, "Executing Migration Runner");
            try
            {
                new TaskExecutor(runnerContext).Execute();
            }
            catch (ProcessorFactoryNotFoundException ex)
            {
                Log.LogError("While executing migrations the following error was encountered: {0}", ex.Message);
                return(false);
            }
            catch (Exception ex)
            {
                Log.LogError("While executing migrations the following error was encountered: {0}, {1}", ex.Message, ex.StackTrace);
                return(false);
            }
            finally
            {
                if (outputWriter != null)
                {
                    outputWriter.Dispose();
                }
            }

            return(true);
        }
Пример #7
0
        protected override void ExecuteTask()
        {
            IAnnouncer announcer = new ConsoleAnnouncer
            {
                ShowElapsedTime = Verbose,
                ShowSql         = Verbose
            };

            StreamWriter outputWriter = null;

            if (Output)
            {
                if (string.IsNullOrEmpty(OutputFilename))
                {
                    OutputFilename = Path.GetFileName(Target) + ".sql";
                }

                outputWriter = new StreamWriter(OutputFilename);
                var fileAnnouncer = new TextWriterAnnouncer(outputWriter)
                {
                    ShowElapsedTime = false,
                    ShowSql         = true
                };

                announcer = new CompositeAnnouncer(announcer, fileAnnouncer);
            }

            var runnerContext = new RunnerContext(announcer)
            {
                ApplicationContext = ApplicationContext,
                Database           = Database,
                Connection         = Connection,
                Targets            = new string[] { Target },
                PreviewOnly        = Preview,
                Namespace          = Namespace,
                NestedNamespaces   = NestedNamespaces,
                Task                  = Task,
                Version               = Version,
                Steps                 = Steps,
                WorkingDirectory      = WorkingDirectory,
                Profile               = Profile,
                Tags                  = Tags.ToTags(),
                Timeout               = Timeout,
                TransactionPerSession = TransactionPerSession
            };

            try
            {
                new TaskExecutor(runnerContext).Execute();
            }
            catch (ProcessorFactoryNotFoundException ex)
            {
                announcer.Error("While executing migrations the following error was encountered: {0}", ex.Message);
                throw;
            }
            catch (Exception e)
            {
                announcer.Error("While executing migrations the following error was encountered: {0}, {1}", e.Message, e.StackTrace);
                throw;
            }
            finally
            {
                if (outputWriter != null)
                {
                    outputWriter.Dispose();
                }
            }
        }