|
namespace WeeklyThaiRecipeManagement.PushNotification
{
using System;
using Elmah;
public class ToastSender
{
private readonly MessageSender messageSender;
public ToastSender(MessageSender messageSender)
{
this.messageSender = messageSender;
}
public void Send(string title, string message, PhoneUriCollection phoneUriCollection)
{
var toastMessage = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
"<wp:Notification xmlns:wp=\"WPNotification\">" +
"<wp:Toast>" +
"<wp:Text1>{0}</wp:Text1>" +
"<wp:Text2>{1}</wp:Text2>" +
"</wp:Toast>" +
"</wp:Notification>";
toastMessage = string.Format(toastMessage, title, message);
var messageBytes = System.Text.Encoding.UTF8.GetBytes(toastMessage);
foreach (var uri in phoneUriCollection.Values)
{
try
{
messageSender.Send(uri, messageBytes, NotificationType.Toast);
}
catch (Exception error)
{
ErrorSignal.FromCurrentContext().Raise(error);
}
}
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
Patrick Kalkman is a senior Software Architect with more than 20 years professional development experience. He works for
SimpleTechture where he helps teams develop state of the art web applications.
Patrick enjoys writing his
blog. It discusses agile software development. Patrick can be reached at patrick@simpletechture.nl.
Published Windows 8 apps:
Published Windows Phone apps:
Awards:
Best Mobile article of March 2012
Best Mobile article of June 2012