Esempio n. 1
0
        public static IApplicationBuilder UseStartPage(this IApplicationBuilder app, Action <StartPageOptions> optionsAction = null)
        {
            var option = new StartPageOptions();

            if (app == null)
            {
                throw new ArgumentNullException(nameof(app));
            }

            optionsAction?.Invoke(option);

            return(app.UseMiddleware <StartPageMiddleware>(Options.Create(option)));
        }
Esempio n. 2
0
        public StartPageMiddleware(RequestDelegate next, IOptions <StartPageOptions> options)
        {
            if (next == null)
            {
                throw new ArgumentNullException(nameof(next));
            }

            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            _next    = next;
            _options = options.Value;
        }
Esempio n. 3
0
        public virtual async Task ExecuteAsync(HttpContext context, StartPageOptions _options, HealthCheckService healthyCheck, CachedHealthCheckService cachedHealthCheckService)
        {
            var s = await GetPageStringAsync();

            s = s.Replace("{{ServiceName}}", _options.Title);

            if (_options.HealthCheckEnable && (healthyCheck != null))
            {
                var servicesString = "";

                var r = await cachedHealthCheckService.GetOrCheckHealthAsync(healthyCheck, context.RequestAborted);

                if (r != null)
                {
                    s = s.Replace("{{Message}}", GetHealthStatusEmojiCode(r.Report.Status) + "  " + r.Report.Status + " - " + GetHealthDateTimeString(r.Date));

                    servicesString  = "<table style='width: 100 % '>";
                    servicesString += "<tr><td> </td><th> Service </th><th> Status </th></tr>";

                    foreach (var hi in r.Report.Entries)
                    {
                        servicesString += "<tr><td> " + GetHealthStatusEmojiCode(hi.Value.Status) + " </td><td> " + hi.Key + " </td><td> " + hi.Value.Status + " </td></tr>";
                    }

                    servicesString += "</table>";
                }
                else
                {
                    s = s.Replace("{{Message}}", "Status: " + "Evaluating...");
                }


                s = s.Replace("{{Services}}", servicesString);
            }
            else
            {
                s = s.Replace("{{Message}}", _options.Message);
                s = s.Replace("{{Services}}", "");
            }

            s = s.Replace("{{Version}}", _options.Version);
            s = s.Replace("{{OrganizationName}}", _options.Organization ?? _options.Title);
            s = s.Replace("{{Year}}", DateTimeOffset.UtcNow.Year.ToString());

            await context.Response.WriteAsync(s);
        }