/// <summary> /// Get taxon count of the taxa that matches fact search criteria. /// </summary> /// <param name="context">Web service request context.</param> /// <param name="searchCriteria">Species fact search criteria.</param> /// <returns>Taxon count of the taxa that matches fact search criteria.</returns> public static Int32 GetTaxaCountBySearchCriteria(WebServiceContext context, WebSpeciesFactSearchCriteria searchCriteria) { Int32 taxonCount = 0; // Check arguments. searchCriteria.CheckNotNull("searchCriteria"); searchCriteria.CheckData(); // Get data from database. using (DataReader dataReader = context.GetTaxonAttributeDatabase().GetSpeciesFactsBySearchCriteria(searchCriteria.GetQuery(WebSpeciesFactSearchCriteriaExtension.QuerySelectPart.QueryTaxonCount), searchCriteria.FactorDataTypeIds, searchCriteria.FactorIds, searchCriteria.HostIds, searchCriteria.TaxonIds)) { while (dataReader.Read()) { taxonCount = dataReader.GetInt32(SpeciesFactData.TAXON_COUNT); if (taxonCount > Settings.Default.MaxSpeciesFacts) { // Exceeding max numbers of taxa that // can be retrieved in one request. throw new ArgumentException("Max " + Settings.Default.MaxSpeciesFacts + " taxa can be retrieved in one call."); } } } return(taxonCount); }
/// <summary> /// Get taxa that matches fact search criteria. /// </summary> /// <param name="context">Web service request context.</param> /// <param name="searchCriteria">Species fact search criteria.</param> /// <returns>Taxa that matches fact search criteria.</returns> public static List <WebTaxon> GetTaxaBySearchCriteria(WebServiceContext context, WebSpeciesFactSearchCriteria searchCriteria) { List <Int32> taxonIds = new List <int>(); // Check arguments. searchCriteria.CheckNotNull("searchCriteria"); searchCriteria.CheckData(); // Get list of taxon ids from database. using (DataReader dataReader = context.GetTaxonAttributeDatabase().GetSpeciesFactsBySearchCriteria(searchCriteria.GetQuery(WebSpeciesFactSearchCriteriaExtension.QuerySelectPart.QueryTaxonIds), searchCriteria.FactorDataTypeIds, searchCriteria.FactorIds, searchCriteria.HostIds, searchCriteria.TaxonIds)) { while (dataReader.Read()) { // Gather distinct list of taxon ids if (!taxonIds.Contains(dataReader.GetInt32(SpeciesFactData.TAXON_ID))) { taxonIds.Add(dataReader.GetInt32(SpeciesFactData.TAXON_ID)); } if (taxonIds.Count > Settings.Default.MaxSpeciesFacts) { // Exceeding max numbers of taxa that // can be retrieved in one request. throw new ArgumentException("Max " + Settings.Default.MaxSpeciesFacts + " taxa can be retrieved in one call."); } } } // Get list of taxa by list of taxon ids return(WebServiceData.TaxonManager.GetTaxaByIds(context, taxonIds)); }
/// <summary> /// Get information about species facts that matches search criteria. /// </summary> /// <param name="context">Web service request context.</param> /// <param name="searchCriteria">Species fact search criteria.</param> /// <returns>Species facts that matches search criteria.</returns> public static List <WebSpeciesFact> GetSpeciesFactsBySearchCriteria(WebServiceContext context, WebSpeciesFactSearchCriteria searchCriteria) { List <WebSpeciesFact> speciesFacts; WebSpeciesFact speciesFact; // Check arguments. searchCriteria.CheckNotNull("searchCriteria"); searchCriteria.CheckData(); // Get data from database. speciesFacts = new List <WebSpeciesFact>(); using (DataReader dataReader = context.GetTaxonAttributeDatabase().GetSpeciesFactsBySearchCriteria(searchCriteria.GetQuery(WebSpeciesFactSearchCriteriaExtension.QuerySelectPart.QueryDefault), searchCriteria.FactorDataTypeIds, searchCriteria.FactorIds, searchCriteria.HostIds, searchCriteria.TaxonIds)) { while (dataReader.Read()) { speciesFact = new WebSpeciesFact(); speciesFact.LoadData(dataReader); speciesFacts.Add(speciesFact); if (speciesFacts.Count > Settings.Default.MaxSpeciesFacts) { // Exceeding max numbers of species facts that // can be retrieved in one request. throw new ArgumentException("Max " + Settings.Default.MaxSpeciesFacts + " species facts can be retrieved in one call."); } } } return(speciesFacts); }