/// <summary> /// The get species facts. /// </summary> /// <param name="userContext"> /// The user context. /// </param> /// <param name="taxa"> /// The taxa. /// </param> /// <param name="factorIds"> /// The factor ids. /// </param> /// <param name="speciesFactList"> /// The species fact list. /// </param> /// <returns> /// The <see cref="Dictionary"/>. /// </returns> public static Dictionary <int, Dictionary <FactorId, SpeciesFact> > GetSpeciesFacts( IUserContext userContext, IEnumerable <ITaxon> taxa, IEnumerable <FactorId> factorIds, out SpeciesFactList speciesFactList) { var intFactorIds = new List <int>(factorIds.Select(factorId => (int)factorId)); FactorList factors = CoreData.FactorManager.GetFactors(userContext, intFactorIds); ISpeciesFactSearchCriteria speciesFactSearchCriteria = new SpeciesFactSearchCriteria(); IPeriod period = CoreData.FactorManager.GetCurrentPublicPeriod(userContext); speciesFactSearchCriteria.EnsureNoListsAreNull(); speciesFactSearchCriteria.IncludeNotValidHosts = true; speciesFactSearchCriteria.IncludeNotValidTaxa = true; speciesFactSearchCriteria.Add(period); speciesFactSearchCriteria.Add(CoreData.FactorManager.GetDefaultIndividualCategory(userContext)); speciesFactSearchCriteria.Taxa = new TaxonList(); foreach (ITaxon taxon in taxa) { speciesFactSearchCriteria.Taxa.Add(taxon); } speciesFactSearchCriteria.Factors = new FactorList(); foreach (IFactor factor in factors) { speciesFactSearchCriteria.Factors.Add(factor); } speciesFactList = CoreData.SpeciesFactManager.GetSpeciesFacts(userContext, speciesFactSearchCriteria); //speciesFactList = CoreData.SpeciesFactManager.GetDyntaxaSpeciesFacts(userContext, speciesFactSearchCriteria); var dic = new Dictionary <int, Dictionary <FactorId, SpeciesFact> >(); foreach (SpeciesFact speciesFact in speciesFactList) { var factorId = (FactorId)speciesFact.Factor.Id; if (!dic.ContainsKey(speciesFact.Taxon.Id)) { dic.Add(speciesFact.Taxon.Id, new Dictionary <FactorId, SpeciesFact>()); } if (!dic[speciesFact.Taxon.Id].ContainsKey(factorId)) { dic[speciesFact.Taxon.Id].Add(factorId, speciesFact); } } return(dic); }
/// <summary> /// Reads species fact. /// </summary> private void InitSpeciesFact() { Stopwatch sp = new Stopwatch(); sp.Start(); try { ISpeciesFactSearchCriteria speciesFactSearchCriteria = new SpeciesFactSearchCriteria(); speciesFactSearchCriteria.EnsureNoListsAreNull(); speciesFactSearchCriteria.IncludeNotValidHosts = true; speciesFactSearchCriteria.IncludeNotValidTaxa = true; speciesFactSearchCriteria.Taxa = new TaxonList(); speciesFactSearchCriteria.Taxa.Add(_taxon); var factorIds = new List <Int32> { (int)FactorId.SwedishOccurrence, (int)FactorId.SwedishHistory }; FactorList factors = CoreData.FactorManager.GetFactors(_user, factorIds); speciesFactSearchCriteria.Factors = new FactorList(); foreach (IFactor factor in factors) { speciesFactSearchCriteria.Factors.Add(factor); } SpeciesFactList speciesFacts = CoreData.SpeciesFactManager.GetDyntaxaSpeciesFacts(_user, speciesFactSearchCriteria); foreach (SpeciesFact speciesFact in speciesFacts) { if (speciesFact.Factor.Id == (int)FactorId.SwedishOccurrence) { _swedishOccourrenceFact = speciesFact; } if (speciesFact.Factor.Id == (int)FactorId.SwedishHistory) { _swedishHistoryFact = speciesFact; } } } catch (Exception ex) { DyntaxaLogger.WriteMessage("Dyntaxa - InitSpeciesFact: " + ex.Message); } sp.Stop(); Debug.WriteLine("Retrieving species fact: {0:N0} milliseconds", sp.ElapsedMilliseconds); }