public void Execute(Query query) { foreach (var doi in GetDois(_rootUrl + "?q=" + query.Build() + "&api_key=" + _apiKey)) { var art= _database.Articles.SingleOrDefault(a => a.DOI == doi); if (art == null) { art = new Article(); _database.Articles.InsertOnSubmit(art); } FillArticle(art, _rootUrl + "?q=doi:" + doi + "&api_key=" + _apiKey); } _database.SubmitChanges(); }
// Articles must be retrieved individually to get the keywords. A listing of multiple articles includes keywords from all articles therein. private void FillArticle(Article article, string url) { using (var stream = WebRequest.Create(url).GetResponse().GetResponseStream()) { var element = XElement.Load(stream); var message = element.Descendants(Pam + "message").Single(); article.Title = message.Descendants(Dc + "title").Single().Value; article.Authors = message.Descendants(Dc + "creator").Select(c => c.Value).Distinct().Select(c => new Author { Name = c }).ToEntitySet(); article.Volume = message.Descendants(Prism + "volume").Single().Value.ToNullableInt(); article.Issue = message.Descendants(Prism + "number").Single().Value.ToNullableInt(); article.Page = message.Descendants(Prism + "startingPage").Single().Value.ToNullableInt(); article.PublishDate = DateTime.Parse(message.Descendants(Prism + "publicationDate").Single().Value); article.DOI = message.Descendants(Prism + "doi").Single().Value; article.Abstract = string.Join("\n", message.Descendants(Xhtml + "body").Single().Descendants("p").Select(p => p.Value)); article.Url = message.Descendants(Prism + "url").Single().Value; article.Keywords = element.Descendants("facet").Where(f => f.Attribute("name").Value == "keyword").Descendants().Select(k => new Keyword { Name = k.Value }).ToEntitySet(); } }
partial void UpdateArticle(Article instance);
partial void DeleteArticle(Article instance);
partial void InsertArticle(Article instance);