예제 #1
0
        // if the user deletes the paragraph containing a reminder, the Meta will be orphaned
        // so this verifies that the paragraph still exists and clears the Meta if it does not
        private async Task <bool> ReminderIsValid(Reminder reminder, string pageID, OneNote one)
        {
            var page = one.GetPage(pageID, OneNote.PageDetail.Basic);

            if (page == null)
            {
                // must be an error?
                logger.WriteLine($"reminder page not found {pageID}");
                return(false);
            }

            if (page.Root.Descendants(page.Namespace + "OE")
                .Any(e => e.Attribute("objectID").Value == reminder.ObjectId))
            {
                // reminder is valid, keep it!
                return(true);
            }

            // clear the orphaned reminder...

            var serializer = new ReminderSerializer();
            var reminders  = serializer.LoadReminders(page);

            if (!reminders.Any())
            {
                // must be an error?
                logger.WriteLine($"reminder not found on page {pageID}");
                return(false);
            }

            var orphan = reminders.FirstOrDefault(r => r.ObjectId == reminder.ObjectId);

            if (orphan == null)
            {
                // must be an error?
                logger.WriteLine($"reminder not found in page meta {pageID}");
                return(false);
            }

            reminders.Remove(orphan);
            page.SetMeta(MetaNames.Reminder, serializer.EncodeContent(reminders));
            await one.Update(page);

            return(false);
        }
예제 #2
0
        public override async Task Execute(params object[] args)
        {
            using (var one = new OneNote(out var page, out var 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 serializer = new ReminderSerializer();
                var reminders  = serializer.LoadReminders(page);
                if (!reminders.Any())
                {
                    UIHelper.ShowError(one.Window, Resx.RemindCommand_noReminder);
                    return;
                }

                var objectID = paragraph.Attribute("objectID").Value;
                var reminder = reminders.FirstOrDefault(r => r.ObjectId == objectID);
                if (reminder == null)
                {
                    UIHelper.ShowError(one.Window, Resx.RemindCommand_noReminder);
                    return;
                }

                XElement tag = null;
                if (!string.IsNullOrEmpty(reminder.Symbol) && reminder.Symbol != "0")
                {
                    reminder.TagIndex = page.GetTagDefIndex(reminder.Symbol);
                    if (reminder.TagIndex != null)
                    {
                        // confirm tag still exists
                        tag = paragraph.Elements(ns + "Tag")
                              .FirstOrDefault(e => e.Attribute("index").Value == reminder.TagIndex);
                    }
                }

                if (tag == null)
                {
                    reminders.Remove(reminder);
                    page.SetMeta(MetaNames.Reminder, serializer.EncodeContent(reminders));
                    await one.Update(page);

                    UIHelper.ShowError(one.Window, Resx.RemindCommand_noReminder);
                    return;
                }

                // complete the reminder...

                reminder.Status    = ReminderStatus.Completed;
                reminder.Percent   = 100;
                reminder.Completed = DateTime.UtcNow;
                serializer.StoreReminder(page, reminder);

                tag.Attribute("completed").Value = "true";
                tag.SetAttributeValue("completionDate", reminder.Completed.ToString(dateFormat));

                await one.Update(page);
            }
        }
예제 #3
0
        public override async Task Execute(params object[] args)
        {
            using (var one = new OneNote(out var page, out var 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 serializer = new ReminderSerializer();
                var reminders  = serializer.LoadReminders(page);
                if (!reminders.Any())
                {
                    UIHelper.ShowError(one.Window, Resx.RemindCommand_noReminder);
                    return;
                }

                var objectID = paragraph.Attribute("objectID").Value;
                var reminder = reminders.FirstOrDefault(r => r.ObjectId == objectID);
                if (reminder == null)
                {
                    UIHelper.ShowError(one.Window, Resx.RemindCommand_noReminder);
                    return;
                }

                XElement tag = null;
                if (!string.IsNullOrEmpty(reminder.Symbol) && reminder.Symbol != "0")
                {
                    reminder.TagIndex = page.GetTagDefIndex(reminder.Symbol);
                    if (reminder.TagIndex != null)
                    {
                        // confirm tag still exists
                        tag = paragraph.Elements(ns + "Tag")
                              .FirstOrDefault(e => e.Attribute("index").Value == reminder.TagIndex);
                    }
                }

                if (tag == null)
                {
                    reminders.Remove(reminder);
                    page.SetMeta(MetaNames.Reminder, serializer.EncodeContent(reminders));
                    await one.Update(page);

                    UIHelper.ShowError(one.Window, Resx.RemindCommand_noReminder);
                    return;
                }

                var result = UIHelper.ShowQuestion(
                    Resx.DeleteReminderCommand_deleteTag, canCancel: true);

                if (result == DialogResult.Cancel)
                {
                    return;
                }

                if (result == DialogResult.Yes)
                {
                    tag.Remove();
                }

                reminders.Remove(reminder);
                page.SetMeta(MetaNames.Reminder, serializer.EncodeContent(reminders));

                await one.Update(page);
            }
        }