-
Notifications
You must be signed in to change notification settings - Fork 0
/
PushMessage.cs
41 lines (35 loc) · 1.51 KB
/
PushMessage.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
using System;
using Jannesen.FileFormat.Json;
namespace Jannesen.PushNotification
{
public class PushMessage
{
public readonly string DeviceToken;
public readonly JsonObject Payload;
public readonly bool HighPriority;
public readonly DateTime ExpireTime;
public PushMessage(string deviceToken, JsonObject payload, bool highPriority, DateTime expireTime)
{
ArgumentException.ThrowIfNullOrEmpty(deviceToken);
ArgumentNullException.ThrowIfNull(payload);
if (expireTime.Ticks < DateTime.UtcNow.Ticks + TimeSpan.TicksPerMinute)
throw new ArgumentException("Invalid expireTime.");
DeviceToken = deviceToken;
Payload = payload;
HighPriority = highPriority;
ExpireTime = expireTime;
}
public PushMessage(string deviceToken, JsonObject payload, bool highPriority, TimeSpan timeToLive)
{
ArgumentException.ThrowIfNullOrEmpty(deviceToken);
ArgumentNullException.ThrowIfNull(payload);
if (timeToLive.Ticks < TimeSpan.TicksPerMinute)
throw new ArgumentException("Invalid timeToLive.");
DeviceToken = deviceToken;
Payload = payload;
HighPriority = highPriority;
ExpireTime = DateTime.UtcNow + timeToLive;
}
}
}