public NotificationParameter[] ResolveNotificationParameters(Notification notification) { var retVal = new List<NotificationParameter>(); var properties = notification.GetType().GetProperties().Where(p => p.GetCustomAttributes(typeof(NotificationParameterAttribute), true).Any()).ToList(); if (properties.Count > 0) { foreach (var property in properties) { var attributes = property.GetCustomAttributes(typeof(NotificationParameterAttribute), true); retVal.Add(new NotificationParameter { ParameterName = property.Name, ParameterDescription = attributes.Length > 0 ? ((NotificationParameterAttribute)(attributes[0])).Description : string.Empty, ParameterCodeInView = GetLiquidCodeOfParameter(property.Name), IsDictionary = property.PropertyType.IsAssignableFrom(typeof(IDictionary)), IsArray = property.PropertyType.IsArray, Type = GetParameterType(property) }); } } return retVal.ToArray(); }
public void ResolveTemplate(Notification notification) { var parameters = ResolveNotificationParameters(notification); var myDict = new Dictionary<string, object>(); foreach (var parameter in parameters) { myDict.Add(parameter.ParameterName, notification.GetType().GetProperty(parameter.ParameterName).GetValue(notification)); } var template = notification.NotificationTemplate; var templateSender = Template.Parse(template.Sender); var sender = templateSender.Render(Hash.FromDictionary(myDict)); if (!string.IsNullOrEmpty(sender)) { notification.Sender = sender; } var templateRecipient = Template.Parse(template.Recipient); var recipient = templateRecipient.Render(Hash.FromDictionary(myDict)); if (!string.IsNullOrEmpty(recipient)) { notification.Recipient = recipient; } var templateSubject = Template.Parse(template.Subject); notification.Subject = templateSubject.Render(Hash.FromDictionary(myDict)); var templateBody = Template.Parse(template.Body); notification.Body = templateBody.Render(Hash.FromDictionary(myDict)); }
public static webModels.Notification ToWebModel(this coreModels.Notification notification) { webModels.Notification retVal = new webModels.Notification(); retVal.InjectFrom(notification); retVal.IsEmail = notification.NotificationSendingGateway is IEmailNotificationSendingGateway; retVal.IsSms = notification.NotificationSendingGateway is ISmsNotificationSendingGateway; return(retVal); }
public void ResolveTemplate(Notification notification) { var parameters = ResolveNotificationParameters(notification); var myDict = new Dictionary<string, object>(); foreach (var parameter in parameters) { myDict.Add(parameter.ParameterName, notification.GetType().GetProperty(parameter.ParameterName).GetValue(notification)); } var templateSubject = Template.Parse(notification.NotificationTemplate.Subject); notification.Subject = templateSubject.Render(Hash.FromDictionary(myDict)); var templateBody = Template.Parse(notification.NotificationTemplate.Body); notification.Body = templateBody.Render(Hash.FromDictionary(myDict)); }
public SendNotificationResult SendNotification(Notification notification) { var retVal = new SendNotificationResult(); try { MailMessage mailMsg = new MailMessage(); //To email mailMsg.To.Add(new MailAddress(notification.Recipient)); //From email mailMsg.From = new MailAddress(notification.Sender); mailMsg.ReplyToList.Add(mailMsg.From); mailMsg.Subject = notification.Subject; mailMsg.Body = notification.Body; mailMsg.IsBodyHtml = true; var login = _settingsManager.GetSettingByName(_smtpClientLoginSettingName).Value; var password = _settingsManager.GetSettingByName(_smtpClientPasswordSettingName).Value; var host = _settingsManager.GetSettingByName(_smtpClientHostSettingName).Value; var port = _settingsManager.GetSettingByName(_smtpClientPortSettingName).Value; var useSsl = _settingsManager.GetValue(_smtpClientUseSslSettingName, false); SmtpClient smtpClient = new SmtpClient(host, Convert.ToInt32(port)); System.Net.NetworkCredential credentials = new System.Net.NetworkCredential(login, password); smtpClient.Credentials = credentials; smtpClient.EnableSsl = useSsl; smtpClient.Send(mailMsg); retVal.IsSuccess = true; } catch (Exception ex) { retVal.ErrorMessage = ex.Message + ex.InnerException; } return retVal; }
public SendNotificationResult SendNotification(Notification notification) { var retVal = new SendNotificationResult(); var mail = new SendGridMessage(); mail.From = new MailAddress(notification.Sender); mail.ReplyTo = new[] { mail.From }; mail.AddTo(notification.Recipient); mail.Subject = notification.Subject; mail.Html = notification.Body; var userName = _settingsManager.GetSettingByName(_sendGridUserNameSettingName).Value; var password = _settingsManager.GetSettingByName(_sendGridPasswordSettingName).Value; var credentials = new NetworkCredential(userName, password); var transportWeb = new Web(credentials); try { Task.Run(async () => await transportWeb.DeliverAsync(mail)).Wait(); retVal.IsSuccess = true; } catch (Exception ex) { retVal.ErrorMessage = ex.Message; var invalidApiRequestException = ex.InnerException as InvalidApiRequestException; if (invalidApiRequestException != null) { if (invalidApiRequestException.Errors != null && invalidApiRequestException.Errors.Length > 0) { retVal.ErrorMessage = string.Join(" ", invalidApiRequestException.Errors); } } } return retVal; }
public bool ValidateNotification(Notification notification) { throw new NotImplementedException(); }
public bool ValidateNotification(Notification notification) { var retVal = ValidateNotificationRecipient(notification.Recipient); return retVal; }