6
6
using System . Threading . Tasks ;
7
7
using System . Web ;
8
8
using Newtonsoft . Json . Linq ;
9
- using PushSharp . Common ;
9
+ using PushSharp . Core ;
10
10
11
11
namespace PushSharp . Windows
12
12
{
13
- public class WindowsPushChannel : Common . PushChannelBase
13
+ public class WindowsPushChannel : PushChannelBase
14
14
{
15
15
public string AccessToken { get ; private set ; }
16
16
public string TokenType { get ; private set ; }
17
17
18
18
WindowsPushChannelSettings channelSettings ;
19
19
20
- public WindowsPushChannel ( WindowsPushChannelSettings channelSettings , PushServiceSettings serviceSettings = null ) : base ( channelSettings , serviceSettings )
20
+ public WindowsPushChannel ( PushServiceBase pushService )
21
+ : base ( pushService )
21
22
{
22
- this . channelSettings = channelSettings ;
23
+ this . channelSettings = this . PushService . ChannelSettings as WindowsPushChannelSettings ;
23
24
}
24
-
25
- public override PlatformType PlatformType
26
- {
27
- get { return Common . PlatformType . Windows ; }
28
- }
29
-
25
+
30
26
void RenewAccessToken ( )
31
27
{
32
28
var postData = new StringBuilder ( ) ;
@@ -42,7 +38,7 @@ void RenewAccessToken()
42
38
var response = string . Empty ;
43
39
44
40
try { response = wc . UploadString ( "https://login.live.com/accesstoken.srf" , "POST" , postData . ToString ( ) ) ; }
45
- catch ( Exception ex ) { this . Events . RaiseChannelException ( ex , PlatformType . Windows ) ; }
41
+ catch ( Exception ex ) { this . Events . RaiseChannelException ( this , ex ) ; }
46
42
47
43
var json = new JObject ( ) ;
48
44
@@ -59,20 +55,20 @@ void RenewAccessToken()
59
55
}
60
56
else
61
57
{
62
- this . Events . RaiseChannelException ( new UnauthorizedAccessException ( "Could not retrieve access token for the supplied Package Security Identifier (SID) and client secret" ) , PlatformType . Windows ) ;
58
+ this . Events . RaiseChannelException ( this , new UnauthorizedAccessException ( "Could not retrieve access token for the supplied Package Security Identifier (SID) and client secret" ) ) ;
63
59
}
64
60
}
65
61
66
- protected override void SendNotification ( Common . Notification notification )
62
+ public override void SendNotification ( Notification notification )
67
63
{
68
64
try { sendNotification ( notification ) ; }
69
65
catch ( Exception ex )
70
66
{
71
- this . Events . RaiseChannelException ( ex , PlatformType . Windows , notification ) ;
67
+ this . Events . RaiseChannelException ( this , ex , notification ) ;
72
68
}
73
69
}
74
70
75
- void sendNotification ( Common . Notification notification )
71
+ void sendNotification ( Notification notification )
76
72
{
77
73
//See if we need an access token
78
74
if ( string . IsNullOrEmpty ( AccessToken ) )
@@ -251,19 +247,19 @@ void HandleStatus(WindowsNotificationStatus status)
251
247
if ( status . HttpStatus == HttpStatusCode . OK
252
248
&& status . NotificationStatus == WindowsNotificationSendStatus . Received )
253
249
{
254
- this . Events . RaiseNotificationSent ( status . Notification ) ;
250
+ this . Events . RaiseNotificationSent ( this , status . Notification ) ;
255
251
return ;
256
252
}
257
253
else if ( status . HttpStatus == HttpStatusCode . NotFound ) //404
258
254
{
259
- this . Events . RaiseDeviceSubscriptionExpired ( PlatformType . Windows , status . Notification . ChannelUri , status . Notification ) ;
255
+ this . Events . RaiseDeviceSubscriptionExpired ( this , status . Notification . ChannelUri , status . Notification ) ;
260
256
}
261
257
else if ( status . HttpStatus == HttpStatusCode . Gone ) //410
262
258
{
263
- this . Events . RaiseDeviceSubscriptionExpired ( PlatformType . Windows , status . Notification . ChannelUri , status . Notification ) ;
259
+ this . Events . RaiseDeviceSubscriptionExpired ( this , status . Notification . ChannelUri , status . Notification ) ;
264
260
}
265
261
266
- this . Events . RaiseNotificationSendFailure ( status . Notification , new WindowsNotificationSendFailureException ( status ) ) ;
262
+ this . Events . RaiseNotificationSendFailure ( this , status . Notification , new WindowsNotificationSendFailureException ( status ) ) ;
267
263
}
268
264
}
269
265
}
0 commit comments