Example #1
0
        public Task <DocumentContent> CreateDocument(string templateName, string mappingName, Stream contents)
        {
            if (string.IsNullOrEmpty(templateName))
            {
                throw new ArgumentNullException(nameof(templateName));
            }
            if (string.IsNullOrEmpty(mappingName))
            {
                throw new ArgumentNullException(nameof(mappingName));
            }
            if (contents == null || contents.Length <= 0)
            {
                throw new ArgumentNullException(nameof(contents));
            }

            var templateVersion = GetLatestTemplateVersion(templateName);

            if (templateVersion == null)
            {
                throw new ArgumentException($"Template {templateName} not found.");
            }
            var mappingVersion = GetLatestMappingVersion(templateName, templateVersion, mappingName);

            if (mappingVersion == null)
            {
                throw new ArgumentException($"Mapping {mappingName} not found.");
            }

            var documentFileName = Path.Combine(DocumentsFolder, $"{templateName}_{templateVersion}_{mappingName}_{mappingVersion}_{DateTime.Now.Ticks}.docx");

            WriteContents(documentFileName, contents);
            var result = ContentItemFactory.BuildDocument(documentFileName, contents);

            return(Task.FromResult(result));
        }
Example #2
0
        public DocumentContent GetDocument(string documentId)
        {
            if (string.IsNullOrEmpty(documentId))
            {
                throw new ArgumentNullException(nameof(documentId));
            }
            var pathPattern      = $"*_{documentId}.docx";
            var documentFileName = Directory
                                   .GetFiles(DocumentsFolder, pathPattern)
                                   .FirstOrDefault();

            if (documentFileName == null)
            {
                return(null);
            }

            return(ContentItemFactory.BuildDocument(documentFileName, ReadContents(documentFileName)));
        }