示例#1
0
 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);
     }
 }
示例#2
0
 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);
     }
 }
示例#3
0
 /// <summary>
 /// Saves the specified template
 /// </summary>
 /// <param name="template"></param>
 /// <returns></returns>
 public virtual bool AddTemplate(NotificationTemplateInfo template)
 {
     return(AddTemplate(template, out string ignore));
 }
示例#4
0
        private string GetFilePath(NotificationTemplateInfo template)
        {
            string fileName = $"{template.Name}.json";

            return(Path.Combine(NotificationTemplateDirectory.FullName, fileName));
        }