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

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

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

            //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());
        }
        ShellTileSchedule mySchedule;
        private void CreateOneTimeSchedule()
        {
            mySchedule = new ShellTileSchedule();
            mySchedule.RemoteImageUri = new Uri("http://windowsteamblog.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-53-84-metablogapi/1033.image_5F00_thumb_5F00_386776A0.png");

            mySchedule.Recurrence = UpdateRecurrence.Onetime;
            mySchedule.StartTime = DateTime.Now;

            // Start the schedule two hours from now.
            mySchedule.StartTime.AddSeconds(15);

            mySchedule.Start();
        }

    }
}