The registration contract for push notifications.
 /// <summary>
 /// Updates the existing registration with the new device registration contract with tags.
 /// </summary>
 /// <param name="registrationId">The registration id of the registration to update.</param>
 /// <param name="deviceRegistrationContract">The device registration contact to update.</param>
 /// <returns>HttpStatusCode of the operation.</returns>
 private async Task<HttpStatusCode> UpdateRegistrationAsync(string registrationId,
     DeviceRegistrationContract deviceRegistrationContract)
 {
     try
     {
         return await _mobileServiceClient.InvokeApiAsync<DeviceRegistrationContract, HttpStatusCode>(
             $"notificationregistration/{registrationId}",
             deviceRegistrationContract,
             HttpMethod.Put,
             null);
     }
     catch (Exception ex)
     {
         throw new ServiceException("Update registration error.", ex);
     }
 }
        /// <summary>
        /// Registers the a notification hub handle with specified notification tags.
        /// </summary>
        /// <param name="handle">The notification handle to register with..</param>
        /// <param name="tags">The tags to register.</param>
        /// <returns>The updated notification registration.</returns>
        public async Task RegisterAsync(string handle, IEnumerable<string> tags)
        {
            var regId = await RetrieveRegistrationIdOrRequestNewOneAsync(handle);

            var deviceRegistrationContract = new DeviceRegistrationContract
            {
                Platform = "wns",
                Handle = handle,
                Tags = tags.ToArray()
            };

            var statusCode = await UpdateRegistrationAsync(regId, deviceRegistrationContract);

            if (statusCode == HttpStatusCode.Gone)
            {
                // Registration id is expired, deleting from local storage & recreating
                var settings = ApplicationData.Current.LocalSettings.Values;
                settings.Remove(LocalNotificationRegistrationId);

                regId = await RetrieveRegistrationIdOrRequestNewOneAsync(handle);
                statusCode = await UpdateRegistrationAsync(regId, deviceRegistrationContract);
            }

            if (statusCode != HttpStatusCode.OK)
            {
                throw new ServiceException("Registering for notification failed.");
            }
        }
        public async Task<HttpStatusCode> Put(string id, DeviceRegistrationContract deviceUpdate)
        {
            RegistrationDescription registration;

            switch (deviceUpdate.Platform)
            {
                case "mpns":
                    registration = new MpnsRegistrationDescription(deviceUpdate.Handle);
                    break;
                case "wns":
                    registration = new WindowsRegistrationDescription(deviceUpdate.Handle);
                    break;
                case "apns":
                    registration = new AppleRegistrationDescription(deviceUpdate.Handle);
                    break;
                case "gcm":
                    registration = new GcmRegistrationDescription(deviceUpdate.Handle);
                    break;
                default:
                    throw new HttpResponseException(HttpStatusCode.BadRequest);
            }

            registration.RegistrationId = id;
            registration.Tags = new HashSet<string>(deviceUpdate.Tags);

            try
            {
                await _hub.CreateOrUpdateRegistrationAsync(registration);
                return HttpStatusCode.OK;
            }
            catch (MessagingException e)
            {
                var webex = e.InnerException as WebException;

                if (webex.Status == WebExceptionStatus.ProtocolError)
                {
                    var response = (HttpWebResponse)webex.Response;

                    if (response.StatusCode == HttpStatusCode.Gone)
                    {
                        // Client will force a refresh for a new id after receiving this message.
                        return HttpStatusCode.Gone;
                    }
                }

                return HttpStatusCode.InternalServerError;
            }
            catch (Exception)
            {
                return HttpStatusCode.InternalServerError;
            }
        }