/// <summary> /// Uses <see cref="EPARTools"/> to ascertain which <see cref="ExpiredProduct"/>s in a <see cref="VMDPID"/> are /// EMA-authorised, search for an SPC document on the EMA website (as no direct links to documents /// are provided in the PID) and then uses <see cref="SPCParser"/> to extract a dictionary of /// products and target species. The product in question is matched to this dictionary by name. /// </summary> /// <param name="inpid"></param> /// <returns>The provided <see cref="VMDPID"/> with EMA-authorised expired products' target species populated</returns> private static async Task <VMDPID> PopulateExpiredProductTargetSpeciesFromEma(VMDPID inpid) { var expiredProducts = new ConcurrentBag <ExpiredProduct>(inpid.ExpiredProducts.Where( ep => EPARTools.IsEPAR(ep.SPC_Link))); var tasks = expiredProducts.Select(async ep => await PopulateTargetSpeciesFromEma(ep)); await Task.WhenAll(tasks); inpid.ExpiredProducts = inpid.ExpiredProducts.Where(ep => !EPARTools.IsEPAR(ep.SPC_Link)) .Union(expiredProducts).ToList(); return(inpid); }
/// <summary> /// Helper method designed for testing to download SPC document /// </summary> /// <param name="p"><see cref="ReferenceProduct"/> to get SPC link for</param> /// <returns>Path to downloaded file in temp folder</returns> public static async Task <string> GetSpc(Product p) { var uri = ((ExpiredProduct)p).SPC_Link; if (EPARTools.IsEPAR(uri)) { uri = (await EPARTools.GetSearchResults(p.Name))[0]; } var tf = Path.GetTempPath() + Path.DirectorySeparatorChar + uri.Split('/')[uri.Split('/').Length - 1]; if (!File.Exists(tf)) { using (var fs = File.OpenWrite(tf)) { (await GetHttpStream(uri)).CopyTo(fs); } } return(tf); }