Пример #1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MigrationRunner"/> class.
 /// </summary>
 /// <param name="options">The migration runner options</param>
 /// <param name="processorOptions">The migration processor options</param>
 /// <param name="profileLoader">The profile loader</param>
 /// <param name="processorAccessor">The migration processor accessor</param>
 /// <param name="maintenanceLoader">The maintenance loader</param>
 /// <param name="migrationLoader">The migration loader</param>
 /// <param name="logger">The logger</param>
 /// <param name="stopWatch">The stopwatch</param>
 /// <param name="migrationRunnerConventionsAccessor">The accessor for migration runner conventions</param>
 /// <param name="assemblySource">The assemblies to scan for migrations, etc...</param>
 /// <param name="migrationValidator">The validator for migrations</param>
 /// <param name="serviceProvider">The service provider</param>
 public MigrationRunner(
     [NotNull] IOptions <RunnerOptions> options,
     [NotNull] IOptionsSnapshot <ProcessorOptions> processorOptions,
     [NotNull] IProfileLoader profileLoader,
     [NotNull] IProcessorAccessor processorAccessor,
     [NotNull] IMaintenanceLoader maintenanceLoader,
     [NotNull] IMigrationInformationLoader migrationLoader,
     [NotNull] ILogger <MigrationRunner> logger,
     [NotNull] IStopWatch stopWatch,
     [NotNull] IMigrationRunnerConventionsAccessor migrationRunnerConventionsAccessor,
     [NotNull] IAssemblySource assemblySource,
     [NotNull] MigrationValidator migrationValidator,
     [NotNull] IServiceProvider serviceProvider)
     : this(
         options,
         processorOptions,
         profileLoader,
         processorAccessor,
         maintenanceLoader,
         migrationLoader,
         logger,
         stopWatch,
         migrationRunnerConventionsAccessor,
         assemblySource,
         migrationValidator,
         serviceProvider,
         migrationScopeHandler : null)
 {
 }
Пример #2
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);
        }
Пример #3
0
        public MigrationRunner(IAssemblyCollection assemblies, IRunnerContext runnerContext, IMigrationProcessor processor)
        {
            _migrationAssemblies = assemblies;
            _announcer = runnerContext.Announcer;
            Processor = processor;
            _stopWatch = runnerContext.StopWatch;
            RunnerContext = runnerContext;

            SilentlyFail = false;
            CaughtExceptions = null;

            Conventions = new MigrationConventions();
            if (!string.IsNullOrEmpty(runnerContext.WorkingDirectory))
                Conventions.GetWorkingDirectory = () => runnerContext.WorkingDirectory;

            _migrationScopeHandler = new MigrationScopeHandler(Processor);
            _migrationValidator = new MigrationValidator(_announcer, Conventions);
            MigrationLoader = new DefaultMigrationInformationLoader(Conventions, _migrationAssemblies, runnerContext.Namespace, runnerContext.NestedNamespaces, runnerContext.Tags);
            ProfileLoader = new ProfileLoader(runnerContext, this, Conventions);
            MaintenanceLoader = new MaintenanceLoader(_migrationAssemblies, runnerContext.Tags, Conventions);

            if (runnerContext.NoConnection){
                VersionLoader = new ConnectionlessVersionLoader(this, _migrationAssemblies, Conventions, runnerContext.StartVersion, runnerContext.Version);
            }
            else{
                VersionLoader = new VersionLoader(this, _migrationAssemblies, Conventions);
            }
        }
Пример #4
0
        public MigrationRunner(IAssemblyCollection assemblies, IRunnerContext runnerContext, IMigrationProcessor processor)
        {
            _migrationAssemblies  = assemblies;
            _announcer            = runnerContext.Announcer;
            Processor             = processor;
            _stopWatch            = runnerContext.StopWatch;
            ApplicationContext    = runnerContext.ApplicationContext;
            TransactionPerSession = runnerContext.TransactionPerSession;

            SilentlyFail     = false;
            CaughtExceptions = null;

            Conventions = new MigrationConventions();
            if (!string.IsNullOrEmpty(runnerContext.WorkingDirectory))
            {
                Conventions.GetWorkingDirectory = () => runnerContext.WorkingDirectory;
            }

            _migrationScopeHandler = new MigrationScopeHandler(Processor);
            _migrationValidator    = new MigrationValidator(_announcer, Conventions);
            MigrationLoader        = new DefaultMigrationInformationLoader(Conventions, _migrationAssemblies, runnerContext.Namespace, runnerContext.NestedNamespaces, runnerContext.Tags);
            ProfileLoader          = new ProfileLoader(runnerContext, this, Conventions);
            MaintenanceLoader      = new MaintenanceLoader(_migrationAssemblies, runnerContext.Tags, Conventions);

            if (runnerContext.NoConnection)
            {
                VersionLoader = new ConnectionlessVersionLoader(this, _migrationAssemblies, Conventions, runnerContext.StartVersion, runnerContext.Version);
            }
            else
            {
                VersionLoader = new VersionLoader(this, _migrationAssemblies, Conventions);
            }
        }
Пример #5
0
 public MigrationRunner(IMigrationConventions conventions, IMigrationProcessor processor, IAnnouncer announcer, IStopWatch stopWatch)
 {
     _announcer = announcer;
     SilentlyFail = false;
     CaughtExceptions = null;
     Conventions = conventions;
     Processor = processor;
     _stopWatch = stopWatch;
 }
Пример #6
0
 static void ShowProgress(float progress, IStopWatch sw)
 {
     if (progress != lastProgress)
     {
         lastProgress  = progress;
         Console.Title = progress.ToString("P");
         Console.WriteLine(sw.Elapsed.FormatTime() + " " + progress.ToString("P"));
     }
 }
Пример #7
0
 public MethodMeasurement(Action action)
 {
     m_Action             = action;
     m_GCRecorder         = Recorder.Get("GC.Alloc");
     m_GCRecorder.enabled = false;
     if (m_Watch == null)
     {
         m_Watch = new StopWatch();
     }
 }
Пример #8
0
        public Performance(string pactUri, IStopWatch stopWatch = null, IStopWatch lapStopWatch = null)
        {
            MaxExecutionTime = new TimeSpan(long.MinValue);
            MinExecutionTime = new TimeSpan(long.MaxValue);

            StopWatch    = stopWatch ?? new CustomStopWatch();
            LapStopWatch = lapStopWatch ?? new CustomStopWatch();

            var random = new Random();

            LocalPact = string.Format("PerformancePactFile-{0}{1}.json", DateTime.Now.ToString("yyyyMMdd-hhmmssfffffff"), random.Next(0, 1000));

            SavePactLocally(pactUri, LocalPact);
        }
Пример #9
0
        /// <summary>
        /// Initializes a new instance of the <see cref="NLog"/> class.
        /// </summary>
        /// <param name="logger"><see cref="ILogger"/></param>
        /// <param name="stopWatch">Performance stopwatch</param>
        public NLog(ILogger logger, IStopWatch stopWatch)
        {
            _logger   = logger;
            StopWatch = stopWatch;
            if (!Configuration.CommonLogEnabled())
            {
                return;
            }

            var props = new Common.Logging.Configuration.NameValueCollection
            {
                { "ConfigType", "INLINE" },
            };

            Common.Logging.LogManager.Adapter = new Common.Logging.NLog.NLogLoggerFactoryAdapter(props);
        }
Пример #10
0
        public MigrationRunner(
            [NotNull] IAssemblyCollection assemblies, [NotNull] IRunnerContext runnerContext,
            [NotNull] IMigrationProcessor processor, [CanBeNull] IVersionTableMetaData versionTableMetaData,
            [CanBeNull] IMigrationRunnerConventions migrationRunnerConventions, [CanBeNull] IConventionSet conventionSet,
            [CanBeNull] IMigrationScopeManager migrationScopeHandler = null)
        {
            _migrationAssemblies = assemblies;
            _logger           = new AnnouncerFluentMigratorLogger(runnerContext.Announcer);
            _stopWatch        = runnerContext.StopWatch;
            _processorOptions = new ProcessorOptions(runnerContext);

            Processor     = processor;
            RunnerContext = runnerContext;

            var migrationRunnerConventionsAccessor = new AssemblySourceMigrationRunnerConventionsAccessor(
                serviceProvider: null,
                new AssemblySource(() => assemblies));

            Conventions = migrationRunnerConventions ?? migrationRunnerConventionsAccessor.MigrationRunnerConventions;

            var convSet = conventionSet ?? new DefaultConventionSet(runnerContext);

            _migrationScopeManager = migrationScopeHandler ?? new MigrationScopeHandler(Processor);
            _migrationValidator    = new MigrationValidator(_logger, convSet);
            MigrationLoader        = new DefaultMigrationInformationLoader(Conventions, _migrationAssemblies,
                                                                           runnerContext.Namespace,
                                                                           runnerContext.NestedNamespaces, runnerContext.Tags);
            ProfileLoader     = new ProfileLoader(runnerContext, this, Conventions);
            MaintenanceLoader = new MaintenanceLoader(_migrationAssemblies, runnerContext.Tags, Conventions);

            if (runnerContext.NoConnection)
            {
                _versionLoader = new Lazy <IVersionLoader>(
                    () => new ConnectionlessVersionLoader(
                        this,
                        _migrationAssemblies,
                        convSet,
                        Conventions,
                        runnerContext,
                        versionTableMetaData));
            }
            else
            {
                _versionLoader = new Lazy <IVersionLoader>(
                    () => new VersionLoader(this, _migrationAssemblies, convSet, Conventions, runnerContext, versionTableMetaData));
            }
        }
Пример #11
0
        public MigrationRunner(Assembly assembly, IRunnerContext runnerContext, IMigrationProcessor processor)
        {
            _migrationAssembly = assembly;
            _announcer = runnerContext.Announcer;
            Processor = processor;
            _stopWatch = runnerContext.StopWatch;

            SilentlyFail = false;
            CaughtExceptions = null;

            Conventions = new MigrationConventions();
            if (!string.IsNullOrEmpty(runnerContext.WorkingDirectory))
                Conventions.GetWorkingDirectory = () => runnerContext.WorkingDirectory;

            VersionLoader = new VersionLoader(this, _migrationAssembly, Conventions);
            MigrationLoader = new MigrationLoader(Conventions, _migrationAssembly, runnerContext.Namespace);
            ProfileLoader = new ProfileLoader(runnerContext, this, Conventions);
        }
Пример #12
0
        public MigrationRunner(ICollection<MigrationAssemblyInfo> assemblyInfos, IRunnerContext runnerContext, IMigrationProcessor processor, bool loadNestedNamespaces)
        {
            _migrationAssemblies = assemblyInfos;
            _announcer = runnerContext.Announcer;
            Processor = processor;
            _stopWatch = runnerContext.StopWatch;
            ApplicationContext = runnerContext.ApplicationContext;

            SilentlyFail = false;
            CaughtExceptions = null;

            Conventions = new MigrationConventions();
            if (!string.IsNullOrEmpty(runnerContext.WorkingDirectory))
                Conventions.GetWorkingDirectory = () => runnerContext.WorkingDirectory;

            VersionLoader = new VersionLoader(this, assemblyInfos, Conventions);
            MigrationLoader = new MigrationLoader(Conventions, assemblyInfos, loadNestedNamespaces , runnerContext.Tags);
            ProfileLoader = new ProfileLoader(runnerContext, this, Conventions);
        }
        public MigrationRunner(Assembly assembly, IRunnerContext runnerContext, IMigrationProcessor processor)
        {
            _migrationAssembly = assembly;
            _announcer = runnerContext.Announcer;
            Processor = processor;
            _stopWatch = runnerContext.StopWatch;

            SilentlyFail = false;
            CaughtExceptions = null;

            Conventions = new MigrationConventions();

            ProcessWorkingDirectory(runnerContext);

            ProcessAutoReverse(runnerContext);

            VersionLoader = new VersionLoader(this, _migrationAssembly, Conventions);
            MigrationLoader = new MigrationLoader(Conventions, _migrationAssembly, runnerContext.Namespace);
            ProfileLoader = new ProfileLoader(runnerContext, this, Conventions);
        }
Пример #14
0
        public MigrationRunner(Assembly assembly, IRunnerContext runnerContext, IMigrationProcessor processor)
        {
            _migrationAssembly = assembly;
            _announcer         = runnerContext.Announcer;
            Processor          = processor;
            _stopWatch         = runnerContext.StopWatch;

            SilentlyFail     = false;
            CaughtExceptions = null;

            Conventions = new MigrationConventions();
            if (!string.IsNullOrEmpty(runnerContext.WorkingDirectory))
            {
                Conventions.GetWorkingDirectory = () => runnerContext.WorkingDirectory;
            }

            VersionLoader   = new VersionLoader(this, _migrationAssembly, Conventions);
            MigrationLoader = new MigrationLoader(Conventions, _migrationAssembly, runnerContext.Namespace);
            ProfileLoader   = new ProfileLoader(runnerContext, this, Conventions);
        }
Пример #15
0
        /// <summary>
        /// Waits for process completion.
        /// </summary>
        /// <param name="timeout">maximum time to wait.</param>
        /// <param name="waitCallBack">Callback while waiting for process exit (should not use up more then 1000ms).</param>
        /// <param name="throwEx">Throw exception if the process does not exit in time.</param>
        /// <returns></returns>
        public bool Wait(TimeSpan timeout, WaitAction waitCallBack, bool throwEx)
        {
            IStopWatch watch = DateTimeStopWatch.StartNew();
            bool       exit  = false;

            while (!exit && (watch.Elapsed < timeout))
            {
                if (Task.WaitAll(new Task[] { errorTask, outputTask }, 1))
                {
                    return(true);
                }

                waitCallBack?.Invoke(out exit);
            }
            if (throwEx)
            {
                throw new TimeoutException();
            }

            return(false);
        }
Пример #16
0
        /**
         * Template method controlling search. It returns the best individual in the
         * specified population, according to the specified FITNESS-FN and goal
         * test.
         *
         * @param initPopulation
         *            a set of individuals
         * @param fitnessFn
         *            a function that measures the fitness of an individual
         * @param goalTest
         *            test determines whether a given individual is fit enough to
         *            return. Can be used in subclasses to implement additional
         *            termination criteria, e.g. maximum number of iterations.
         * @param maxTimeMilliseconds
         *            the maximum time in milliseconds that the algorithm is to run
         *            for (approximate). Only used if > 0L.
         * @return the best individual in the specified population, according to the
         *         specified FITNESS-FN and goal test.
         */
        // function GENETIC-ALGORITHM(population, FITNESS-FN) returns an individual
        // inputs: population, a set of individuals
        // FITNESS-FN, a function that measures the fitness of an individual
        public virtual Individual <A> geneticAlgorithm(ICollection <Individual <A> > initPopulation, IFitnessFunction <A> fitnessFn,
                                                       GoalTest <Individual <A> > goalTest, long maxTimeMilliseconds)
        {
            Individual <A> bestIndividual = null;

            // Create a local copy of the population to work with
            ICollection <Individual <A> > population = CollectionFactory.CreateQueue <Individual <A> >(initPopulation);

            // Validate the population and setup the instrumentation
            validatePopulation(population);
            updateMetrics(population, 0, 0L);

            IStopWatch sw = CommonFactory.CreateStopWatch();

            // repeat
            int itCount = 0;

            do
            {
                population     = nextGeneration(population, fitnessFn);
                bestIndividual = retrieveBestIndividual(population, fitnessFn);

                updateMetrics(population, ++itCount, sw.GetElapsedMilliseconds());

                // until some individual is fit enough, or enough time has elapsed
                if (maxTimeMilliseconds > 0L && sw.GetElapsedMilliseconds() > maxTimeMilliseconds)
                {
                    break;
                }
                if (currIsCancelled)
                {
                    break;
                }
            } while (!goalTest(bestIndividual));

            notifyProgressTrackers(itCount, population);
            // return the best individual in population, according to FITNESS-FN
            return(bestIndividual);
        }
        public MigrationRunner(Assembly assembly, IRunnerContext runnerContext, IMigrationProcessor processor)
        {
            _migrationAssembly = assembly;
            _announcer = runnerContext.Announcer;
            Processor = processor;
            _stopWatch = runnerContext.StopWatch;
            ApplicationContext = runnerContext.ApplicationContext;
            TransactionPerSession = runnerContext.TransactionPerSession;

            SilentlyFail = false;
            CaughtExceptions = null;

            Conventions = new MigrationConventions();
            if (!string.IsNullOrEmpty(runnerContext.WorkingDirectory))
                Conventions.GetWorkingDirectory = () => runnerContext.WorkingDirectory;

            _migrationScopeHandler = new MigrationScopeHandler(Processor);
            _migrationValidator = new MigrationValidator(_announcer, Conventions);
            VersionLoader = new VersionLoader(this, _migrationAssembly, Conventions);
            MigrationLoader = new DefaultMigrationInformationLoader(Conventions, _migrationAssembly, runnerContext.Namespace, runnerContext.NestedNamespaces, runnerContext.Tags);
            ProfileLoader = new ProfileLoader(runnerContext, this, Conventions);
        }
Пример #18
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MigrationRunner"/> class.
        /// </summary>
        /// <param name="options">The migration runner options</param>
        /// <param name="processorOptions">The migration processor options</param>
        /// <param name="profileLoader">The profile loader</param>
        /// <param name="processorAccessor">The migration processor accessor</param>
        /// <param name="maintenanceLoader">The maintenance loader</param>
        /// <param name="migrationLoader">The migration loader</param>
        /// <param name="logger">The logger</param>
        /// <param name="stopWatch">The stopwatch</param>
        /// <param name="migrationRunnerConventionsAccessor">The accessor for migration runner conventions</param>
        /// <param name="assemblySource">The assemblies to scan for migrations, etc...</param>
        /// <param name="migrationValidator">The validator for migrations</param>
        /// <param name="serviceProvider">The service provider</param>
        /// <param name="migrationScopeHandler">THe migration scope handler</param>
        public MigrationRunner(
            [NotNull] IOptions <RunnerOptions> options,
            [NotNull] IOptionsSnapshot <ProcessorOptions> processorOptions,
            [NotNull] IProfileLoader profileLoader,
            [NotNull] IProcessorAccessor processorAccessor,
            [NotNull] IMaintenanceLoader maintenanceLoader,
            [NotNull] IMigrationInformationLoader migrationLoader,
            [NotNull] ILogger <MigrationRunner> logger,
            [NotNull] IStopWatch stopWatch,
            [NotNull] IMigrationRunnerConventionsAccessor migrationRunnerConventionsAccessor,
            [NotNull] IAssemblySource assemblySource,
            [NotNull] MigrationValidator migrationValidator,
            [NotNull] IServiceProvider serviceProvider,
            [CanBeNull] IMigrationScopeManager migrationScopeHandler)
        {
            Processor         = processorAccessor.Processor;
            Conventions       = migrationRunnerConventionsAccessor.MigrationRunnerConventions;
            ProfileLoader     = profileLoader;
            MaintenanceLoader = maintenanceLoader;
            MigrationLoader   = migrationLoader;

            _serviceProvider  = serviceProvider;
            _options          = options.Value;
            _logger           = logger;
            _stopWatch        = stopWatch;
            _processorOptions = processorOptions.Value;

            _migrationScopeManager = migrationScopeHandler ?? new MigrationScopeHandler(Processor, processorOptions.Value);
            _migrationValidator    = migrationValidator;
            _versionLoader         = new Lazy <IVersionLoader>(serviceProvider.GetRequiredService <IVersionLoader>);

#pragma warning disable 612
#pragma warning disable 618
            _migrationAssemblies = new AssemblyCollectionService(assemblySource);
#pragma warning restore 618
#pragma warning restore 612
        }
Пример #19
0
        public MigrationRunner(Assembly assembly, IRunnerContext runnerContext, IMigrationProcessor processor, IVersionTableMetaData versionTableMetaData = null)
        {
            _migrationAssembly    = assembly;
            _announcer            = runnerContext.Announcer;
            Processor             = processor;
            _stopWatch            = runnerContext.StopWatch;
            ApplicationContext    = runnerContext.ApplicationContext;
            TransactionPerSession = runnerContext.TransactionPerSession;

            SilentlyFail     = false;
            CaughtExceptions = null;

            Conventions = new MigrationConventions();
            if (!string.IsNullOrEmpty(runnerContext.WorkingDirectory))
            {
                Conventions.GetWorkingDirectory = () => runnerContext.WorkingDirectory;
            }

            _migrationScopeHandler = new MigrationScopeHandler(Processor);
            _migrationValidator    = new MigrationValidator(_announcer, Conventions);
            VersionLoader          = new VersionLoader(this, _migrationAssembly, Conventions, versionTableMetaData);
            MigrationLoader        = new DefaultMigrationInformationLoader(Conventions, _migrationAssembly, runnerContext.Namespace, runnerContext.NestedNamespaces, runnerContext.Tags);
            ProfileLoader          = new ProfileLoader(runnerContext, this, Conventions);
        }
Пример #20
0
        public LoggingStopWatch(IStopWatch decoratedStopWatch)
        {
            this.decoratedStopWatch = decoratedStopWatch;

        }
Пример #21
0
 public LoggingInterceptionBehavior(ILogger logger, IStopWatch stopWatch, ISerilogOptions options)
 {
     _logger    = logger;
     _stopWatch = stopWatch;
     _options   = options;
 }
 public ConstrainedMigrationRunner(
     IOptions <RunnerOptions> options, IOptionsSnapshot <ProcessorOptions> processorOptions,
     IProfileLoader profileLoader, IProcessorAccessor processorAccessor, IMaintenanceLoader maintenanceLoader,
     IMigrationInformationLoader migrationLoader, ILogger <MigrationRunner> logger, IStopWatch stopWatch,
     IMigrationRunnerConventionsAccessor migrationRunnerConventionsAccessor, IAssemblySource assemblySource,
     MigrationValidator migrationValidator, IServiceProvider serviceProvider
     ) : base(options, processorOptions, profileLoader,
              processorAccessor, maintenanceLoader, migrationLoader, logger, stopWatch, migrationRunnerConventionsAccessor, assemblySource,
              migrationValidator, serviceProvider
              )
 {
 }
Пример #23
0
 public void SetStopWatch(IStopWatch stopWatch)
 {
     this.StopWatch = stopWatch;
 }
Пример #24
0
 public ProfilingComponent(IComponent decoratedComponent,IStopWatch stopWatch)
 {
     this.decoratedComponent = decoratedComponent;
     this.stopWatch = stopWatch;
 }
Пример #25
0
 public Profiler(IConsole console, IGarbageCollector garbageCollector, IStopWatch stopWatch)
 {
     _console = console;
     _garbageCollector = garbageCollector;
     _stopWatch = stopWatch;
 }
Пример #26
0
        internal MethodMeasurement StopWatch(IStopWatch watch)
        {
            m_Watch = watch;

            return(this);
        }