Exemple #1
0
        /// <summary>
        /// Returns a profiler for <paramref name="url"/>. Only child steps will take any time,
        /// e.g. when <paramref name="childDepth"/> is 0, the resulting <see cref="MiniProfiler.DurationMilliseconds"/> will be zero.
        /// </summary>
        /// <param name="url">The uri of the request.</param>
        /// <param name="childDepth">number of levels of child steps underneath result's <see cref="MiniProfiler.Root"/></param>
        /// <param name="stepsEachTakeMilliseconds">Amount of time each step will "do work for" in each step</param>
        /// <returns>The generated <see cref="MiniProfiler"/>.</returns>
        public async Task <MiniProfiler> GetProfilerAsync(
            string url     = DefaultRequestUrl,
            int childDepth = 0,
            int stepsEachTakeMilliseconds = StepTimeMilliseconds)
        {
            // TODO: Consolidate with above, maybe some out params
            MiniProfiler result   = null;
            Action       step     = null;
            var          curDepth = 0;

            // recursively add child steps
            step = () =>
            {
                if (curDepth++ < childDepth)
                {
                    using (result.Step("Depth " + curDepth))
                    {
                        Increment(stepsEachTakeMilliseconds);
                        step();
                    }
                }
            };

            using (GetRequest(url, startAndStopProfiler: false))
            {
                result = MiniProfiler.Start();
                step();

                if (_testStorage != null)
                {
                    result.Storage = _testStorage;
                }

                await MiniProfiler.StopAsync().ConfigureAwait(false);
            }

            return(result);
        }
Exemple #2
0
        public async Task StartAsync(CancellationToken cancellationToken)
        {
            Logger.LogDebug("SchemaScripter started");

            var hasConfigError = false;

            if (string.IsNullOrWhiteSpace(Config.Server))
            {
                Logger.LogError($"Invalid {nameof(Config.Server)}");
                hasConfigError = true;
            }
            if (string.IsNullOrWhiteSpace(Config.User))
            {
                Logger.LogError($"Invalid {nameof(Config.User)}");
                hasConfigError = true;
            }
            if (string.IsNullOrWhiteSpace(Config.Password))
            {
                Logger.LogError($"Invalid {nameof(Config.Password)}");
                hasConfigError = true;
            }
            if (string.IsNullOrWhiteSpace(Config.Database))
            {
                Logger.LogError($"Invalid {nameof(Config.Database)}");
                hasConfigError = true;
            }
            if (string.IsNullOrWhiteSpace(Config.ExportFolder))
            {
                Logger.LogError($"Invalid {nameof(Config.ExportFolder)}");
                hasConfigError = true;
            }

            if (hasConfigError)
            {
                ApplicationLifetime.StopApplication();
                return;
            }

            var availability = await DB.CheckAvailabilityAsync();

            if (!availability.IsSuccess)
            {
                Logger.LogError(availability.ErrorMessage ?? "Error connecting to server");
                ApplicationLifetime.StopApplication();
                return;
            }
            if (!await DB.UseDatabaseAsync(Config.Database))
            {
                Logger.LogError($"Cannot connect to database {Config.Database}");
                ApplicationLifetime.StopApplication();
                return;
            }

            Profiler = MiniProfiler.StartNew(nameof(SchemaScripterService));

            using (Profiler.Step("Tables"))
            {
                await ExportTablesAsync(cancellationToken);
            }

            using (Profiler.Step("Stored Procedures"))
            {
                await ExportStoredProceduresAsync(cancellationToken);
            }

            using (Profiler.Step("Views"))
            {
                await ExportViewsAsync(cancellationToken);
            }

            using (Profiler.Step("Functions"))
            {
                await ExportFunctionsAsync(cancellationToken);
            }

            ExportViaSMO();

            await Profiler.StopAsync();

            Logger.LogDebug(Profiler.RenderPlainText());

            ApplicationLifetime.StopApplication();
        }