/// <summary> /// Checks the status of the other. /// </summary> public void CheckStatus() { try { var sw = new Stopwatch(); sw.Start(); Status = PerformCheckStatus(); sw.Stop(); if (string.IsNullOrWhiteSpace(Status.Description)) { Status.Description = $"Response time: {sw.Elapsed}"; } } catch (Exception ex) { Status = new ExternalDependencyStatus() { IsFailing = true, Description = ex.Message }; } finally { Status.Date = DateTime.Now; } }
/// <summary> /// Performs the check status. /// </summary> /// <returns>The check status.</returns> protected internal override ExternalDependencyStatus PerformCheckStatus() { var result = new ExternalDependencyStatus(); var request = (HttpWebRequest)HttpWebRequest.Create(m_url); var response = (HttpWebResponse)request.GetResponse(); if (response.StatusCode == m_expectedStatusCode) { result.IsFailing = false; } else { result.IsFailing = true; result.Description = $"Expected HTTP status code was '{m_expectedStatusCode}', but the url '{m_url}' returns a status '{response.StatusCode}'."; } return(result); }