Пример #1
0
        private void ShowBookmarkNotDownloaded(BookmarkViewModel bookmarkViewModel)
        {
            var bookmark = App.DbDataContext.Bookmarks.Where(b => b.BookmarkId == bookmarkViewModel.BookmarkId).Single();

            bookmarkViewModel.IsDownloaded = false;
            bookmarkViewModel.Description  = "Downloading...";
            App.DbDataContext.SubmitChanges();

            MessageBox.Show("This bookmark is not downloaded", "Please wait for the download to complete, or retry by pressing the refresh button", MessageBoxButton.OK);
        }
Пример #2
0
        /// <summary>
        /// This removes an item from the view model and local storage without actually calling the API.
        /// </summary>
        public void RemoveItem(BookmarkViewModel bookmarkViewModel, SortedObservableCollection <BookmarkViewModel> bookmarksCollection)
        {
            var bookmarkToDelete = bookmarksCollection.Where(b => b.BookmarkId == bookmarkViewModel.BookmarkId).FirstOrDefault();

            if (bookmarkToDelete != null)
            {
                bookmarksCollection.Remove(bookmarkToDelete);
            }

            var bookmarkDbItem = App.DbDataContext.Bookmarks.Where(b => b.BookmarkId == bookmarkViewModel.BookmarkId).FirstOrDefault();

            if (bookmarkDbItem != null)
            {
                App.DbDataContext.Bookmarks.DeleteOnSubmit(bookmarkDbItem);
                App.DbDataContext.SubmitChanges();
            }
        }
Пример #3
0
        public void RemoveItem(BookmarkViewModel bookmarkViewModel)
        {
            SortedObservableCollection <BookmarkViewModel> bookmarksCollection;

            if (bookmarkViewModel.Folder == "archive")
            {
                bookmarksCollection = ArchivedBookmarks;
            }
            else if (bookmarkViewModel.Folder == "starred")
            {
                bookmarksCollection = StarredBookmarks;
            }
            else
            {
                bookmarksCollection = Bookmarks;
            }

            RemoveItem(bookmarkViewModel, bookmarksCollection);
        }
Пример #4
0
        /// <summary>
        /// Creates and adds a few ItemViewModel objects into the Items collection.
        /// </summary>
        public void LoadData()
        {
            this.IsLoading = true;

            var bookmarks = App.DbDataContext.Bookmarks.ToList();

            UpdateBookmarkCacheStatus();

            foreach (var bookmark in bookmarks)
            {
                var bookmarkViewModel = new BookmarkViewModel(bookmark);

                SortedObservableCollection <BookmarkViewModel> bookmarksCollection;
                if (bookmark.Folder == "archive")
                {
                    bookmarksCollection = ArchivedBookmarks;
                }
                else if (bookmark.Folder == "starred")
                {
                    bookmarksCollection = StarredBookmarks;
                }
                else
                {
                    bookmarksCollection = Bookmarks;
                }

                var existingBookmark = bookmarksCollection.FirstOrDefault(b => b.BookmarkId == bookmark.BookmarkId);

                if (existingBookmark == null) // new bookmark
                {
                    bookmarksCollection.Add(bookmarkViewModel);
                }
            }

            this.IsLoading = false;
        }
Пример #5
0
        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();
        }