using System.Diagnostics;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Notification;

namespace WPReceiveTile
{
    public partial class MainPage : PhoneApplicationPage
    {
        string channelName = "WP7NotifyTile";
        HttpNotificationChannel channel;

        // Constructor
        public MainPage()
        {
            InitializeComponent();

            channel = HttpNotificationChannel.Find(channelName);

            if (channel == null)
            {
                channel = new HttpNotificationChannel(channelName);
                //Wird die URL für den Kanal erstellt, so wird dieses Ereignis ausgeführt
                channel.ChannelUriUpdated += channel_ChannelUriUpdated;
                channel.ErrorOccurred += channel_ErrorOccurred;
                channel.Open();
                //Aktiviert die Tile - Benachrichtigungen
                channel.BindToShellTile();
            }
            else
            {
                channel.ChannelUriUpdated += channel_ChannelUriUpdated;
                channel.ErrorOccurred += channel_ErrorOccurred;
            }
        }

        void channel_ErrorOccurred(object sender, NotificationChannelErrorEventArgs e)
        {
            //Fehlerbenahdlung
        }
        void channel_ChannelUriUpdated(object sender, NotificationChannelUriEventArgs e)
        {
            Debug.WriteLine(e.ChannelUri.ToString());
        }
    }
}