diff options
author | Aryadev Chavali <aryadevchavali1@gmail.com> | 2019-02-10 14:51:05 +0000 |
---|---|---|
committer | Aryadev Chavali <aryadevchavali1@gmail.com> | 2019-02-10 14:51:05 +0000 |
commit | 265b4e4377302b199d7f5815e6cb52fb268c5bd6 (patch) | |
tree | bc17c22fede263dec5e519fb7f0ec41fccaa2e89 | |
parent | f606a8fb5cfb80541891bfb5dacc3f8716b37291 (diff) | |
download | newsaggregator-265b4e4377302b199d7f5815e6cb52fb268c5bd6.tar.gz newsaggregator-265b4e4377302b199d7f5815e6cb52fb268c5bd6.tar.bz2 newsaggregator-265b4e4377302b199d7f5815e6cb52fb268c5bd6.zip |
Found error
-rw-r--r-- | Main/Program.cs | 78 |
1 files changed, 46 insertions, 32 deletions
diff --git a/Main/Program.cs b/Main/Program.cs index 808de98..4ad64af 100644 --- a/Main/Program.cs +++ b/Main/Program.cs @@ -9,42 +9,56 @@ 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);
+ // 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()) {
- int start;
try {
- start = db.Articles.Last().ArticleID;
- } catch (Exception) {
- start = 0;
+ await db.Articles.AddAsync(new Article() {
+ Title = "TITLE"
+ });
+ await db.SaveChangesAsync();
+ }
+ catch (Microsoft.EntityFrameworkCore.DbUpdateException) {
+ Console.WriteLine("Duplicate!");
}
- 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!");
}
}
}
|