Esempio n. 1
0
        private async Task Scan()
        {
            using (var one = new OneNote())
            {
                var hierarchy = await one.SearchMeta(string.Empty, MetaNames.Reminder);

                if (hierarchy == null)
                {
                    // may need to restart OneNote
                    return;
                }

                var ns = hierarchy.GetNamespaceOfPrefix(OneNote.Prefix);

                var metas = hierarchy.Descendants(ns + "Meta").Where(e =>
                                                                     e.Attribute("name").Value == MetaNames.Reminder &&
                                                                     e.Attribute("content").Value.Length > 0);

                if (!metas.Any())
                {
                    return;
                }

                var serializer = new ReminderSerializer();
                foreach (var meta in metas)
                {
                    var reminders = serializer.DecodeContent(meta.Attribute("content").Value);
                    var pageID    = meta.Parent.Attribute("ID").Value;
                    foreach (var reminder in reminders)
                    {
                        if (reminder.Silent)
                        {
                            continue;
                        }

                        if (reminder.Snooze != SnoozeRange.None &&
                            DateTime.UtcNow.CompareTo(reminder.SnoozeTime) < 0)
                        {
                            continue;
                        }

                        if (RemindScheduler.WaitingOn(reminder))
                        {
                            continue;
                        }

                        await Test(reminder, pageID, one);
                    }
                }
            }
        }
Esempio n. 2
0
        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);
                }
            }
        }
Esempio n. 3
0
        private async Task Test(Reminder reminder, string pageID, OneNote one)
        {
            // is it not started but after the planned start date?
            if (reminder.Status == ReminderStatus.NotStarted ||
                reminder.Status == ReminderStatus.Waiting)
            {
                if (DateTime.UtcNow.CompareTo(reminder.Start) > 0 &&
                    await ReminderIsValid(reminder, pageID, one))
                {
                    Send(
                        string.Format(
                            Resx.Reminder_PastStart,
                            reminder.Due.ToShortFriendlyString(),
                            reminder.Subject
                            ),
                        $"{pageID};{reminder.ObjectId}"
                        );

                    RemindScheduler.ScheduleNotification(reminder, false);
                }
            }
            // is it not completed but after the planned due date?
            else if (reminder.Status == ReminderStatus.InProgress)
            {
                if (DateTime.UtcNow.CompareTo(reminder.Due) > 0 &&
                    await ReminderIsValid(reminder, pageID, one))
                {
                    Send(
                        string.Format(
                            Resx.Reminder_PastDue,
                            reminder.Due.ToShortFriendlyString(),
                            reminder.Subject
                            ),
                        $"{pageID};{reminder.ObjectId}"
                        );

                    RemindScheduler.ScheduleNotification(reminder, true);
                }
            }
        }
Esempio n. 4
0
        public override async Task Execute(params object[] args)
        {
            logger.StartDiagnostic();
            logger.WriteLine("Diagnostics.Execute()");
            logger.WriteLine(new string('-', 80));

            var processes  = Process.GetProcessesByName("ONENOTE");
            var moduledesc = "unknown";

            if (processes.Length > 0)
            {
                var module = processes[0].MainModule;
                moduledesc = $"{module.FileName} ({module.FileVersionInfo.ProductVersion})";
            }

            logger.WriteLine($"ONENOTE...: {moduledesc}");
            logger.WriteLine($"Addin path: {Assembly.GetExecutingAssembly().Location}");
            logger.WriteLine($"Data path.: {PathFactory.GetAppDataPath()}");
            logger.WriteLine($"Log path..: {logger.LogPath}");
            logger.WriteLine();

            using (var one = new OneNote())
            {
                var(backupFolder, defaultFolder, unfiledFolder) = one.GetFolders();
                logger.WriteLine($"Default path: {defaultFolder}");
                logger.WriteLine($"Backup  path: {backupFolder}");
                logger.WriteLine($"Unfiled path: {unfiledFolder}");
                logger.WriteLine();

                var info = one.GetPageInfo();
                logger.WriteLine($"Page name: {info.Name}");
                logger.WriteLine($"Page path: {info.Path}");
                logger.WriteLine($"Page link: {info.Link}");
                logger.WriteLine();

                info = one.GetSectionInfo();
                logger.WriteLine($"Section name: {info.Name}");
                logger.WriteLine($"Section path: {info.Path}");
                logger.WriteLine($"Section link: {info.Link}");
                logger.WriteLine();

                var notebook = await one.GetNotebook();

                var notebookId = one.CurrentNotebookId;
                logger.WriteLine($"Notebook name: {notebook.Attribute("name").Value}");
                logger.WriteLine($"Notebook link: {one.GetHyperlink(notebookId, null)}");
                logger.WriteLine();

                one.ReportWindowDiagnostics(logger);

                logger.WriteLine();

                var page           = one.GetPage();
                var pageColor      = page.GetPageColor(out _, out _);
                var pageBrightness = pageColor.GetBrightness();

                logger.WriteLine($"Page background: {pageColor.ToRGBHtml()}");
                logger.WriteLine($"Page brightness: {pageBrightness}");
                logger.WriteLine($"Page is dark...: {pageBrightness < 0.5}");

                (float dpiX, float dpiY) = UIHelper.GetDpiValues();
                logger.WriteLine($"Screen DPI.....: horizontal/X:{dpiX} vertical/Y:{dpiY}");

                (float scalingX, float scalingY) = UIHelper.GetScalingFactors();
                logger.WriteLine($"Scaling factors: horizontal/X:{scalingX} vertical/Y:{scalingY}");

                RemindCommand.ReportDiagnostics(logger);
                RemindScheduler.ReportDiagnostics(logger);

                logger.WriteLine(new string('-', 80));

                using (var dialog = new DiagnosticsDialog(logger.LogPath))
                {
                    dialog.ShowDialog(owner);
                }
            }

            // turn headers back on
            logger.End();

            await Task.Yield();
        }