diff options
author | Aryadev Chavali <aryadevchavali1@gmail.com> | 2019-02-10 15:40:47 +0000 |
---|---|---|
committer | Aryadev Chavali <aryadevchavali1@gmail.com> | 2019-02-10 15:40:47 +0000 |
commit | 17dea16bc59f6781407f467d3df7e28667a874f6 (patch) | |
tree | 342011755950f72b94dff485cd16771d6d912a76 /Main/Program.cs | |
parent | 7beffadae9179095b39eff36a708e3d508ee21fd (diff) | |
download | newsaggregator-17dea16bc59f6781407f467d3df7e28667a874f6.tar.gz newsaggregator-17dea16bc59f6781407f467d3df7e28667a874f6.tar.bz2 newsaggregator-17dea16bc59f6781407f467d3df7e28667a874f6.zip |
Testing program with usage of insertArticles
Diffstat (limited to 'Main/Program.cs')
-rw-r--r-- | Main/Program.cs | 83 |
1 files changed, 17 insertions, 66 deletions
diff --git a/Main/Program.cs b/Main/Program.cs index 0e88199..a96762c 100644 --- a/Main/Program.cs +++ b/Main/Program.cs @@ -9,74 +9,25 @@ 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()) {
- int start;
- try {
- start = db.Articles.Last().ArticleID;
- }
- catch (Exception) {
- start = 0;
- }
- try {
- var articles = new List<Article>() {
- new Article() {
- Title = "TITLE1"
- },
- new Article() {
- Title = "TITLE2"
- },
- new Article() {
- Title = "TITLE3"
- }
- };
- await db.AddRangeAsync(articles.Select((article, index) => new Article() {
- ArticleID = index + start,
- Title = article.Title}));
- await db.SaveChangesAsync();
- }
- catch (Microsoft.EntityFrameworkCore.DbUpdateException) {
- Console.WriteLine("Duplicate!");
+ 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("Wrote");
+
+ using (var db = new DatabaseContext()) {
+ await db.InsertArticles(articles);
}
}
}
|