Skip to content

Commit

Permalink
Add MailWebRoutinen
Browse files Browse the repository at this point in the history
  • Loading branch information
gdl-reif committed Oct 18, 2023
1 parent d06883e commit 16d4175
Showing 1 changed file with 65 additions and 0 deletions.
65 changes: 65 additions & 0 deletions Gandalan.IDAS.WebApi.Client/BusinessRoutinen/MailWebRoutinen.cs
Original file line number Diff line number Diff line change
@@ -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<JobStatusResponseDTO> Send(MailJobInfo job, List<string> 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<JobStatusResponseDTO>(await PostDataAsync("Mail", content));
//return response;
}

public async Task<IList<JobStatusEntryDTO>> GetStatus(Guid guid) =>
await GetAsync<IList<JobStatusEntryDTO>>($"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; }
}
}

0 comments on commit 16d4175

Please sign in to comment.