Esempio n. 1
0
        public async Task <Core.Models.HealthModel> AddHealthResponse(bool success, int statusCode, int elapsedMilliseconds, string url)
        {
            var healthModel = new Models.HealthModel
            {
                Success             = success,
                Timestamp           = DateTime.UtcNow,
                Url                 = url,
                ElapsedMilliseconds = elapsedMilliseconds,
                StatusCode          = statusCode
            };

            if (_context.HealthCollection == null)
            {
                throw new NullReferenceException("Database not initialized");
            }

            await _context.HealthCollection.InsertOneAsync(healthModel);

            return(new Core.Models.HealthModel
            {
                StatusCode = healthModel.StatusCode,
                ElapsedMilliseconds = healthModel.ElapsedMilliseconds,
                Timestamp = healthModel.Timestamp,
                Success = healthModel.Success,
                Url = healthModel.Url
            });
        }
        // GET: api/Health
        public HttpResponseMessage Get()
        {
            try
            {
                var errorModel = new Models.ErrorModel
                {
                    InnerException = "string",
                    Message        = "string",
                    Code           = 0
                };

                var healthModel = new Models.HealthModel {
                    Error   = errorModel,
                    message = "string",
                    Health  = nameof(Models.HealthModel.health.green)
                };

                return(Request.CreateResponse(HttpStatusCode.OK, healthModel));
            }
            catch
            {
                var errorModel = new Models.ErrorModel
                {
                    InnerException = "Unexpected condition encountered",
                    Message        = "Oops, this wasn't supposed to happen !!!",
                    Code           = 50001
                };
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, errorModel));
            }
        }