コード例 #1
0
ファイル: ReaderHelper.cs プロジェクト: ScottIsAFool/Speader
        public async Task <ReaderItem> SaveArticle(Uri url)
        {
            var article = await _pocketClient.GetArticle(url, false, false);

            if (article != null)
            {
                var savedArticle = article.ToReaderItem();
                savedArticle.Source = SourceProvider.Local;

                var response = await _cacheService.GetLocalItemsFromCache();

                var articleExists = response.ReaderItems.FirstOrDefault(x => x.Id == savedArticle.Id);
                if (articleExists != null)
                {
                    response.ReaderItems.Remove(articleExists);
                }

                await _cacheService.SaveArticle(savedArticle);

                savedArticle.Text = string.Empty;

                response.ReaderItems.Insert(0, savedArticle);

                await _cacheService.SaveLocalItems(response.ReaderItems);

                return(savedArticle);
            }

            return(null);
        }
コード例 #2
0
        protected override async Task <ReaderItem> GetArticle(ReaderItem item, bool isRefresh = false)
        {
            if (item == null)
            {
                return(null);
            }

            if (!isRefresh)
            {
                var article = await CacheService.GetArticle(item);

                if (article != null)
                {
                    return(article);
                }
            }

            try
            {
                var response = await _pocketClient.GetArticle(new Uri(item.Url, UriKind.Absolute), forceRefresh : isRefresh);

                if (response != null)
                {
                    var article = response.ToReaderItem();
                    item.IsDownloaded = true;
                    await CacheService.SaveArticle(article).ConfigureAwait(false);

                    return(article);
                }
            }
            catch (Exception ex)
            {
                Log.ErrorException("GetArticle", ex);
            }

            return(null);
        }