示例#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());
                }
            }
        }
示例#3
0
        /// <summary>Checks the resolution.</summary>
        /// <param name="watch">The IStopWatch to check.</param>
        /// <param name="samples">The samples.</param>
        /// <returns>The resolution.</returns>
        /// <exception cref="ArgumentNullException">watch.</exception>
        public static TimeSpan CheckResolution(IStopWatch watch, int samples = 50)
        {
            if (watch == null)
            {
                throw new ArgumentNullException(nameof(watch));
            }

            if (!watch.IsRunning)
            {
                watch.Start();
            }

            var best = TimeSpan.MaxValue;

            for (var i = 0; i < samples; i++)
            {
                var start = watch.Elapsed;
                var next  = watch.Elapsed;
                while (next == start)
                {
                    next = watch.Elapsed;
                }

                var res = next - start;
                if (res < best)
                {
                    best = res;
                }
            }

            return(best);
        }
示例#4
0
        public IMethodReturn Invoke(IMethodInvocation input, GetNextInterceptionBehaviorDelegate getNext)
        {
            _stopWatch.Start();
            IMethodReturn result = getNext()(input, getNext);

            if (IgnoreMethod(input))
            {
                return(result);
            }

            var method = input.MethodBase as MethodInfo;

            if (result.ReturnValue != null &&
                method != null &&
                typeof(Task).IsAssignableFrom(method.ReturnType))
            {
                // If this method returns a Task, override the original return value.
                // More info on this pattern: https://msdn.microsoft.com/en-us/magazine/dn574805.aspx
                var task = (Task)result.ReturnValue;
                return(input.CreateMethodReturn(
                           GetWrapperCreator(method.ReturnType)(task, input), result.Outputs));
            }

            // If this method does not return a task, just log and return value.
            LogMethodResult(input, result.ReturnValue, result.Exception);
            return(result);
        }
示例#5
0
        public void Something()
        {
            stopwatch.Start();
            decoratedComponent.Something();
            var elapsedMilliseconds = stopwatch.Stop();

            Console.WriteLine("메서드 실행 시간: {0}", elapsedMilliseconds / 1000);
        }
        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
        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;
                }
            }
        }
 public void Start()
 {
     decoratedStopwatch.Start();
     Console.WriteLine("스탑워치가 시작되었습니다.");
 }