From cb849fe4aeef9d1e9bc41969d1c96c47ebcbc84d Mon Sep 17 00:00:00 2001 From: Aryadev Chavali Date: Thu, 21 Feb 2019 18:18:36 +0000 Subject: Created static class for Aggregator service --- Main/Jobs/AggregatorJob.cs | 57 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 Main/Jobs/AggregatorJob.cs (limited to 'Main') diff --git a/Main/Jobs/AggregatorJob.cs b/Main/Jobs/AggregatorJob.cs new file mode 100644 index 0000000..dc7c354 --- /dev/null +++ b/Main/Jobs/AggregatorJob.cs @@ -0,0 +1,57 @@ +using System.Threading.Tasks; +using System.Collections.Generic; + +using Classes; +using Database; +using Aggregator; + +namespace Main.Jobs { + public static class AggregatorJob { + private static List configs = new List { + new Config { + Source = "BBC", + Title = 0, + Description = 1, + ArticleLink = 2, + ImageLink = 5, + PublishDate = 4 + }, + new Config { + Source = "Sky", + Title = 0, + Description = 2, + ArticleLink = 1, + ImageLink = 7, + PublishDate = 3 + }, + new Config { + Source = "ABC", + Title = 7, + Description = 11, + ArticleLink = 8, + ImageLink = 0, + PublishDate = 10 + } + }; + + private static List sites = new List { + "http://feeds.bbci.co.uk/news/rss.xml", + "http://feeds.skynews.com/feeds/rss/world.xml", + "https://abcnews.go.com/abcnews/topstories" + }; + + public static async void Process(DatabaseContext context) { + var articles = await parseMultiple(); + await context.InsertArticles(articles); + } + + private static async Task> parseMultiple() { + var xmls = new List(); + foreach (string site in sites) { + xmls.Add(await Download.DownloadXML(site)); + } + + return ParserService.ParseMultiple(xmls.ToArray(), configs).ToList(); + } + } +} \ No newline at end of file -- cgit v1.2.3-13-gbd6f