-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
65 additions
and
0 deletions.
There are no files selected for viewing
65 changes: 65 additions & 0 deletions
65
Gandalan.IDAS.WebApi.Client/BusinessRoutinen/MailWebRoutinen.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; } | ||
} | ||
} |