Skip to content

Commit f92e896

Browse files
committed
Refactored Windows 8
1 parent ec751d5 commit f92e896

8 files changed

+94
-34
lines changed

PushSharp.Windows/PushSharp.Windows.csproj

+3-2
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
<Reference Include="System.Xml" />
5353
</ItemGroup>
5454
<ItemGroup>
55-
<Compile Include="..\PushSharp.Common\AssemblyVersionInfo.cs">
55+
<Compile Include="..\PushSharp.Core\AssemblyVersionInfo.cs">
5656
<Link>AssemblyVersionInfo.cs</Link>
5757
</Compile>
5858
<Compile Include="Exceptions.cs" />
@@ -61,13 +61,14 @@
6161
<Compile Include="WindowsNotification.cs" />
6262
<Compile Include="WindowsNotificationFactory.cs" />
6363
<Compile Include="WindowsNotificationStatus.cs" />
64+
<Compile Include="WindowsPushBrokerExtensions.cs" />
6465
<Compile Include="WindowsPushChannel.cs" />
6566
<Compile Include="WindowsPushChannelSettings.cs" />
6667
<Compile Include="Properties\AssemblyInfo.cs" />
6768
<Compile Include="WindowsPushService.cs" />
6869
</ItemGroup>
6970
<ItemGroup>
70-
<ProjectReference Include="..\PushSharp.Common\PushSharp.Core.csproj">
71+
<ProjectReference Include="..\PushSharp.Core\PushSharp.Core.csproj">
7172
<Project>{836f225f-6cd9-48de-910c-70f8a7cf54aa}</Project>
7273
<Name>PushSharp.Core</Name>
7374
</ProjectReference>

PushSharp.Windows/WindowsNotification.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
using System.Text;
55
using System.Threading.Tasks;
66
using System.Xml.Linq;
7+
using PushSharp.Core;
78

89
namespace PushSharp.Windows
910
{
10-
public abstract class WindowsNotification : Common.Notification
11+
public abstract class WindowsNotification : Notification
1112
{
1213
protected WindowsNotification()
1314
{
14-
this.Platform = Common.PlatformType.Windows;
1515
}
1616

1717
public string ChannelUri { get; set; }

PushSharp.Windows/WindowsNotificationFactory.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33
using System.Linq;
44
using System.Text;
55
using System.Threading.Tasks;
6+
using PushSharp.Core;
67

78
namespace PushSharp.Windows
89
{
9-
public class WindowsNotificationFactory : Common.Notification
10+
public class WindowsNotificationFactory : Notification
1011
{
1112
public WindowsToastNotification Toast()
1213
{
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using PushSharp.Windows;
6+
using PushSharp.Core;
7+
8+
namespace PushSharp
9+
{
10+
public static class WindowsPushBrokerExtensions
11+
{
12+
public static void RegisterAppleService(this PushBroker broker, WindowsPushChannelSettings channelSettings, PushServiceSettings serviceSettings = null)
13+
{
14+
var service = new WindowsPushService(new WindowsPushChannelFactory(), channelSettings, serviceSettings);
15+
16+
broker.RegisterService<WindowsRawNotification>(service);
17+
broker.RegisterService<WindowsTileNotification>(service);
18+
broker.RegisterService<WindowsToastNotification>(service);
19+
broker.RegisterService<WindowsBadgeNumericNotification>(service);
20+
broker.RegisterService<WindowsBadgeGlyphNotification>(service);
21+
}
22+
23+
public static WindowsRawNotification WindowsRawNotification(this PushBroker broker)
24+
{
25+
return new WindowsRawNotification();
26+
}
27+
28+
public static WindowsTileNotification WindowsTileNotification(this PushBroker broker)
29+
{
30+
return new WindowsTileNotification();
31+
}
32+
33+
public static WindowsToastNotification WindowsToastNotification(this PushBroker broker)
34+
{
35+
return new WindowsToastNotification();
36+
}
37+
38+
public static WindowsBadgeNumericNotification WindowsBadgeNumericNotification(this PushBroker broker)
39+
{
40+
return new WindowsBadgeNumericNotification();
41+
}
42+
43+
public static WindowsBadgeGlyphNotification WindowsBadgeGlyphNotification(this PushBroker broker)
44+
{
45+
return new WindowsBadgeGlyphNotification();
46+
}
47+
}
48+
}

PushSharp.Windows/WindowsPushChannel.cs

+15-19
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,23 @@
66
using System.Threading.Tasks;
77
using System.Web;
88
using Newtonsoft.Json.Linq;
9-
using PushSharp.Common;
9+
using PushSharp.Core;
1010

1111
namespace PushSharp.Windows
1212
{
13-
public class WindowsPushChannel : Common.PushChannelBase
13+
public class WindowsPushChannel : PushChannelBase
1414
{
1515
public string AccessToken { get; private set; }
1616
public string TokenType { get; private set; }
1717

1818
WindowsPushChannelSettings channelSettings;
1919

20-
public WindowsPushChannel(WindowsPushChannelSettings channelSettings, PushServiceSettings serviceSettings = null) : base(channelSettings, serviceSettings)
20+
public WindowsPushChannel(PushServiceBase pushService)
21+
: base(pushService)
2122
{
22-
this.channelSettings = channelSettings;
23+
this.channelSettings = this.PushService.ChannelSettings as WindowsPushChannelSettings;
2324
}
24-
25-
public override PlatformType PlatformType
26-
{
27-
get { return Common.PlatformType.Windows; }
28-
}
29-
25+
3026
void RenewAccessToken()
3127
{
3228
var postData = new StringBuilder();
@@ -42,7 +38,7 @@ void RenewAccessToken()
4238
var response = string.Empty;
4339

4440
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); }
4642

4743
var json = new JObject();
4844

@@ -59,20 +55,20 @@ void RenewAccessToken()
5955
}
6056
else
6157
{
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"));
6359
}
6460
}
6561

66-
protected override void SendNotification(Common.Notification notification)
62+
public override void SendNotification(Notification notification)
6763
{
6864
try { sendNotification(notification); }
6965
catch (Exception ex)
7066
{
71-
this.Events.RaiseChannelException(ex, PlatformType.Windows, notification);
67+
this.Events.RaiseChannelException(this, ex, notification);
7268
}
7369
}
7470

75-
void sendNotification(Common.Notification notification)
71+
void sendNotification(Notification notification)
7672
{
7773
//See if we need an access token
7874
if (string.IsNullOrEmpty(AccessToken))
@@ -251,19 +247,19 @@ void HandleStatus(WindowsNotificationStatus status)
251247
if (status.HttpStatus == HttpStatusCode.OK
252248
&& status.NotificationStatus == WindowsNotificationSendStatus.Received)
253249
{
254-
this.Events.RaiseNotificationSent(status.Notification);
250+
this.Events.RaiseNotificationSent(this, status.Notification);
255251
return;
256252
}
257253
else if (status.HttpStatus == HttpStatusCode.NotFound) //404
258254
{
259-
this.Events.RaiseDeviceSubscriptionExpired(PlatformType.Windows, status.Notification.ChannelUri, status.Notification);
255+
this.Events.RaiseDeviceSubscriptionExpired(this, status.Notification.ChannelUri, status.Notification);
260256
}
261257
else if (status.HttpStatus == HttpStatusCode.Gone) //410
262258
{
263-
this.Events.RaiseDeviceSubscriptionExpired(PlatformType.Windows, status.Notification.ChannelUri, status.Notification);
259+
this.Events.RaiseDeviceSubscriptionExpired(this, status.Notification.ChannelUri, status.Notification);
264260
}
265261

266-
this.Events.RaiseNotificationSendFailure(status.Notification, new WindowsNotificationSendFailureException(status));
262+
this.Events.RaiseNotificationSendFailure(this, status.Notification, new WindowsNotificationSendFailureException(status));
267263
}
268264
}
269265
}

PushSharp.Windows/WindowsPushChannelSettings.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33
using System.Linq;
44
using System.Text;
55
using System.Threading.Tasks;
6+
using PushSharp.Core;
67

78
namespace PushSharp.Windows
89
{
9-
public class WindowsPushChannelSettings : Common.PushChannelSettings
10+
public class WindowsPushChannelSettings : PushChannelSettings
1011
{
1112
public WindowsPushChannelSettings(string packageName, string packageSecurityIdentifier, string clientSecret)
1213
{

PushSharp.Windows/WindowsPushService.cs

+9-9
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,22 @@
33
using System.Linq;
44
using System.Text;
55
using System.Threading.Tasks;
6+
using PushSharp.Core;
67

78
namespace PushSharp.Windows
89
{
9-
public class WindowsPushService : Common.PushServiceBase<WindowsPushChannelSettings>
10+
public class WindowsPushService : PushServiceBase
1011
{
11-
public WindowsPushService(WindowsPushChannelSettings channelSettings, Common.PushServiceSettings serviceSettings) : base(channelSettings, serviceSettings)
12+
public WindowsPushService(IPushChannelFactory pushChannelFactory, WindowsPushChannelSettings channelSettings, PushServiceSettings serviceSettings)
13+
: base(pushChannelFactory, channelSettings, serviceSettings)
1214
{ }
15+
}
1316

14-
protected override Common.PushChannelBase CreateChannel(Common.PushChannelSettings channelSettings)
15-
{
16-
return new WindowsPushChannel(channelSettings as WindowsPushChannelSettings);
17-
}
18-
19-
public override Common.PlatformType Platform
17+
public class WindowsPushChannelFactory : IPushChannelFactory
18+
{
19+
public PushChannelBase CreateChannel(PushServiceBase pushService)
2020
{
21-
get { return Common.PlatformType.Windows; }
21+
return new WindowsPushChannel(pushService);
2222
}
2323
}
2424
}

PushSharp.sln

+13
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PushSharp.Core", "PushSharp
2727
EndProject
2828
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PushSharp.Google", "PushSharp.Android\PushSharp.Google.csproj", "{71E27C37-FBBF-481B-934B-1F7DBDE3C5D6}"
2929
EndProject
30+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PushSharp.Windows", "PushSharp.Windows\PushSharp.Windows.csproj", "{0EC3A31E-B869-4465-ABDC-90C2E3CCC17D}"
31+
EndProject
3032
Global
3133
GlobalSection(SolutionConfigurationPlatforms) = preSolution
3234
Debug|Any CPU = Debug|Any CPU
@@ -87,13 +89,24 @@ Global
8789
{71E27C37-FBBF-481B-934B-1F7DBDE3C5D6}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
8890
{71E27C37-FBBF-481B-934B-1F7DBDE3C5D6}.Release|Mixed Platforms.Build.0 = Release|Any CPU
8991
{71E27C37-FBBF-481B-934B-1F7DBDE3C5D6}.Release|x86.ActiveCfg = Release|Any CPU
92+
{0EC3A31E-B869-4465-ABDC-90C2E3CCC17D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
93+
{0EC3A31E-B869-4465-ABDC-90C2E3CCC17D}.Debug|Any CPU.Build.0 = Debug|Any CPU
94+
{0EC3A31E-B869-4465-ABDC-90C2E3CCC17D}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
95+
{0EC3A31E-B869-4465-ABDC-90C2E3CCC17D}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
96+
{0EC3A31E-B869-4465-ABDC-90C2E3CCC17D}.Debug|x86.ActiveCfg = Debug|Any CPU
97+
{0EC3A31E-B869-4465-ABDC-90C2E3CCC17D}.Release|Any CPU.ActiveCfg = Release|Any CPU
98+
{0EC3A31E-B869-4465-ABDC-90C2E3CCC17D}.Release|Any CPU.Build.0 = Release|Any CPU
99+
{0EC3A31E-B869-4465-ABDC-90C2E3CCC17D}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
100+
{0EC3A31E-B869-4465-ABDC-90C2E3CCC17D}.Release|Mixed Platforms.Build.0 = Release|Any CPU
101+
{0EC3A31E-B869-4465-ABDC-90C2E3CCC17D}.Release|x86.ActiveCfg = Release|Any CPU
90102
EndGlobalSection
91103
GlobalSection(SolutionProperties) = preSolution
92104
HideSolutionNode = FALSE
93105
EndGlobalSection
94106
GlobalSection(NestedProjects) = preSolution
95107
{83C67156-893D-4AFF-9169-DB34771989CB} = {C09BBA3E-9CF3-4479-A4C3-3006820E2046}
96108
{71E27C37-FBBF-481B-934B-1F7DBDE3C5D6} = {C09BBA3E-9CF3-4479-A4C3-3006820E2046}
109+
{0EC3A31E-B869-4465-ABDC-90C2E3CCC17D} = {C09BBA3E-9CF3-4479-A4C3-3006820E2046}
97110
{1B9A3A8B-3690-4435-BF9C-B557BF2713DB} = {04A9AE38-795E-4CB5-A9AD-C1FA83DC342C}
98111
{5961A8F2-DE0A-4BBA-BEB3-B99C19C301A8} = {04A9AE38-795E-4CB5-A9AD-C1FA83DC342C}
99112
EndGlobalSection

0 commit comments

Comments
 (0)