/// <summary> /// Search PubMed for all of the related publications and add them to the database, keep trying until search is successful /// </summary> /// <param name="relatedPmids">Related publications</param> /// <returns>NCBI search results</returns> private string SearchPubMedForRelatedPublications(List <int> relatedPmids) { StringBuilder searchQuery = new StringBuilder(); foreach (int relatedPmid in relatedPmids) { // Build the search query to issue the PubMed search for related IDs searchQuery.AppendFormat("{0}{1}[uid]", searchQuery.Length == 0 ? String.Empty : " OR ", relatedPmid); } NCBI.UsePostRequest = true; // If ncbi.Search() throws an exception, retry -- web connection may be temporarily down bool searchSuccessful = false; string searchResults = null; while (!searchSuccessful) { try { searchResults = ncbi.Search(searchQuery.ToString()); searchSuccessful = true; } catch (Exception ex) { Trace.WriteLine(DateTime.Now + " - web request error during NCBI search, retrying search. Error message: " + ex.Message); System.Threading.Thread.Sleep(2000); } } return(searchResults); }
/// <summary> /// Retrieve all of the publications a set of colleagues /// </summary> /// <param name="Star">Star whose colleagues are being retrieved</param> /// <param name="Colleagues">List of colleagues whose publications should be retrieved</param> public void GetColleaguePublications(Person[] Colleagues, string[] Languages, List <int> AllowedPubTypeCategories) { // Keep a list of written Setnbs, just to make sure we don't write the // same colleage twice ArrayList WrittenSetnbs = new ArrayList(); // Process each colleague foreach (Person Colleague in Colleagues) { // Only process a colleague that hasn't yet been touched if (!WrittenSetnbs.Contains(Colleague.Setnb)) { WrittenSetnbs.Add(Colleague.Setnb); // Get the colleague's publications // Search NCBI -- if an error is thrown, write that error to the database string results; try { results = ncbi.Search(Colleague.MedlineSearch); } catch (Exception ex) { string Message = "Error reading publications for " + Colleague.Last + " (" + Colleague.Setnb + ex.Message; ColleagueFinder.WriteErrorToDB(Message, DB, Colleague); throw new Exception(Message); } // Turn the results into a set of publications for the colleague if ((results != null) && (results.Trim() != "")) { Publications ColleaguePublications = new Publications(results, pubTypes); // Write the publications to the database -- but only if they // actually belong to the colleague. if (ColleaguePublications.PublicationList != null) { foreach (Publication pub in ColleaguePublications.PublicationList) { // If the publication has no authors, it's clearly not actually // a publication that belongs to this colleague. // Also, since the publication harvester only harvests // English publications, we exclude any non-English ones as well. if ((pub.Authors != null) && (pub.Language == "eng") && (AllowedPubTypeCategories.Contains(pubTypes.GetCategoryNumber(pub.PubType)))) { // Add a row to the ColleaguePublications table -- this will // return False if the publication doesn't actually belong // to the colleague bool PubBelongsToColleague = WriteColleaguePublicationsToDB(DB, Colleague, pub, pubTypes, Languages); if (PubBelongsToColleague) { // Make sure the publication doesn't already exist, then write // it to the database. if (DB.GetIntValue("SELECT Count(*) FROM Publications WHERE PMID = " + pub.PMID.ToString()) == 0) { Publications.WriteToDB(pub, DB, pubTypes, Languages); } } } } } // Update the Harvested column in the Colleagues table ArrayList Parameters = new ArrayList(); Parameters.Add(Database.Parameter(Colleague.Setnb)); DB.ExecuteNonQuery("UPDATE Colleagues SET Harvested = 1 WHERE Setnb = ?", Parameters); } } } }