Skip to content

Commit

Permalink
Windows Phone refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
Redth committed Mar 7, 2013
1 parent bac4018 commit 214435a
Show file tree
Hide file tree
Showing 8 changed files with 182 additions and 122 deletions.
5 changes: 3 additions & 2 deletions PushSharp.WindowsPhone/PushSharp.WindowsPhone.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,12 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="..\PushSharp.Common\AssemblyVersionInfo.cs">
<Compile Include="..\PushSharp.Core\AssemblyVersionInfo.cs">
<Link>AssemblyVersionInfo.cs</Link>
</Compile>
<Compile Include="Exceptions.cs" />
<Compile Include="WindowsPhoneMessageStatus.cs" />
<Compile Include="WindowsPhonePushBrokerExtensions.cs" />
<Compile Include="WindowsPhonePushChannelSettings.cs" />
<Compile Include="WindowsPhoneNotification.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
Expand All @@ -59,7 +60,7 @@
<Compile Include="WindowsPhoneTransportResponse.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\PushSharp.Common\PushSharp.Core.csproj">
<ProjectReference Include="..\PushSharp.Core\PushSharp.Core.csproj">
<Project>{836F225F-6CD9-48DE-910C-70F8A7CF54AA}</Project>
<Name>PushSharp.Core</Name>
</ProjectReference>
Expand Down
24 changes: 12 additions & 12 deletions PushSharp.WindowsPhone/WindowsPhoneNotification.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Text;
using System.Xml.Linq;
using System.Xml.Schema;
using PushSharp.Core;

namespace PushSharp.WindowsPhone
{
Expand All @@ -28,7 +29,7 @@ public enum NotificationType
Raw
}

public class WindowsPhoneNotificationFactory : Common.Notification
public class WindowsPhoneNotificationFactory : Notification
{
public WindowsPhoneRawNotification Raw()
{
Expand All @@ -45,27 +46,26 @@ public WindowsPhoneToastNotification Toast()
return new WindowsPhoneToastNotification();
}

public WindowsPhoneCycleTile CycleTile()
public WindowsPhoneCycleTileNotification CycleTile()
{
return new WindowsPhoneCycleTile();
return new WindowsPhoneCycleTileNotification();
}

public WindowsPhoneFlipTile FlipTile()
public WindowsPhoneFlipTileNotification FlipTile()
{
return new WindowsPhoneFlipTile();
return new WindowsPhoneFlipTileNotification();
}

public WindowsPhoneIconicTile IconicTile()
public WindowsPhoneIconicTileNotification IconicTile()
{
return new WindowsPhoneIconicTile();
return new WindowsPhoneIconicTileNotification();
}
}

public abstract class WindowsPhoneNotification : Common.Notification
public abstract class WindowsPhoneNotification : Notification
{
protected WindowsPhoneNotification()
{
this.Platform = Common.PlatformType.WindowsPhone;
this.MessageID = Guid.NewGuid();
}

Expand Down Expand Up @@ -224,7 +224,7 @@ public override string PayloadToString()
}
}

public class WindowsPhoneFlipTile : WindowsPhoneNotification
public class WindowsPhoneFlipTileNotification : WindowsPhoneNotification
{
public string Title { get; set; }
public bool ClearTitle { get; set; }
Expand Down Expand Up @@ -324,7 +324,7 @@ public override string PayloadToString()
}
}

public class WindowsPhoneIconicTile : WindowsPhoneNotification
public class WindowsPhoneIconicTileNotification : WindowsPhoneNotification
{
public string Title { get; set; }
public bool ClearTitle { get; set; }
Expand Down Expand Up @@ -409,7 +409,7 @@ public override string PayloadToString()
}
}

public class WindowsPhoneCycleTile : WindowsPhoneNotification
public class WindowsPhoneCycleTileNotification : WindowsPhoneNotification
{
public string Title { get; set; }
public bool ClearTitle { get; set; }
Expand Down
54 changes: 54 additions & 0 deletions PushSharp.WindowsPhone/WindowsPhonePushBrokerExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PushSharp.WindowsPhone;
using PushSharp.Core;

namespace PushSharp
{
public static class ApplePushBrokerExtensions
{
public static void RegisterWindowsPhoneService(this PushBroker broker, WindowsPhonePushChannelSettings channelSettings, PushServiceSettings serviceSettings = null)
{
var service = new WindowsPhonePushService(new WindowsPhonePushChannelFactory(), channelSettings, serviceSettings);

broker.RegisterService<WindowsPhoneCycleTileNotification>(service);
broker.RegisterService<WindowsPhoneFlipTileNotification>(service);
broker.RegisterService<WindowsPhoneIconicTileNotification>(service);
broker.RegisterService<WindowsPhoneTileNotification>(service);
broker.RegisterService<WindowsPhoneToastNotification>(service);
broker.RegisterService<WindowsPhoneRawNotification>(service);
}

public static WindowsPhoneCycleTileNotification WindowsPhoneCycleTileNotification(this PushBroker broker)
{
return new WindowsPhoneCycleTileNotification();
}

public static WindowsPhoneFlipTileNotification WindowsPhoneFlipTileNotification(this PushBroker broker)
{
return new WindowsPhoneFlipTileNotification();
}

public static WindowsPhoneIconicTileNotification WindowsPhoneIconicTileNotification(this PushBroker broker)
{
return new WindowsPhoneIconicTileNotification();
}

public static WindowsPhoneTileNotification WindowsPhoneTileNotification(this PushBroker broker)
{
return new WindowsPhoneTileNotification();
}

public static WindowsPhoneToastNotification WindowsPhoneToastNotification(this PushBroker broker)
{
return new WindowsPhoneToastNotification();
}

public static WindowsPhoneRawNotification WindowsPhoneRawNotification(this PushBroker broker)
{
return new WindowsPhoneRawNotification();
}
}
}
33 changes: 14 additions & 19 deletions PushSharp.WindowsPhone/WindowsPhonePushChannel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,20 @@
using System.Linq;
using System.Net;
using System.Text;
using PushSharp.Common;
using PushSharp.Core;

namespace PushSharp.WindowsPhone
{
public class WindowsPhonePushChannel : PushChannelBase
{
WindowsPhonePushChannelSettings windowsPhoneSettings;

public WindowsPhonePushChannel(WindowsPhonePushChannelSettings channelSettings, PushServiceSettings serviceSettings = null) : base(channelSettings, serviceSettings)
public WindowsPhonePushChannel(PushServiceBase pushService) : base(pushService)
{
windowsPhoneSettings = channelSettings;
windowsPhoneSettings = pushService.ChannelSettings as WindowsPhonePushChannelSettings;
}

public override PlatformType PlatformType
{
get { return Common.PlatformType.WindowsPhone; }
}

protected override void SendNotification(Notification notification)
public override void SendNotification(Notification notification)
{
var wpNotification = notification as WindowsPhoneNotification;

Expand All @@ -41,9 +36,9 @@ protected override void SendNotification(Notification notification)
slowValue = 22;
}
else if (wpNotification is WindowsPhoneTileNotification ||
wpNotification is WindowsPhoneCycleTile ||
wpNotification is WindowsPhoneFlipTile ||
wpNotification is WindowsPhoneIconicTile)
wpNotification is WindowsPhoneCycleTileNotification ||
wpNotification is WindowsPhoneFlipTileNotification ||
wpNotification is WindowsPhoneIconicTileNotification)
{
immediateValue = 1;
mediumValue = 11;
Expand All @@ -65,9 +60,9 @@ wpNotification is WindowsPhoneFlipTile ||
if (wpNotification is WindowsPhoneToastNotification)
wr.Headers.Add("X-WindowsPhone-Target", "toast");
else if (wpNotification is WindowsPhoneTileNotification ||
wpNotification is WindowsPhoneCycleTile ||
wpNotification is WindowsPhoneFlipTile ||
wpNotification is WindowsPhoneIconicTile)
wpNotification is WindowsPhoneCycleTileNotification ||
wpNotification is WindowsPhoneFlipTileNotification ||
wpNotification is WindowsPhoneIconicTileNotification)
wr.Headers.Add("X-WindowsPhone-Target", "token");

if (wpNotification.MessageID != null)
Expand Down Expand Up @@ -153,19 +148,19 @@ void HandleStatus(WindowsPhoneMessageStatus status, WindowsPhoneNotification not
{
if (status.SubscriptionStatus == WPSubscriptionStatus.Expired)
{
this.Events.RaiseDeviceSubscriptionExpired(PlatformType.WindowsPhone, notification.EndPointUrl, notification);
this.Events.RaiseNotificationSendFailure(notification, new WindowsPhoneNotificationSendFailureException(status));
this.Events.RaiseDeviceSubscriptionExpired(this, notification.EndPointUrl, notification);
this.Events.RaiseNotificationSendFailure(this, notification, new WindowsPhoneNotificationSendFailureException(status));
return;
}

if (status.HttpStatus == HttpStatusCode.OK
&& status.NotificationStatus == WPNotificationStatus.Received)
{
this.Events.RaiseNotificationSent(status.Notification);
this.Events.RaiseNotificationSent(this, status.Notification);
return;
}

this.Events.RaiseNotificationSendFailure(status.Notification, new WindowsPhoneNotificationSendFailureException(status));
this.Events.RaiseNotificationSendFailure(this, status.Notification, new WindowsPhoneNotificationSendFailureException(status));
}
}
}
2 changes: 1 addition & 1 deletion PushSharp.WindowsPhone/WindowsPhonePushChannelSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using System.Linq;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using PushSharp.Common;
using PushSharp.Core;

namespace PushSharp.WindowsPhone
{
Expand Down
Loading

0 comments on commit 214435a

Please sign in to comment.