aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Main/Jobs/AggregatorJob.cs17
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));