Beispiel #1
0
        public void MigrateUp(bool useAutomaticTransactionManagement)
        {
            try
            {
                foreach (var version in MigrationLoader.Migrations.Keys)
                {
                    if (useAutomaticTransactionManagement)
                    {
                        Processor.BeginTransaction();
                    }
                    ApplyMigrationUp(version);
                    if (useAutomaticTransactionManagement)
                    {
                        Processor.CommitTransaction();
                    }
                }

                if (useAutomaticTransactionManagement)
                {
                    Processor.BeginTransaction();
                }
                ApplyProfiles();
                if (useAutomaticTransactionManagement)
                {
                    Processor.CommitTransaction();
                }

                if (useAutomaticTransactionManagement)
                {
                    Processor.BeginTransaction();
                }
                VersionLoader.LoadVersionInfo();
                if (useAutomaticTransactionManagement)
                {
                    Processor.CommitTransaction();
                }
            }
            catch (Exception err)
            {
                _announcer.Error(err.ToString());
                if (useAutomaticTransactionManagement)
                {
                    Processor.RollbackTransaction();
                }
                throw;
            }
        }
Beispiel #2
0
        /// <summary>
        /// Validates each migration expression that has implemented the ICanBeValidated interface.
        /// It throws an InvalidMigrationException exception if validation fails.
        /// </summary>
        /// <param name="migration">The current migration being run</param>
        /// <param name="expressions">All the expressions contained in the up or down action</param>
        protected void ApplyConventionsToAndValidateExpressions(IMigration migration, IEnumerable <IMigrationExpression> expressions)
        {
            var invalidExpressions = new Dictionary <string, string>();

            foreach (var expression in expressions)
            {
                expression.ApplyConventions(Conventions);

                var errors = new Collection <string>();
                expression.CollectValidationErrors(errors);

                if (errors.Count > 0)
                {
                    invalidExpressions.Add(expression.GetType().Name, string.Join(" ", errors.ToArray()));
                }
            }

            if (invalidExpressions.Count > 0)
            {
                var errorMessage = DictToString(invalidExpressions, "{0}: {1}");
                _announcer.Error("The migration {0} contained the following Validation Error(s): {1}", migration.GetType().Name, errorMessage);
                throw new InvalidMigrationException(migration, errorMessage);
            }
        }
        /// <summary>
        /// execute each migration expression in the expression collection
        /// </summary>
        /// <param name="expressions"></param>
        protected void ExecuteExpressions(ICollection <IMigrationExpression> expressions)
        {
            long insertTicks = 0;
            int  insertCount = 0;

            foreach (IMigrationExpression expression in expressions)
            {
                try
                {
                    expression.ApplyConventions(Conventions);
                    if (expression is InsertDataExpression)
                    {
                        insertTicks += Time(() => expression.ExecuteWith(Processor));
                        insertCount++;
                    }
                    else
                    {
                        AnnounceTime(expression.ToString(), () => expression.ExecuteWith(Processor));
                    }
                }
                catch (Exception er)
                {
                    _announcer.Error(er.Message);

                    //catch the error and move onto the next expression
                    if (SilentlyFail)
                    {
                        CaughtExceptions.Add(er);
                        continue;
                    }
                    throw;
                }
            }

            if (insertCount > 0)
            {
                var avg = new TimeSpan(insertTicks / insertCount);
                var msg = string.Format("-> {0} Insert operations completed in {1} taking an average of {2}", insertCount, new TimeSpan(insertTicks), avg);
                _announcer.Say(msg);
            }
        }
Beispiel #4
0
        /// <summary>
        /// Validates each migration expression that has implemented the ICanBeValidated interface.
        /// It throws an InvalidMigrationException exception if validation fails.
        /// </summary>
        /// <param name="migration">The current migration being run</param>
        /// <param name="expressions">All the expressions contained in the up or down action</param>
        public void ApplyConventionsToAndValidateExpressions(IMigration migration, IEnumerable <IMigrationExpression> expressions)
        {
            var errorMessageBuilder = new StringBuilder();

            foreach (var expression in expressions.Apply(_conventions))
            {
                var errors = new Collection <string>();
                expression.CollectValidationErrors(errors);

                if (errors.Count > 0)
                {
                    AppendError(errorMessageBuilder, expression.GetType().Name, string.Join(" ", errors.ToArray()));
                }
            }

            if (errorMessageBuilder.Length > 0)
            {
                var errorMessage = errorMessageBuilder.ToString();
                _announcer.Error("The migration {0} contained the following Validation Error(s): {1}", migration.GetType().Name, errorMessage);
                throw new InvalidMigrationException(migration, errorMessage);
            }
        }
 public static void Error(this IAnnouncer announcer, string message, params object[] args)
 {
     announcer.Error(string.Format(message, args));
 }
Beispiel #6
0
        public void Error_Should_Error_string_formatted_message()
        {
            Mock.Get(announcer).Setup(a => a.Error("Hello Error"));

            announcer.Error("Hello {0}", "Error");
        }
Beispiel #7
0
 /// <inheritdoc />
 protected override void WriteError(string message)
 {
     _announcer.Error(message);
 }
Beispiel #8
0
        public void ErrorShouldErrorStringFormattedMessage()
        {
            Mock.Get(_announcer).Setup(a => a.Error("Hello Error"));

            _announcer.Error("Hello {0}", "Error");
        }