Пример #1
0
        public void SetRange(DateTime startDate, DateTime endDate, CalendarPages pages)
        {
            listbox.Items.Clear();

            var date = startDate;

            while (date <= endDate)
            {
                var settings = new SettingsProvider();

                var daypages = new CalendarPages();

                // filtering prioritizes modified over created and prevent pages from being
                // displayed twice in the month if both created and modified in the same month
                daypages.AddRange(pages.Where(p =>
                                              (settings.Modified && p.Modified.Date.Equals(date)) ||
                                              (!settings.Modified && p.Created.Date.Equals(date))
                                              ));

                if (daypages.Any() || settings.Empty)
                {
                    listbox.Items.Add(new DayItem
                    {
                        Date  = date,
                        Pages = daypages
                    });
                }

                date = date.AddDays(1);
            }

            Invalidate();
        }
Пример #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="startDate"></param>
        /// <param name="endDate"></param>
        /// <param name="notebookIDs"></param>
        /// <param name="created"></param>
        /// <param name="modified"></param>
        /// <param name="deleted"></param>
        /// <returns></returns>
        public async Task <CalendarPages> GetPages(
            DateTime startDate, DateTime endDate,
            IEnumerable <string> notebookIDs,
            bool created, bool modified, bool deleted)
        {
            using (one = new OneNote())
            {
                var notebooks = await GetNotebooks(notebookIDs);

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

                // filter to selected month...

                var pages = new CalendarPages();

                pages.AddRange(notebooks.Descendants(ns + "Page")
                               .Where(e => deleted || e.Attribute("isInRecycleBin") == null)
                               // collect all pages
                               .Select(e => new
                {
                    Page      = e,
                    Created   = DateTime.Parse(e.Attribute("dateTime").Value),
                    Modified  = DateTime.Parse(e.Attribute("lastModifiedTime").Value),
                    IsDeleted = e.Attribute("isInRecycleBin") != null
                })
                               // filter by one or both filters
                               .Where(a =>
                                      (created && a.Created.InRange(startDate, endDate)) ||
                                      (modified && a.Modified.InRange(startDate, endDate)))
                               // prefer creation time
                               .OrderBy(a => created ? a.Created : a.Modified)
                               // pretty it up
                               .Select(a => new CalendarPage
                {
                    PageID = a.Page.Attribute("ID").Value,
                    Path   = a.Page.Ancestors()
                             .Where(n => n.Attribute("name") != null)
                             .Select(n => n.Attribute("name").Value)
                             .Aggregate((name1, name2) => $"{name2} > {name1}"),
                    Title     = a.Page.Attribute("name").Value,
                    Created   = a.Created,
                    Modified  = a.Modified,
                    IsDeleted = a.IsDeleted
                }));

                pages.ForEach(page =>
                {
                    var DeletedPages = "OneNote_RecycleBin > Deleted Pages";
                    if (page.Path.EndsWith(DeletedPages))
                    {
                        page.Path = page.Path.Substring(
                            0, page.Path.Length - DeletedPages.Length) + "Recycle Bin";
                    }
                });

                return(pages);
            }
        }