Beispiel #1
0
        public MainViewModel()
        {
            ApiBaseUrl     = "";
            ConsumerKey    = "";
            ConsumerSecret = "";

            ProgressVisible = false;
            DataStorage     = new DataStorage();
            BookmarkList    = new BookmarkList();

            ReadabilityClient = new ReadabilityApi.ReadabilityClient(ApiBaseUrl, ConsumerKey, ConsumerSecret);

            Observable.Buffer(Observable.FromEventPattern(this, "ReadingListUpdated").Throttle(TimeSpan.FromSeconds(1)), 1)
            .Subscribe(e =>
            {
                ShellTile tile = ShellTile.ActiveTiles.First();
                if (tile != null && ReadingList.Count > 0)     //Do nothing if there's no tile pinned or there are no items in the list.
                {
                    var firstArticleInReadingList = ReadingList.First().Article;

                    IconicTileData TileData = new IconicTileData()
                    {
                        Title           = "Now Readable",
                        Count           = ReadingListCount,
                        WideContent1    = firstArticleInReadingList.Title,
                        WideContent2    = firstArticleInReadingList.Excerpt.Substring(0, 100),
                        WideContent3    = firstArticleInReadingList.Author,
                        SmallIconImage  = new Uri("Assets/Tiles/SmallIconImage.png", UriKind.Relative),
                        IconImage       = new Uri("Assets/Tiles/IconImage.png", UriKind.Relative),
                        BackgroundColor = System.Windows.Media.Colors.Red
                    };

                    tile.Update(TileData);
                }
            });
        }
        /// <summary>
        /// Saves the given bookmark list to a file and downloads all the articles in those bookmarks.
        /// </summary>
        /// <param name="readabilityClient">The readability client to use to request the documents.</param>
        /// <param name="bookmarkList">The bookmark list to be saved.</param>
        /// <returns>A simple task to make this awaitable.</returns>
        public async Task SaveBookmarkList(ReadabilityClient readabilityClient, BookmarkList masterList)
        {
            StorageFolder local = Windows.Storage.ApplicationData.Current.LocalFolder;

            var file = await local.CreateFileAsync("bookmarks", CreationCollisionOption.ReplaceExisting);
            var fileStream = await file.OpenStreamForWriteAsync();
            using (var writer = new BsonWriter(new BinaryWriter(fileStream)))
            {
                var serializer = new JsonSerializer();
                serializer.Serialize(writer, masterList);
            }
        }
        public MainViewModel()
        {
            ApiBaseUrl = "";
            ConsumerKey = "";
            ConsumerSecret = "";

            ProgressVisible = false;
            DataStorage = new DataStorage();
            BookmarkList = new BookmarkList();

            ReadabilityClient = new ReadabilityApi.ReadabilityClient(ApiBaseUrl, ConsumerKey, ConsumerSecret);

            Observable.Buffer(Observable.FromEventPattern(this, "ReadingListUpdated").Throttle(TimeSpan.FromSeconds(1)), 1)
                .Subscribe(e =>
                {
                    ShellTile tile = ShellTile.ActiveTiles.First();
                    if (tile != null && ReadingList.Count > 0) //Do nothing if there's no tile pinned or there are no items in the list.
                    {
                        var firstArticleInReadingList = ReadingList.First().Article;

                        IconicTileData TileData = new IconicTileData()
                        {
                            Title = "Now Readable",
                            Count = ReadingListCount,
                            WideContent1 = firstArticleInReadingList.Title,
                            WideContent2 = firstArticleInReadingList.Excerpt.Substring(0, 100),
                            WideContent3 = firstArticleInReadingList.Author,
                            SmallIconImage = new Uri("Assets/Tiles/SmallIconImage.png", UriKind.Relative),
                            IconImage = new Uri("Assets/Tiles/IconImage.png", UriKind.Relative),
                            BackgroundColor = System.Windows.Media.Colors.Red
                        };

                        tile.Update(TileData);
                    }
                });
        }
        /// <summary>
        /// Saves a single article and updates the progress indicator when done.
        /// </summary>
        /// <param name="bookmark">The bookmark that has information about the article.</param>
        /// <param name="readabilityClient">The client to use for connection.</param>
        /// <param name="local">The folder representing the user's local storage.</param>
        /// <param name="saveCompleteAction">An callback when save is complete.</param>
        /// <returns>An awaitable task.</returns>
        async Task SaveArticle(Bookmark bookmark, ReadabilityClient readabilityClient, StorageFolder local, Action saveCompleteAction)
        {
            var article = await readabilityClient.ArticleEndpoint.GetArticle(bookmark);
            var folder = await local.CreateFolderAsync(bookmark.Article.Id, CreationCollisionOption.OpenIfExists);
            try
            {
                var articleFile = await folder.CreateFileAsync(bookmark.Article.Id, CreationCollisionOption.FailIfExists);
                var articleStream = await articleFile.OpenStreamForWriteAsync();
                using (var innerWriter = new BinaryWriter(articleStream))
                {
                    var bson = new BsonWriter(innerWriter);
                    var innerSerializer = new JsonSerializer();
                    innerSerializer.Serialize(bson, article);
                }
            }
            catch
            {
                //swallow exception?
            }

            if (null != saveCompleteAction)
                saveCompleteAction();
        }