Exemplo n.º 1
0
        public override async Task SendPushNotificationTokenAsync(string token, CancellationToken cancellationToken)
        {
            AmazonS3Client s3 = null;

            try
            {
                s3 = await CreateS3ClientAsync();

                // get the token JSON payload
                PushNotificationRequestFormat localFormat = PushNotificationRequest.LocalFormat;
                string localFormatAzureIdentifier = PushNotificationRequest.GetAzureFormatIdentifier(localFormat);
                byte[] tokenBytes = Encoding.UTF8.GetBytes("{" +
                                                             "\"device\":" + JsonConvert.ToString(SensusServiceHelper.Get().DeviceId) + "," + 
                                                             "\"protocol\":" + JsonConvert.ToString(Protocol.Id) + "," + 
                                                             "\"format\":" + JsonConvert.ToString(localFormatAzureIdentifier) + "," +
                                                             "\"token\":" + JsonConvert.ToString(token) +
                                                           "}");
                                                            
                MemoryStream dataStream = new MemoryStream(tokenBytes);

                await PutAsync(s3, dataStream, GetPushNotificationTokenKey(), "application/json", cancellationToken);
            }
            finally
            {
                DisposeS3(s3);
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="T:Sensus.Notifications.PushNotificationRequest"/> class. The
 /// intent of this instance will be to deliver a <see cref="PushNotificationUpdate"/> to the app. This update
 /// does not necessarily have any user-targeted content.
 /// </summary>
 /// <param name="id">Identifier of the request. To update a previously issued request, submit a new request
 /// with the same identifier.</param>
 /// <param name="deviceId">Identifier of target device.</param>
 /// <param name="protocol">Target protocol.</param>
 /// <param name="update">Update.</param>
 /// <param name="format">Format.</param>
 /// <param name="notificationTime">Time to deliver the notification.</param>
 /// <param name="backendKey">Backend storage key. It is reasonable to supply a new <see cref="Guid"/> for each
 /// <see cref="PushNotificationRequest"/> instance.</param>
 public PushNotificationRequest(string id,
                                string deviceId,
                                Protocol protocol,
                                PushNotificationUpdate update,
                                PushNotificationRequestFormat format,
                                DateTimeOffset notificationTime,
                                Guid backendKey)
     : this(id, deviceId, protocol, null, null, null, format, notificationTime, backendKey)
 {
     _update = update;
 }
Exemplo n.º 3
0
 /// <summary>
 /// Gets the Azure format identifier for the native push notification service.
 /// </summary>
 /// <returns>The Azure format identifier.</returns>
 /// <param name="format">Format.</param>
 public static string GetAzureFormatIdentifier(PushNotificationRequestFormat format)
 {
     if (format == PushNotificationRequestFormat.FirebaseCloudMessaging)
     {
         return("gcm");
     }
     else if (format == PushNotificationRequestFormat.ApplePushNotificationService)
     {
         return("apple");
     }
     else
     {
         SensusException.Report("Unrecognized push notification request format:  " + format);
         return("");
     }
 }
Exemplo n.º 4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="T:Sensus.Notifications.PushNotificationRequest"/> class. The
 /// intent of this instance will be to deliver user-targeted information to the device in the form of a
 /// notification with a message title, body, etc.
 /// </summary>
 /// <param name="id">Identifier of the request. To update a previously issued request, submit a new request
 /// with the same identifier.</param>
 /// <param name="deviceId">Identifier of target device.</param>
 /// <param name="protocol">Target protocol.</param>
 /// <param name="title">Title.</param>
 /// <param name="body">Body.</param>
 /// <param name="sound">Sound.</param>
 /// <param name="format">Format.</param>
 /// <param name="notificationTime">Time to deliver the notification.</param>
 /// <param name="backendKey">Backend storage key. It is reasonable to supply a new <see cref="Guid"/> for each
 /// <see cref="PushNotificationRequest"/> instance.</param>
 public PushNotificationRequest(string id,
                                string deviceId,
                                Protocol protocol,
                                string title,
                                string body,
                                string sound,
                                PushNotificationRequestFormat format,
                                DateTimeOffset notificationTime,
                                Guid backendKey)
 {
     _id               = id;
     _deviceId         = deviceId;
     _protocol         = protocol ?? throw new ArgumentNullException(nameof(protocol));
     _title            = title;
     _body             = body;
     _sound            = sound;
     _format           = format;
     _notificationTime = notificationTime;
     _backendKey       = backendKey;
     _creationTime     = DateTimeOffset.UtcNow;
 }