private Task DoFeedQueue(ConcurrentQueue <FeedModel> queue, bool incrementProgress = true)
        {
            return(ExecuteSafe(async() =>
            {
                FeedModel model;
                while (queue.TryDequeue(out model))
                {
                    var media = ArticleHelper.GetMediaSource(model, _themeRepository);
                    if (media != null)
                    {
                        if (await _permissionsService.CanDownloadFeeds())
                        {
                            var articles = await media.EvaluateFeed(model);
                            if (articles != null)
                            {
                                await SaveHelper.SaveFeed(model, articles, _sqliteService, _imageDownloadService);
                            }
                            _imageDownloadService.Download(model);
                        }
                    }

                    if (incrementProgress)
                    {
                        _progressService.Incremenent(ProgressType.Feed);
                    }
                }
            }));
        }
        private Task DoArticleStack(ConcurrentStack <ArticleModel> stack, bool incrementProgress = true)
        {
            return(ExecuteSafe(async() =>
            {
                ArticleModel model;
                while (stack.TryPop(out model))
                {
                    model.LoadingState = LoadingState.Loading;
                    var media = ArticleHelper.GetMediaSource(model, _themeRepository);
                    if (await _permissionsService.CanDownloadArticles())
                    {
                        if (media != null)
                        {
                            await media.EvaluateArticle(model);

                            model.LoadingState = LoadingState.Loaded;
                            await SaveHelper.SaveArticle(model, _sqliteService);
                            await SaveHelper.SaveArticleLeadImage(model, _sqliteService);
                            await SaveHelper.SaveArticleContent(model, _sqliteService);
                            _imageDownloadService.Download(model);
                        }
                        else
                        {
                            model.LoadingState = LoadingState.LoadingFailed;
                            await SaveHelper.SaveArticle(model, _sqliteService);
                        }
                    }

                    if (incrementProgress)
                    {
                        _progressService.Incremenent(ProgressType.Article);
                    }
                }
            }));
        }
Beispiel #3
0
        public void AllMediaSourceHelpers()
        {
            var values = Enum.GetValues(typeof(Sources));

            foreach (var value in values)
            {
                var enu = (Sources)value;
                Assert.IsNotNull(ArticleHelper.GetMediaSource(enu, SimpleIoc.Default.GetInstance <IThemeRepository>()), "media source not found for source " + enu);
            }
        }
Beispiel #4
0
        private async Task TestFeedEvaluationFeedTask(ConcurrentStack <FeedModel> feeds, SourceModel source, LogEntry sourceLogEntry, AssertHelper assertHelper, bool testArticles = false)
        {
            FeedModel feed;

            while (feeds.TryPop(out feed))
            {
                var feedLogEntry = new LogEntry()
                {
                    Content = "Testing " + feed.Name + " (" + feed.Url + ")"
                };

                var msh         = ArticleHelper.GetMediaSource(source.Source, SimpleIoc.Default.GetInstance <IThemeRepository>());
                var sqs         = SimpleIoc.Default.GetInstance <ISqliteService>();
                var ids         = SimpleIoc.Default.GetInstance <IImageDownloadService>();
                var newArticles = await msh.EvaluateFeed(feed);

                await SaveHelper.SaveFeed(feed, newArticles, sqs, ids);

                foreach (var articleModel in newArticles)
                {
                    var articleLogEntry = new LogEntry()
                    {
                        Content = "Testing " + articleModel.Title + " (" + articleModel.LogicUri + ", " + articleModel.PublicUri + ")"
                    };
                    articleModel.Feed = feed;

                    await SaveHelper.SaveArticle(articleModel, sqs);

                    await SaveHelper.SaveArticleLeadImage(articleModel, sqs, true);

                    await SaveHelper.SaveArticleContent(articleModel, sqs, true);


                    assertHelper.TestFeedArticleProperties(articleModel, articleLogEntry);

                    if (articleModel.LoadingState != LoadingState.Loaded && !await msh.EvaluateArticle(articleModel))
                    {
                        articleLogEntry.LogEntries.Add(new LogEntry()
                        {
                            Content    = "Evaluation failed!",
                            IsFaillure = true
                        });
                    }
                    else
                    {
                        articleModel.LoadingState = LoadingState.Loaded;
                        assertHelper.TestFullArticleProperties(articleModel, articleLogEntry);
                    }

                    feedLogEntry.LogEntries.Add(articleLogEntry);
                }

                sourceLogEntry.LogEntries.Add(feedLogEntry);
            }
        }