// POST api/register
        // This creates a registration id
        public async Task <string> Post()
        {
            string value = await Request.Content.ReadAsStringAsync();

            var    entidad = System.Web.Helpers.Json.Decode(value);
            string handle  = entidad.key;


            string newRegistrationId = null;

            // make sure there are no existing registrations for this push handle (used for iOS and Android)
            if (handle != null)
            {
                var registrations = await hub.GetRegistrationsByChannelAsync(handle, 100);

                foreach (RegistrationDescription registration in registrations)
                {
                    if (newRegistrationId == null)
                    {
                        newRegistrationId = registration.RegistrationId;
                    }
                    else
                    {
                        await hub.DeleteRegistrationAsync(registration);
                    }
                }
            }

            if (newRegistrationId == null)
            {
                newRegistrationId = await hub.CreateRegistrationIdAsync();
            }

            return(newRegistrationId);
        }
示例#2
0
        public async Task <RegistrationResponse> CreateRegistration(string handle)
        {
            RegistrationResponse response = new RegistrationResponse();

            string newRegistrationId = null;

            // make sure there are no existing registrations for this push handle (used for iOS and Android)
            if (handle != null)
            {
                var registrations = await _hub.GetRegistrationsByChannelAsync(handle, 100);

                foreach (RegistrationDescription registration in registrations)
                {
                    if (newRegistrationId == null)
                    {
                        newRegistrationId = registration.RegistrationId;
                    }
                    else
                    {
                        await _hub.DeleteRegistrationAsync(registration);
                    }
                }
            }

            if (newRegistrationId == null)
            {
                newRegistrationId = await _hub.CreateRegistrationIdAsync();
            }

            response.RegistrationId = newRegistrationId;
            response.IsSuccess      = true;
            return(response);
        }
        private async Task <Response <string> > GetRegistrationIdForDeviceAsync(string handle)
        {
            Response <string> response = new Response <string>();

            try
            {
                if (!string.IsNullOrEmpty(handle))
                {
                    var registrations = await hub.GetRegistrationsByChannelAsync(handle, 100);

                    foreach (RegistrationDescription registration in registrations)
                    {
                        if (response.Value == null)
                        {
                            response.Value = registration.RegistrationId;
                        }
                        else
                        {
                            await hub.DeleteRegistrationAsync(registration);
                        }
                    }
                }

                if (response.Value == null)
                {
                    response.Value = await hub.CreateRegistrationIdAsync();
                }
            }
            catch (Exception ex)
            {
                response.IsSuccess = false;
                response.Message   = Constants.GENERIC_ERROR_MESSAGE + ex.Message;
            }
            return(response);
        }
示例#4
0
        //POST api/register
        //this creates a registration id
        public async Task <string> Post(string handle = null)
        {
            string newRegistrationId = null;

            if (handle != null)
            {
                var registrations = await hub.GetRegistrationsByChannelAsync(handle, 100);

                foreach (var registration in registrations)
                {
                    if (newRegistrationId == null)
                    {
                        newRegistrationId = registration.RegistrationId;
                    }
                    else
                    {
                        await hub.DeleteRegistrationAsync(registration);
                    }
                }
            }

            if (newRegistrationId == null)
            {
                newRegistrationId = await hub.CreateRegistrationIdAsync();
            }

            return(newRegistrationId);
        }
        // POST api/register
        // This creates a registration id
        public async Task <string> Post(string handle = null)
        {
            string newRegistrationId = null;

            // This is requied - to make uniform handle format, otherwise could have some issue.
            handle = handle.ToUpper();

            // make sure there are no existing registrations for this push handle (used for iOS and Android)
            if (handle != null)
            {
                var registrations = await hub.GetRegistrationsByChannelAsync(handle, 100);

                foreach (RegistrationDescription registration in registrations)
                {
                    if (newRegistrationId == null)
                    {
                        newRegistrationId = registration.RegistrationId;
                    }
                    else
                    {
                        await hub.DeleteRegistrationAsync(registration);
                    }
                }
            }

            if (newRegistrationId == null)
            {
                newRegistrationId = await hub.CreateRegistrationIdAsync();
            }

            return(newRegistrationId);
        }
示例#6
0
        public async Task <string> Post(string handle = null)
        {
            string newRegistrationId = null;

            // make sure there are no existing registrations for this push handle (used for iOS and Android)
            if (handle != null)
            {
                var registrations = await hub.GetRegistrationsByChannelAsync(handle, 100);

                foreach (RegistrationDescription registration in registrations)
                {
                    if (newRegistrationId == null)
                    {
                        newRegistrationId = registration.RegistrationId;
                    }
                    else
                    {
                        await hub.DeleteRegistrationAsync(registration);
                    }
                }
            }

            if (newRegistrationId == null)
            {
                newRegistrationId = await hub.CreateRegistrationIdAsync();
            }

            return(newRegistrationId);
        }
        // POST api/register
        // Cria um id de registro
        public async Task <string> Post(string handle = null)
        {
            string newRegistrationId = null;

            // ter certeza que não existe registros para esse push handle (usado para iOS e Android)
            if (handle != null)
            {
                var registrations = await hub.GetRegistrationsByChannelAsync(handle, 100);

                foreach (RegistrationDescription registration in registrations)
                {
                    if (newRegistrationId == null)
                    {
                        newRegistrationId = registration.RegistrationId;
                    }
                    else
                    {
                        await hub.DeleteRegistrationAsync(registration);
                    }
                }
            }

            if (newRegistrationId == null)
            {
                newRegistrationId = await hub.CreateRegistrationIdAsync();
            }

            return(newRegistrationId);
        }
        public async Task <HttpStatusCode> Delete(string id)
        {
            try
            {
                await _hub.DeleteRegistrationAsync(id);

                return(HttpStatusCode.OK);
            }
            catch (Exception)
            {
                return(HttpStatusCode.InternalServerError);
            }
        }
示例#9
0
        public Task RegisterGoogle(Guid account_id, string deviceToken)
        {
            return(Task.Run(async delegate()
            {
                try
                {
                    NotificationHubClient hubClient = this.HubClient;

                    Account account = this.API.Direct.Accounts.GetById(account_id);
                    string previousRegistrationID = account.push_google;

                    if (!string.IsNullOrEmpty(previousRegistrationID))
                    {
                        if (await hubClient.RegistrationExistsAsync(previousRegistrationID))
                        {
                            await hubClient.DeleteRegistrationAsync(previousRegistrationID);
                        }
                    }

                    string accountTag = string.Format(PushAssumptions.TARGET_ACCOUNT_FORMAT, account_id.ToString().ToLower());

                    var registrations = await hubClient.GetRegistrationsByTagAsync(accountTag, 100);

                    foreach (RegistrationDescription registration in registrations)
                    {
                        if (registration.Tags.Contains("droid"))
                        {
                            await hubClient.DeleteRegistrationAsync(registration);
                        }
                    }

                    List <string> tags = new List <string>();
                    tags.Add(accountTag);
                    tags.Add("droid");


                    GcmRegistrationDescription newRegistration = await hubClient.CreateGcmNativeRegistrationAsync(deviceToken, tags);

                    if (newRegistration != null)
                    {
                        this.API.Direct.Accounts.UpdatePushTokenGoogle(account.account_id, newRegistration.RegistrationId);
                    }
                }
                catch (Exception ex)
                {
                    base.IFoundation.LogError(ex);
                }
            }));
        }
示例#10
0
        public static async Task <string> GetRegistrationIdAsync(NotificationHubClient _hub, string deviceToken = null)
        {
            string newRegistrationId = null;

            if (deviceToken != null)
            {
                var registrations = await _hub.GetRegistrationsByChannelAsync(deviceToken, 50);

                foreach (RegistrationDescription registration in registrations)
                {
                    if (newRegistrationId == null)
                    {
                        newRegistrationId = registration.RegistrationId;
                    }
                    else
                    {
                        await _hub.DeleteRegistrationAsync(registration);
                    }
                }
            }
            if (newRegistrationId == null)
            {
                newRegistrationId = await _hub.CreateRegistrationIdAsync();
            }
            return(newRegistrationId);
        }
示例#11
0
        public async Task <IHttpActionResult> GetRegistrationId(string pns_FCM_Token = null)
        {
            string newRegistrationId = null;


            if (pns_FCM_Token != null)
            {
                var registrations = await _hubClient.GetRegistrationsByChannelAsync(pns_FCM_Token, 10);

                foreach (RegistrationDescription registration in registrations)
                {
                    if (newRegistrationId == null)
                    {
                        newRegistrationId = registration.RegistrationId;
                    }
                    else
                    {
                        await _hubClient.DeleteRegistrationAsync(registration);
                    }
                }
            }

            if (newRegistrationId == null)
            {
                newRegistrationId = await _hubClient.CreateRegistrationIdAsync();
            }

            return(Ok(newRegistrationId));
        }
示例#12
0
文件: Ntfy.cs 项目: jimliuxyz/UW
        /// <summary>
        /// 以tag取得或新建一個azure regId, 並刪除舊id的內容
        /// </summary>
        /// <param name="tag"></param>
        /// <returns></returns>
        private async Task <string> getRegIdAsync(string tag = null)
        {
            string newRegistrationId = null;

            if (tag != null)
            {
                var registrations = await hub.GetRegistrationsByTagAsync(tag, 100);

                foreach (RegistrationDescription registration in registrations)
                {
                    if (newRegistrationId == null)
                    {
                        newRegistrationId = registration.RegistrationId;
                    }
                    else
                    {
                        await hub.DeleteRegistrationAsync(registration);
                    }
                }
            }

            if (newRegistrationId == null)
            {
                newRegistrationId = await hub.CreateRegistrationIdAsync();
            }

            return(newRegistrationId);
        }
示例#13
0
        private static async Task CreateAndDeleteRegistrationAsync(NotificationHubClient nhClient)
        {
            var registrationId = await nhClient.CreateRegistrationIdAsync();

            //var registrationDescr = await nhClient.CreateFcmNativeRegistrationAsync(registrationId);
            var registrationDescr = await nhClient.CreateAppleNativeRegistrationAsync(registrationId);

            //Console.WriteLine($"Created APNS registration {registrationDescr.FcmRegistrationId}");
            Console.WriteLine($"Create APNS registration {registrationDescr.RegistrationId}");

            var allRegistrations = await nhClient.GetAllRegistrationsAsync(1000);

            foreach (var regFromServer in allRegistrations)
            {
                if (regFromServer.RegistrationId == registrationDescr.RegistrationId)
                {
                    //Console.WriteLine($"Found FCM registration {registrationDescr.FcmRegistrationId}");
                    Console.WriteLine($"Found APNS registration {registrationDescr.RegistrationId}");
                    break;
                }
            }

            //commented out by code creator (next 2 lines)
            //registrationDescr = await nhClient.GetRegistrationAsync<FcmRegistrationDescription>(registrationId);
            //Console.WriteLine($"Retrieved FCM registration {registrationDescr.FcmRegistrationId}");

            await nhClient.DeleteRegistrationAsync(registrationDescr);

            //Console.WriteLine($"Deleted FCM registration {registrationDescr.FcmRegistrationId}");
            Console.WriteLine($"Deleted APNS registration {registrationDescr.RegistrationId}");
        }
        /// <summary>
        ///     Unregisters a user in Azure Notifcations Hub.
        /// </summary>
        /// <remarks>
        ///     This will log a warning if the user is registered multiple times
        ///     in the Azure Notification Hub. This will always remove ALL existing
        ///     registrations.
        /// </remarks>
        /// <param name="internalRegistration">Internal registration object.</param>
        public async Task UnregisterAsync(NotificationRegistration internalRegistration)
        {
            if (internalRegistration is null)
            {
                throw new ArgumentNullException(nameof(internalRegistration));
            }

            // Log and exit if no registration exists
            if (!await IsRegisteredAsync(internalRegistration.Id))
            {
                _logger.LogWarning("User is not registered in Azure Notification Hub but does have an internal notification registration, doing nothing.");
                return;
            }
            else
            {
                var externalRegistrations = await _hubClient.GetRegistrationsByTagAsync(internalRegistration.Id.ToString(), 0);

                // Having multiple registrations should never happen, log a warning and skip.
                if (externalRegistrations.Count() > 1)
                {
                    _logger.LogWarning("User is registered multiple times in Azure Notification Hub, cleaning up all of them before making new registration");
                }

                // Remove all existing registrations
                await Task.WhenAll(externalRegistrations.Select(x => _hubClient.DeleteRegistrationAsync(x.RegistrationId)));
            }
        }
示例#15
0
        public async Task <IActionResult> RegisterDevice(string handle)
        {
            string newRegistrationId = null;

            if (handle != null)
            {
                var registrations = await hub.GetRegistrationsByChannelAsync(handle, 100);

                foreach (RegistrationDescription registration in registrations)
                {
                    if (newRegistrationId == null)
                    {
                        newRegistrationId = registration.RegistrationId;
                    }
                    else
                    {
                        await hub.DeleteRegistrationAsync(registration);
                    }
                }
            }

            if (newRegistrationId == null)
            {
                newRegistrationId = await hub.CreateRegistrationIdAsync();
            }

            return(Ok(newRegistrationId));
        }
示例#16
0
        async Task DeleteAllRegistrationsAndInstallations()
        {
            string continuationToken;

            do
            {
                var registrations = await _hubClient.GetAllRegistrationsAsync(100);

                continuationToken = registrations.ContinuationToken;

                foreach (var registrationDescription in registrations)
                {
                    await _hubClient.DeleteRegistrationAsync(registrationDescription.RegistrationId);
                }
            } while (continuationToken != null);
        }
示例#17
0
        public async Task <ApiResult> Register(RegisterPushDto registerPushDto)
        {
            string newRegistrationId = null;

            if (registerPushDto == null)
            {
                return(ErrorApiResult(300, "Какая то херня пришла от тебя братиш"));
            }
            var handle = registerPushDto.Handle;

            // make sure there are no existing registrations for this push handle (used for iOS and Android)
            if (handle != null)
            {
                var registrations = await _hub.GetRegistrationsByChannelAsync(handle, 100);

                foreach (RegistrationDescription registration in registrations)
                {
                    await _hub.DeleteRegistrationAsync(registration);
                }
            }

            newRegistrationId = await _hub.CreateRegistrationIdAsync();

            return(SuccessApiResult(newRegistrationId));
        }
        private static async Task CreateAndDeleteRegistrationAsync(NotificationHubClient nhClient)
        {
            var registrationId = await nhClient.CreateRegistrationIdAsync();

            var registrationDescr = await nhClient.CreateGcmNativeRegistrationAsync(registrationId);

            Console.WriteLine($"Created GCM registration {registrationDescr.GcmRegistrationId}");

            var allRegistrations = await nhClient.GetAllRegistrationsAsync(1000);

            foreach (var regFromServer in allRegistrations)
            {
                if (regFromServer.RegistrationId == registrationDescr.RegistrationId)
                {
                    Console.WriteLine($"Found GCM registration {registrationDescr.GcmRegistrationId}");
                    break;
                }
            }

            //registrationDescr = await nhClient.GetRegistrationAsync<GcmRegistrationDescription>(registrationId);
            //Console.WriteLine($"Retrieved GCM registration {registrationDescr.GcmRegistrationId}");

            await nhClient.DeleteRegistrationAsync(registrationDescr);

            Console.WriteLine($"Deleted GCM registration {registrationDescr.GcmRegistrationId}");
        }
示例#19
0
        public static async Task <bool> SendNotificationAsync(string message, string idNotificacao, bool broadcast = false)
        {
            string[] userTag = new string[1];

            // Obs importantíssima: O username tá na primeira parte do id da
            // notificação antes do ":"(dois pontos). Para mandar broadcast é só
            //enviar o username em branco
            userTag[0] = string.Empty;


            string defaultFullSharedAccessSignature = util.configTools.getConfig("hubnotificacao");
            string hubName = util.configTools.getConfig("hubname");
            string handle  = idNotificacao;//hubName;

            NotificationHubClient _hub = NotificationHubClient.CreateClientFromConnectionString(defaultFullSharedAccessSignature, hubName);
            //await _hub.DeleteRegistrationAsync(idNotificacao);

            //Excluindo registros
            var registrations = await _hub.GetRegistrationsByChannelAsync(handle, 100);

            foreach (RegistrationDescription xregistration in registrations)
            {
                try
                {
                    await _hub.DeleteRegistrationAsync(xregistration);
                }
                catch (Exception ex) { string sm = ex.Message; }
            }


            if (!broadcast)
            {
                string to_tag = idNotificacao.Split(':')[0];
                userTag[0] = "username:"******"{ \"data\" : {\"message\":\"" + message + "\"}}";

            outcome = await _hub.SendGcmNativeNotificationAsync(notif, userTag);

            if (outcome != null)
            {
                if (!((outcome.State == NotificationOutcomeState.Abandoned) ||
                      (outcome.State == NotificationOutcomeState.Unknown)))
                {
                    return(true);
                }
            }
            return(false);
        }
示例#20
0
        public static async void DeleteRegistration(string id)
        {
            NotificationHubClient hub = NotificationHubClient.CreateClientFromConnectionString(Setting.HUB_Path, Setting.HUB_Name);

            await hub.DeleteRegistrationAsync(id);

            ((Window.Current.Content as Frame).Content as MainPage)
            .id_registration.Text = "no registration";
        }
示例#21
0
        public async Task <RegistrationDescription> Register(string platform, string registerId, string key)
        {
            if (!string.IsNullOrEmpty(key))
            {
                await _notificationHubClient.DeleteRegistrationAsync(key);
            }

            switch (platform)
            {
            case "android":
                return(await _notificationHubClient.CreateGcmNativeRegistrationAsync(registerId));

            case "ios":
                return(await _notificationHubClient.CreateAppleNativeRegistrationAsync(registerId));

            default:
                throw new Exception("Not supported platform.");
            }
        }
示例#22
0
 async Task DeleteRegistrationsOnHubByID(NotificationHubClient hub, string id)
 {
     try
     {
         await hub.DeleteRegistrationAsync(id);
     }
     catch (Exception e)
     {
     }
 }
示例#23
0
        private async void OnDeleteDeviceClicked(object sender, RoutedEventArgs e)
        {
            Button             button = sender as Button;
            DeviceRegistration device = (button.DataContext) as DeviceRegistration;

            NotificationHubClient client = NotificationHubClient.CreateClientFromConnectionString(ConnectionString, "uwpsample");
            await client.DeleteRegistrationAsync(device.RegistrationId);

            devices.Remove(device);
        }
        public async Task DeleteAllRegistrationsAsync()
        {
            NotificationHubClient client = NotificationHubClient.CreateClientFromConnectionString(_connectionstring, _hubName);
            var items = await client.GetAllRegistrationsAsync(400);

            foreach (var item in items)
            {
                await client.DeleteRegistrationAsync(item.RegistrationId);
            }
        }
示例#25
0
        public async Task <DeviceRegistrationReturn> Post([FromBody] DeviceRegistration input)
        {
            DeviceRegistrationReturn ret = new DeviceRegistrationReturn();

            ret.success        = true;
            ret.actionRes      = "";
            ret.RegistrationId = null;
            // string newRegistrationId = null;

            // make sure there are no existing registrations for this push handle (used for iOS and Android)
            if (input != null)
            {
                var registrations = await hub.GetRegistrationsByChannelAsync(input.channelURI, 100);


                foreach (RegistrationDescription registration in registrations)
                {
                    if (ret.RegistrationId == null)
                    {
                        ret.RegistrationId = registration.RegistrationId;
                    }
                    else
                    {
                        await hub.DeleteRegistrationAsync(registration);
                    }
                }
            }

            if (ret.RegistrationId == null)
            {
                ret.RegistrationId = await hub.CreateRegistrationIdAsync();
            }

            if (ret.RegistrationId == "" || ret.RegistrationId == null)
            {
                ret.success        = false;
                ret.actionRes      = "Something went wrong";
                ret.RegistrationId = "";
            }

            return(ret);
        }
示例#26
0
        public async Task <HttpResponseMessage> Register(Registration registration)
        {
            // You'd also want to verify that the user in the registration is allowed to register for that tag

            // Get notification hubs registrations for that "username" tag.
            // Usually, you should get only 1, if we get more than one (for example, during development you make mistakes), delete all others
            // The "100" parameter just represents how many registrations to return
            var registrationsForUser = await hub.GetRegistrationsByTagAsync(registration.Username, 100);

            bool firstRegistration    = true;
            bool existingRegistration = false;

            foreach (var reg in registrationsForUser)
            {
                if (firstRegistration)
                {
                    // Update the registration with the incoming channel
                    var winReg = reg as WindowsRegistrationDescription;
                    winReg.ChannelUri = new Uri(registration.Channel);
                    winReg.Tags       = new HashSet <string> {
                        registration.Username
                    };
                    await hub.UpdateRegistrationAsync(winReg);

                    firstRegistration    = false;
                    existingRegistration = true;
                }
                else
                {
                    // Delete other registrations for that user
                    await hub.DeleteRegistrationAsync(reg);
                }
            }

            // Register with the notification hub and listen to the "username" tag, if this is a new registration
            if (!existingRegistration)
            {
                switch (registration.Platform)
                {
                case "WindowsStore":
                    await hub.CreateWindowsNativeRegistrationAsync(registration.Channel, new List <string> {
                        registration.Username
                    });

                    break;

                default:
                    // If the platform isn't supported, return Bad Request
                    return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, registration.Platform + " platform is not supported."));
                }
            }

            return(Request.CreateResponse(HttpStatusCode.OK));
        }
示例#27
0
        async public Task <string> Register(DeviceRegistration registration)
        {
            if (string.IsNullOrWhiteSpace(registration.Handle))
            {
                return(null);
            }

            const string templateBodyAPNS = @"{ ""aps"" : { ""content-available"" : 1, ""alert"" : { ""title"" : ""$(title)"", ""body"" : ""$(message)"", ""badge"":""#(badge)"" } }, ""payload"" : ""$(payload)"" }";
            const string templateBodyFCM  = @"{""data"":{""title"":""$(title)"",""message"":""$(message)"",""payload"":""$(payload)""}}";

            string newRegistrationId = null;
            // make sure there are no existing registrations for this push handle (used for iOS and Android)
            var registrations = await _hub.GetRegistrationsByChannelAsync(registration.Handle, 100);

            foreach (var reg in registrations)
            {
                if (newRegistrationId == null)
                {
                    newRegistrationId = reg.RegistrationId;
                }
                else
                {
                    await _hub.DeleteRegistrationAsync(reg);
                }
            }

            if (newRegistrationId == null)
            {
                newRegistrationId = await _hub.CreateRegistrationIdAsync();
            }

            RegistrationDescription description;

            switch (registration.Platform)
            {
            case "iOS":
                registration.Handle = registration.Handle.Replace("<", "").Replace(">", "").Replace(" ", "").ToUpper();
                description         = new AppleTemplateRegistrationDescription(registration.Handle, templateBodyAPNS, registration.Tags);
                break;

            case "Android":
                description = new GcmTemplateRegistrationDescription(registration.Handle, templateBodyFCM, registration.Tags);
                break;

            default:
                return(null);
            }

            description.RegistrationId = newRegistrationId;
            var result = await _hub.CreateOrUpdateRegistrationAsync(description);

            return(result?.RegistrationId);
        }
示例#28
0
        /// <summary>
        /// 指定された ID の登録を削除します
        /// </summary>
        public async Task <IHttpActionResult> Delete(DeleteRegistrationFormModel data)
        {
            // 送信されたデータが正しいか検証する
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            // ID に紐付く登録を削除
            await _client.DeleteRegistrationAsync(data.RegistrationId);

            return(Ok());
        }
示例#29
0
        ///
        /// <summary>
        /// Delete registration ID from Azure Notification Hub
        /// </summary>
        /// <param name="registrationId"></param>
        public async Task <HubResponse> DeleteRegistration(string registrationId)
        {
            try
            {
                await _hubClient.DeleteRegistrationAsync(registrationId);

                return(new HubResponse());
            }
            catch (Exception ex)
            {
                return(new HubResponse().AddErrorMessage("Deletion of Registration failed!. PLease register once again. \n Exception Message:" + ex.Message.ToString()));
            }
        }
示例#30
0
        public async Task <RegistrationDescription> Register(Guid userId, string installationId, string deviceToken)
        {
            if (Guid.Empty == userId)
            {
                throw new ArgumentException("userId");
            }

            // Get registrations for the current installation ID.
            var regsForInstId = await hubClient.GetRegistrationsByTagAsync(installationId, 100);


            var updated           = false;
            var firstRegistration = true;
            RegistrationDescription registration = null;

            // Check for existing registrations.
            foreach (var registrationDescription in regsForInstId)
            {
                if (firstRegistration)
                {
                    // Update the tags.
                    registrationDescription.Tags = new HashSet <string>()
                    {
                        installationId, userId.ToString()
                    };

                    var iosReg = registrationDescription as AppleRegistrationDescription;
                    iosReg.DeviceToken = deviceToken;
                    registration       = await hubClient.UpdateRegistrationAsync(iosReg);

                    updated           = true;
                    firstRegistration = false;
                }
                else
                {
                    await hubClient.DeleteRegistrationAsync(registrationDescription);
                }
            }

            if (!updated)
            {
                registration = await hubClient.CreateAppleNativeRegistrationAsync(deviceToken,
                                                                                  new string[] { installationId, userId.ToString() });
            }

            // Send out a welcome notification.
            await this.Send(userId, "Thanks for registering");

            return(registration);
        }