diff options
author | Aryadev Chavali <aryadevchavali1@gmail.com> | 2019-02-25 11:37:20 +0000 |
---|---|---|
committer | Aryadev Chavali <aryadevchavali1@gmail.com> | 2019-02-25 11:37:20 +0000 |
commit | 496eb3a4252dce5e37c735b47b30927d1aa85a18 (patch) | |
tree | 1b91c4d380b3059e1e840cdfdbc2c1a5b4104148 /Main | |
parent | c18180f553ae280afffc2daa6e861fa2acc92bd6 (diff) | |
download | newsaggregator-496eb3a4252dce5e37c735b47b30927d1aa85a18.tar.gz newsaggregator-496eb3a4252dce5e37c735b47b30927d1aa85a18.tar.bz2 newsaggregator-496eb3a4252dce5e37c735b47b30927d1aa85a18.zip |
Made it take a string for configuration and accessing database
Diffstat (limited to 'Main')
-rw-r--r-- | Main/Jobs/AggregatorJob.cs | 17 |
1 files changed, 12 insertions, 5 deletions
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<Config> configs = new List<Config> { 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<DatabaseContext>(); + builder.UseMySQL(config); + using (var context = new DatabaseContext(builder.Options)) { + var articles = await parseMultiple(); + await context.InsertArticles(articles); + } } - private static async Task<List<Article>> parseMultiple() { + private async Task<List<Article>> parseMultiple() { var xmls = new List<string>(); foreach (string site in sites) { xmls.Add(await Download.DownloadXML(site)); |