Permalink
Browse files

final check in for notification

  • Loading branch information...
1 parent a2e263f commit 18f71ce11580ead54a08d01c375e1a10163df9d1 @michaelsync michaelsync committed Nov 29, 2011
@@ -86,11 +86,17 @@
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
+ <RowDefinition Height="Auto" />
+ <RowDefinition Height="Auto" />
</Grid.RowDefinitions>
- <TextBlock Text="Message:" VerticalAlignment="Top" Margin="0,5,0,0" />
+ <TextBlock Text="Message 1:" VerticalAlignment="Top" Margin="0,5,0,0" />
+
+ <TextBox x:Name="Rawtext1" Grid.Column="1" Width="300" Height="50" Margin="20,5" />
+
+ <TextBlock Text="Message 2:" VerticalAlignment="Top" Margin="0,5,0,0" Grid.Row="1" />
- <TextBox x:Name="Rawtext" Grid.Column="1" Width="300" Height="100" Margin="20,5" />
+ <TextBox x:Name="Rawtext2" Grid.Column="1" Width="300" Height="50" Margin="20,5" Grid.Row="1" />
<Button Content="Send Message" Grid.Column="1" Grid.Row="2" Margin="20,5" Click="SendRaw_Click" />
</Grid>
@@ -25,20 +25,21 @@ public partial class MainWindow : Window {
private void SendToast_Click(object sender, RoutedEventArgs e) {
var client = new NotificationServiceClient();
- client.SendToast(new Toast() { Text1 = ToastText1.Text, Text2 = ToastText2.Text });
+ client.SendToast(new Toast() { Text1 = ToastText1.Text, Text2 = ToastText2.Text, BackingInterval = ToastBackingInterval.ImmediateDelivery });
}
private void SendTile_Click(object sender, RoutedEventArgs e) {
var client = new NotificationServiceClient();
client.SendTitle(new Title() {
Title1 = new TitleItem() { Title = TileTitle1.Text, Count = TileCount1.Text, BackgroundImagePath = TileImage1.Text },
Title2 = new TitleItem() { Title = TileTitle2.Text, Count = TileCount2.Text, BackgroundImagePath = TileImage2.Text },
+ BackingInterval = TitleBackingInterval.ImmediateDelivery
});
}
private void SendRaw_Click(object sender, RoutedEventArgs e) {
var client = new NotificationServiceClient();
- client.SendRaw(new Raw() { Text1 = Rawtext.Text });
+ client.SendRaw(new Raw() { Text1 = Rawtext1.Text, Text2 = Rawtext2.Text, BackingInterval = RawBackingInterval.ImmediateDelivery });
}
}
}
@@ -14,6 +14,7 @@
using Microsoft.Phone.Notification;
using WPNotificationClient.Services;
using System.Collections.ObjectModel;
+using System.IO;
namespace WPNotificationClient {
public partial class MainPage : PhoneApplicationPage {
@@ -32,77 +33,70 @@ public partial class MainPage : PhoneApplicationPage {
_appId = Guid.NewGuid();
IsolatedStorageSettings.ApplicationSettings["AppID"] = _appId;
}
+
+ SetUpChannel();
}
void SetUpChannel() {
_channel = HttpNotificationChannel.Find(CHANNEL_NAME);
- if (_channel == null) {
+ if (_channel == null) {
_channel = new HttpNotificationChannel(CHANNEL_NAME);
_channel.ChannelUriUpdated += OnChannelUriUpdated;
- _channel.ErrorOccurred += OnErrorOccurred;
_channel.Open();
}
- else {
- RegisterForNotifications();
+ else {
+ _channel.ChannelUriUpdated += OnChannelUriUpdated;
+ Subscribe();
}
+
+
}
- void RegisterForNotifications() {
- RegisterWithSubscriptionService();
+ private void SubscribeEvents() {
+ _channel.ErrorOccurred += OnErrorOccurred;
_channel.ShellToastNotificationReceived += OnShellToastNotificationReceived;
_channel.HttpNotificationReceived += OnHttpNotificationReceived;
- _channel.ErrorOccurred += OnErrorOccurred;
- }
- void RegisterWithSubscriptionService() {
+ if (!_channel.IsShellTileBound) {
+ _channel.BindToShellTile();
+ }
+
+ if (!_channel.IsShellToastBound) {
+ _channel.BindToShellToast();
+ }
+ }
+
+ void Subscribe() {
+ SubscribeEvents();
+
var svc = new NotificationServiceClient();
svc.SubscribeCompleted += (s, e) => {
if (e.Error != null) {
-
+ MessageBox.Show(e.Error.Message);
}
};
svc.SubscribeAsync(_appId, _channel.ChannelUri.ToString());
}
-
- void UnRegisterForNotifications() {
- _channel.HttpNotificationReceived -= OnHttpNotificationReceived;
- _channel.ShellToastNotificationReceived -= OnShellToastNotificationReceived;
- _channel.ErrorOccurred -= OnErrorOccurred;
- }
+
void OnChannelUriUpdated(object sender, NotificationChannelUriEventArgs e) {
- _channel.ErrorOccurred -= OnErrorOccurred;
- _channel.ChannelUriUpdated -= OnChannelUriUpdated;
-
- _channel = HttpNotificationChannel.Find(CHANNEL_NAME);
-
- if (!_channel.IsShellTileBound) {
- Collection<Uri> uris = new Collection<Uri>();
- uris.Add(new Uri("http://chris.59north.com/"));
- _channel.BindToShellTile(uris);
- }
-
- if (!_channel.IsShellToastBound)
- _channel.BindToShellToast();
-
- RegisterForNotifications();
-
-
+ SetUpChannel();
}
void OnErrorOccurred(object sender, NotificationChannelErrorEventArgs e) {
-
- //OnErrorOccurred(e.Message);
+ MessageBox.Show(e.Message);
}
void OnHttpNotificationReceived(object sender, HttpNotificationEventArgs e) {
- //StreamReader sr = new StreamReader(e.Notification.Body);
- //OnRawMessageReceived(sr.ReadToEnd());
- //sr.Close();
+ StreamReader sr = new StreamReader(e.Notification.Body);
+ var msg = sr.ReadToEnd();
+ sr.Close();
}
void OnShellToastNotificationReceived(object sender, NotificationEventArgs e) {
- //ToastData td = new ToastData(e.Collection["wp:Text1"], e.Collection["wp:Text2"]);
- //OnToastReceived(td);
+ Deployment.Current.Dispatcher.BeginInvoke(() => {
+ ToastText1Textblock.Text = e.Collection["wp:Text1"];
+ ToastText2Textblock.Text = e.Collection["wp:Text2"];
+ });
}
}
}
@@ -0,0 +1,34 @@
+
+Microsoft Visual Studio Solution File, Format Version 11.00
+# Visual Studio 2010
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WPNotificationClient", "WPNotificationClient\WPNotificationClient.csproj", "{6A6FAAD6-A821-4978-9201-A17DA499C08D}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Any CPU = Debug|Any CPU
+ Debug|Mixed Platforms = Debug|Mixed Platforms
+ Debug|x86 = Debug|x86
+ Release|Any CPU = Release|Any CPU
+ Release|Mixed Platforms = Release|Mixed Platforms
+ Release|x86 = Release|x86
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {6A6FAAD6-A821-4978-9201-A17DA499C08D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {6A6FAAD6-A821-4978-9201-A17DA499C08D}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {6A6FAAD6-A821-4978-9201-A17DA499C08D}.Debug|Any CPU.Deploy.0 = Debug|Any CPU
+ {6A6FAAD6-A821-4978-9201-A17DA499C08D}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
+ {6A6FAAD6-A821-4978-9201-A17DA499C08D}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
+ {6A6FAAD6-A821-4978-9201-A17DA499C08D}.Debug|Mixed Platforms.Deploy.0 = Debug|Any CPU
+ {6A6FAAD6-A821-4978-9201-A17DA499C08D}.Debug|x86.ActiveCfg = Debug|Any CPU
+ {6A6FAAD6-A821-4978-9201-A17DA499C08D}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {6A6FAAD6-A821-4978-9201-A17DA499C08D}.Release|Any CPU.Build.0 = Release|Any CPU
+ {6A6FAAD6-A821-4978-9201-A17DA499C08D}.Release|Any CPU.Deploy.0 = Release|Any CPU
+ {6A6FAAD6-A821-4978-9201-A17DA499C08D}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
+ {6A6FAAD6-A821-4978-9201-A17DA499C08D}.Release|Mixed Platforms.Build.0 = Release|Any CPU
+ {6A6FAAD6-A821-4978-9201-A17DA499C08D}.Release|Mixed Platforms.Deploy.0 = Release|Any CPU
+ {6A6FAAD6-A821-4978-9201-A17DA499C08D}.Release|x86.ActiveCfg = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+EndGlobal
@@ -21,20 +21,19 @@ public class NotificationService : INotificationService {
string tileMessage = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
"<wp:Notification xmlns:wp=\"WPNotification\">" +
- "<wp:Tile Id=\"Navigation Uri of the Tile to update\">" +
+ "<wp:Tile>" +
"<wp:BackgroundImage>{0}</wp:BackgroundImage>" +
"<wp:Count>{1}</wp:Count>" +
- "<wp:Title>{2}</wp:Title>" +
- "<wp:BackBackgroundImage>{3}</wp:BackBackgroundImage>"+
- "<wp:BackTitle>{4}</wp:BackTitle>"+
- "<wp:BackContent>{5}</wp:BackContent>"+
+ "<wp:Title>{2}</wp:Title>" +
"</wp:Tile> " +
"</wp:Notification>";
+
+
string rawMessage = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
"<root>" +
"<Value1>{0}<Value1>" +
- "<Value2>{0}<Value2>" +
+ "<Value2>{1}<Value2>" +
"</root>";
@@ -86,29 +85,29 @@ public class NotificationService : INotificationService {
public IList<NotificationResponse> SendToast(Toast toast) {
List<NotificationResponse> statuses = new List<NotificationResponse>();
string message = string.Format(toastMessage, toast.Text1, toast.Text2, toast.Param);
- NotifyAll(statuses, message, (int)ToastBackingInterval.ImmediateDelivery);
+ NotifyAll(statuses, message, (int)ToastBackingInterval.ImmediateDelivery, "toast");
return statuses;
}
- private void NotifyAll(List<NotificationResponse> statuses, string message, int interval) {
+ private void NotifyAll(List<NotificationResponse> statuses, string message, int interval, string target) {
byte[] msg = System.Text.Encoding.UTF8.GetBytes(message);
foreach (var uri in clients.Values) {
- statuses.Add(Post(uri, msg, interval, "toast"));
+ statuses.Add(Post(uri, msg, interval, target));
}
}
public IList<NotificationResponse> SendTitle(Title title) {
List<NotificationResponse> statuses = new List<NotificationResponse>();
string message = string.Format(tileMessage, title.Title1.BackgroundImagePath, title.Title1.Count, title.Title1.Title,
- title.Title2.BackgroundImagePath, title.Title2.Count, title.Title2.Title, "token");
- NotifyAll(statuses, message, (int)TitleBackingInterval.ImmediateDelivery);
+ title.Title2.BackgroundImagePath, title.Title2.Count, title.Title2.Title);
+ NotifyAll(statuses, message, (int)TitleBackingInterval.ImmediateDelivery, "token");
return statuses;
}
public IList<NotificationResponse> SendRaw(Raw raw) {
List<NotificationResponse> statuses = new List<NotificationResponse>();
- string message = string.Format(toastMessage, raw.Text1, raw.Text2);
- NotifyAll(statuses, message, (int)RawBackingInterval.ImmediateDelivery);
+ string message = string.Format(rawMessage, raw.Text1, raw.Text2);
+ NotifyAll(statuses, message, (int)RawBackingInterval.ImmediateDelivery, string.Empty);
return statuses;
}
}
@@ -80,7 +80,7 @@
<WebProjectProperties>
<UseIIS>False</UseIIS>
<AutoAssignPort>True</AutoAssignPort>
- <DevelopmentServerPort>3448</DevelopmentServerPort>
+ <DevelopmentServerPort>18558</DevelopmentServerPort>
<DevelopmentServerVPath>/</DevelopmentServerVPath>
<IISUrl>
</IISUrl>

0 comments on commit 18f71ce

Please sign in to comment.