Ejemplo n.º 1
0
        public static async Task <IActionResult> HealthCheck(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "healthcheck")] HttpRequest req,
            TraceWriter log)
        {
            // get the user ID
            if (!await UserAuthenticationService.GetUserIdAsync(req, out var userId, out var responseResult))
            {
                return(responseResult);
            }

            // list the categories
            try
            {
                var healthCheckResult = await ImagesService.HealthCheckApi(userId, req.Host.Host);

                if (healthCheckResult == null)
                {
                    return(new NotFoundResult());
                }

                // serialise the summaries using a custom converter
                var settings = new JsonSerializerSettings
                {
                    NullValueHandling = NullValueHandling.Ignore,
                    Formatting        = Formatting.Indented
                };
                var json = JsonConvert.SerializeObject(healthCheckResult, settings);

                return(new ContentResult
                {
                    Content = json,
                    ContentType = JsonContentType,
                    StatusCode = StatusCodes.Status200OK
                });
            }
            catch (Exception ex)
            {
                log.Error("Unhandled exception", ex);
                return(new ExceptionResult(ex, false));
            }
        }