public MailContentData CreateSummaryEmailAlertMessage(ParseEmailParam param, ILogger logger) { var mailData = new MailContentData(); mailData.MailInfo = new MailInfo(); if (param.Recipients == null && !param.Recipients.Any()) { throw new ArgumentNullException(RecipientNullErrorMessage); } mailData.MailInfo.Recipients = param.Recipients; mailData.MailInfo.Subject = _temperatureFilterConfiguration.Subject; mailData.MailInfo.ContentBody = ApplyTextReplacement(_temperatureFilterConfiguration.EmailTemplate, param); mailData.MailInfo.Sender = _temperatureFilterConfiguration.Sender; mailData.MailInfo.SenderName = _temperatureFilterConfiguration.SenderName; return(mailData); }
public async Task ProcessMessage(ILogger logger) { logger.LogInformation($"NotificationSummaryProcessor : Getting summary email list of notifications." + $"Connecion:{_notificationServiceBusConfiguration.ServiceBusConnection} and queuename: {_notificationServiceBusConfiguration.QueueName}"); var queryParameter = CreateParam(); var totalScan = ComputeTotalSummaryScans(queryParameter, logger); if (totalScan != null) { logger.LogInformation($"View count : {totalScan?.Count()}"); var _messageSender = MessageBusServiceFactory.CreateServiceBusMessageSender(_notificationServiceBusConfiguration, logger); foreach (var item in totalScan) { logger.LogInformation($"Total Amount daily scan - {item.TotalScans}."); var mailParam = new ParseEmailParam(item.CompanyId, item.TotalScans); mailParam.Recipients = _dataProcessor.GetRecipientsByCompanyId(item.CompanyId); mailParam.TotalAbnormalDetected = item.TotalAbnormalScan; var mailData = _summaryMailContentParser.CreateSummaryEmailAlertMessage(mailParam, logger); if (mailData != null) { var messageInstance = MessageConverter.Serialize(mailData); await _messageSender.SendMessagesAsync(messageInstance); logger.LogInformation($"Sent content {messageInstance} data to notification queue."); } else { logger.LogInformation($"No notifcation sent to queue. {DateTime.Now}"); } } } else { logger.LogInformation($"Unable to find any summary record matches in the database.{DateTime.Now}"); } }
private string ApplyTextReplacement(string emailTemplate, ParseEmailParam param) { var replacedContent = emailTemplate.ReplaceContent("###TOTAL_SCANS###", param.TotalScans.ToString()).ReplaceContent("###ABNORMAL_SCANS###", param.TotalAbnormalDetected.ToString()); return(replacedContent); }