예제 #1
0
        public async Task <DocumentRecord> CreateNoticeDocument(
            ProcessingInformation principalInformation,
            Mandate mandate)
        {
            var templatePath = GetFullPathToPDFForm(principalInformation.DocumentTemplate, _options.TemplateDirectory);
            var outputName   = $"{Guid.NewGuid().ToString("N")}.pdf";
            var memorystream = new MemoryStream();
            var outputWriter = new PdfWriter(memorystream);

            outputWriter.SetCloseStream(false);

            var          pdf    = new PdfDocument(new PdfReader(templatePath), outputWriter);
            var          form   = PdfAcroForm.GetAcroForm(pdf, true);
            var          fields = form.GetFormFields();
            PdfFormField toSet;

            foreach (var valuePair in principalInformation.FormParameters)
            {
                if (fields.TryGetValue(valuePair.Key, out toSet))
                {
                    toSet.SetValue(valuePair.Value);
                }
                else
                {
                    throw new DocumentServiceException($"Key {valuePair.Key} does not exist in form parameters");
                }
            }

            form.FlattenFields();
            pdf.Close();
            memorystream.Seek(0, SeekOrigin.Begin);
            await _noticeStorage.UploadFileFromStream(outputName, memorystream);

            return(new DocumentRecord
            {
                DocumentName = outputName,
                WasSuccessful = true
            });
        }
예제 #2
0
        internal async Task <string> ArchiveMessage(MimeMessage message)
        {
            string filename = $"{Guid.NewGuid().ToString("N")}.eml";

            try
            {
                var memoryStream = new MemoryStream();

                message.WriteTo(memoryStream);

                memoryStream.Seek(0, SeekOrigin.Begin);

                await _noticeStorage.UploadFileFromStream(filename, memoryStream);

                return(filename);
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.Message, ex);
                throw new EmailServiceException(ex);
            }
        }