using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel.Composition;
using System.Windows.Input;
using System.IO;
using Microsoft.Win32;
using WindowsPhone.Recipes.Push.Messasges;
using WindowsPhone.Recipes.Push.Server.Models;
namespace WindowsPhone.Recipes.Push.Server.ViewModels
{
///
/// Represents the One Time push notification pattern.
///
///
/// This is the simplest push notification pattern of just pushing single time message
/// to a registered client.
///
[Export(typeof(PushPatternViewModel)), PartCreationPolicy(CreationPolicy.Shared)]
internal sealed class OneTimePushPatternViewModel : PushPatternViewModel
{
#region Properties
///
/// Gets or sets a value indicating if tile message should be sent.
///
public bool IsTileEnabled { get; set; }
///
/// Gets or sets a value indicating if toast message should be sent.
///
public bool IsToastEnabled { get; set; }
///
/// Gets or sets a value indicating if raw message should be sent.
///
public bool IsRawEnabled { get; set; }
#endregion
#region Ctor
///
/// Initialize new instance of this type with defaults.
///
public OneTimePushPatternViewModel()
{
InitializeDefaults();
}
#endregion
#region Overrides
///
/// Depends on what message was selected, send all subscribers zero or all three push message types (Tile, Toast, Raw).
///
protected override void OnSend()
{
var messages = new List();
if (IsTileEnabled)
{
// Prepare a tile push notification message.
messages.Add(new TilePushNotificationMessage(MessageSendPriority.High)
{
BackgroundImageUri = BackgroundImageUri,
Count = Count,
Title = Title
});
}
if (IsToastEnabled)
{
// Prepare a toast push notification message.
messages.Add(new ToastPushNotificationMessage(MessageSendPriority.High)
{
Title = ToastTitle,
SubTitle = ToastSubTitle
});
}
if (IsRawEnabled)
{
// Prepare a raw push notification message.
messages.Add(new RawPushNotificationMessage(MessageSendPriority.High)
{
RawData = Encoding.ASCII.GetBytes(RawMessage)
});
}
foreach (var subscriber in PushService.Subscribers)
{
messages.ForEach(m => m.SendAsync(subscriber.ChannelUri, Log, Log));
}
}
#endregion
#region Privates
private void InitializeDefaults()
{
DisplayName = "One Time";
Description = "This is the simplest push notification pattern of just pushing single time message to a registered client.";
Count = 1;
Title = "Game Update";
ToastTitle = Title;
ToastSubTitle = "Game has been released";
RawMessage = ToastSubTitle;
IsTileEnabled = true;
IsToastEnabled = true;
IsRawEnabled = true;
}
#endregion
}
}