public IEnumerable <TemplateContentSummary> GetTemplateVersions(string templateName) { var templates = Directory.GetFiles(TemplatesFolder, "*.docx") .Select(f => new { Path = f, NameParts = Path.GetFileNameWithoutExtension(f).Split('_', 2) }) .Select(a => new { FullName = a.Path, Name = a.NameParts[0], Version = a.NameParts[1] }) .Where(a => a.Name.Equals(templateName, StringComparison.CurrentCultureIgnoreCase)) .Select(a => ContentItemFactory.BuildTemplate(a.FullName, ReadContents(a.FullName))); return(templates); }
public TemplateContent GetTemplate(string templateName, string version = null) { if (string.IsNullOrEmpty(version)) { return(GetLatestTemplate(templateName)); } else { var templateFileName = $"{templateName}_{version}.docx"; var templatePath = Path.Combine(TemplatesFolder, templateFileName); if (!File.Exists(templatePath)) { return(null); } return(ContentItemFactory.BuildTemplate(templatePath, ReadContents(templatePath))); } }
public TemplateContent GetLatestTemplate(string templateName) { if (string.IsNullOrEmpty(templateName)) { throw new ArgumentNullException(nameof(templateName)); } var templateFileName = Directory .GetFiles(TemplatesFolder, $"{templateName}_*.docx") .OrderByDescending(o => o) .FirstOrDefault(); if (templateFileName == null) { return(null); } return(ContentItemFactory.BuildTemplate(templateFileName, ReadContents(templateFileName))); }
public Task <TemplateContent> CreateTemplate(string templateName, Stream contents) { if (string.IsNullOrEmpty(templateName)) { throw new ArgumentNullException(nameof(templateName)); } if (contents == null || contents.Length == 0) { throw new ArgumentNullException(nameof(contents)); } var templateVersionName = $"{templateName}_{DateTime.Now.Ticks}"; var templateFilename = $"{templateVersionName}.docx"; var templatePath = Path.Combine(TemplatesFolder, templateFilename); WriteContents(templatePath, contents); TemplateContent result = ContentItemFactory.BuildTemplate(templatePath, contents); return(Task.FromResult(result)); }