示例#1
0
        /// <summary>
        /// Register a particular channelUri
        /// </summary>
        /// <param name="channelUri">The channelUri to register</param>
        /// <param name="tags">The tags to register to receive notifcations from</param>
        /// <returns>Task that completes when registration is complete</returns>
        public Task RegisterNativeAsync(string channelUri, IEnumerable<string> tags)
        {
            if (string.IsNullOrWhiteSpace(channelUri))
            {
                throw new ArgumentNullException("channelUri");
            }

            var registration = new Registration(channelUri, tags);
            return this.RegistrationManager.RegisterAsync(registration);
        }
        public async Task CreateOrUpdateRegistrationAsync(Registration registration)
        {
            var regId = registration.RegistrationId;

            // Ensures RegistrationId is not serialized and sent to service.
            registration.RegistrationId = null;

            var content = JsonConvert.SerializeObject(registration);
            await this.client.HttpClient.RequestAsync(HttpMethod.Put, string.Format("/push/registrations/{0}", Uri.EscapeUriString(regId)), this.client.CurrentUser, content, ensureResponseContent: false);
            
            // Ensure local storage is updated properly
            registration.RegistrationId = regId;
        }
        /// <summary>
        /// If local storage does not have this registrationName, we will create a new one.
        /// If local storage has this name, we will call update.
        /// If update failed with 404(not found), we will create a new one.
        /// </summary>
        /// <param name="registration"></param>
        /// <returns></returns>
        public async Task RegisterAsync(Registration registration)
        {
            // if localStorage is empty or has different storage version, we need retrieve registrations and refresh local storage
            if (this.LocalStorageManager.IsRefreshNeeded)
            {
                string refreshDeviceId = string.IsNullOrEmpty(this.LocalStorageManager.PushHandle) ? registration.PushHandle : this.LocalStorageManager.PushHandle;
                await this.RefreshRegistrationsForChannelAsync(refreshDeviceId);
                this.LocalStorageManager.RefreshFinished(refreshDeviceId);
            }

            var cached = this.LocalStorageManager.GetRegistration(registration.Name);
            if (cached != null)
            {
                registration.RegistrationId = cached.RegistrationId;
            }
            else
            {
                await this.CreateRegistrationIdAsync(registration);
            }

            try
            {
                await this.UpsertRegistration(registration);
                return;
            }
            catch (MobileServiceInvalidOperationException e)
            {
                // if we get an RegistrationGoneException (410) from service, we will recreate registration id and will try to do upsert one more time.
                // The likely cause of this is an expired registration in local storage due to a long unused app.
                if (e.Response.StatusCode != HttpStatusCode.Gone)
                {
                    throw;
                }
            }

            // recreate registration id if we encountered a previously expired registrationId
            await this.CreateRegistrationIdAsync(registration);
            await this.UpsertRegistration(registration);
        }        
        /// <summary>
        /// Register for notifications
        /// </summary>
        /// <param name="registration">The object defining the registration</param>
        /// <returns>Task that will complete when the registration is completed</returns>
        public Task RegisterAsync(Registration registration)
        {
            if (registration == null)
            {
                throw new ArgumentNullException("registration");
            }

            if (string.IsNullOrWhiteSpace(registration.PushHandle))
            {
                throw new ArgumentNullException("registration.deviceId");
            }

            return this.RegistrationManager.RegisterAsync(registration);
        }
 private async Task UpsertRegistration(Registration registration)
 {
     await this.PushHttpClient.CreateOrUpdateRegistrationAsync(registration);
     this.LocalStorageManager.UpdateRegistrationByName(registration.Name, registration.RegistrationId, registration.PushHandle);
 }
 private async Task<Registration> CreateRegistrationIdAsync(Registration registration)
 {
     registration.RegistrationId = await this.PushHttpClient.CreateRegistrationIdAsync();
     this.LocalStorageManager.UpdateRegistrationByName(registration.Name, registration.RegistrationId, registration.PushHandle);
     return registration;
 }
示例#7
0
        /// <summary>
        /// Register for notifications
        /// </summary>
        /// <param name="registration">The object defining the registration</param>
        /// <returns>Task that will complete when the registration is completed</returns>
        public Task RegisterAsync(Registration registration)
        {
            if (registration == null)
            {
                throw new ArgumentNullException("registration");
            }

            if (string.IsNullOrWhiteSpace(registration.ChannelUri))
            {
                throw new ArgumentNullException("registration.ChannelUri");
            }

            return this.RegistrationManager.RegisterAsync(registration);
        }
示例#8
0
        async Task UpsertRegistration(Registration registration)
        {
            await this.PushHttpClient.CreateOrUpdateRegistrationAsync(registration);

            this.LocalStorageManager.UpdateRegistrationByName(registration.Name, registration.RegistrationId, registration.ChannelUri);
        }