private static async Task <BookMarkFolder> MoveNoLongerFoundDomains(this BookMarkFolder bookMarks)
        {
            var flattened          = bookMarks.FlattenBookMarks().ToList();
            var bookMarksToResolve = flattened
                                     .OfType <BookMark>()
                                     .Select(GetHostWithBookMark)
                                     .Where(h => h.Host != null)
                                     .ToArray();

            var locker = new object();
            var dict   = new Dictionary <string, Task <bool> >();

            Parallel.For(0, bookMarksToResolve.Length, (i) =>
            {
                var(host, bookMark, _) = bookMarksToResolve[i];
                if (!dict.ContainsKey(host))
                {
                    lock (locker)
                    {
                        if (!dict.ContainsKey(host))
                        {
                            dict[host] = HostExists(host);
                        }
                    }
                }
                bookMarksToResolve[i] = (host, bookMark, dict[host]);
            });
        private static BookMarkFolder ParseFolder(string line, BookMarkFolder containingFolder)
        {
            var(innerText, attributes) = GetNode($"{line}</DT>", "DT", "H3");
            var createdDate           = attributes.TryGetValue("ADD_DATE", out var unixDateStr1) ? ParseUnixDate(unixDateStr1) : ParseUnixDate("0");
            var lastModifiedDate      = attributes.TryGetValue("LAST_MODIFIED", out var unixDateStr2) ? ParseUnixDate(unixDateStr2) : ParseUnixDate("0");
            var personalToolbarFolder = attributes.TryGetValue("PERSONAL_TOOLBAR_FOLDER", out var personalToolbarFolderStr) && bool.Parse(personalToolbarFolderStr);

            return(new BookMarkFolder(innerText, containingFolder.Depth + 1, createdDate, lastModifiedDate, containingFolder, personalToolbarFolder));
        }
        private static BookMark ParseBookMark(string line, BookMarkFolder containingFolder)
        {
            var(innerText, attributes) = GetNode($"{line}</DT>", "DT", "A");
            var link    = attributes.TryGetValue("HREF", out var hrefStr) ? hrefStr : null;
            var icon    = attributes.TryGetValue("ICON", out var iconStr) ? iconStr : null;
            var addDate = attributes.TryGetValue("ADD_DATE", out var unixDateStr) ? ParseUnixDate(unixDateStr) : ParseUnixDate("0");

            return(new BookMark(innerText, icon, link, containingFolder.Depth + 1, addDate, containingFolder));
        }
 public BookMark(string title, string icon, string link, int depth, DateTime createdDate, BookMarkFolder parent)
 {
     Title       = title;
     Icon        = icon;
     Link        = link;
     Depth       = depth;
     CreatedDate = createdDate;
     Parent      = parent;
 }
Пример #5
0
 public BookMarkFolder(string title, int depth, DateTime createdDate, DateTime lastModifiedDate, BookMarkFolder parent, bool personalToolbarFolder = false, IEnumerable <IBookMarkNode> children = null)
 {
     Title                 = title;
     Depth                 = depth;
     CreatedDate           = createdDate;
     LastModifiedDate      = lastModifiedDate;
     Parent                = parent;
     PersonalToolbarFolder = personalToolbarFolder;
     Children              = new List <IBookMarkNode>(children ?? new IBookMarkNode[0]);
     FullTitle             = $"{Parent?.FullTitle}/{Title}";
 }
        private static BookMarkFolder RemoveShallowestDuplicates(this BookMarkFolder bookMarks)
        {
            var flattened         = bookMarks.FlattenBookMarks().ToList();
            var bookMarksToRemove = flattened
                                    .OfType <BookMark>()
                                    .GroupBy(bm => bm.Link)
                                    .Where(grp => grp.Count() > 1)
                                    .Select(g => g.OrderBy(b => b.Depth).ToList())
                                    .SelectMany(g => g.Take(g.Count - 1));

            foreach (var nodeToRemove in bookMarksToRemove)
            {
                Console.WriteLine($"Removing BookMark '{nodeToRemove.Title}' from '{nodeToRemove.Parent.FullTitle}'");
                nodeToRemove.Parent.Children.Remove(nodeToRemove);
            }
            return(bookMarks);
        }