@@ -231,52 +231,89 @@ public HttpRequestMessage GenerateRequestDetails(PushSubscription subscription,
231231 return request ;
232232 }
233233
234- /// <summary>
235- /// To send a push notification call this method with a subscription, optional payload and any options
236- /// Will exception is unsuccessful
237- /// </summary>
238- /// <param name="subscription">The PushSubscription you wish to send the notification to.</param>
239- /// <param name="payload">The payload you wish to send to the user</param>
240- /// <param name="options">Options for the GCM API key and vapid keys can be passed in if they are unique for each notification.</param>
241- public void SendNotification ( PushSubscription subscription , string payload = null , Dictionary < string , object > options = null )
234+ /// <summary>
235+ /// To send a push notification call this method with a subscription, optional payload and any options
236+ /// Will exception is unsuccessful
237+ /// </summary>
238+ /// <param name="subscription">The PushSubscription you wish to send the notification to.</param>
239+ /// <param name="payload">The payload you wish to send to the user</param>
240+ /// <param name="options">Options for the GCM API key and vapid keys can be passed in if they are unique for each notification.</param>
241+ public void SendNotification ( PushSubscription subscription , string payload = null , Dictionary < string , object > options = null )
242+ {
243+ SendNotificationAsync ( subscription , payload , options ) . Wait ( ) ;
244+ }
245+
246+ /// <summary>
247+ /// To send a push notification call this method with a subscription, optional payload and any options
248+ /// Will exception is unsuccessful
249+ /// </summary>
250+ /// <param name="subscription">The PushSubscription you wish to send the notification to.</param>
251+ /// <param name="payload">The payload you wish to send to the user</param>
252+ /// <param name="vapidDetails">The vapid details for the notification.</param>
253+ public void SendNotification ( PushSubscription subscription , string payload , VapidDetails vapidDetails )
254+ {
255+ SendNotificationAsync ( subscription , payload , vapidDetails ) . Wait ( ) ;
256+ }
257+
258+ /// <summary>
259+ /// To send a push notification call this method with a subscription, optional payload and any options
260+ /// Will exception is unsuccessful
261+ /// </summary>
262+ /// <param name="subscription">The PushSubscription you wish to send the notification to.</param>
263+ /// <param name="payload">The payload you wish to send to the user</param>
264+ /// <param name="gcmAPIKey">The GCM API key</param>
265+ public void SendNotification ( PushSubscription subscription , string payload , string gcmAPIKey )
266+ {
267+ SendNotificationAsync ( subscription , payload , gcmAPIKey ) . Wait ( ) ;
268+ }
269+
270+ /// <summary>
271+ /// To send a push notification asyncronously call this method with a subscription, optional payload and any options
272+ /// Will exception is unsuccessful
273+ /// </summary>
274+ /// <param name="subscription">The PushSubscription you wish to send the notification to.</param>
275+ /// <param name="payload">The payload you wish to send to the user</param>
276+ /// <param name="options">Options for the GCM API key and vapid keys can be passed in if they are unique for each notification.</param>
277+ public async Task SendNotificationAsync ( PushSubscription subscription , string payload = null , Dictionary < string , object > options = null )
242278 {
279+
243280 HttpRequestMessage request = GenerateRequestDetails ( subscription , payload , options ) ;
244- Task < HttpResponseMessage > webTask = httpClient . SendAsync ( request ) ;
245- webTask . Wait ( ) ;
246281
247- HttpResponseMessage response = webTask . Result ;
282+ HttpResponseMessage response = await httpClient . SendAsync ( request ) ;
283+
248284 if ( response . StatusCode != System . Net . HttpStatusCode . Created ) //201
249285 {
250286 throw new WebPushException ( @"Received unexpected response code" , response . StatusCode , response . Headers , subscription ) ;
251287 }
288+
252289 }
253290
254- /// <summary>
255- /// To send a push notification call this method with a subscription, optional payload and any options
256- /// Will exception is unsuccessful
257- /// </summary>
258- /// <param name="subscription">The PushSubscription you wish to send the notification to.</param>
259- /// <param name="payload">The payload you wish to send to the user</param>
260- /// <param name="vapidDetails">The vapid details for the notification.</param>
261- public void SendNotification ( PushSubscription subscription , string payload , VapidDetails vapidDetails )
291+ /// <summary>
292+ /// To send a push notification asyncronously call this method with a subscription, optional payload and any options
293+ /// Will exception is unsuccessful
294+ /// </summary>
295+ /// <param name="subscription">The PushSubscription you wish to send the notification to.</param>
296+ /// <param name="payload">The payload you wish to send to the user</param>
297+ /// <param name="vapidDetails">The vapid details for the notification.</param>
298+ public async Task SendNotificationAsync ( PushSubscription subscription , string payload , VapidDetails vapidDetails )
262299 {
263300 Dictionary < string , object > options = new Dictionary < string , object > ( ) ;
264301 options [ "vapidDetails" ] = vapidDetails ;
265- SendNotification ( subscription , payload , options ) ;
302+ await SendNotificationAsync ( subscription , payload , options ) ;
266303 }
267304
268- /// <summary>
269- /// To send a push notification call this method with a subscription, optional payload and any options
270- /// Will exception is unsuccessful
271- /// </summary>
272- /// <param name="subscription">The PushSubscription you wish to send the notification to.</param>
273- /// <param name="payload">The payload you wish to send to the user</param>
274- /// <param name="gcmAPIKey">The GCM API key</param>
275- public void SendNotification ( PushSubscription subscription , string payload , string gcmAPIKey )
305+ /// <summary>
306+ /// To send a push notification asyncronously call this method with a subscription, optional payload and any options
307+ /// Will exception is unsuccessful
308+ /// </summary>
309+ /// <param name="subscription">The PushSubscription you wish to send the notification to.</param>
310+ /// <param name="payload">The payload you wish to send to the user</param>
311+ /// <param name="gcmAPIKey">The GCM API key</param>
312+ public async Task SendNotificationAsync ( PushSubscription subscription , string payload , string gcmAPIKey )
276313 {
277314 Dictionary < string , object > options = new Dictionary < string , object > ( ) ;
278315 options [ "gcmAPIKey" ] = gcmAPIKey ;
279- SendNotification ( subscription , payload , options ) ;
316+ await SendNotificationAsync ( subscription , payload , options ) ;
280317 }
281318 }
282319}
0 commit comments