public static Directory Build(IEnumerable<WeaveClientSession> clientSessions)
        {
            Directory rootDirectory = new Directory("Open Tabs", "tabs");
            foreach (Directory directory in ConvertWeaveClientSessions(clientSessions))
                rootDirectory.Directories.Add(directory);

            return rootDirectory;
        }
        /// <summary>
        /// Build a hierarchic directory structure.
        /// </summary>
        /// <param name="bookmarks"></param>
        /// <returns></returns>
        public static Directory Build(IEnumerable<WeaveBookmark> bookmarks)
        {
            Dictionary<string, Directory> directoryIdMapping = new Dictionary<string, Directory>();
            Dictionary<string, Bookmark> bookmarkIdMapping = new Dictionary<string, Bookmark>();

            IList<WeaveBookmark> directories = (from b in bookmarks
                                                where b.BookmarkType == BookmarkType.Folder
                                                select b).ToList();

            IList<WeaveBookmark> items = (from b in bookmarks
                                                where b.BookmarkType == BookmarkType.Bookmark
                                                select b).ToList();

            // Create directory objects
            foreach (WeaveBookmark weaveDirectory in directories)
            {
                directoryIdMapping.Add(weaveDirectory.Id, new Directory(weaveDirectory.Title, weaveDirectory.Id));
            }

            // Create bookmark objects
            foreach (WeaveBookmark weaveBookmark in items)
            {
                bookmarkIdMapping.Add(weaveBookmark.Id, new Bookmark(weaveBookmark.Title, weaveBookmark.Uri));
            }

            // Assign parent values
            foreach (WeaveBookmark weaveDirectory in directories)
            {
                if (directoryIdMapping.ContainsKey(weaveDirectory.ParentId))
                    directoryIdMapping[weaveDirectory.Id].Parent = directoryIdMapping[weaveDirectory.ParentId];
            }

            // Assign items
            foreach (WeaveBookmark weaveDirectory in directories)
            {
                Directory directory = directoryIdMapping[weaveDirectory.Id];

                foreach (string child in weaveDirectory.Children)
                {
                    if (bookmarkIdMapping.ContainsKey(child))
                    {
                        Bookmark bookmark = bookmarkIdMapping[child];
                        directory.Bookmarks.Add(bookmark);
                    }
                    else if (directoryIdMapping.ContainsKey(child))
                    {
                        Directory childDirectory = directoryIdMapping[child];
                        directory.Directories.Add(childDirectory);
                    }
                }
            }

            Directory bookmarksDirectory = new Directory("All Bookmarks", "bookmarks");
            bookmarksDirectory.Directories.Add(directoryIdMapping["toolbar"]);
            bookmarksDirectory.Directories.Add(directoryIdMapping["menu"]);
            return bookmarksDirectory;
        }
        public static Directory Build(IEnumerable<WeaveHistoryItem> weaveHistoryItems)
        {
            if (weaveHistoryItems.IsEmpty())
            {
                return new Directory("All History", "history");
            }
            else
            {
                // Today
                var todayQuery = from b in weaveHistoryItems
                                 let dateTime = b.Visits!= null ? b.Visits.First().Date : DateTime.MinValue
                                 where IsToday(dateTime)
                                 orderby dateTime
                                 select b;

                Directory today = new Directory("Today", "today");
                foreach (WeaveHistoryItem historyItem in todayQuery)
                    today.Bookmarks.Add(new Bookmark(historyItem.Title, historyItem.Uri));

                // Yesterday
                var yesterdayQuery = from b in weaveHistoryItems
                                     let dateTime = b.Visits != null ? b.Visits.First().Date : DateTime.MinValue
                                     where IsYesterday(dateTime)
                                     orderby dateTime
                                     select b;

                Directory yesterday = new Directory("Yesterday", "yesterday");
                foreach (WeaveHistoryItem historyItem in yesterdayQuery)
                    yesterday.Bookmarks.Add(new Bookmark(historyItem.Title, historyItem.Uri));

                // This Month
                var thisMonthQuery = from b in weaveHistoryItems
                                     let dateTime = b.Visits != null ? b.Visits.First().Date : DateTime.MinValue
                                     where IsThisMonth(dateTime)
                                     orderby dateTime
                                     select b;

                Directory thisMonth = new Directory("This Month", "thismonth");
                foreach (WeaveHistoryItem historyItem in thisMonthQuery)
                    thisMonth.Bookmarks.Add(new Bookmark(historyItem.Title, historyItem.Uri));

                // History
                Directory history = new Directory("All History", "history");
                history.Directories.Add(today);
                history.Directories.Add(yesterday);
                history.Directories.Add(thisMonth);

                return history;
            }
        }
        private static IList<Directory> ConvertWeaveClientSessions(IEnumerable<WeaveClientSession> weaveClientSessions)
        {
            List<Directory> directories = new List<Directory>();

            foreach (WeaveClientSession weaveClientSession in weaveClientSessions)
            {
                Directory clientDirectory = new Directory(weaveClientSession.ClientName, weaveClientSession.ClientName);
                directories.Add(clientDirectory);

                foreach (WeaveTab weaveTab in weaveClientSession.OpenTabs)
                    clientDirectory.Bookmarks.Add(new Bookmark(weaveTab.Title, weaveTab.UrlHistory[0]));
            }

            return directories;
        }