/// <summary> /// The get factor value. /// </summary> /// <param name="speciesFact"> /// The species Fact. /// </param> /// <returns> /// The <see cref="string"/>. /// </returns> public static string GetFactorValue(SpeciesFact speciesFact) { if (speciesFact != null) { if (speciesFact.MainField != null) { var factorField = speciesFact.MainField.Value as FactorFieldEnumValue; if (factorField != null) { return(factorField.OriginalLabel); } } } return(null); }
/// <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); }
/// <summary> /// The get factor value. /// </summary> /// <param name="dicFactors"> /// The dic factors. /// </param> /// <param name="factorId"> /// The factor id. /// </param> /// <returns> /// The <see cref="string"/>. /// </returns> public static string GetFactorValue(Dictionary <FactorId, SpeciesFact> dicFactors, FactorId factorId) { SpeciesFact speciesFact = null; dicFactors.TryGetValue(factorId, out speciesFact); if (speciesFact != null) { if (speciesFact.MainField != null) { var factorField = speciesFact.MainField.Value as FactorFieldEnumValue; if (factorField != null) { return(factorField.OriginalLabel); } } } return(null); }
/// <summary> /// Convert a WebSpeciesFact instance into /// an ISpeciesFact instance. /// </summary> /// <param name="webSpeciesFact">A WebSpeciesFact instance.</param> /// <param name="factors">List of factors.</param> /// <param name="individualCategories">List of individual categories.</param> /// <param name="periods">List of periods.</param> /// <returns>An ISpeciesFact instance.</returns> private ISpeciesFact GetSpeciesFact( WebSpeciesFact webSpeciesFact, FactorList factors, IndividualCategoryList individualCategories, PeriodList periods) { IFactor factor; IPeriod period; ISpeciesFact speciesFact; ITaxon host, taxon; factor = factors.Get(webSpeciesFact.FactorId); if (webSpeciesFact.IsHostSpecified) { host = new Data.Taxon(); host.Id = webSpeciesFact.HostId; } else { if (factor.IsTaxonomic) { host = new Data.Taxon { Id = (int)TaxonId.Life }; } else { host = null; } } if (webSpeciesFact.IsPeriodSpecified) { period = periods.Get(webSpeciesFact.PeriodId); } else { period = null; } taxon = new Data.Taxon(); taxon.Id = webSpeciesFact.TaxonId; speciesFact = new SpeciesFact( webSpeciesFact.Id, taxon, individualCategories.Get(webSpeciesFact.IndividualCategoryId), factor, host, period, webSpeciesFact.FieldValue1, webSpeciesFact.IsFieldValue1Specified, webSpeciesFact.FieldValue2, webSpeciesFact.IsFieldValue2Specified, webSpeciesFact.FieldValue3, webSpeciesFact.IsFieldValue3Specified, webSpeciesFact.FieldValue4, webSpeciesFact.IsFieldValue4Specified, webSpeciesFact.FieldValue5, webSpeciesFact.IsFieldValue5Specified, null, null, webSpeciesFact.ModifiedBy, webSpeciesFact.ModifiedDate); return(speciesFact); }