From 496eb3a4252dce5e37c735b47b30927d1aa85a18 Mon Sep 17 00:00:00 2001 From: Aryadev Chavali Date: Mon, 25 Feb 2019 11:37:20 +0000 Subject: Made it take a string for configuration and accessing database --- Main/Jobs/AggregatorJob.cs | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'Main') diff --git a/Main/Jobs/AggregatorJob.cs b/Main/Jobs/AggregatorJob.cs index eec9aff..065a1f0 100644 --- a/Main/Jobs/AggregatorJob.cs +++ b/Main/Jobs/AggregatorJob.cs @@ -2,12 +2,15 @@ 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 static class AggregatorJob { + public class AggregatorJob { private static List configs = new List { new Config { Source = "BBC", @@ -41,12 +44,16 @@ namespace Main.Jobs { "https://abcnews.go.com/abcnews/topstories" }; - public static async Task Process(DatabaseContext context) { - var articles = await parseMultiple(); - await context.InsertArticles(articles); + 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 static async Task> parseMultiple() { + private async Task> parseMultiple() { var xmls = new List(); foreach (string site in sites) { xmls.Add(await Download.DownloadXML(site)); -- cgit v1.2.3-13-gbd6f