/// <summary> /// Cache taxon list information about all valid taxa. /// </summary> private void LoadTaxonListInformation() { // Get taxa. ITaxonSearchCriteria searchCriteria = new TaxonSearchCriteria(); searchCriteria.IsValidTaxon = true; TaxonList taxa = CoreData.TaxonManager.GetTaxa(mContext, searchCriteria); // Init new taxon information items. foreach (ITaxon taxon in taxa) { var taxonListInformation = new TaxonListInformation { CommonName = taxon.CommonName, Id = taxon.Id, CategoryId = taxon.Category.Id, ParentCategoryId = taxon.Category.ParentId, ScientificName = taxon.ScientificName }; mTaxonInformationCache.TaxonInformation[taxon.Id] = taxonListInformation; } // Add species fact information. //GetLandscapeTypeSpeciesFactsToCache(); //GetOrganismGroupSpeciesFactsToCache(); GetRedListCategorySpeciesFactsToCache(); //GetRedListCriteriaSpeciesFactsToCache(); //GetRedListTaxonCategorySpeciesFactsToCache(); //GetSwedishOccurrenceSpeciesFactsToCache(); //GetRedListOldCategorySpeciesFactsToCache(); }
/// <summary> /// Get taxon list information about specified taxa. /// Returned list has the same order as the input taxon list. /// </summary> /// <param name="taxonIds">Taxon ids.</param> /// <param name="useNonCategorizedTaxaIdOnly">Indicates if filtering on only data without category 743 is to be returned.</param> /// <param name="selectedCategories">Selected categories.</param> /// <returns>Taxon list information about specified taxa.</returns> public List <TaxonListInformation> GetTaxonListInformation( TaxonIdList taxonIds, bool useNonCategorizedTaxaIdOnly, IList <RedListCategoryItemViewModel> selectedCategories) { if (!mIsInitialized) { throw new Exception("TaxonListInformation cache is not initialized"); } var taxonListInformation = new List <TaxonListInformation>(); if (taxonIds.IsNotEmpty()) { CheckCachedInformation(taxonIds); foreach (ITaxonId taxonId in taxonIds) { TaxonListInformation taxonInfo = TaxonInformationCache.TaxonInformation[taxonId.Id]; // Check if only non categorized taxa are to be shown. if (useNonCategorizedTaxaIdOnly) { bool taxonFound = selectedCategories.Any(category => category.OrderNumber == taxonInfo.RedListCategoryId); // First we check if taxon is beloning to a selected category if so add this taxon. if (taxonFound) { taxonListInformation.Add(taxonInfo); } else if (!taxonInfo.IsRedListed && !taxonInfo.IsRedListedEnsured) { // Not add taxon since it is ensured or redlisted and selected catgories is not choosen // This option is needed to select taxon which is not redlisted or ensured. These taxa should not be added. // This selcetion is keept for debugging purposes. // Only non categorized species are used here taxonListInformation.Add(taxonInfo); } } else { taxonListInformation.Add(taxonInfo); } } } return(taxonListInformation); }
/// <summary> /// Cache taxon list information about specified taxa. /// </summary> /// <param name="taxonIds">Taxon ids.</param> private void LoadTaxonListInformation(IEnumerable <ITaxonId> taxonIds) { // Get taxa. var taxonIdList = taxonIds.Select(taxonId => taxonId.Id).ToList(); TaxonList taxa = CoreData.TaxonManager.GetTaxa(mContext, taxonIdList); // Init new taxon information items. var tempTaxonInformation = new Dictionary <Int32, TaxonListInformation>(); foreach (ITaxon taxon in taxa) { var taxonListInformation = new TaxonListInformation { CommonName = taxon.CommonName, Id = taxon.Id, CategoryId = taxon.Category.Id, ParentCategoryId = taxon.Category.ParentId, ScientificName = taxon.ScientificName }; tempTaxonInformation[taxon.Id] = taxonListInformation; } // Add species fact information. var speciesFacts = GetSpeciesFacts(taxa); if (speciesFacts.IsNotEmpty()) { foreach (ISpeciesFact speciesFact in speciesFacts) { tempTaxonInformation[speciesFact.Taxon.Id].SetSpeciesFact(speciesFact); } } // Add new taxon information items to cache. lock (CacheLock) { foreach (ITaxon taxon in taxa) { if (!TaxonInformationCache.TaxonInformation.ContainsKey(taxon.Id)) { TaxonInformationCache.TaxonInformation[taxon.Id] = tempTaxonInformation[taxon.Id]; } } } }
/// <summary> /// Cache taxon list information about specified taxa. /// </summary> /// <param name="taxa">The taxa.</param> private void LoadTaxonListInformation(TaxonList taxa) { // Init new taxon information items. var tempTaxonInformation = new Dictionary <Int32, TaxonListInformation>(); foreach (ITaxon taxon in taxa) { var taxonListInformation = new TaxonListInformation { CommonName = taxon.CommonName, Id = taxon.Id, CategoryId = taxon.Category.Id, ParentCategoryId = taxon.Category.ParentId, ScientificName = taxon.ScientificName }; tempTaxonInformation[taxon.Id] = taxonListInformation; } // Add species fact information. SpeciesFactList speciesFacts = GetSpeciesFacts(taxa); if (speciesFacts.IsNotEmpty()) { foreach (ISpeciesFact speciesFact in speciesFacts) { tempTaxonInformation[speciesFact.Taxon.Id].SetSpeciesFact(speciesFact); } } // Add new taxon information items lock (CacheLock) { foreach (ITaxon taxon in taxa) { if (!TaxonInformationCache.TaxonInformation.ContainsKey(taxon.Id)) { TaxonInformationCache.TaxonInformation[taxon.Id] = tempTaxonInformation[taxon.Id]; } } } }
/// <summary> /// Get taxon information about specified taxon. /// Returned taxon has the same order id as the input taxon id. /// </summary> /// <param name="taxon">Taxon to get chached information on.</param> /// <returns>Taxon list information about specified taxa.</returns> public TaxonListInformation GetTaxonInformationFromCache(ITaxon taxon) { if (!mIsInitialized) { throw new Exception("TaxonListInformation cache is not initialized"); } TaxonListInformation tempTaxon = null; if (TaxonInformationCache.TaxonInformation.IsNotNull() && TaxonInformationCache.TaxonInformation.ContainsKey(taxon.Id) && taxon.IsNotNull()) { var taxa = new TaxonList { taxon }; // Check is performed on list therefore a temporary list is created with one item. CheckCachedInformation(taxa); tempTaxon = TaxonInformationCache.TaxonInformation[taxon.Id]; } return(tempTaxon); }