Ejemplo n.º 1
0
        public static bool CreateServiceStatusEmail(ServiceInfo info, ILog log = null)
        {
            bool   result     = false;
            string methodName = MethodBase.GetCurrentMethod().Name;

            try
            {
                var repo     = new EmailConfigRepository();
                var template = repo.GetEmailTemplate(SERVICE_STATUS);
                var list     = new List <string>();
                if (template != null)
                {
                    if (template.Subscribers != null)
                    {
                        foreach (var subscriber in template.Subscribers)
                        {
                            if (!string.IsNullOrEmpty(subscriber.EmailAddress))
                            {
                                list.Add(subscriber.EmailAddress);
                            }
                        }
                    }
                    EmailFileTemplate fileTemplate = new EmailFileTemplate();

                    fileTemplate.EmailSubject = template.TemplateSubject
                                                .Replace("{{SERVICE_NAME}}", info.ServiceName)
                                                .Replace("{{SERVICE_STATUS}}", info.ServiceStatus.ToString());

                    fileTemplate.EmailMessage = template.TemplateMessage.Replace("\\n", "\n")
                                                .Replace("{{DATETIME}}", DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss"))
                                                .Replace("{{SERVICE_NAME}}", info.ServiceName)
                                                .Replace("{{SERVICE_STATUS}}", info.ServiceStatus.ToString());

                    fileTemplate.BccEmailAddresses = list;

                    if (fileTemplate != null)
                    {
                        var json = JsonConvert.SerializeObject(fileTemplate);
                        var file = string.Format(@"{0}\Gateway_{1}.json", EmailManager.Instance.Configurations.EmailFolderPath,
                                                 DateTime.UtcNow.ToString("yyyyMMddHHmmss"));

                        FileHelper.WriteAllText(file, json);
                        result = true;
                    }
                }
            }
            catch (Exception ex)
            {
                log?.Error(className, methodName, ex.ToString());
                result = false;
            }
            return(result);
        }
Ejemplo n.º 2
0
 public void GetServiceStatusEmail()
 {
     var repo = new EmailConfigRepository();
     var res  = repo.GetEmailTemplate("SERVICE_STATUS");
 }
Ejemplo n.º 3
0
 public void GetNoChannelConnectedEmail()
 {
     var repo = new EmailConfigRepository();
     var res  = repo.GetEmailTemplate("NO_CHANNEL_CONNECTED");
 }