Beispiel #1
0
        /// <summary>
        /// Get all species facts.
        /// </summary>
        /// <param name="context">Web service request context.</param>
        /// <param name="speciesFactIds">Ids for speciesFacts to get information about.</param>
        /// <returns>SpeciesFacts information.</returns>
        public static List <WebSpeciesFact> GetSpeciesFactsByIds(WebServiceContext context, List <int> speciesFactIds)
        {
            List <WebSpeciesFact> speciesFacts;
            WebSpeciesFact        speciesFact;

            // Check arguments.
            speciesFactIds.CheckNotEmpty("speciesFactIds");
            if (speciesFactIds.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.");
            }

            // Get data from database.
            speciesFacts = new List <WebSpeciesFact>();
            using (DataReader dataReader = context.GetTaxonAttributeDatabase().GetSpeciesFactsByIds(speciesFactIds))
            {
                while (dataReader.Read())
                {
                    speciesFact = new WebSpeciesFact();
                    speciesFact.LoadData(dataReader);
                    speciesFacts.Add(speciesFact);
                }
            }

            if (speciesFacts.Count != speciesFactIds.Count)
            {
                // Probably invalid speciesFact ids.
                throw new ArgumentException("Invalid speciesFact ids!");
            }

            return(speciesFacts);
        }
Beispiel #2
0
        /// <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);
        }
Beispiel #3
0
        /// <summary>
        /// Get species facts with specified identifiers.
        /// Only existing species facts are returned,
        /// e.g. species fact identifiers that does not
        /// match existing species fact does not affect
        /// the returned species facts.
        /// </summary>
        /// <param name="context">Web service request context.</param>
        /// <param name="speciesFactIdentifiers">
        /// Species facts identifiers. E.g. WebSpeciesFacts
        /// instances where id for requested combination of
        /// factor, host, individual category, period and taxon
        /// has been set.
        /// Host id is only used together with taxonomic factors.
        /// Period id is only used together with periodic factors.
        /// </param>
        /// <returns>
        /// Existing species facts among the
        /// requested species facts.
        /// </returns>
        public static List <WebSpeciesFact> GetSpeciesFactsByIdentifiers(WebServiceContext context,
                                                                         List <WebSpeciesFact> speciesFactIdentifiers)
        {
            DataTable             speciesFactIdentifiersTable;
            List <WebSpeciesFact> speciesFacts;
            Object         host, period;
            WebSpeciesFact speciesFact;

            // Check arguments.
            speciesFactIdentifiers.CheckNotEmpty("speciesFacts");
            if (speciesFactIdentifiers.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.");
            }

            // Get data from database.
            speciesFactIdentifiersTable = GetSpeciesFactIdentifiersTable();
            foreach (WebSpeciesFact webSpeciesFact in speciesFactIdentifiers)
            {
                if (webSpeciesFact.IsHostSpecified)
                {
                    host = webSpeciesFact.HostId;
                }
                else
                {
                    host = DBNull.Value;
                }

                if (webSpeciesFact.IsPeriodSpecified)
                {
                    period = webSpeciesFact.PeriodId;
                }
                else
                {
                    period = DBNull.Value;
                }

                speciesFactIdentifiersTable.Rows.Add(webSpeciesFact.TaxonId, webSpeciesFact.FactorId, webSpeciesFact.IndividualCategoryId, host, period);
            }

            speciesFacts = new List <WebSpeciesFact>();
            using (DataReader dataReader = context.GetTaxonAttributeDatabase().GetSpeciesFactsByIdentifiers(speciesFactIdentifiersTable))
            {
                while (dataReader.Read())
                {
                    speciesFact = new WebSpeciesFact();
                    speciesFact.LoadData(dataReader);
                    speciesFacts.Add(speciesFact);
                }
            }

            return(speciesFacts);
        }