1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
using System;
using System.Linq;
using System.Threading.Tasks;
using System.Collections.Generic;
using Database;
using Classes;
using Aggregator.Parser;
namespace Main {
internal static class Program {
// private static async Task Main(string[] args) {
// List<Config> configs = new List<Config>() {
// new Config() {
// Source = "BBC",
// Title = 0,
// Description = 1,
// ArticleLink = 2,
// ImageLink = 5,
// PublishDate = 4
// }
// };
// string[] xmls = new[] {
// await Download.DownloadXML("http://feeds.bbci.co.uk/news/rss.xml")
// };
// List<Article> articles = ParserService.ParseMultiple(xmls, configs).ToList();
// Console.WriteLine(articles.Count);
// using (var db = new DatabaseContext()) {
// int start;
// try {
// start = db.Articles.Last().ArticleID;
// } catch (Exception) {
// start = 0;
// }
// var insertReady = articles.Select((article, index) => new Article() {
// ArticleID = index + start,
// Source = article.Source,
// Title = article.Title,
// Description = article.Description,
// ArticleLink = article.ArticleLink,
// ImageLink = article.ImageLink,
// PublishDate = article.PublishDate
// }).ToList();
// insertReady.ForEach(async article => await db.Articles.AddAsync(article));
// int records = await db.SaveChangesAsync();
// Console.WriteLine($"Wrote {records} records!");
// }
// }
private static async Task Main(string[] args) {
using (var db = new DatabaseContext()) {
try {
await db.Articles.AddAsync(new Article() {
Title = "TITLE"
});
await db.SaveChangesAsync();
}
catch (Microsoft.EntityFrameworkCore.DbUpdateException) {
Console.WriteLine("Duplicate!");
}
}
}
}
}
|