using System.Linq; using System.Threading.Tasks; using System.Collections.Generic; using Microsoft.Extensions.DependencyInjection; using Microsoft.EntityFrameworkCore; using Classes; using Database; using Aggregator; namespace Main.Jobs { public 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 async Task Start(string config) { var builder = new DbContextOptionsBuilder(); builder.UseMySQL(config); using (var context = new DatabaseContext(builder.Options)) { var articles = await parseMultiple(); await context.InsertArticles(articles); } } private 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(); } } }