forked from ks-no/fiks-io-client-dotnet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMessageSender.cs
42 lines (36 loc) · 1.52 KB
/
MessageSender.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
using System;
using System.Reflection;
using System.Threading.Tasks;
using KS.Fiks.IO.Client;
using KS.Fiks.IO.Client.Models;
using Serilog;
namespace ExampleApplication.FiksIO;
public class MessageSender
{
private readonly IFiksIOClient _fiksIoClient;
private readonly AppSettings _appSettings;
private static readonly ILogger Log = Serilog.Log.ForContext(MethodBase.GetCurrentMethod()?.DeclaringType);
public MessageSender(IFiksIOClient fiksIoClient, AppSettings appSettings)
{
_fiksIoClient = fiksIoClient;
_appSettings = appSettings;
}
public async Task<Guid> Send(string messageType, Guid toAccountId)
{
try
{
var klientMeldingId = Guid.NewGuid();
Log.Information("MessageSender - sending messagetype {MessageType} to account id: {AccountId} with klientMeldingId {KlientMeldingId}", messageType, toAccountId, klientMeldingId);
var sendtMessage = await _fiksIoClient
.Send(new MeldingRequest(_appSettings.FiksIOConfig.FiksIoAccountId, toAccountId, messageType, klientMeldingId: klientMeldingId), "testfile.txt")
.ConfigureAwait(false);
Log.Information("MessageSender - message sendt with messageid: {MessageId}", sendtMessage.MeldingId);
return sendtMessage.MeldingId;
}
catch (Exception e)
{
Log.Error("MessageSender - could not send message to account id {AccountId}. Error: {ErrorMessage}",toAccountId, e.Message);
throw;
}
}
}