示例#1
0
        public List <Template> GetTemplates()
        {
            var templates = new List <Template>();

            var exts = new[] { "pdf", "jpg", "jpeg", "png" };

            var path  = ioService.GetTemplateDirectory();
            var files = ioService.EnumerateFiles(path, "*.*")
                        .Where(file => exts.Any(x => file.EndsWith(x, StringComparison.OrdinalIgnoreCase)));

            var thumbnailPath = ioService.GetThumbnailDirectory();

            foreach (var filePath in files)
            {
                if (ioService.IsFileExists(filePath))
                {
                    var fileName = Path.GetFileName(filePath);

                    var template = new Template
                    {
                        Name      = fileName,
                        Path      = filePath,
                        Type      = TemplateTypeEnum.Image,
                        Thumbnail = Path.Combine(thumbnailPath, Path.ChangeExtension(fileName, ".png"))
                    };

                    if (template.Name.EndsWith("pdf", StringComparison.OrdinalIgnoreCase))
                    {
                        template.Type = TemplateTypeEnum.PDF;
                    }

                    templates.Add(template);
                }
            }

            return(templates);
        }