public void SerializationTest()
        {
            string TestTaskName = "PickUpBook-HarryPotterAndTheChamberOfSecrets";
            string TestTaskNote = "BooksAtLibrary";
            AppTask GetBooks = new AppTask(TestTaskName, TestTaskNote, 0);
            GetBooks.RingTone = "Ringaling.wav";

            XmlWriter writer = XmlWriter.Create("SerializationTest.xml");
            writer.WriteStartDocument();
            GetBooks.WriteXML(writer);
            writer.WriteEndDocument();
            writer.Dispose();

            XmlReader reader = XmlReader.Create("SerializationTest.xml");
            reader.Read();
            AppTask compareTask = new AppTask("", "", -1);
            compareTask.ReadXML(reader);
            reader.Dispose();

            Assert.AreEqual(compareTask.TaskID, GetBooks.TaskID);
            Assert.AreEqual(compareTask.TaskName, GetBooks.TaskName);
            Assert.AreEqual(compareTask.TaskNotes, GetBooks.TaskNotes);
            Assert.AreEqual(compareTask.ReminderEnd, GetBooks.ReminderEnd);
            Assert.AreEqual(compareTask.RingTone, GetBooks.RingTone);
            Assert.AreEqual(compareTask.Done, GetBooks.Done);
            Assert.AreEqual(compareTask.Frequency, GetBooks.Frequency);
            Assert.AreEqual(compareTask.FrequencyUnit, GetBooks.FrequencyUnit);

            reader.Dispose();
        }
        public void SchedulerSerializationTest()
        {
            Scheduler scheduler = new Scheduler();
            AppTask task1 = new AppTask();
            AppTask task2 = new AppTask();

            task1.TaskName = "Task1";
            task1.TaskNotes = "Task One!";
            task1.Frequency = 2;
            task1.FrequencyUnit = "Days";
            task1.Done = false;
            task1.ReminderEnd = System.DateTime.Now;
            scheduler.AddTask(task1);

            task2.TaskName = "Task2";
            task2.TaskNotes = "Task Two.";
            task2.Frequency = 4;
            task2.FrequencyUnit = "Months";
            task2.Done = true;
            task2.ReminderEnd = System.DateTime.Now;
            scheduler.AddTask(task2);

            Assert.AreEqual(2, scheduler.TaskCount);

            scheduler.Write("Test.xml");

            Scheduler schedulerToCompare = new Scheduler("Test.xml");
            Assert.AreEqual(2, schedulerToCompare.TaskCount);
            Assert.AreEqual(1, scheduler.GetTasks(false).Count);
            Assert.AreEqual(scheduler.TaskAt(0).TaskName, "Task1");
            Assert.AreEqual(scheduler.TaskAt(1).TaskName, "Task2");
        }
 public void CheckingIfTaskNameLessThan40IsShortend()
 {
     string TestTaskName = "PickUpBook-HarryPotterAndTheChamberOfSecrets";
     string TestTaskNote = "BooksAtLibrary";
     AppTask GetBooks = new AppTask(TestTaskName, TestTaskNote, 0);
     //Console.WriteLine(GetBooks.TaskNotes);
     Assert.AreEqual(TestTaskNote, GetBooks.TaskNotes);
     Assert.AreEqual(TestTaskName.Substring(0,40), GetBooks.TaskName);
 }
 public void CheckingIfNamesAndNotesAreLoaded()
 {
     string TestTaskName = "PickUpBook-HarryPotter";
     string TestTaskNote = "BooksAtLibrary";
     AppTask GetBooks = new AppTask(TestTaskName, TestTaskNote, 0);
     //Console.WriteLine(GetBooks.TaskNotes);
     Assert.AreEqual(TestTaskNote, GetBooks.TaskNotes);
     Assert.AreEqual(TestTaskName, GetBooks.TaskName);
 }
Exemple #5
0
        public void UpdateTaskWithInfo(int taskID, string name,
                                       string notes, DateTime reminderBegin, DateTime reminderEnd,
                                       string ringToneName, int frequency, string frequencyUnit)
        {
            AppTask updateTask = FindTaskById(taskID);

            updateTask.TaskName      = name;
            updateTask.TaskNotes     = notes;
            updateTask.ReminderEnd   = reminderEnd;
            updateTask.RingTone      = ringToneName;
            updateTask.Frequency     = frequency;
            updateTask.FrequencyUnit = frequencyUnit;

            System.Threading.Tasks.Task.Run(() => Write(tasksPath)).Wait();
        }
Exemple #6
0
        public void AddTask(AppTask taskToAdd)
        {
            if (taskToAdd.TaskName == null)
            {
                throw new ArgumentNullException("taskToAdd.TaskName");
            }
            else if (taskToAdd.ReminderEnd == null)
            {
                throw new ArgumentNullException("taskToAdd.ReminderEndDate");
            }
            else
            {
                tasks.Add(taskToAdd);
            }

            System.Threading.Tasks.Task.Run(() => Write(tasksPath)).Wait();
        }
        public void AddTask(AppTask taskToAdd)
        {
           
            if (taskToAdd.TaskName == null)
            {
                throw new ArgumentNullException("taskToAdd.TaskName");
            }
            else if (taskToAdd.ReminderEnd == null)
            {
                throw new ArgumentNullException("taskToAdd.ReminderEndDate");
            }
            else
            {
                tasks.Add(taskToAdd);
            }

            System.Threading.Tasks.Task.Run(() => Write(tasksPath)).Wait();
        }
        public Main()
        {
            Title = "Scheduler App 2016";
            Core      MainCore      = Core.GetCore();
            Scheduler MainScheduler = MainCore.GetScheduler();

            listView = new ListView();
            listView.ItemSelected += (sender, e) => {
                AppTask x = (AppTask)e.SelectedItem;
                if (x is AppTask)
                {
                    Navigation.PushAsync(new pageTask(Core.GetCore().GetScheduler().FindTaskById(x.TaskID)));
                    ((ListView)sender).SelectedItem = null;
                }
            };

            AddTask = new Button {
                Text  = "Add Task",
                Style = MainCore.GetConfig().GenerateButtonStyle()
            };
            AddTask.Clicked += (sender, e) => {
                var pAddTask = new pageTask();
                this.Navigation.PushAsync(pAddTask);
            };
            ConfigButton = new Button {
                Text = "Configuration", Style = MainCore.GetConfig().GenerateButtonStyle()
            };
            ConfigButton.Clicked += (sender, e) => {
                var pAppSettings = new pageAppConfig();

                this.Navigation.PushAsync(pAppSettings);
            };

            Content = new StackLayout {
                VerticalOptions = LayoutOptions.Center,
                Children        =
                {
                    listView,
                    AddTask,
                    ConfigButton
                }
            };
        }
        public async AppTask RunPendingTaskListUpdate(CancellationToken token)
        {
            await AppTask.Run(async() =>
            {
                token.ThrowIfCancellationRequested();

                await AppTask.Delay(1000);

                var pendingTasks = new PendingTaskMessage
                {
                    tasks = ScheduleApp.Core.GetCore().GetScheduler().GetTasks(false);
                };

                Device.BeginInvokeOnMainThread(() =>
                {
                    MessagingCenter.Send <List>(pendingTasks, "TickedMessage");
                });
            }, token);
        }
        public async void Read(string path)
        {
            try
            { 
                ExistenceCheckResult result = await FileSystem.Current.LocalStorage.CheckExistsAsync(path);
                                
                if (result == ExistenceCheckResult.FileExists)
                {
                    IFile file = await FileSystem.Current.LocalStorage.GetFileAsync(path);
                    XmlReader reader = XmlReader.Create(await file.OpenAsync(FileAccess.Read));

                    tasks.Clear();

                    reader.ReadToDescendant("Task");

                    while (reader != null && reader.Name == "Task")
                    { 
                        AppTask task = new AppTask();
                        task.ReadXML(reader);
                        tasks.Add(task);
                    }
                }
                else
                {
                    System.Threading.Tasks.Task.Run(() => Write(path)).Wait();
                }
            }
            catch(Exception e)
            {
                String error = e.Message;
            }

        }
Exemple #11
0
        public pageTask(AppTask existingTask = null)
        {
            AppConfig config = Core.GetCore().GetConfig();

            Title = "Add Task";
            var nameLabel = new Label {
                Text = "Task Name", Style = config.GenerateLabelStyle()
            };

            Entry nameEntry = new Entry {
                Placeholder = "New Task Name"
            };

            nameEntry.Style = config.GenerateEntryStyle();

            var noteLabel = new Label {
                Text = "Task Note", Style = config.GenerateLabelStyle()
            };
            Entry noteEntry = new Entry {
                Placeholder = "New Task Notes"
            };

            noteEntry.Style = config.GenerateEntryStyle();

            var doneLabel = new Label {
                Text = "Done", Style = config.GenerateLabelStyle()
            };
            var donePicker = new Picker {
                Style = config.GeneratePickerStyle()
            };

            donePicker.Items.Add("False");
            donePicker.Items.Add("True");
            donePicker.SelectedIndex = 0;

            var reminderBeginDateLabel = new Label {
                Text = "Set Begin Date", Style = config.GenerateLabelStyle()
            };
            var reminderBeginDatePicker = new DatePicker
            {
                Format = "D",
                Style  = config.GeneratePickerStyle()
            };

            var reminderEndDateLabel = new Label {
                Text = "Set End Date", Style = config.GenerateLabelStyle()
            };
            var reminderEndDatePicker = new DatePicker {
                Format = "D",
                Style  = config.GeneratePickerStyle()
            };

            Button ringTonePickerBtn = new Button
            {
                Text = "Select RingTone",
            };

            ringTonePickerBtn.Clicked += (sender, args) =>
            {
                DependencyService.Get <iRingTones>().GetRingTonePicker(existingTask);
            };

            var frequencyLabel = new Label {
                Text = "Select Frequency", Style = config.GenerateLabelStyle()
            };
            var frequencyPicker = new Picker {
                Style = config.GeneratePickerStyle()
            };

            for (int i = 1; i <= 10; i++)
            {
                frequencyPicker.Items.Add(i.ToString());
            }

            var frequencyUnitLabel = new Label {
                Text = "Select Unit", Style = config.GenerateLabelStyle()
            };
            var frequencyUnitPicker = new Picker {
                Style = config.GeneratePickerStyle()
            };

            frequencyUnitPicker.Items.Add("Minutes");
            frequencyUnitPicker.Items.Add("Hours");
            frequencyUnitPicker.Items.Add("Days");
            frequencyUnitPicker.Items.Add("Weeks");

            Button deleteButton = new Button
            {
                Text  = "Delete",
                Style = config.GenerateButtonStyle()
            };

            deleteButton.IsVisible = false;

            deleteButton.Clicked += async(sender, e) =>
            {
                bool willDelete = await DisplayAlert("Delete Confirmation", "Are you sure you want to remove this task?", "Yes", "No");

                if (willDelete)
                {
                    Core.GetCore().GetScheduler().RemoveTask(existingTask.TaskID);
                    await Navigation.PopAsync();
                }
            };

            if (existingTask == null)
            {
                frequencyPicker.SelectedIndex     = 5;
                frequencyUnitPicker.SelectedIndex = 2;
            }
            else
            {
                nameEntry.Text = existingTask.TaskName;
                noteEntry.Text = existingTask.TaskNotes;

                if (existingTask.Done)
                {
                    donePicker.SelectedIndex = 1;
                }
                else
                {
                    donePicker.SelectedIndex = 0;
                }

                reminderBeginDatePicker.Date = existingTask.ReminderBegin;
                reminderEndDatePicker.Date   = existingTask.ReminderEnd;

                for (int i = 0; i < frequencyPicker.Items.Count; i++)
                {
                    if (existingTask.Frequency.ToString() == frequencyPicker.Items[i])
                    {
                        frequencyPicker.SelectedIndex = i;
                        break;
                    }
                }

                for (int i = 0; i < frequencyUnitPicker.Items.Count; i++)
                {
                    if (existingTask.FrequencyUnit == frequencyUnitPicker.Items[i])
                    {
                        frequencyUnitPicker.SelectedIndex = i;
                        break;
                    }
                }

                deleteButton.IsVisible = true;
            }

            var SaveButton = new Button {
                Text  = "Save!",
                Style = config.GenerateButtonStyle()
            };

            SaveButton.Clicked += (sender, e) => {
                string   tTaskName;
                string   tTaskNotes;
                DateTime tReminderBeginDate;
                DateTime tReminderEndDate;
                bool     tDone;
                int      tFrequency;
                string   tFrequencyUnit;
                string   tNotificationSound;

                if (nameEntry.Text != null && noteEntry.Text != null)
                {
                    tTaskName          = nameEntry.Text.ToString();
                    tTaskNotes         = noteEntry.Text.ToString();
                    tReminderBeginDate = reminderBeginDatePicker.Date;
                    tReminderEndDate   = reminderEndDatePicker.Date;
                    tDone              = Convert.ToBoolean(donePicker.Items [donePicker.SelectedIndex]);
                    tFrequency         = Convert.ToInt32(frequencyPicker.Items[frequencyPicker.SelectedIndex]);
                    tFrequencyUnit     = frequencyUnitPicker.Items[frequencyUnitPicker.SelectedIndex];
                    tNotificationSound = DependencyService.Get <iRingTones>().GetSelectedRingTone();

                    if (existingTask == null)
                    {
                        Core.GetCore().GetScheduler().AddTaskWithInfo(
                            tTaskName, tTaskNotes, tReminderBeginDate,
                            tReminderEndDate, tNotificationSound, tFrequency, tFrequencyUnit);
                    }
                    else
                    {
                        Core.GetCore().GetScheduler().UpdateTaskWithInfo(
                            existingTask.TaskID, tTaskName, tTaskNotes,
                            tReminderBeginDate, tReminderEndDate, tNotificationSound,
                            tFrequency, tFrequencyUnit);
                    }

                    Navigation.PopAsync();
                }
                else
                {
                    DisplayAlert("But wait!", "Please write a little about your Task name and task notes.", "Ok");
                };
            };

            ScrollView scrollView = new ScrollView {
                VerticalOptions = LayoutOptions.FillAndExpand,
                Content         = new StackLayout {
                    VerticalOptions = LayoutOptions.CenterAndExpand,
                    Padding         = new Thickness(20),
                    Children        =
                    {
                        nameLabel,
                        nameEntry,
                        noteLabel,
                        noteEntry,
                        doneLabel,
                        donePicker,
                        ringTonePickerBtn,
                        reminderBeginDateLabel,
                        reminderBeginDatePicker,
                        frequencyLabel,
                        frequencyPicker,
                        frequencyUnitLabel,
                        frequencyUnitPicker,
                        reminderEndDateLabel,
                        reminderEndDatePicker,
                        SaveButton,
                        deleteButton
                    }
                }
            };

            this.Content = scrollView;
        }