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 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)); }