Ejemplo n.º 1
0
 private void AddPushNotificationRequestToSend(PushNotificationRequest pushNotificationRequest)
 {
     lock (_pushNotificationRequestsToSend)
     {
         if (!_pushNotificationRequestsToSend.Any(p => p.BackendKey == pushNotificationRequest.BackendKey))
         {
             _pushNotificationRequestsToSend.Add(pushNotificationRequest);
         }
     }
 }
Ejemplo n.º 2
0
        public async Task SendPushNotificationRequestAsync(PushNotificationRequest request, CancellationToken cancellationToken)
        {
            // request can be null (e.g., if being called when working with the app-level health test callback, which has no associated protocol)
            if (request == null)
            {
                return;
            }

            // if the PNR targets the current device but the protocol isn't listening, then don't send the request. this
            // will eliminate unnecessary network traffic and prevent invalid PNRs from accumulating in the backend.
            if (request.DeviceId == SensusServiceHelper.Get().DeviceId)
            {
                if (string.IsNullOrWhiteSpace(request.Protocol.PushNotificationsHub) || string.IsNullOrWhiteSpace(request.Protocol.PushNotificationsSharedAccessSignature))
                {
                    SensusServiceHelper.Get().Logger.Log("PNR targets current device, which is not listening for PNs. Not sending PNR.", LoggingLevel.Normal, GetType());
                    return;
                }
            }

            // send the push notification request to the remote data store
            try
            {
                await request.Protocol.RemoteDataStore.SendPushNotificationRequestAsync(request, cancellationToken);

                RemovePushNotificationRequestToSend(request.BackendKey);
            }
            catch (Exception sendException)
            {
                SensusServiceHelper.Get().Logger.Log("Exception while sending push notification request:  " + sendException.Message, LoggingLevel.Normal, GetType());

                AddPushNotificationRequestToSend(request);
            }
            finally
            {
                // we just attempted to send the push notification request, so it does not make sense for the
                // request to be pending deletion. remove any pending push notification deletions.
                RemovePushNotificationRequestToDelete(request.BackendKey);
            }
        }