/// <summary> /// Get all taxon names for specified taxa. /// The result is sorted in the same order as input taxa. /// </summary> /// <param name="userContext">The user context.</param> /// <param name="taxa">Taxa.</param> /// <returns>Taxon names.</returns> public override List <TaxonNameList> GetTaxonNames(IUserContext userContext, TaxonList taxa) { Hashtable allTaxonNamesUnsorted; Int32 index; List <TaxonNameList> allTaxonNamesSorted, allTaxonNamesNotCached; TaxonList notCachedTaxa; TaxonNameList taxonNames; if (userContext.CurrentRole.IsNotNull() && userContext.CurrentRole.Identifier.IsNotEmpty() && userContext.CurrentRole.Identifier.StartsWith(Settings.Default.DyntaxaRevisionRoleIdentifier)) { // Do not cache taxon names if user is in a revision. allTaxonNamesSorted = base.GetTaxonNames(userContext, taxa); } else { allTaxonNamesUnsorted = new Hashtable(); notCachedTaxa = new TaxonList(); // Get already cached taxon names. foreach (ITaxon taxon in taxa) { taxonNames = GetTaxonNames(taxon, userContext.Locale); if (taxonNames.IsEmpty()) { notCachedTaxa.Add(taxon); } else { allTaxonNamesUnsorted[taxon.Id] = taxonNames; } } // Get not already cached taxon names. if (notCachedTaxa.IsNotEmpty()) { allTaxonNamesNotCached = base.GetTaxonNames(userContext, notCachedTaxa); foreach (TaxonNameList tempTaxonNames in allTaxonNamesNotCached) { allTaxonNamesUnsorted[tempTaxonNames[0].Taxon.Id] = tempTaxonNames; // Cache not already cached taxon names. SetTaxonNames(tempTaxonNames, tempTaxonNames[0].Taxon, userContext.Locale); } } // Create sorted output. allTaxonNamesSorted = new List <TaxonNameList>(); for (index = 0; index < taxa.Count; index++) { allTaxonNamesSorted.Add((TaxonNameList)(allTaxonNamesUnsorted[taxa[index].Id])); } } return(allTaxonNamesSorted); }
/// <summary> /// Get taxa with specified ids. /// </summary> /// <param name="userContext">User context.</param> /// <param name="taxonIds">Taxon ids</param> /// <returns>Taxa with specified ids.</returns> public override TaxonList GetTaxa(IUserContext userContext, List <Int32> taxonIds) { ITaxon taxon; List <Int32> notFoundTaxonIds; TaxonList foundTaxa, notFoundTaxa, taxa; if (userContext.CurrentRole.IsNotNull() && userContext.CurrentRole.Identifier.IsNotEmpty() && userContext.CurrentRole.Identifier.StartsWith(Settings.Default.DyntaxaRevisionRoleIdentifier)) { // Do not cache taxa if user is in a revision. taxa = base.GetTaxa(userContext, taxonIds); } else { // Get cached taxa. foundTaxa = new TaxonList(true); notFoundTaxa = null; notFoundTaxonIds = new List <Int32>(); foreach (Int32 taxonId in taxonIds) { taxon = GetTaxon(taxonId, userContext.Locale); if (taxon.IsNull()) { notFoundTaxonIds.Add(taxonId); } else { foundTaxa.Add(taxon); } } // Get taxa from data source. if (notFoundTaxonIds.IsNotEmpty()) { notFoundTaxa = base.GetTaxa(userContext, notFoundTaxonIds); foundTaxa.Merge(notFoundTaxa); taxa = new TaxonList(true); foreach (Int32 taxonId in taxonIds) { taxa.Add(foundTaxa.Get(taxonId)); } } else { taxa = foundTaxa; } // Save taxa in cache. if (notFoundTaxa.IsNotEmpty()) { foreach (ITaxon tempTaxon in notFoundTaxa) { SetTaxon(tempTaxon, userContext.Locale); } } } return(taxa); }
/// <summary> /// Update information about which factors, hosts, /// individual categories, periods, references and taxa /// that are used in the species facts. /// </summary> /// <param name="userContext"> /// Information about the user that makes this method call. /// </param> /// <param name="selection"> /// Scope of the data set is defined by this /// species fact data set selection. /// </param> /// <param name="speciesFacts">Species facts.</param> private void UpdateScope(IUserContext userContext, ISpeciesFactDataSetSelection selection, SpeciesFactList speciesFacts) { Factors = new FactorList(true); Factors.AddRange(selection.Factors); Hosts = new TaxonList(true); Hosts.AddRange(selection.Hosts); IndividualCategories = new IndividualCategoryList(true); IndividualCategories.AddRange(selection.IndividualCategories); Periods = new PeriodList(true); Periods.AddRange(selection.Periods); References = new ReferenceList(true); Taxa = new TaxonList(true); Taxa.AddRange(selection.Taxa); if (speciesFacts.IsNotEmpty()) { foreach (ISpeciesFact speciesFact in speciesFacts) { Factors.Merge(speciesFact.Factor); if (speciesFact.HasHost) { Hosts.Merge(speciesFact.Host); } IndividualCategories.Merge(speciesFact.IndividualCategory); if (speciesFact.HasPeriod) { Periods.Merge(speciesFact.Period); } if (speciesFact.HasReference) { References.Merge(speciesFact.Reference); } Taxa.Merge(speciesFact.Taxon); } } // Set default values if no values are entered. if (Hosts.IsEmpty()) { Hosts.Add(CoreData.TaxonManager.GetTaxon(userContext, TaxonId.Life)); } if (IndividualCategories.IsEmpty()) { IndividualCategories.Add(CoreData.FactorManager.GetDefaultIndividualCategory(userContext)); } if (Periods.IsEmpty()) { Periods.AddRange(CoreData.FactorManager.GetPeriods(userContext)); } // Sort all lists. Factors.Sort(); Hosts.Sort(); IndividualCategories.Sort(); Periods.Sort(); References.Sort(); Taxa.Sort(); }