private void clearCacheButton_Click(object sender, RoutedEventArgs e) { Dispatcher.BeginInvoke(() => { BookmarksController.ClearBookmarks(); BookmarksStorageManager.DeleteAllCache(); App.ViewModel.Bookmarks.Clear(); App.ViewModel.LoadDataFromWeb(); NavigationService.GoBack(); }); }
private void UpdateBookmarkCacheStatus() { var bookmarks = App.DbDataContext.Bookmarks.ToList(); var downloadsController = new DownloadsController(); foreach (var bookmark in bookmarks) { if (!BookmarksStorageManager.DoesBookmarkBodyExist(bookmark.BookmarkId) && bookmark.IsDownloaded) { bookmark.IsDownloaded = false; bookmark.ShortBodyText = "Downloading..."; downloadsController.AddBookmark(bookmark); } } App.DbDataContext.SubmitChanges(); downloadsController.ProcessQueue(); }
public void ProcessQueue() { Deployment.Current.Dispatcher.BeginInvoke(() => { WeiranZhang.Metropaper.Controls.GlobalLoading.Instance.IsLoading = true; }); ThreadPool.QueueUserWorkItem(delegate { lock (_downloadsQueue) { while (_downloadsQueue.Count > 0) { var queuedBookmark = _downloadsQueue.Dequeue(); var bookmarkId = queuedBookmark.BookmarkId; var bookmarkViewModel = GetBookmarkViewModel(queuedBookmark); if (!bookmarkViewModel.IsDownloaded) { var bookmarkText = App.InstapaperAPI.GetBookmarkTextSync(bookmarkId); var html = new HtmlDocument(); html.LoadHtml(bookmarkText); var wordCount = GetWordCount(html.DocumentNode.InnerText); var story = html.DocumentNode.SelectSingleNode("//div[@id='story']"); if (story == null) { story = html.DocumentNode; } BookmarksStorageManager.SaveBookmarkBody(bookmarkId, story.InnerHtml); ProcessBodyImages(bookmarkId, bookmarkText); var shortBodyText = GetDescriptionContent(bookmarkText); queuedBookmark.BodyLength = wordCount; queuedBookmark.ShortBodyText = shortBodyText; queuedBookmark.IsDownloaded = true; if (bookmarkViewModel != null) { Deployment.Current.Dispatcher.BeginInvoke(() => { bookmarkViewModel.ShortBodyText = shortBodyText; bookmarkViewModel.IsDownloaded = true; App.DbDataContext.SubmitChanges(); }); } } } Deployment.Current.Dispatcher.BeginInvoke(() => { WeiranZhang.Metropaper.Controls.GlobalLoading.Instance.IsLoading = false; }); } }); }
public String GetBodyFromStorage() { return(BookmarksStorageManager.GetBookmarkBody(BookmarkId)); }
private void UpdateBookmarksWithData(IEnumerable <Bookmark> newBookmarks) { SortedObservableCollection <BookmarkViewModel> bookmarksCollection; var firstBookmark = newBookmarks.FirstOrDefault(); if (firstBookmark == null) { return; } else if (firstBookmark.Folder == "archive") { bookmarksCollection = ArchivedBookmarks; } else if (firstBookmark.Folder == "starred") { bookmarksCollection = StarredBookmarks; } else { bookmarksCollection = Bookmarks; } foreach (var bookmark in newBookmarks) { var bookmarkViewModel = new BookmarkViewModel(bookmark); var existingBookmark = bookmarksCollection.FirstOrDefault(b => b.BookmarkId == bookmark.BookmarkId); if (existingBookmark == null) // new bookmark { try { bookmarksCollection.Add(bookmarkViewModel); App.DbDataContext.Bookmarks.InsertOnSubmit(bookmark); } catch (InvalidOperationException e) { // probably trying to insert dulpicate item continue; } } else { if (bookmark.Hash != existingBookmark.Hash) { // if hash doesn't match, clear the body and description BookmarksStorageManager.DeleteBookmarkCache(bookmark.BookmarkId); bookmark.ShortBodyText = "Downloading..."; bookmarkViewModel.IsDownloaded = false; } } } // delete any items that have been removed from the api foreach (var existingBookmark in bookmarksCollection.ToList()) { if (newBookmarks.Count(b => b.BookmarkId == existingBookmark.BookmarkId) == 0) { RemoveItem(existingBookmark, bookmarksCollection); } } App.DbDataContext.SubmitChanges(); }