using System;
using System.Collections.Generic;
using System.Windows;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Scheduler;

namespace PhoneAppReminder
{
    public partial class MainPage : PhoneApplicationPage
    {
        // Constructor
        public MainPage()
        {
            InitializeComponent();

            string reminderName = "HelloWorldReminder";

            ScheduledAction scheduledAction= ScheduledActionService.Find(reminderName);
            if (scheduledAction!=null)
            {
                ScheduledActionService.Remove(reminderName);
            }

            Reminder reminder = new Reminder(reminderName);
            reminder.Title = "Hello Reminder";
            reminder.Content = "Dies ist der erste eigene Reminder";
            reminder.BeginTime = DateTime.Now.AddMinutes(1.0);
            reminder.ExpirationTime = DateTime.Now.AddMinutes(2.0);
            reminder.RecurrenceType = RecurrenceInterval.None;
            reminder.NavigationUri = new Uri("/MainPage.xaml?param=Some%20Parameter", UriKind.RelativeOrAbsolute);

            // Register the reminder with the system.
            ScheduledActionService.Add(reminder);


            string alarmName = "HelloWorldAlarm";

            Alarm alarm = new Alarm(alarmName);
            alarm.Content = "Dies ist der erste eigene Wecker";
            alarm.BeginTime = DateTime.Now.AddMinutes(1.0);
            alarm.ExpirationTime = DateTime.Now.AddMinutes(2.0);
            alarm.RecurrenceType = RecurrenceInterval.None;
            
            //alarm.Sound = new Uri("mymusic.wma",UriKind.Relative);

            // Register the reminder with the system.
            ScheduledActionService.Add(alarm);
            
            //Alle Reminder- und Alarm-Objekte laden
            foreach (ScheduledAction action in ScheduledActionService.GetActions<ScheduledAction>())
            {
                if (action is Alarm)
                {
                    Alarm alarmtemp = (Alarm)action;
                    // ...
                }
                else
                {
                    Reminder remindertemp = (Reminder)action;
                    // ...
                }
            }
        }
        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);
            string paramValue = "";

            NavigationContext.QueryString.TryGetValue("param", out paramValue);

            if (paramValue != null)
            {
                MessageBox.Show("Parameter: " + paramValue);
            }
        }
    }
}