From 16d41750f6ea73e9e76ef5fcb42f260c6ab46d93 Mon Sep 17 00:00:00 2001 From: Phil Reif Date: Wed, 18 Oct 2023 15:04:27 +0200 Subject: [PATCH] Add MailWebRoutinen --- .../BusinessRoutinen/MailWebRoutinen.cs | 65 +++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 Gandalan.IDAS.WebApi.Client/BusinessRoutinen/MailWebRoutinen.cs diff --git a/Gandalan.IDAS.WebApi.Client/BusinessRoutinen/MailWebRoutinen.cs b/Gandalan.IDAS.WebApi.Client/BusinessRoutinen/MailWebRoutinen.cs new file mode 100644 index 00000000..53b6a062 --- /dev/null +++ b/Gandalan.IDAS.WebApi.Client/BusinessRoutinen/MailWebRoutinen.cs @@ -0,0 +1,65 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Net.Http; +using System.Threading.Tasks; +using Gandalan.IDAS.Client.Contracts.Contracts; +using Gandalan.IDAS.WebApi.Client.Mail; +using Newtonsoft.Json; + +namespace Gandalan.IDAS.WebApi.Client.BusinessRoutinen +{ + public class MailWebRoutinen : WebRoutinenBase + { + public MailWebRoutinen(IWebApiConfig settings) : base(settings) + { + } + + public async Task Send(MailJobInfo job, List attachments) + { + MultipartFormDataContent content = new MultipartFormDataContent(); + content.Add(new StringContent(JsonConvert.SerializeObject(job)), "jobAsString"); + if (attachments != null && attachments.Count > 0) + { + foreach (var attachment in attachments) + { + // read each file and add it to the multipart form data + var fileContent = new ByteArrayContent(File.ReadAllBytes(attachment)); + fileContent.Headers.ContentDisposition = new System.Net.Http.Headers.ContentDispositionHeaderValue("attachment") + { + FileName = Path.GetFileName(attachment) + }; + content.Add(fileContent, "files", Path.GetFileName(attachment)); + } + } + await PostDataAsync("Mail", content, version : "2.0"); + return new JobStatusResponseDTO(); + //var response = JsonConvert.DeserializeObject(await PostDataAsync("Mail", content)); + //return response; + } + + public async Task> GetStatus(Guid guid) => + await GetAsync>($"Mail/{guid}"); + } + + public sealed class JobStatusEntryDTO + { + public Guid JobGuid { get; set; } + public DateTime Timestamp { get; set; } + public string StatusText { get; set; } + public Guid RowKey { get; private set; } + + public JobStatusEntryDTO(Guid jobGuid, string statusText) + { + JobGuid = jobGuid; + RowKey = Guid.NewGuid(); + StatusText = statusText; + Timestamp = DateTime.UtcNow; + } + } + + public sealed class JobStatusResponseDTO + { + public Guid JobGuid { get; set; } + } +}