public async Task <PushChannelConfiguration> RegisterAsync(string userId, PushChannelRegistration registration) { var config = await pushConfigurationStore.RegisterAsync(userId, registration); var provider = await pushProviderFactory.CreateProvider(config); await provider.InitializeAsync(); return(config); }
public async void RegisterPushChannel() { var channel = await PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync(); var oldChannel = (localSettings.Values["PushChannelUri"] as string); if (null == oldChannel || oldChannel != channel.Uri) { var hub = new NotificationHub(notificationHubName, notificationHubEndpoint); var result = await hub.RegisterNativeAsync(channel.Uri); if (result.RegistrationId != null) { var pushChannelRegistration = new PushChannelRegistration() { Uri = result.RegistrationId }; try //retry here because it's one of the calls where the user is active { await client.SetupPushChannelAsync(pushChannelRegistration); } catch (UnauthorizedException) { var authenticationProvider = DigitServiceBuilder.AuthenticationProvider(); await authenticationProvider.AuthenticateUser(); try { await client.SetupPushChannelAsync(pushChannelRegistration); } catch (UnauthorizedException e) { await client.LogAsync($"Authorization error while push channel registration: {e.Message}", 3); return; } } catch (DigitServiceException s) { await client.LogAsync($"Failed to register notification channel: {s.Message}", 3); return; } localSettings.Values["PushChannelUri"] = channel.Uri; await client.LogAsync($"Successfully registered notification channel {result.RegistrationId}", 1); } else { await client.LogAsync($"Failed to register channel at hub", -1); } } }
public async Task UpdateAsync(string userId, string configurationId, PushChannelRegistration registration) { var channel = configurationContext.PushChannelConfigurations.Include(v => v.Options).Where(v => v.UserId == userId && v.Id == configurationId).Single(); foreach (var opt in channel.Options) { configurationContext.PushChannelOptions.Remove(opt); } channel.Endpoint = registration.Endpoint; channel.ExpirationTime = registration.ExpirationTime; channel.EndpointInfo = registration.EndpointInfo; channel.Type = registration.PushChannelType; await CreateOptionsAsync(registration.Options, channel.Id, false); await CreateOptionsAsync(registration.EndpointOptions, channel.Id, true); await configurationContext.SaveChangesAsync(); }
public Task UpdateAsync(string userId, string configurationId, PushChannelRegistration registration) { return(pushConfigurationStore.UpdateAsync(userId, configurationId, registration)); }
public async Task <Abstractions.Models.PushChannelConfiguration> RegisterAsync(string userId, PushChannelRegistration registration) { var channel = new Entities.PushChannelConfiguration() { Id = Guid.NewGuid().ToString(), UserId = userId, Endpoint = registration.Endpoint, EndpointInfo = registration.EndpointInfo, Type = registration.PushChannelType, ExpirationTime = registration.ExpirationTime, }; await configurationContext.PushChannelConfigurations.AddAsync(channel); await CreateOptionsAsync(registration.Options, channel.Id, false); await CreateOptionsAsync(registration.EndpointOptions, channel.Id, true); await configurationContext.SaveChangesAsync(); return(new Abstractions.Models.PushChannelConfiguration() { EndpointInfo = channel.EndpointInfo, Id = channel.Id, ChannelType = channel.Type, Options = registration.Options }); }