Skip to content

Commit 214435a

Browse files
committed
Windows Phone refactoring
1 parent bac4018 commit 214435a

8 files changed

+182
-122
lines changed

PushSharp.WindowsPhone/PushSharp.WindowsPhone.csproj

+3-2
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,12 @@
4545
<Reference Include="System.Xml" />
4646
</ItemGroup>
4747
<ItemGroup>
48-
<Compile Include="..\PushSharp.Common\AssemblyVersionInfo.cs">
48+
<Compile Include="..\PushSharp.Core\AssemblyVersionInfo.cs">
4949
<Link>AssemblyVersionInfo.cs</Link>
5050
</Compile>
5151
<Compile Include="Exceptions.cs" />
5252
<Compile Include="WindowsPhoneMessageStatus.cs" />
53+
<Compile Include="WindowsPhonePushBrokerExtensions.cs" />
5354
<Compile Include="WindowsPhonePushChannelSettings.cs" />
5455
<Compile Include="WindowsPhoneNotification.cs" />
5556
<Compile Include="Properties\AssemblyInfo.cs" />
@@ -59,7 +60,7 @@
5960
<Compile Include="WindowsPhoneTransportResponse.cs" />
6061
</ItemGroup>
6162
<ItemGroup>
62-
<ProjectReference Include="..\PushSharp.Common\PushSharp.Core.csproj">
63+
<ProjectReference Include="..\PushSharp.Core\PushSharp.Core.csproj">
6364
<Project>{836F225F-6CD9-48DE-910C-70F8A7CF54AA}</Project>
6465
<Name>PushSharp.Core</Name>
6566
</ProjectReference>

PushSharp.WindowsPhone/WindowsPhoneNotification.cs

+12-12
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Text;
55
using System.Xml.Linq;
66
using System.Xml.Schema;
7+
using PushSharp.Core;
78

89
namespace PushSharp.WindowsPhone
910
{
@@ -28,7 +29,7 @@ public enum NotificationType
2829
Raw
2930
}
3031

31-
public class WindowsPhoneNotificationFactory : Common.Notification
32+
public class WindowsPhoneNotificationFactory : Notification
3233
{
3334
public WindowsPhoneRawNotification Raw()
3435
{
@@ -45,27 +46,26 @@ public WindowsPhoneToastNotification Toast()
4546
return new WindowsPhoneToastNotification();
4647
}
4748

48-
public WindowsPhoneCycleTile CycleTile()
49+
public WindowsPhoneCycleTileNotification CycleTile()
4950
{
50-
return new WindowsPhoneCycleTile();
51+
return new WindowsPhoneCycleTileNotification();
5152
}
5253

53-
public WindowsPhoneFlipTile FlipTile()
54+
public WindowsPhoneFlipTileNotification FlipTile()
5455
{
55-
return new WindowsPhoneFlipTile();
56+
return new WindowsPhoneFlipTileNotification();
5657
}
5758

58-
public WindowsPhoneIconicTile IconicTile()
59+
public WindowsPhoneIconicTileNotification IconicTile()
5960
{
60-
return new WindowsPhoneIconicTile();
61+
return new WindowsPhoneIconicTileNotification();
6162
}
6263
}
6364

64-
public abstract class WindowsPhoneNotification : Common.Notification
65+
public abstract class WindowsPhoneNotification : Notification
6566
{
6667
protected WindowsPhoneNotification()
6768
{
68-
this.Platform = Common.PlatformType.WindowsPhone;
6969
this.MessageID = Guid.NewGuid();
7070
}
7171

@@ -224,7 +224,7 @@ public override string PayloadToString()
224224
}
225225
}
226226

227-
public class WindowsPhoneFlipTile : WindowsPhoneNotification
227+
public class WindowsPhoneFlipTileNotification : WindowsPhoneNotification
228228
{
229229
public string Title { get; set; }
230230
public bool ClearTitle { get; set; }
@@ -324,7 +324,7 @@ public override string PayloadToString()
324324
}
325325
}
326326

327-
public class WindowsPhoneIconicTile : WindowsPhoneNotification
327+
public class WindowsPhoneIconicTileNotification : WindowsPhoneNotification
328328
{
329329
public string Title { get; set; }
330330
public bool ClearTitle { get; set; }
@@ -409,7 +409,7 @@ public override string PayloadToString()
409409
}
410410
}
411411

412-
public class WindowsPhoneCycleTile : WindowsPhoneNotification
412+
public class WindowsPhoneCycleTileNotification : WindowsPhoneNotification
413413
{
414414
public string Title { get; set; }
415415
public bool ClearTitle { get; set; }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using PushSharp.WindowsPhone;
6+
using PushSharp.Core;
7+
8+
namespace PushSharp
9+
{
10+
public static class ApplePushBrokerExtensions
11+
{
12+
public static void RegisterWindowsPhoneService(this PushBroker broker, WindowsPhonePushChannelSettings channelSettings, PushServiceSettings serviceSettings = null)
13+
{
14+
var service = new WindowsPhonePushService(new WindowsPhonePushChannelFactory(), channelSettings, serviceSettings);
15+
16+
broker.RegisterService<WindowsPhoneCycleTileNotification>(service);
17+
broker.RegisterService<WindowsPhoneFlipTileNotification>(service);
18+
broker.RegisterService<WindowsPhoneIconicTileNotification>(service);
19+
broker.RegisterService<WindowsPhoneTileNotification>(service);
20+
broker.RegisterService<WindowsPhoneToastNotification>(service);
21+
broker.RegisterService<WindowsPhoneRawNotification>(service);
22+
}
23+
24+
public static WindowsPhoneCycleTileNotification WindowsPhoneCycleTileNotification(this PushBroker broker)
25+
{
26+
return new WindowsPhoneCycleTileNotification();
27+
}
28+
29+
public static WindowsPhoneFlipTileNotification WindowsPhoneFlipTileNotification(this PushBroker broker)
30+
{
31+
return new WindowsPhoneFlipTileNotification();
32+
}
33+
34+
public static WindowsPhoneIconicTileNotification WindowsPhoneIconicTileNotification(this PushBroker broker)
35+
{
36+
return new WindowsPhoneIconicTileNotification();
37+
}
38+
39+
public static WindowsPhoneTileNotification WindowsPhoneTileNotification(this PushBroker broker)
40+
{
41+
return new WindowsPhoneTileNotification();
42+
}
43+
44+
public static WindowsPhoneToastNotification WindowsPhoneToastNotification(this PushBroker broker)
45+
{
46+
return new WindowsPhoneToastNotification();
47+
}
48+
49+
public static WindowsPhoneRawNotification WindowsPhoneRawNotification(this PushBroker broker)
50+
{
51+
return new WindowsPhoneRawNotification();
52+
}
53+
}
54+
}

PushSharp.WindowsPhone/WindowsPhonePushChannel.cs

+14-19
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,20 @@
33
using System.Linq;
44
using System.Net;
55
using System.Text;
6-
using PushSharp.Common;
6+
using PushSharp.Core;
77

88
namespace PushSharp.WindowsPhone
99
{
1010
public class WindowsPhonePushChannel : PushChannelBase
1111
{
1212
WindowsPhonePushChannelSettings windowsPhoneSettings;
1313

14-
public WindowsPhonePushChannel(WindowsPhonePushChannelSettings channelSettings, PushServiceSettings serviceSettings = null) : base(channelSettings, serviceSettings)
14+
public WindowsPhonePushChannel(PushServiceBase pushService) : base(pushService)
1515
{
16-
windowsPhoneSettings = channelSettings;
16+
windowsPhoneSettings = pushService.ChannelSettings as WindowsPhonePushChannelSettings;
1717
}
1818

19-
public override PlatformType PlatformType
20-
{
21-
get { return Common.PlatformType.WindowsPhone; }
22-
}
23-
24-
protected override void SendNotification(Notification notification)
19+
public override void SendNotification(Notification notification)
2520
{
2621
var wpNotification = notification as WindowsPhoneNotification;
2722

@@ -41,9 +36,9 @@ protected override void SendNotification(Notification notification)
4136
slowValue = 22;
4237
}
4338
else if (wpNotification is WindowsPhoneTileNotification ||
44-
wpNotification is WindowsPhoneCycleTile ||
45-
wpNotification is WindowsPhoneFlipTile ||
46-
wpNotification is WindowsPhoneIconicTile)
39+
wpNotification is WindowsPhoneCycleTileNotification ||
40+
wpNotification is WindowsPhoneFlipTileNotification ||
41+
wpNotification is WindowsPhoneIconicTileNotification)
4742
{
4843
immediateValue = 1;
4944
mediumValue = 11;
@@ -65,9 +60,9 @@ wpNotification is WindowsPhoneFlipTile ||
6560
if (wpNotification is WindowsPhoneToastNotification)
6661
wr.Headers.Add("X-WindowsPhone-Target", "toast");
6762
else if (wpNotification is WindowsPhoneTileNotification ||
68-
wpNotification is WindowsPhoneCycleTile ||
69-
wpNotification is WindowsPhoneFlipTile ||
70-
wpNotification is WindowsPhoneIconicTile)
63+
wpNotification is WindowsPhoneCycleTileNotification ||
64+
wpNotification is WindowsPhoneFlipTileNotification ||
65+
wpNotification is WindowsPhoneIconicTileNotification)
7166
wr.Headers.Add("X-WindowsPhone-Target", "token");
7267

7368
if (wpNotification.MessageID != null)
@@ -153,19 +148,19 @@ void HandleStatus(WindowsPhoneMessageStatus status, WindowsPhoneNotification not
153148
{
154149
if (status.SubscriptionStatus == WPSubscriptionStatus.Expired)
155150
{
156-
this.Events.RaiseDeviceSubscriptionExpired(PlatformType.WindowsPhone, notification.EndPointUrl, notification);
157-
this.Events.RaiseNotificationSendFailure(notification, new WindowsPhoneNotificationSendFailureException(status));
151+
this.Events.RaiseDeviceSubscriptionExpired(this, notification.EndPointUrl, notification);
152+
this.Events.RaiseNotificationSendFailure(this, notification, new WindowsPhoneNotificationSendFailureException(status));
158153
return;
159154
}
160155

161156
if (status.HttpStatus == HttpStatusCode.OK
162157
&& status.NotificationStatus == WPNotificationStatus.Received)
163158
{
164-
this.Events.RaiseNotificationSent(status.Notification);
159+
this.Events.RaiseNotificationSent(this, status.Notification);
165160
return;
166161
}
167162

168-
this.Events.RaiseNotificationSendFailure(status.Notification, new WindowsPhoneNotificationSendFailureException(status));
163+
this.Events.RaiseNotificationSendFailure(this, status.Notification, new WindowsPhoneNotificationSendFailureException(status));
169164
}
170165
}
171166
}

PushSharp.WindowsPhone/WindowsPhonePushChannelSettings.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
using System.Linq;
44
using System.Security.Cryptography.X509Certificates;
55
using System.Text;
6-
using PushSharp.Common;
6+
using PushSharp.Core;
77

88
namespace PushSharp.WindowsPhone
99
{

0 commit comments

Comments
 (0)