コード例 #1
0
        /// <summary>
        /// Syncs the all the users data from a given DateTime.
        /// </summary>
        /// <param name="readabilityClient">The client to use to make the requests.</param>
        /// <param name="syncDateTime">The date and time from when to sync.</param>
        public async Task Sync(MainViewModel mainViewModel, DateTime syncDateTime)
        {
            mainViewModel.ProgressText = "Starting sync...";
            mainViewModel.ProgressIndeterminate = true;
            mainViewModel.ProgressVisible = true;

            var conditions = new Conditions { UpdatedSince = syncDateTime };
            var updateList = await mainViewModel.ReadabilityClient.BookmarkListEndpoint.GetAllBookmarks(conditions);
            await MergeSaveBookmarkList(mainViewModel, updateList);

            conditions.OnlyDeleted = 1;
            var deleteList = await mainViewModel.ReadabilityClient.BookmarkListEndpoint.GetAllBookmarks(conditions);
            if (!syncDateTime.Equals(new DateTime()))
            {
                await DeleteBookmarkList(mainViewModel.BookmarkList, deleteList);
            }

            mainViewModel.ProgressVisible = false;
        }
コード例 #2
0
        /// <summary>
        /// Merges the two lists and downloads their articles.
        /// </summary>
        /// <param name="readabilityClient">The readabilty client to use to request the documents.</param>
        /// <param name="masterList">The list that will contain the final list of bookmarks.</param>
        /// <param name="bookmarkList">The bookmark list to be saved.</param>
        /// <returns>An awaitable task.</returns>
        public async Task MergeSaveBookmarkList(MainViewModel mainViewModel, BookmarkList bookmarkList)
        {
            mainViewModel.ProgressValue = 0;
            mainViewModel.ProgressIndeterminate = false;
            mainViewModel.ProgressText = "Syncing...";

            StorageFolder local = Windows.Storage.ApplicationData.Current.LocalFolder;

            var tasks = new List<Task>();
            foreach (var bookmark in bookmarkList.Bookmarks)
            {
                var saveCompleteAction = new Action(() =>
                {
                    int position = mainViewModel.BookmarkList.Bookmarks.IndexOf(bookmark);
                    mainViewModel.BookmarkList.Bookmarks.Remove(bookmark);
                    if (position == -1)
                    {
                        mainViewModel.BookmarkList.Bookmarks.Add(bookmark);
                    }
                    else
                    {
                        mainViewModel.BookmarkList.Bookmarks.Insert(position, bookmark);
                    }
                    mainViewModel.ProgressValue += ((double)1 / (double)bookmarkList.Bookmarks.Count);
                });
                tasks.Add(SaveArticle(bookmark, mainViewModel.ReadabilityClient, local, saveCompleteAction));
            }

            await Task.WhenAll(tasks);

            mainViewModel.ProgressIndeterminate = true;
            mainViewModel.ProgressText = "Almost done...";
            await SaveBookmarkList(mainViewModel.ReadabilityClient, mainViewModel.BookmarkList);
        }