public bool AddTemplate(NotificationTemplateInfo template, out string filePath) { filePath = string.Empty; try { filePath = GetFilePath(template); NotificationTemplateInfo copy = template.CopyAs <NotificationTemplateInfo>(); Templates.AddTemplate(copy.Name, copy.Content); copy.Content = null; copy.Save(filePath); return(true); } catch (Exception ex) { Logger.AddEntry("Error adding template {0}: {1}", ex, template?.PropertiesToLine(), ex.Message); return(false); } }
public bool TemplateNotify(string recipientIdentifier, string templateName, object data, string subject = null) { try { NotificationTemplateInfo template = GetTemplate(templateName); return(Notify( recipientIdentifier, new EmailBody { IsHtml = template.IsHtml, Content = Templates.Render(template.Name, data) }, subject ?? template.Subject ?? DefaultSubject )); } catch (Exception ex) { Logger.AddEntry("Error sending notification to ({0}) using template ({1}) with data ({2}): '{3}'", ex, recipientIdentifier, templateName, data?.PropertiesToLine() ?? "[null]", ex.Message); return(false); } }
/// <summary> /// Saves the specified template /// </summary> /// <param name="template"></param> /// <returns></returns> public virtual bool AddTemplate(NotificationTemplateInfo template) { return(AddTemplate(template, out string ignore)); }
private string GetFilePath(NotificationTemplateInfo template) { string fileName = $"{template.Name}.json"; return(Path.Combine(NotificationTemplateDirectory.FullName, fileName)); }