예제 #1
0
        public virtual void ApplyMigrationUp(IMigrationInfo migrationInfo, bool useTransaction)
        {
            if (migrationInfo == null)
            {
                throw new ArgumentNullException("migrationInfo");
            }

            if (!_alreadyOutputPreviewOnlyModeWarning && Processor.Options.PreviewOnly)
            {
                _announcer.Heading("PREVIEW-ONLY MODE");
                _alreadyOutputPreviewOnlyModeWarning = true;
            }

            if (!migrationInfo.IsAttributed() || !VersionLoader.VersionInfo.HasAppliedMigration(migrationInfo.Version))
            {
                var name = migrationInfo.GetName();
                _announcer.Heading(string.Format("{0} migrating", name));

                _stopWatch.Start();

                using (IMigrationScope scope = _migrationScopeHandler.CreateOrWrapMigrationScope(useTransaction))
                {
                    try
                    {
                        if (migrationInfo.IsAttributed() && migrationInfo.IsBreakingChange &&
                            !RunnerContext.PreviewOnly && !RunnerContext.AllowBreakingChange)
                        {
                            throw new InvalidOperationException(
                                      string.Format(
                                          "The migration {0} is identified as a breaking change, and will not be executed unless the necessary flag (allow-breaking-changes|abc) is passed to the runner.",
                                          migrationInfo.GetName()));
                        }

                        ExecuteMigration(migrationInfo.Migration, (m, c) => m.GetUpExpressions(c));

                        if (migrationInfo.IsAttributed())
                        {
                            VersionLoader.UpdateVersionInfo(migrationInfo.Version, migrationInfo.Description ?? migrationInfo.Migration.GetType().Name);
                        }

                        scope.Complete();
                    }
                    catch
                    {
                        if (useTransaction && scope.IsActive)
                        {
                            scope.Cancel();  // SQLAnywhere needs explicit call to rollback transaction
                        }
                        throw;
                    }

                    _stopWatch.Stop();

                    _announcer.Say(string.Format("{0} migrated", name));
                    _announcer.ElapsedTime(_stopWatch.ElapsedTime());
                }
            }
        }
        public virtual void ApplyMigrationUp(IMigrationInfo migrationInfo, bool useTransaction)
        {
            if (migrationInfo == null)
            {
                throw new ArgumentNullException("migrationInfo");
            }

            if (!_alreadyOutputPreviewOnlyModeWarning && Processor.Options.PreviewOnly)
            {
                _announcer.Heading("PREVIEW-ONLY MODE");
                _alreadyOutputPreviewOnlyModeWarning = true;
            }

            if (!migrationInfo.IsAttributed() || !VersionLoader.VersionInfo.HasAppliedMigration(migrationInfo.Version))
            {
                var name = migrationInfo.GetName();
                _announcer.Heading(string.Format("{0} migrating", name));

                _stopWatch.Start();

                using (IMigrationScope scope = _migrationScopeHandler.CreateOrWrapMigrationScope(useTransaction))
                {
                    try
                    {
                        ExecuteMigration(migrationInfo.Migration, (m, c) => m.GetUpExpressions(c));

                        if (migrationInfo.IsAttributed())
                        {
                            VersionLoader.UpdateVersionInfo(migrationInfo.Version, migrationInfo.Description ?? migrationInfo.Migration.GetType().Name);
                        }

                        scope.Complete();
                    }
                    catch
                    {
                        if (useTransaction && scope.IsActive)
                        {
                            scope.Cancel();  // SQLAnywhere needs explicit call to rollback transaction
                        }
                        throw;
                    }

                    _stopWatch.Stop();

                    _announcer.Say(string.Format("{0} migrated", name));
                    _announcer.ElapsedTime(_stopWatch.ElapsedTime());
                }
            }
        }
        public long Stop()
        {
            var elapsedMilliseconds = decoratedStopwatch.Stop();

            Console.WriteLine("스톱워치가 {0}초 후에 정지되었습니다.", TimeSpan.FromMilliseconds(elapsedMilliseconds).TotalSeconds);
            return(elapsedMilliseconds);
        }
예제 #4
0
        public void Something()
        {
            stopwatch.Start();
            decoratedComponent.Something();
            var elapsedMilliseconds = stopwatch.Stop();

            Console.WriteLine("메서드 실행 시간: {0}", elapsedMilliseconds / 1000);
        }
예제 #5
0
        private void LogMethodResult(IMethodInvocation input, object value, Exception exception)
        {
            _stopWatch.Stop();
            var builder = new TraceLogBuilder(input, value, exception, _stopWatch.Elapsed, _logger);
            var message = builder.Build();
            var level   = GetLevel(exception);

            builder.Logger.Write(level, exception, message, builder.PropertyValues);
        }
예제 #6
0
        public void Up(IMigration migration)
        {
            var name = GetMigrationName(migration);

            _announcer.Heading(string.Format("{0} migrating", name));

            CaughtExceptions = new List <Exception>();

            var context = new MigrationContext(Conventions, Processor, MigrationAssembly, ApplicationContext);

            migration.GetUpExpressions(context);

            _stopWatch.Start();
            ExecuteExpressions(context.Expressions);
            _stopWatch.Stop();

            _announcer.Say(string.Format("{0} migrated", name));
            _announcer.ElapsedTime(_stopWatch.ElapsedTime());
        }
예제 #7
0
        public void Up(IMigration migration)
        {
            var name = migration.GetType().Name;

            _announcer.Heading(name + ": migrating");

            CaughtExceptions = new List <Exception>();

            var context = new MigrationContext(Conventions, Processor, MigrationAssembly);

            migration.GetUpExpressions(context);

            _stopWatch.Start();
            ExecuteExpressions(context.Expressions);
            _stopWatch.Stop();

            _announcer.Say(name + ": migrated");
            _announcer.ElapsedTime(_stopWatch.ElapsedTime());
        }
예제 #8
0
        /// <summary>
        /// Profiles the method in question
        /// </summary>
        /// <param name="description">the description of the test</param>
        /// <param name="iterations">the number of iterations to perform</param>
        /// <param name="func">the method to execute</param>
        /// <remarks>
        /// This method was taken from the following question at stackoverflow.com.
        /// It was chosen due to the simplicity, which is the main principle of this program: http://stackoverflow.com/a/1048708
        /// </remarks>
        public void Profile(string description, int iterations, Action func)
        {
            // clean up
            _garbageCollector.Collect();
            _garbageCollector.WaitForPendingFinalizers();
            _garbageCollector.Collect();

            // warm up
            func();

            IStopWatch watch = _stopWatch.StartNew();

            for (int i = 0; i < iterations; i++)
            {
                func();
            }

            watch.Stop();
            WriteToConsole(description);
            WriteToConsole(string.Format("Time Elapsed {0} ms", watch.ElapsedMilliseconds));
        }
예제 #9
0
        private void ApplyMigrationUp(IMigrationInfo migrationInfo, bool useTransaction)
        {
            if (!_alreadyOutputPreviewOnlyModeWarning && Processor.Options.PreviewOnly)
            {
                _announcer.Heading("PREVIEW-ONLY MODE");
                _alreadyOutputPreviewOnlyModeWarning = true;
            }

            if (!VersionLoader.VersionInfo.HasAppliedMigration(migrationInfo.Version))
            {
                var name = GetMigrationName(migrationInfo);
                _announcer.Heading(string.Format("{0} migrating", name));

                try
                {
                    _stopWatch.Start();

                    if (useTransaction)
                    {
                        Processor.BeginTransaction();
                    }

                    ExecuteMigration(migrationInfo.Migration, (m, c) => m.GetUpExpressions(c));
                    VersionLoader.UpdateVersionInfo(migrationInfo.Version);

                    if (useTransaction)
                    {
                        Processor.CommitTransaction();
                    }

                    _stopWatch.Stop();

                    _announcer.Say(string.Format("{0} migrated", name));
                    _announcer.ElapsedTime(_stopWatch.ElapsedTime());
                }
                catch (Exception)
                {
                    if (useTransaction)
                    {
                        Processor.RollbackTransaction();
                    }
                    throw;
                }
            }
        }