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 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); }