private async Task NavigateToReminder(string args) { var parts = args.Split(';'); var pageId = parts[0]; var objectId = parts[1]; using (var one = new OneNote()) { Native.SetForegroundWindow(one.WindowHandle); await one.NavigateTo(pageId, objectId); page = one.GetPage(pageId); ns = page.Namespace; var paragraph = page.Root.Descendants(ns + "OE") .FirstOrDefault(e => e.Attribute("objectID").Value == objectId); var reminder = GetReminder(paragraph); if (reminder == null) { // TODO: message? return; } using (var dialog = new RemindDialog(reminder, true)) { if (dialog.ShowDialog(owner) == DialogResult.OK) { if (SetReminder(paragraph, dialog.Reminder)) { await one.Update(page); } } } if (reminder.Silent || reminder.Snooze != SnoozeRange.None) { RemindScheduler.CancelOverride(reminder); } else { var started = ( reminder.Status == ReminderStatus.InProgress || reminder.Status == ReminderStatus.Waiting) && DateTime.UtcNow.CompareTo(reminder.Started) > 0; RemindScheduler.ScheduleNotification(reminder, started); } } }
public override async Task Execute(params object[] args) { if (args.Length > 0 && args[0] is string arg) { // received via toast activation await NavigateToReminder(arg); return; } using (var one = new OneNote(out page, out ns)) { PageNamespace.Set(ns); var paragraph = page.Root.Descendants(ns + "T") .Where(e => e.Attribute("selected")?.Value == "all") .Select(e => e.Parent) .FirstOrDefault(); if (paragraph == null) { UIHelper.ShowInfo(one.Window, Resx.RemindCommand_noContext); return; } var reminder = GetReminder(paragraph); using (var dialog = new RemindDialog(reminder, false)) { if (dialog.ShowDialog(owner) == DialogResult.OK) { if (SetReminder(paragraph, dialog.Reminder)) { await one.Update(page); } } } } }