private CompanyServerStatus HandleServiceStatusResponse(string companyKey, string companyName, ServiceStatusResponse serviceStatusResponse, string url)
        {
            var companyServerStatus = _serviceStatusRepository
                                      .FirstOrDefault(status => status.CompanyKey == companyKey && status.IsProduction == serviceStatusResponse.IsProduction);

            var emailSentForCurrentError = SendEmailIfNeeded(serviceStatusResponse, companyName, url, companyServerStatus);

            if (companyServerStatus == null)
            {
                companyServerStatus = new CompanyServerStatus
                {
                    IsProduction = serviceStatusResponse.IsProduction,
                    CompanyName  = companyName,
                    CompanyKey   = companyKey
                };
            }

            companyServerStatus.ServiceStatus              = serviceStatusResponse.ServiceStatus;
            companyServerStatus.IsApiAvailable             = serviceStatusResponse.IsApiAvailable;
            companyServerStatus.IsServerAvailable          = serviceStatusResponse.IsServerAvailable;
            companyServerStatus.IsEmailSentForCurrentError = emailSentForCurrentError;
            companyServerStatus.HasAuthenticationError     = serviceStatusResponse.HasAuthenticationError;

            return(companyServerStatus);
        }
Beispiel #2
0
 private CompanyStatusModel GetModelFromDbObject(CompanyServerStatus status)
 {
     return(new CompanyStatusModel
     {
         CompanyKey = status.CompanyKey,
         CompanyName = status.CompanyName,
         ServiceStatus = status.ServiceStatus,
         IsServerAvailable = status.IsServerAvailable,
         IsApiAvailable = status.IsApiAvailable,
         HasAuthenticationError = status.HasAuthenticationError
     });
 }
        private bool SendEmailIfNeeded(ServiceStatusResponse serviceStatus, string companyName, string url, CompanyServerStatus previousStatus)
        {
            if (serviceStatus.ServiceStatus.SelectOrDefault(response => response.IsServerHealthy(), !serviceStatus.IsApiAvailable))
            {
                return(false);
            }

            if (!previousStatus.SelectOrDefault(status => status.IsEmailSentForCurrentError))
            {
                try
                {
                    _emailSender.SendServiceStatusEmail(companyName, url, serviceStatus.ServiceStatus, serviceStatus.StatusCode);
                }
                catch (Exception ex)
                {
                    _logger.LogError(ex);
                    return(false);
                }
            }
            return(true);
        }