-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMeshSendCaasSubscribe.cs
More file actions
69 lines (57 loc) · 2.23 KB
/
MeshSendCaasSubscribe.cs
File metadata and controls
69 lines (57 loc) · 2.23 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
namespace Common;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using NHS.MESH.Client.Contracts.Services;
using NHS.MESH.Client.Models;
using ParquetSharp;
using ParquetSharp.IO;
public class MeshSendCaasSubscribe : IMeshSendCaasSubscribe
{
private ILogger<MeshSendCaasSubscribe> _logger;
private IMeshOutboxService _meshOutboxService;
private MeshSendCaasSubscribeConfig _config;
public MeshSendCaasSubscribe(ILogger<MeshSendCaasSubscribe> logger, IMeshOutboxService meshOutboxService, IOptions<MeshSendCaasSubscribeConfig> config)
{
_logger = logger;
_meshOutboxService = meshOutboxService;
_config = config.Value;
}
public async Task<string> SendSubscriptionRequest(long nhsNumber, string toMailbox, string fromMailbox)
{
var content = CreateParquetFile(nhsNumber);
FileAttachment file = new FileAttachment
{
FileName = "CaaSSubscribe.parquet",
Content = content,
ContentType = "application/octet-stream"
};
await File.WriteAllBytesAsync("Testpremesh.parquet", content);
var result = await _meshOutboxService.SendCompressedMessageAsync(fromMailbox, toMailbox, _config.SendCaasWorkflowId, file);
if (!result.IsSuccessful)
{
_logger.LogError("Could't send mesh message Error Code: {ErrorCode}, Error Description: {ErrorDescription}, ", result.Error.ErrorCode, result.Error.ErrorDescription);
return null;
}
return result.Response.MessageId;
}
private static byte[] CreateParquetFile(long nhsNumber)
{
var columns = new Column[]
{
new Column<long>("nhs_number"),
};
long[] nhsNumberList = { nhsNumber };
using var stream = new MemoryStream();
using var writer = new ManagedOutputStream(stream);
using (var file = new ParquetFileWriter(writer, columns))
{
using var rowGroup = file.AppendRowGroup();
using (var nhsNumberColumn = rowGroup.NextColumn().LogicalWriter<long>())
{
nhsNumberColumn.WriteBatch(nhsNumberList);
}
}
return stream.ToArray();
}
}