/// <summary> /// Creates a new registration (or updates an existing one) as specified /// in the registration parameter. Depending upon the type of the registration /// parameter (Registration or TemplateRegistration), the registration of a native /// or template notification is created or updated. /// </summary> /// <param name="registration"></param> /// <returns></returns> public async Task<Registration> RegisterAsync(Registration registration) { try { return await registerInternal(registration); } catch (Exception ex) { throw ex; } }
/// <summary> /// Asynchronously registers the device for native notifications. /// </summary> /// <param name="channelUri"></param> /// <param name="tags"></param> /// <returns></returns> public async Task<Registration> RegisterNativeAsync(string channelUri, IEnumerable<string> tags) { if (String.IsNullOrEmpty(channelUri)) { throw new ArgumentException("channelUri"); } Registration registration = new Registration(channelUri, tags); try { return await registerInternal(registration); } catch (Exception ex) { throw ex; } }
public void RegisterForRemoteHubNotifications(string notificationHubName, string connectionString, string channelName, string[] tags) { var channel = HttpNotificationChannel.Find(channelName); if (channel == null) { channel = new HttpNotificationChannel(channelName); channel.Open(); channel.BindToShellToast(); } channel.ChannelUriUpdated += new EventHandler <NotificationChannelUriEventArgs>(async(o, args) => { Hub = new NotificationHub(notificationHubName, connectionString); Microsoft.WindowsAzure.Messaging.Registration registration = await Hub.RegisterNativeAsync(args.ChannelUri.ToString(), tags); if (this.NotificationRegistered != null) { this.NotificationRegistered(this, new AzureNotificationEventArgs("Success", registration.RegistrationId)); } Console.WriteLine("RegisterForRemoteHubNotifications completed"); }); }
private async Task<Registration> upsertRegistrationInternal(Registration registration) { Connection conn = new Connection(Connection); String resource = Path + "/Registrations/" + registration.RegistrationId; String content = registration.ToXml(); try { String response = await conn.executeRequest(resource, content, XML_CONTENT_TYPE, HttpMethod.Put, null); Registration result = new Registration(); result.loadXml(response, Path); storeRegistrationId(result.Name, result.RegistrationId, registration.ChannelUri); return result; } catch (Exception ex) { throw ex; } }
private async Task<Registration> registerInternal(Registration registration) { String registrationId = retrieveRegistrationId(); if (String.IsNullOrWhiteSpace(registrationId)) { try { registrationId = await createRegistrationId(); } catch (Exception ex) { throw ex; } } registration.RegistrationId = registrationId; try { return await upsertRegistrationInternal(registration); } catch (RegistrationGoneException ex) { throw ex; // if we get an RegistrationGoneException (410) from service, we will recreate registration id and will try to do upsert one more time. } catch (Exception ex) { throw ex; } registrationId = await createRegistrationId(); registration.RegistrationId = registrationId; try { return await upsertRegistrationInternal(registration); } catch (Exception ex) { throw ex; } }
/// <summary> /// Asynchronously deletes the registration identified by the registration object /// specified by the registration parameter. Note that the registration object must /// have a non-null RegistrationId property. /// </summary> /// <param name="registration"></param> /// <returns></returns> public async Task UnregisterAsync(Registration registration) { if (!String.IsNullOrWhiteSpace(registration.RegistrationId)) { try { await deleteRegistrationInternal(registration.RegistrationId); } catch (Exception ex) { throw ex; } } }