public async Task Invoke(HttpContext context)
        {
            // resolve Profiler right away
            var profiler = context.GetProfiler();

            await _next.Invoke(context);

            profiler.Stop();

            context.Response.Headers.Add("X-Profiler-Id", profiler.Id.ToString());

            profiler.Printout();
        }
Beispiel #2
0
        private async Task SomeWork(HttpContext context)
        {
            using (context.GetProfiler().Step("SOMETHING TO DO BEFORE"))
                await Task.Delay(TimeSpan.FromMilliseconds(R.NextDouble() * 150 + 50));

            using (context.GetProfiler().Step("SOME WORK"))
            {
                await context.Response.WriteAsync("<ul>");

                for (int i = 1; i <= 5; i++)
                {
                    using (context.GetProfiler().Step("RENDER <LI>"))
                    {
                        await Task.Delay(TimeSpan.FromMilliseconds(R.NextDouble() * 150 + 50));
                        await context.Response.WriteAsync($"<li>Item #{i}</li>");
                    }
                }
            }

            using (context.GetProfiler().Step("SOMETHING TO DO AFTER"))
                await Task.Delay(TimeSpan.FromMilliseconds(R.NextDouble() * 150 + 50));

            await context.Response.WriteAsync("</ul>");
        }
Beispiel #3
0
        private async Task WaitForExactDelays(HttpContext context, string title,  TimeSpan delay1, TimeSpan delay2)
        {
            using (context.GetProfiler().Step($"TITLE: '{title}', CONTAINER"))
            {
                using (context.GetProfiler().Step($"TITLE: '{title}', First delay"))
                {
                    await Task.Delay(delay1);
                }

                using (context.GetProfiler().Step($"TITLE: '{title}', Second delay"))
                {
                    await Task.Delay(delay2);
                }
            }
        }
Beispiel #4
0
        private async Task<string> GetSomeRandomTextWithDelays(HttpContext context, string input)
        {
            using (context.GetProfiler().Step($"CALCULATING STRING OF '{input}'"))
            {
                await Task.Delay(TimeSpan.FromMilliseconds(R.NextDouble() * 1500 + 100));

                var result = $"String '{input}' has lengths of {input.Length} characters.";

                _logger.LogInformation($"Results for '{input}' are ready, but we need to wait more");

                await Task.Delay(TimeSpan.FromMilliseconds(R.NextDouble() * 1500 + 100));

                return result;
            }
        }