private async Task DeleteRegistrationsForDeviceAsync(string pnsHandle) { var isDeleted = false; while (!isDeleted) { try { await _hub.DeleteRegistrationsByChannelAsync(pnsHandle); isDeleted = true; } catch (MessagingEntityNotFoundException) { // Intentionally doing nothing here // Internally, Azure SDK will delete registrations concurrently with Task.WhenAll. // If at least one deletion fails (e.g. due to a race condition with other delete operation, 404 response is returned), // we need to retry to ensure everything is deleted } catch (MessagingException ex) { throw new PushNotificationException($"Something went wrong during deleting registrations for device handle: '{pnsHandle}'.", ex); } } }
public async Task <bool> DeleteRegistration(string deviceToken) { Trace.TraceInformation("Deleting Registration"); await hub.DeleteRegistrationsByChannelAsync(deviceToken); return(true); }
// POST api/RegisterDevice public void Post([FromBody] string value) { var connectionString = ConfigurationManager.AppSettings["NotificationHubConnectionString"]; var notificationHubName = ConfigurationManager.AppSettings["NotificationHubName"]; NotificationHubClient hub = NotificationHubClient.CreateClientFromConnectionString(connectionString, notificationHubName); // Decode from Base64 string Base64DecodedChannelUri = Encoding.UTF8.GetString(Convert.FromBase64String(value)); hub.DeleteRegistrationsByChannelAsync(Base64DecodedChannelUri).Wait(); hub.CreateWindowsNativeRegistrationAsync(Base64DecodedChannelUri); }
public async Task DeleteRegistrationsByChannelAsync_DeleteAppleNativeRegistrationByChannel_RegistrationIsDeleted() { LoadMockData(); await DeleteAllRegistrationsAndInstallations(); var registration = new AppleRegistrationDescription(_configuration["AppleDeviceToken"]); var createdRegistration = await _hubClient.CreateRegistrationAsync(registration); await _hubClient.DeleteRegistrationsByChannelAsync(_configuration["AppleDeviceToken"]); await Assert.ThrowsAsync <MessagingEntityNotFoundException>(async() => await _hubClient.GetRegistrationAsync <AppleRegistrationDescription>(createdRegistration.RegistrationId)); RecordTestResults(); }
public async Task DeleteRegistrationByDeviceId(string handle) { await _hub.DeleteRegistrationsByChannelAsync(handle); }