示例#1
0
        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);
        }
示例#2
0
 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)));
     }
 }
示例#3
0
        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)));
        }
示例#4
0
        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));
        }