/
SendNotificationOperationIdentifier.cs
74 lines (65 loc) · 2.26 KB
/
SendNotificationOperationIdentifier.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
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
70
71
72
73
74
using System.Text.Json;
using System.Text.Json.Serialization;
namespace Altinn.Notifications.Email.Core
{
/// <summary>
/// Class grouping identifiers of a notificaiton and operation
/// </summary>
public class SendNotificationOperationIdentifier
{
/// <summary>
/// The notification id
/// </summary>
public Guid NotificationId { get; set; }
/// <summary>
/// The send operation id
/// </summary>
public string OperationId { get; set; } = string.Empty;
/// <summary>
/// When the operation id was last checked against the send client
/// </summary>
public DateTime LastStatusCheck { get; set; } = DateTime.UtcNow;
/// <summary>
/// Json serializes the <see cref="SendNotificationOperationIdentifier"/>
/// </summary>
public string Serialize()
{
return JsonSerializer.Serialize(
this,
new JsonSerializerOptions
{
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull,
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
Converters = { new JsonStringEnumConverter() }
});
}
/// <summary>
/// Try to parse a json string into a<see cref="SendNotificationOperationIdentifier"/>
/// </summary>
public static bool TryParse(string input, out SendNotificationOperationIdentifier value)
{
SendNotificationOperationIdentifier? parsedOutput;
value = new SendNotificationOperationIdentifier();
if (string.IsNullOrEmpty(input))
{
return false;
}
try
{
parsedOutput = JsonSerializer.Deserialize<SendNotificationOperationIdentifier>(
input!,
new JsonSerializerOptions()
{
PropertyNameCaseInsensitive = true
});
value = parsedOutput!;
return value.NotificationId != Guid.Empty;
}
catch
{
// try parse, we simply return false if fails
}
return false;
}
}
}