@@ -18,11 +18,25 @@ public PushNotificationScheduler(IToDoRepository repository)
1818 this . repository = repository ;
1919 }
2020
21+ bool HasEqualDueDatest ( Task task , PushNotification notification )
22+ {
23+ var taskDate = task . CheckedTargetDate ( ) ;
24+ var notificationDate = notification ? . DueDate ;
25+
26+ if ( taskDate . HasValue && notificationDate . HasValue )
27+ {
28+ return taskDate . Value . ToUniversalTime ( ) . ToString ( "yyyy-MM-dd'T'HH:mm:ss.fffzz" ) ==
29+ notificationDate . Value . ToUniversalTime ( ) . ToString ( "yyyy-MM-dd'T'HH:mm:ss.fffzz" ) ;
30+ }
31+ else
32+ return false ;
33+ }
34+
2135 public async System . Threading . Tasks . Task SchedulePushNotification ( Task task )
2236 {
2337 var currentNotification = task . PushNotifications . FirstOrDefault ( ) ;
2438
25- if ( currentNotification ? . DueDate == task . CheckedTargetDate ( ) )
39+ if ( HasEqualDueDatest ( task , currentNotification ) )
2640 return ;
2741
2842 await DeletePushNotification ( currentNotification ) ;
@@ -35,13 +49,30 @@ async System.Threading.Tasks.Task DeletePushNotification(PushNotification notifi
3549 return ;
3650
3751 var url = String . Format ( "https://onesignal.com/api/v1/notifications/{0}?app_id={1}" ,
38- notification . ServiceId . ToString ( ) , Environment . GetEnvironmentVariable ( "ONE_SIGNAL_KEY " ) ) ;
52+ notification . ServiceId . ToString ( ) , Environment . GetEnvironmentVariable ( "ONE_SIGNAL_APP_ID " ) ) ;
3953 var request = WebRequest . Create ( url ) as HttpWebRequest ;
4054
55+ request . ContentType = "application/json; charset=utf-8" ;
4156 request . Method = "DELETE" ;
4257 request . Headers [ "authorization" ] = String . Format ( "Basic {0}" , Environment . GetEnvironmentVariable ( "ONE_SIGNAL_KEY" ) ) ;
4358
44- await request . GetResponseAsync ( ) ;
59+ try
60+ {
61+ using ( var writer = await request . GetRequestStreamAsync ( ) )
62+ {
63+ writer . Write ( new Byte [ 0 ] , 0 , 0 ) ;
64+ }
65+ await request . GetResponseAsync ( ) ;
66+ }
67+ #if DEBUG
68+ catch ( WebException ex )
69+ {
70+ System . Diagnostics . Debug . WriteLine ( ex . Message ) ;
71+ System . Diagnostics . Debug . WriteLine ( new StreamReader ( ex . Response . GetResponseStream ( ) ) . ReadToEnd ( ) ) ;
72+ }
73+ #else
74+ catch { }
75+ #endif
4576
4677 repository . DeletePushNotification ( notification ) ;
4778 }
0 commit comments