public static void GenerateDefaultTemplates() { var systemWordTemplates = Database.Query <SystemWordTemplateEntity>().Where(se => !se.WordTemplates().Any()).ToList(); List <string> exceptions = new List <string>(); foreach (var se in systemWordTemplates) { try { var defaultTemplate = SystemWordTemplateLogic.CreateDefaultTemplate(se); if (defaultTemplate != null) { defaultTemplate.Save(); } } catch (Exception ex) { exceptions.Add("{0} in {1}:\r\n{2}".FormatWith(ex.GetType().Name, se.FullClassName, ex.Message.Indent(4))); } } if (exceptions.Any()) { throw new Exception(exceptions.ToString("\r\n\r\n")); } }
private static SqlPreCommand Regenerate(WordTemplateEntity template, Replacements replacements) { var newTemplate = SystemWordTemplateLogic.CreateDefaultTemplate(template.SystemWordTemplate); if (newTemplate == null) { return(null); } var file = template.Template.Retrieve(); using (file.AllowChanges()) { file.BinaryFile = newTemplate.Template.Entity.BinaryFile; file.FileName = newTemplate.Template.Entity.FileName; return(Schema.Current.Table <FileEntity>().UpdateSqlSync(file, comment: "WordTemplate Regenerated: " + template.Name)); } }