public PushSubscriptionsController( IPushSubscriptionsService pushSubscriptionsService, PushServiceClient pushClient) { _pushSubscriptionsService = pushSubscriptionsService; _pushClient = pushClient; }
private void UpdateServerInfo() { try { var pushService = new PushServiceClient(); pushService.GetServerInfoCompleted += (s1, e1) => { try { pushService.CloseAsync(); if (e1.Result != null) { Dispatcher.BeginInvoke(() => { PushPattern = e1.Result.PushPattern; Counter = e1.Result.Counter; }); } } catch (Exception ex) { ex.Show(); } }; pushService.GetServerInfoAsync(); } catch (Exception ex) { ex.Show(); } }
// GET: Admin/Notification public ActionResult Send() { var publicKey = "BP2HjQtANkxLEBNq37OAth8Q1Oi59ZcWZO_lKbtRorfg_qY30lSlzMxGHYqH_a4S1p449HLOBy1jM2jy-bliq0o"; var privateKey = "QJoWkpOGd9H2YFkrU9PeT2jwRM1bU2I4spb3HD2Lgm8"; PushServiceClient pushClient = new PushServiceClient(); pushClient.DefaultAuthentication = new VapidAuthentication(publicKey, privateKey) { Subject = "https://acceleratex.org" }; PushMessage notification = new AngularPushNotification { Title = "news from wiQuiz", Body = $"eine neues Quiz ist da", // Icon = "Assets/icon-96x96.png" - so geht es nicht, andere Art des Pfads }.ToPushMessage(); pushClient.RequestPushMessageDeliveryAsync(MyPushSubscription.Instance.subscription, notification); return(RedirectToAction("Index", "Dashboard", new { area = "" })); }
public PushServicePushNotificationService(PushServiceClient pushClient, IPushSubscriptionStoreAccessorProvider subscriptionStoreAccessorProvider, ILogger <PushServicePushNotificationService> logger) { _pushClient = pushClient; _subscriptionStoreAccessorProvider = subscriptionStoreAccessorProvider; _logger = logger; }
/// <summary> /// 车辆旋转(掉头) /// </summary> /// <returns></returns> public void VehicleRotation() { PushServiceClient push = new PushServiceClient(new System.ServiceModel.InstanceContext(CStaticClass.myCallback)); push.VehicleRotation(m_nWareHouse); push.Close(); }
public PushSubscriptionController(IMapper mapper, IPushSubscriptionApplication pushSubscriptionApp, PushServiceClient pushServiceClient) { _mapper = mapper; _pushSubscriptionApp = pushSubscriptionApp; _pushServiceClient = pushServiceClient; }
/// <summary> /// 判断该库区是否有作业 /// </summary> /// <returns>true:有作业 false:无作业</returns> public bool IsHasTask() { PushServiceClient push = new PushServiceClient(new System.ServiceModel.InstanceContext(CStaticClass.myCallback)); bool bReturn = push.IsHasTask(m_nWareHouse); push.Close(); return(bReturn); }
public void DeregisterDevice(string token) { using (var pushClient = new PushServiceClient()) { pushClient.DeregisterDevice( CoreContext.TenantManager.GetCurrentTenant().TenantId, SecurityContext.CurrentAccount.ID.ToString(), token); } }
public PushSubscriptionsController(IPushSubscriptionsService pushSubscriptionsService, PushServiceClient pushClient, IOptions <PushNotificationsOptions> options) { _pushSubscriptionsService = pushSubscriptionsService; _pushClient = pushClient; _pushClient.DefaultAuthentication = new VapidAuthentication(options.Value.PublicKey, options.Value.PrivateKey) { Subject = "https://cc-angularpwa.firebaseapp.com" }; }
public WeatherNotificationsProducer(IOptions <PushNotificationsOptions> options, IPushSubscriptionsService pushSubscriptionsService, PushServiceClient pushClient) { _pushSubscriptionsService = pushSubscriptionsService; _pushClient = pushClient; _pushClient.DefaultAuthentication = new VapidAuthentication(options.Value.PublicKey, options.Value.PrivateKey) { Subject = "https://angular-pushnotifications.demo.io" }; }
public PushServicePushNotificationService( PushServiceClient pushClient, IPushSubscriptionStore pushSubscriptionStore, ILogger <PushServicePushNotificationService> logger ) { _pushClient = pushClient; _pushSubscriptionStore = pushSubscriptionStore; _logger = logger; }
private void SendInput() { string input = InputTextBox.Text.Trim(); if (!string.IsNullOrEmpty(input)) { InputTextBox.Text = string.Empty; PushServiceClient.SendMessage(App.ClientInfo, input); } }
public void DeregisterDevice(string token) { using (var pushClient = new PushServiceClient()) { pushClient.DeregisterDevice( CoreContext.TenantManager.GetCurrentTenant().TenantId, SecurityContext.CurrentAccount.ID.ToString(), token); } }
public void SendNotification(string message, int? badge, IEnumerable<string> deviceTokens) { using (var pushClient = new PushServiceClient()) { pushClient.EnqueueNotification( CoreContext.TenantManager.GetCurrentTenant().TenantId, SecurityContext.CurrentAccount.ID.ToString(), PushNotification.ApiNotification(message, badge), deviceTokens.ToList()); } }
public void SendNotification(string message, int?badge, IEnumerable <string> deviceTokens) { using (var pushClient = new PushServiceClient()) { pushClient.EnqueueNotification( CoreContext.TenantManager.GetCurrentTenant().TenantId, SecurityContext.CurrentAccount.ID.ToString(), PushNotification.ApiNotification(message, badge), deviceTokens.ToList()); } }
// GET: Notification public ActionResult SendMeANotofication() { var user = GetCurrentUser(); var device = user.Devices.FirstOrDefault(x => x.Platform == DevicePlatform.PWA); if (device != null) { var subscription = JsonConvert.DeserializeObject <PushSubscription>(device.DeviceName); /* * https://tools.reactpwa.com/vapid * { * "subject": "mailto:[email protected]", * "publicKey": "BPI8YpVBlwF62LYEapQb6zEj8i75ZYPHp3ugnYn0Sc8GBBX0s-pZEL-POjEAbzeIBzMQHx1bcq1yhY982hMm7oA", * "privateKey": "yMXePWjZMvx_xwZczffh6nG1j-E6oW0fcUVHOYeXR0c" * } */ var publicKey = "BPI8YpVBlwF62LYEapQb6zEj8i75ZYPHp3ugnYn0Sc8GBBX0s-pZEL-POjEAbzeIBzMQHx1bcq1yhY982hMm7oA"; var privateKey = "yMXePWjZMvx_xwZczffh6nG1j-E6oW0fcUVHOYeXR0c"; PushServiceClient pushClient = new PushServiceClient(); pushClient.DefaultAuthentication = new VapidAuthentication(publicKey, privateKey) { Subject = "mailto:[email protected]" }; var notification = new AngularPushNotification { Title = "news from NINE", Body = $"from nine to fillter", // Icon = "Assets/icon-96x96.png" - so geht es nicht, andere Art des Pfads Data = new Dictionary <string, object>(), Icon = "img.png" }; notification.Data["url"] = "https://nine.hm.edu"; notification.Data["room"] = "R 2.089"; notification.Data["lecturer"] = "Hinz"; var pushNMessage = notification.ToPushMessage(); pushClient.RequestPushMessageDeliveryAsync(subscription, pushNMessage); } return(RedirectToAction("Index", "Home")); }
public async Task PushService_OtherClientError_ThrowsPushServiceClientException() { _pushSubscription.Endpoint = CLIENT_ERROR_ENDPOINT; PushMessage pushMessage = new PushMessage(WALRUS_CONTENT); PushServiceClient pushClient = PreparePushServiceClient(); await Assert.ThrowsAsync <PushServiceClientException>(async() => { await pushClient.RequestPushMessageDeliveryAsync(_pushSubscription, pushMessage); }); }
public PushServicePushNotificationService(IOptions <PushNotificationServiceOptions> optionsAccessor, IVapidTokenCache vapidTokenCache, PushServiceClient pushClient, ILogger <PushServicePushNotificationService> logger) { _options = optionsAccessor.Value; _pushClient = pushClient; _pushClient.DefaultAuthentication = new VapidAuthentication("BPggdcXPKdvSpyjQHXlufrPQ7YPs_3TsoMnrDkg3wJ7mc-6l2fXEzjJlAopRaWdR1f5MRpxil68rLqDpYFp-YN0", "dO6qPKtyBD9TWsOksZqA527DplqID0czx-K1-LqjynU") { Subject = "mailto:[email protected]", TokenCache = vapidTokenCache }; _logger = logger; }
public PushNotificationService(PushServiceClient client, IPushSubscriptionService pushService, IOptions <AppSettings> appSettings, ILogger <PushNotificationService> logger) { _pushService = pushService; _logger = logger; _client = client; var config = appSettings.Value.PushNotifications; _client.DefaultAuthentication = new VapidAuthentication(config.PublicKey, config.PrivateKey) { Subject = config.ServerUrl }; _serverUrl = config.ServerUrl; }
public PushNotificationsProducer( IPushSubscriptionsService pushSubscriptionsService, PushServiceClient pushClient, HttpClient httpClient, ILogger <PushNotificationsProducer> logger, IConfiguration configuration) { _pushSubscriptionsService = pushSubscriptionsService; _pushClient = pushClient; _httpClient = httpClient; _logger = logger; _configuration = configuration; }
public PushServicePushNotificationService(IOptions<PushNotificationServiceOptions> optionsAccessor, IVapidTokenCache vapidTokenCache, PushServiceClient pushClient, ILogger<PushServicePushNotificationService> logger) { _options = optionsAccessor.Value; _pushClient = pushClient; _pushClient.DefaultAuthentication = new VapidAuthentication(_options.PublicKey, _options.PrivateKey) { Subject = _options.Subject, TokenCache = vapidTokenCache }; _logger = logger; }
public IEnumerable <GetFeedResponse> GetFeed(string deviceToken, ApiDateTime from, ApiDateTime to) { using (var pushClient = new PushServiceClient()) { return(pushClient .GetFeed(CoreContext.TenantManager.GetCurrentTenant().TenantId, SecurityContext.CurrentAccount.ID.ToString(), deviceToken, from ?? DateTime.MinValue, to ?? DateTime.MaxValue) .Select(notification => new GetFeedResponse(notification))); } }
public AppPushService(NotificationDbContext context, IConfiguration configuration) { this.context = context; this.client = new PushServiceClient(); var vapidSubject = configuration.GetValue <string>("Vapid:Subject"); this.vapidPublicKey = configuration.GetValue <string>("Vapid:PublicKey"); this.vapidPrivateKey = configuration.GetValue <string>("Vapid:PrivateKey"); ValidateVapidKeys(vapidSubject, vapidPublicKey, vapidPrivateKey); vapidDetails = new VapidDetails(vapidSubject, vapidPublicKey, vapidPrivateKey); }
private async Task SendNotificationAsync(Lib.Net.Http.WebPush.PushSubscription subscription, PushMessage message, CancellationToken cancellationToken) { var _pushClient = new PushServiceClient(); _pushClient.DefaultAuthentication = new VapidAuthentication("BP3KYW8aPpClaCjP2MUceUNTwqBSaK88kTnl6SWg0k134zAy_dNNub8LfGHo83bbkm-LUGAd_aLKM0z_4cpUlY8", "SSvrSz8WiLxNJB4SOZXiBs12n3VPLyftqHR05xpobGo"); try { await _pushClient.RequestPushMessageDeliveryAsync(subscription, message, cancellationToken); } catch (Exception ex) { //_logger?.LogError(ex, "Failed requesting push message delivery to {0}.", subscription.Endpoint); } }
/// <summary> /// Adds the <see cref="PushServiceClient"/> and related services to the <see cref="IServiceCollection"/>. /// </summary> /// <param name="services">The <see cref="IServiceCollection"/>.</param> /// <returns>The <see cref="IServiceCollection"/>.</returns> public static IServiceCollection AddPushServiceClient(this IServiceCollection services) { if (services == null) { throw new ArgumentNullException(nameof(services)); } services.AddHttpClient(HTTP_CLIENT_NAME); services.AddTransient(serviceProvider => { IHttpClientFactory clientFactory = serviceProvider.GetRequiredService <IHttpClientFactory>(); IOptions <PushServiceClientOptions> options = serviceProvider.GetRequiredService <IOptions <PushServiceClientOptions> >(); PushServiceClient pushServiceClient = new PushServiceClient(clientFactory.CreateClient(HTTP_CLIENT_NAME)); if (options.Value != null) { PushServiceClientOptions optionsValue = options.Value; if (!String.IsNullOrWhiteSpace(optionsValue.PrivateKey) && !String.IsNullOrWhiteSpace(optionsValue.PublicKey)) { pushServiceClient.DefaultAuthentication = new VapidAuthentication(optionsValue.PublicKey, optionsValue.PrivateKey) { Subject = optionsValue.Subject }; if (optionsValue.Expiration.HasValue) { pushServiceClient.DefaultAuthentication.Expiration = optionsValue.Expiration.Value; } pushServiceClient.DefaultAuthentication.TokenCache = serviceProvider.GetService <IVapidTokenCache>(); } pushServiceClient.DefaultAuthenticationScheme = optionsValue.DefaultAuthenticationScheme; if (optionsValue.DefaultTimeToLive.HasValue) { pushServiceClient.DefaultTimeToLive = optionsValue.DefaultTimeToLive.Value; } pushServiceClient.AutoRetryAfter = optionsValue.AutoRetryAfter; pushServiceClient.MaxRetriesAfter = optionsValue.MaxRetriesAfter; } return(pushServiceClient); }); return(services); }
public async Task PushService_TooManyRequests_DeliversPushMessageWithRetryAfter() { _pushSubscription.Endpoint = RETRY_AFTER_ENDPOINT; PushMessage pushMessage = new PushMessage(WALRUS_CONTENT); PushServiceClient pushClient = PreparePushServiceClient(); Exception pushMessageDeliveryException = await Record.ExceptionAsync(async() => { await pushClient.RequestPushMessageDeliveryAsync(_pushSubscription, pushMessage); }); Assert.Null(pushMessageDeliveryException); }
public WebPushClient( IConfiguration configuration, PushServiceClient pushClient, ILogger <WebPushClient> logger) { _configuration = configuration; _pushClient = pushClient; _logger = logger; _pushClient.DefaultAuthentication = new VapidAuthentication( _configuration["Push_Public_Key"], _configuration["Push_Private_Key"]) { Subject = _configuration["Ui_Url"] }; }
public object RegisterDevice(string token, DeviceType type) { UsageData.SetIsMobileAppUser(SecurityContext.CurrentAccount.ID, type); using (var pushClient = new PushServiceClient()) { string regid = pushClient.RegisterDevice( CoreContext.TenantManager.GetCurrentTenant().TenantId, SecurityContext.CurrentAccount.ID.ToString(), token, type); return(new { regid }); } }
public async Task PushService_TooManyRequests_MaxRetriesAfter_ThrowsPushServiceClientException() { _pushSubscription.Endpoint = RETRY_AFTER_ALWAYS_ENDPOINT; PushMessage pushMessage = new PushMessage(WALRUS_CONTENT); PushServiceClient pushClient = PreparePushServiceClient(); pushClient.MaxRetriesAfter = 1; await Assert.ThrowsAsync <PushServiceClientException>(async() => { await pushClient.RequestPushMessageDeliveryAsync(_pushSubscription, pushMessage); }); }
public async Task PushService_OtherClientError_PushServiceClientExceptionContainsResponseReasonPhrase() { _pushSubscription.Endpoint = CLIENT_ERROR_ENDPOINT; PushMessage pushMessage = new PushMessage(WALRUS_CONTENT); PushServiceClient pushClient = PreparePushServiceClient(); PushServiceClientException pushMessageDeliveryException = await Record.ExceptionAsync(async() => { await pushClient.RequestPushMessageDeliveryAsync(_pushSubscription, pushMessage); }) as PushServiceClientException; Assert.Equal(FakePushServiceStartup.OTHER_CLIENT_ERROR_REASON_PHRASE, pushMessageDeliveryException.Message); }
public async Task PushService_OtherClientError_PushServiceClientExceptionContainsPushSubscription() { _pushSubscription.Endpoint = CLIENT_ERROR_ENDPOINT; PushMessage pushMessage = new PushMessage(WALRUS_CONTENT); PushServiceClient pushClient = PreparePushServiceClient(); PushServiceClientException pushMessageDeliveryException = await Record.ExceptionAsync(async() => { await pushClient.RequestPushMessageDeliveryAsync(_pushSubscription, pushMessage); }) as PushServiceClientException; Assert.Equal(_pushSubscription, pushMessageDeliveryException.PushSubscription); }
public object RegisterDevice(string token, DeviceType type) { UsageData.SetIsMobileAppUser(SecurityContext.CurrentAccount.ID, type); using (var pushClient = new PushServiceClient()) { string regid = pushClient.RegisterDevice( CoreContext.TenantManager.GetCurrentTenant().TenantId, SecurityContext.CurrentAccount.ID.ToString(), token, type); return new {regid}; } }
public async Task PushService_NoError_DeliversPushMessage() { _pushSubscription.Endpoint = CREATED_ENDPOINT; PushMessage pushMessage = new PushMessage(WALRUS_CONTENT); PushServiceClient pushClient = PreparePushServiceClient(); Exception pushMessageDeliveryException = await Record.ExceptionAsync(async() => { await pushClient.RequestPushMessageDeliveryAsync(_pushSubscription, pushMessage); }); Assert.Null(pushMessageDeliveryException); }
private void RegisterClient(Uri channelUri) { // Register the URI with 3rd party web service. try { var pushService = new PushServiceClient(); pushService.RegisterCompleted += (s, e) => { pushService.CloseAsync(); Completed(e.Error); }; pushService.RegisterAsync(UserName, channelUri); } catch (Exception ex) { Completed(ex); } }
private void ButtonTestNow_Click(object sender, RoutedEventArgs e) { try { var pushService = new PushServiceClient(); pushService.UpdateTileCompleted += (s1, e1) => { try { pushService.CloseAsync(); } catch (Exception ex) { ex.Show(); } }; pushService.UpdateTileAsync(PushContext.Current.NotificationChannel.ChannelUri, SelectedServerImage); } catch (Exception ex) { ex.Show(); } }
private void UpdateServerInfo() { try { var pushService = new PushServiceClient(); pushService.GetServerInfoCompleted += (s1, e1) => { try { pushService.CloseAsync(); if (e1.Result != null) { Dispatcher.BeginInvoke(() => { PushPattern = e1.Result.PushPattern; Counter = e1.Result.Counter; }); } } catch (Exception ex) { ex.Show(); } }; pushService.GetServerInfoAsync(); } catch (Exception ex) { ex.Show(); } }
public IEnumerable<GetFeedResponse> GetFeed(string deviceToken, ApiDateTime from, ApiDateTime to) { using (var pushClient = new PushServiceClient()) { return pushClient .GetFeed(CoreContext.TenantManager.GetCurrentTenant().TenantId, SecurityContext.CurrentAccount.ID.ToString(), deviceToken, from ?? DateTime.MinValue, to ?? DateTime.MaxValue) .Select(notification => new GetFeedResponse(notification)); } }