/// <summary>
        /// Get swedish occurrence type species facts.
        /// </summary>
        private void GetSwedishOccurrenceSpeciesFactsToCache()
        {
            ISpeciesFactSearchCriteria searchCriteria = new SpeciesFactSearchCriteria();

            searchCriteria.Factors = new FactorList();
            IFactor factor = CoreData.FactorManager.GetFactor(mContext, FactorId.SwedishOccurrence);

            searchCriteria.Factors.Add(factor);
            searchCriteria.IndividualCategories = new IndividualCategoryList
            {
                CoreData.FactorManager.GetDefaultIndividualCategory(mContext)
            };
            ISpeciesFactDataSource speciesFactDataSource = new RedListSpeciesFactDataSource();
            SpeciesFactList        speciesFacts          = speciesFactDataSource.GetSpeciesFacts(mContext, searchCriteria);

            if (speciesFacts.IsNotEmpty())
            {
                foreach (ISpeciesFact speciesFact in speciesFacts)
                {
                    if (TaxonInformationCache.TaxonInformation.ContainsKey(speciesFact.Taxon.Id))
                    {
                        TaxonInformationCache.TaxonInformation[speciesFact.Taxon.Id].SetSpeciesFact(speciesFact);
                    }
                }
            }
        }
コード例 #2
0
        public void Merge()
        {
            Int32 count;
            ISpeciesFactSearchCriteria searchCriteria;
            SpeciesFactList            speciesFacts;

            // Get species fact list with species facts.
            searchCriteria = new SpeciesFactSearchCriteria();
            searchCriteria.IncludeNotValidHosts = true;
            searchCriteria.IncludeNotValidTaxa  = true;
            searchCriteria.Add(CoreData.FactorManager.GetFactor(GetUserContext(), FactorId.ActionPlan));
            speciesFacts = CoreData.SpeciesFactManager.GetSpeciesFacts(GetUserContext(), searchCriteria);
            Assert.IsTrue(speciesFacts.IsNotEmpty());

            // Merge species fact that already are in the list.
            count = speciesFacts.Count;
            speciesFacts.Merge(GetUserContext(),
                               speciesFacts[0].Taxon,
                               speciesFacts[0].IndividualCategory,
                               speciesFacts[0].Factor,
                               speciesFacts[0].Host,
                               speciesFacts[0].Period);
            Assert.AreEqual(count, speciesFacts.Count);

            // Merge species fact that is not in the list.
            count = speciesFacts.Count;
            speciesFacts.Merge(GetUserContext(),
                               speciesFacts[0].Taxon,
                               speciesFacts[0].IndividualCategory,
                               CoreData.FactorManager.GetFactor(GetUserContext(), FactorId.SwedishHistory),
                               speciesFacts[0].Host,
                               speciesFacts[0].Period);
            Assert.AreEqual(count, speciesFacts.Count - 1);
        }
        public void CountyMapSecondConstructorTest()
        {
            IUserContext          userContext           = LoginTestUser();
            IFactorSearchCriteria factorSearchCrieteria = new FactorSearchCriteria();
            List <Int32>          countyIds             = new List <Int32>();

            countyIds.Add((Int32)FactorId.CountyOccurrence);
            factorSearchCrieteria.RestrictSearchToFactorIds = countyIds;
            factorSearchCrieteria.RestrictReturnToScope     = ArtDatabanken.Data.FactorSearchScope.LeafFactors;
            FactorList counties = CoreData.FactorManager.GetFactors(userContext, factorSearchCrieteria);
            ISpeciesFactSearchCriteria parameters = new SpeciesFactSearchCriteria();
            ITaxon taxon = CoreData.TaxonManager.GetTaxon(userContext, 101656);

            parameters.Taxa = new TaxonList {
                taxon
            };
            parameters.Factors = counties;
            parameters.IncludeNotValidHosts = true;
            parameters.IncludeNotValidTaxa  = true;
            SpeciesFactList countyInformation = CoreData.SpeciesFactManager.GetSpeciesFacts(userContext, parameters);

            string shapeFileName = Path.Combine(AbsoluteResourceFolderPath, "Sverigekarta med län.shp");

            Console.WriteLine("Reading file: {0}", shapeFileName);
            CountyOccurrenceMap.InitializeMap(shapeFileName);
            CountyOccurrenceMap countyOccurenceMap = new CountyOccurrenceMap(countyInformation);

            string imagePath = Path.Combine(AbsoluteTempFolderPath, "testSpeciesFactMapWithLegend.png");

            Console.WriteLine("Generating image: {0}", imagePath);
            countyOccurenceMap.Save(imagePath, System.Drawing.Imaging.ImageFormat.Png);
        }
コード例 #4
0
        /// <summary>
        /// Constructor of a County occurrece map object. Make sure that the static methos InitializeMap is called before using this constructor.
        /// </summary>
        /// <param name="userContext">
        /// The user Context.
        /// </param>
        /// <param name="taxon">
        /// A taxon object
        /// </param>
        public CountyOccurrenceMap(IUserContext userContext, ITaxon taxon)
        {
            FontName = TEXT_FONT;
            IFactorSearchCriteria factorSearchCrieteria = new FactorSearchCriteria();
            List <Int32>          countyIds             = new List <Int32>();

            countyIds.Add((Int32)FactorId.CountyOccurrence);
            factorSearchCrieteria.RestrictSearchToFactorIds = countyIds;
            factorSearchCrieteria.RestrictReturnToScope     = ArtDatabanken.Data.FactorSearchScope.LeafFactors;
            _counties = CoreData.FactorManager.GetFactors(userContext, factorSearchCrieteria);
            ISpeciesFactSearchCriteria parameters = new SpeciesFactSearchCriteria();

            parameters.Taxa = new TaxonList {
                taxon
            };
            parameters.Factors = new FactorList();
            parameters.Factors = _counties;
            parameters.IncludeNotValidHosts = true;
            parameters.IncludeNotValidTaxa  = true;
            _countyInformation = CoreData.SpeciesFactManager.GetSpeciesFacts(userContext, parameters);
            UpdateInformation  = null;
            if (!_countyInformation.IsNotEmpty())
            {
                _countyInformationExist = false;
            }
        }
        /// <summary>
        /// Get landscape type species facts.
        /// </summary>
        private void GetLandscapeTypeSpeciesFactsToCache()
        {
            ISpeciesFactSearchCriteria searchCriteria = new SpeciesFactSearchCriteria();

            searchCriteria.Factors = new FactorList();
            FactorList factors = CoreData.FactorManager.GetFactorTree(mContext, FactorId.LandscapeFactors).GetAllLeafFactors();

            searchCriteria.Factors.AddRange(factors);
            searchCriteria.IndividualCategories = new IndividualCategoryList
            {
                CoreData.FactorManager.GetDefaultIndividualCategory(mContext)
            };
            ISpeciesFactDataSource speciesFactDataSource = new RedListSpeciesFactDataSource();
            SpeciesFactList        speciesFacts          = speciesFactDataSource.GetSpeciesFacts(mContext, searchCriteria);

            if (speciesFacts.IsNotEmpty())
            {
                foreach (ISpeciesFact speciesFact in speciesFacts)
                {
                    if (TaxonInformationCache.TaxonInformation.ContainsKey(speciesFact.Taxon.Id))
                    {
                        TaxonInformationCache.TaxonInformation[speciesFact.Taxon.Id].SetSpeciesFact(speciesFact);
                    }
                }
            }
        }
        ///// <summary>
        ///// Get factors that are used in Alva.
        ///// </summary>
        //private void GetSpeciesInformationDocument()
        //{
        //    IFactor speciesInformationDocumentIsPublishableFactor = CoreData.FactorManager.GetFactor(mUserContext, FactorId.SpeciesInformationDocumentIsPublishable);
        //    ISpeciesFactSearchCriteria searchCriteria = new SpeciesFactSearchCriteria
        //    {
        //        Factors = new FactorList { speciesInformationDocumentIsPublishableFactor },
        //        Taxa = new TaxonList { mTaxon }
        //    };
        //    SpeciesFactList speciesFacts = CoreData.SpeciesFactManager.GetSpeciesFacts(mUserContext, searchCriteria);

        //    if (speciesFacts.IsNotEmpty())
        //    {
        //        ISpeciesFact speciesInformationDocumentIsPublishableSpeciesFact = speciesFacts[0];

        //        if (speciesInformationDocumentIsPublishableSpeciesFact.IsSpeciesInformationDocumentIsPublishableSpecified())
        //        {
        //            mTaxonSpeciesFact.IsSpeciesInformationDocumentPublishable = speciesInformationDocumentIsPublishableSpeciesFact.MainField.BooleanValue;

        //            if (mTaxonSpeciesFact.IsSpeciesInformationDocumentPublishable)
        //            {
        //                IFactor speciesInformationDocumentPreambleFactor = CoreData.FactorManager.GetFactor(mUserContext, FactorId.SpeciesInformationDocumentPreamble);
        //                IFactor speciesInformationDocumentDescriptionFactor = CoreData.FactorManager.GetFactor(mUserContext, FactorId.SpeciesInformationDocumentDescription);
        //                IFactor speciesInformationDocumentDistributionFactor = CoreData.FactorManager.GetFactor(mUserContext, FactorId.SpeciesInformationDocumentDistribution);
        //                IFactor speciesInformationDocumentEcologyFactor = CoreData.FactorManager.GetFactor(mUserContext, FactorId.SpeciesInformationDocumentEcology);
        //                IFactor speciesInformationDocumentThreatsFactor = CoreData.FactorManager.GetFactor(mUserContext, FactorId.SpeciesInformationDocumentThreats);
        //                IFactor speciesInformationDocumentMeasuresFactor = CoreData.FactorManager.GetFactor(mUserContext, FactorId.SpeciesInformationDocumentMeasures);
        //                IFactor speciesInformationDocumentExtraFactor = CoreData.FactorManager.GetFactor(mUserContext, FactorId.SpeciesInformationDocumentExtra);
        //                IFactor speciesInformationDocumentReferencesFactor = CoreData.FactorManager.GetFactor(mUserContext, FactorId.SpeciesInformationDocumentReferences);
        //                IFactor speciesInformationDocumentAuthorAndYearFactor = CoreData.FactorManager.GetFactor(mUserContext, FactorId.SpeciesInformationDocumentAuthorAndYear);
        //                IFactor speciesInformationDocumentItalicsInReferences = CoreData.FactorManager.GetFactor(mUserContext, FactorId.SpeciesInformationDocumentItalicsInReferences);
        //                IFactor speciesInformationDocumentItalicsInText = CoreData.FactorManager.GetFactor(mUserContext, FactorId.SpeciesInformationDocumentItalicsInText);
        //                ISpeciesFact speciesInformationDocumentPreambleSpeciesFact = null;
        //                ISpeciesFact speciesInformationDocumentDescriptionSpeciesFact = null;
        //                ISpeciesFact speciesInformationDocumentDistributionSpeciesFact = null;
        //                ISpeciesFact speciesInformationDocumentEcologySpeciesFact = null;
        //                ISpeciesFact speciesInformationDocumentThreatsSpeciesFact = null;
        //                ISpeciesFact speciesInformationDocumentMeasuresSpeciesFact = null;
        //                ISpeciesFact speciesInformationDocumentExtraSpeciesFact = null;
        //                ISpeciesFact speciesInformationDocumentReferencesSpeciesFact = null;
        //                ISpeciesFact speciesInformationDocumentAuthorAndYearSpeciesFact = null;
        //                ISpeciesFact speciesInformationDocumentItalicsInReferencesSpeciesFact = null;
        //                ISpeciesFact speciesInformationDocumentItalicsInTextSpeciesFact = null;

        //                searchCriteria.Factors.Remove(speciesInformationDocumentIsPublishableFactor);
        //                searchCriteria.Add(speciesInformationDocumentPreambleFactor);
        //                searchCriteria.Add(speciesInformationDocumentDescriptionFactor);
        //                searchCriteria.Add(speciesInformationDocumentDistributionFactor);
        //                searchCriteria.Add(speciesInformationDocumentEcologyFactor);
        //                searchCriteria.Add(speciesInformationDocumentThreatsFactor);
        //                searchCriteria.Add(speciesInformationDocumentMeasuresFactor);
        //                searchCriteria.Add(speciesInformationDocumentExtraFactor);
        //                searchCriteria.Add(speciesInformationDocumentReferencesFactor);
        //                searchCriteria.Add(speciesInformationDocumentAuthorAndYearFactor);
        //                searchCriteria.Add(speciesInformationDocumentItalicsInReferences);
        //                searchCriteria.Add(speciesInformationDocumentItalicsInText);
        //                speciesFacts = CoreData.SpeciesFactManager.GetSpeciesFacts(mUserContext, searchCriteria);
        //                if (speciesFacts.IsNotEmpty())
        //                {
        //                    foreach (ISpeciesFact speciesFact in speciesFacts)
        //                    {
        //                        switch (speciesFact.Factor.Id)
        //                        {
        //                            case (int)FactorId.SpeciesInformationDocumentPreamble:
        //                                speciesInformationDocumentPreambleSpeciesFact = speciesFact;
        //                                break;
        //                            case (int)FactorId.SpeciesInformationDocumentDescription:
        //                                speciesInformationDocumentDescriptionSpeciesFact = speciesFact;
        //                                break;
        //                            case (int)FactorId.SpeciesInformationDocumentDistribution:
        //                                speciesInformationDocumentDistributionSpeciesFact = speciesFact;
        //                                break;
        //                            case (int)FactorId.SpeciesInformationDocumentEcology:
        //                                speciesInformationDocumentEcologySpeciesFact = speciesFact;
        //                                break;
        //                            case (int)FactorId.SpeciesInformationDocumentThreats:
        //                                speciesInformationDocumentThreatsSpeciesFact = speciesFact;
        //                                break;
        //                            case (int)FactorId.SpeciesInformationDocumentMeasures:
        //                                speciesInformationDocumentMeasuresSpeciesFact = speciesFact;
        //                                break;
        //                            case (int)FactorId.SpeciesInformationDocumentExtra:
        //                                speciesInformationDocumentExtraSpeciesFact = speciesFact;
        //                                break;
        //                            case (int)FactorId.SpeciesInformationDocumentReferences:
        //                                speciesInformationDocumentReferencesSpeciesFact = speciesFact;
        //                                break;
        //                            case (int)FactorId.SpeciesInformationDocumentAuthorAndYear:
        //                                speciesInformationDocumentAuthorAndYearSpeciesFact = speciesFact;
        //                                break;
        //                            case (int)FactorId.SpeciesInformationDocumentItalicsInReferences:
        //                                speciesInformationDocumentItalicsInReferencesSpeciesFact = speciesFact;
        //                                break;
        //                            case (int)FactorId.SpeciesInformationDocumentItalicsInText:
        //                                speciesInformationDocumentItalicsInTextSpeciesFact = speciesFact;
        //                                break;
        //                        }
        //                    }
        //                }

        //                mTaxonSpeciesFact.InitSpeciesInformationDocumentInformation(speciesInformationDocumentPreambleSpeciesFact,
        //                                                                           speciesInformationDocumentDescriptionSpeciesFact,
        //                                                                           speciesInformationDocumentDistributionSpeciesFact,
        //                                                                           speciesInformationDocumentEcologySpeciesFact,
        //                                                                           speciesInformationDocumentThreatsSpeciesFact,
        //                                                                           speciesInformationDocumentMeasuresSpeciesFact,
        //                                                                           speciesInformationDocumentExtraSpeciesFact,
        //                                                                           speciesInformationDocumentReferencesSpeciesFact,
        //                                                                           speciesInformationDocumentAuthorAndYearSpeciesFact,
        //                                                                           speciesInformationDocumentItalicsInReferencesSpeciesFact,
        //                                                                           speciesInformationDocumentItalicsInTextSpeciesFact);
        //            }
        //        }
        //    }
        //}

        ///// <summary>
        ///// Creates a list of Link items for all links recommended for a certain taxon.
        ///// </summary>
        ///// <param name="taxonId">The taxon.</param>
        ///// <returns>A list of link items.</returns>
        //public static List<LinkItem> GetRecommendedLinks(int taxonId)
        //{
        //    var sp = new Stopwatch();
        //    sp.Start();

        //    var links = new List<LinkItem>();
        //    var linkManager = new LinkManager();
        //    LinkItem item;
        //    IUserContext userContext = CoreData.UserManager.GetCurrentUser();
        //    ITaxon taxon = CoreData.TaxonManager.GetTaxon(userContext, taxonId);

        //    // Add link to Photos from Artportalen
        //    string url = linkManager.GetUrlToMediaAp(taxon.Id.ToString(CultureInfo.InvariantCulture));

        //    if (url.IsNotEmpty())
        //    {
        //        item = new LinkItem(LinkType.Url, LinkQuality.ApprovedByExpert, RedListResource.LinkToPhotosAPLabel, url);
        //        links.Add(item);
        //    }

        //    // Add links to search in Dyntaxa
        //    url = linkManager.GetUrlToDyntaxa(taxon.Id.ToString(CultureInfo.InvariantCulture));

        //    if (url.IsNotEmpty())
        //    {
        //        item = new LinkItem(LinkType.Url, LinkQuality.ApprovedByExpert, RedListResource.LinkToDyntaxaLabel, url);
        //        links.Add(item);
        //    }

        //    // Add link to Google images.
        //    url = linkManager.GetUrlToGoogleImagesResults(taxon.ScientificName);
        //    if (url.IsNotEmpty())
        //    {
        //        item = new LinkItem(LinkType.Url, LinkQuality.Automatic, RedListResource.LinkToGoogleImagesLabel, url);
        //        links.Add(item);
        //    }

        //    if (taxon.ScientificName.IsNotEmpty())
        //    {
        //        // Add link to GBIF
        //        url = linkManager.GetUrlToGbif(taxon.ScientificName);
        //        if (url.IsNotEmpty())
        //        {
        //            item = new LinkItem(LinkType.Url, LinkQuality.Automatic, RedListResource.LinkToGbifLabel, url);
        //            links.Add(item);
        //        }

        //        // Add link to EoL
        //        url = linkManager.GetUrlToEoL(taxon.ScientificName);
        //        if (url.IsNotEmpty())
        //        {
        //            item = new LinkItem(LinkType.Url, LinkQuality.Automatic, RedListResource.LinkToEoLLabel, url);
        //            links.Add(item);
        //        }

        //        // Add link to Biodiversity Heritage Library.
        //        url = linkManager.GetUrlToBiodiversityHeritageLibrary(taxon.ScientificName);
        //        if (url.IsNotEmpty())
        //        {
        //            item = new LinkItem(LinkType.Url, LinkQuality.Automatic, "Biodiversity Heritage Library", url);
        //            links.Add(item);
        //        }
        //    }

        //    // Add a link to ITIS Taxon information.
        //    var itisNumberNames = taxon.GetTaxonNamesBySearchCriteria(userContext, (int)TaxonNameCategoryId.ItisNumber, null, null, true, false, false);
        //    foreach (var name in itisNumberNames)
        //    {
        //        url = AppSettings.Default.UrlToGetITISTaxonInformation.Replace("[Id]", name.Name);
        //        var linkItem = new LinkItem(LinkType.Url, LinkQuality.ApprovedByExpert, RedListResource.LinkToItisLabel, url);
        //        links.Add(linkItem);
        //    }

        //    var guidNames = taxon.GetTaxonNamesBySearchCriteria(userContext, (int)TaxonNameCategoryId.Guid, null, null, null, false, false);
        //    foreach (var name in guidNames)
        //    {
        //        LinkItem linkItem;

        //        // Add a link to PESI Taxon information.
        //        url = AppSettings.Default.UrlToGetPESITaxonInformation.Replace("[GUID]", name.Name);
        //        if (name.IsRecommended)
        //        {
        //            linkItem = new LinkItem(LinkType.Url, LinkQuality.ApprovedByExpert, RedListResource.LinkToPesiLabel, url);
        //            links.Add(linkItem);
        //        }
        //        else
        //        {
        //            linkItem = new LinkItem(LinkType.Url, LinkQuality.Automatic, RedListResource.LinkToPesiLabel, url);
        //            links.Add(linkItem);
        //        }

        //        // Add a link to Fauna Europea Taxon information.
        //        url = linkManager.GetUrlToFaunaEuropeaTaxonInformation(name.Name);
        //        if (url.IsNotEmpty())
        //        {
        //            linkItem = new LinkItem(LinkType.Url, LinkQuality.Automatic, RedListResource.LinkToFaunaEuropeaLabel, url);
        //            links.Add(linkItem);
        //        }

        //        // Add a link to Marbef (ERMS) Taxon information.
        //        url = linkManager.GetUrlToMarbefTaxonInformation(name.Name);
        //        if (url.IsNotEmpty())
        //        {
        //            linkItem = new LinkItem(LinkType.Url, LinkQuality.Automatic, RedListResource.LinkToMarbefLabel, url);
        //            links.Add(linkItem);

        //            url = linkManager.GetUrlToNordicMicroalgaeTaxonInformation(taxon.ScientificName);
        //            linkItem = new LinkItem(LinkType.Url, LinkQuality.Automatic, RedListResource.LinkToNordicMicroalgaeLabel, url);
        //            links.Add(linkItem);
        //        }

        //        // Add a link to Algaebase Taxon information.
        //        url = linkManager.GetUrlToAlgaebaseTaxonInformation(name.Name);
        //        if (url.IsNotEmpty())
        //        {
        //            linkItem = new LinkItem(LinkType.Url, LinkQuality.Automatic, RedListResource.LinkToAlgaebaseLabel, url);
        //            links.Add(linkItem);

        //            url = linkManager.GetUrlToNordicMicroalgaeTaxonInformation(taxon.ScientificName);
        //            linkItem = new LinkItem(LinkType.Url, LinkQuality.Automatic, RedListResource.LinkToNordicMicroalgaeLabel, url);
        //            links.Add(linkItem);
        //        }
        //    }

        //    // Add link to Naturforskaren taxon information
        //    url = linkManager.GetUrlToNaturforskaren(taxon.ScientificName);
        //    if (url.IsNotEmpty())
        //    {
        //        item = new LinkItem(LinkType.Url, LinkQuality.Automatic, RedListResource.LinkToNaturforskarenLabel, url);
        //        links.Add(item);
        //    }

        //    // Add link to WIKI taxon information
        //    url = linkManager.GetUrlToWikipedia(taxon.ScientificName);
        //    if (url.IsNotEmpty())
        //    {
        //        item = new LinkItem(LinkType.Url, LinkQuality.Automatic, RedListResource.LinkToWikipediaLabel, url);
        //        links.Add(item);
        //    }

        //    sp.Stop();
        //    Debug.WriteLine("TaxonInfo - Retrieving links: {0:N0} milliseconds", sp.ElapsedMilliseconds);
        //    return links;
        //}

        //public byte[] GetCountyMap(ITaxon taxon)
        //{
        //    // Set swedish locale
        //    SetSwedishLangugage();

        //    // Check so that we have a valid SpeciesFactList containing elements
        //    if (IsSpeciesFactFactListEmpty(taxon))
        //    {
        //        return null;
        //    }

        //    byte[] buffer = null;
        //    var returnStream = new MemoryStream();

        //    try
        //    {
        //        var countyMapProvider = new RedListCountyOccurrenceMap(mUserContext, taxon);

        //        if (countyMapProvider.CountyInformationExist)
        //        {
        //            countyMapProvider.Height = 800;
        //            countyMapProvider.UpdateInformation = RedListResource.TaxonInfoDistributionInSwedenCountyOccurrence;

        //            var map = countyMapProvider.Bitmap;
        //            map.Save(returnStream, ImageFormat.Png);

        //            buffer = returnStream.GetBuffer();
        //            returnStream.Close();
        //        }
        //    }
        //    catch (Exception ex)
        //    {
        //        throw new Exception("Failed to update county map cache", ex);
        //    }

        //    return buffer;
        //}

        private bool IsSpeciesFactFactListEmpty(ITaxon taxon)
        {
            IFactorSearchCriteria factorSearchCrieteria = new FactorSearchCriteria();
            var countyIds = new List <int> {
                (int)FactorId.CountyOccurrence
            };

            factorSearchCrieteria.RestrictSearchToFactorIds = countyIds;
            factorSearchCrieteria.RestrictReturnToScope     = FactorSearchScope.LeafFactors;
            FactorList counties = CoreData.FactorManager.GetFactors(mUserContext, factorSearchCrieteria);

            ISpeciesFactSearchCriteria parameters = new SpeciesFactSearchCriteria();

            parameters.Taxa = new TaxonList {
                taxon
            };
            parameters.Factors = new FactorList();
            parameters.Factors = counties;
            parameters.IncludeNotValidHosts = true;
            parameters.IncludeNotValidTaxa  = true;

            SpeciesFactList sList = CoreData.SpeciesFactManager.GetSpeciesFacts(mUserContext, parameters);

            return(sList.IsEmpty());
        }
        /// <summary>
        /// Get all species facts that are needed to initialize
        /// properties in class TaxonListInformation.
        /// </summary>
        /// <param name="taxa">The taxa.</param>
        /// <returns>Taxon list information about specified taxa.</returns>
        private SpeciesFactList GetSpeciesFacts(IEnumerable <ITaxon> taxa)
        {
            ISpeciesFactSearchCriteria searchCriteria = new SpeciesFactSearchCriteria();

            searchCriteria.Factors = new FactorList();
            FactorList landscapeFactors = CoreData.FactorManager.GetFactorTree(mContext, FactorId.LandscapeFactors).GetAllLeafFactors();

            searchCriteria.Factors.AddRange(landscapeFactors);
            IFactor redlistCategoryFactor = CoreData.FactorManager.GetFactor(mContext, FactorId.RedlistCategory);

            searchCriteria.Factors.Add(redlistCategoryFactor);
            IFactor redlistTaxonTypeFactor = CoreData.FactorManager.GetFactor(mContext, FactorId.Redlist_TaxonType);

            searchCriteria.Factors.Add(redlistTaxonTypeFactor);
            IFactor redlistOrganismLabel1 = CoreData.FactorManager.GetFactor(mContext, FactorId.Redlist_OrganismLabel1);

            searchCriteria.Factors.Add(redlistOrganismLabel1);
            IFactor redlistCriteriaFactor = CoreData.FactorManager.GetFactor(mContext, FactorId.RedlistCriteriaString);

            searchCriteria.Factors.Add(redlistCriteriaFactor);
            searchCriteria.IndividualCategories = new IndividualCategoryList
            {
                CoreData.FactorManager.GetDefaultIndividualCategory(mContext)
            };
            searchCriteria.Periods = new PeriodList {
                CoreData.FactorManager.GetCurrentRedListPeriod(mContext)
            };
            searchCriteria.Taxa = new TaxonList();
            searchCriteria.Taxa.AddRange(taxa);
            ISpeciesFactDataSource speciesFactDataSource = new RedListSpeciesFactDataSource();
            SpeciesFactList        speciesFacts          = speciesFactDataSource.GetSpeciesFacts(mContext, searchCriteria);

            return(speciesFacts);
        }
コード例 #8
0
        /// <summary>
        /// A method that obtains red list information.
        /// </summary>
        /// <param name="userContext">User context.</param>
        private void LoadRedListInformation(IUserContext userContext)
        {
            ISpeciesFactSearchCriteria searchCriteria;
            SpeciesFactList            speciesFacts;

            if (_organismGroupName.IsNull())
            {
                _organismGroupName          = String.Empty;
                _redlistCategoryName        = String.Empty;
                _redlistCategoryShortString = String.Empty;
                _redlistCriteria            = String.Empty;

                searchCriteria = new SpeciesFactSearchCriteria();
                searchCriteria.Add(CoreData.FactorManager.GetFactor(userContext, FactorId.RedlistCategory));
                searchCriteria.Add(CoreData.FactorManager.GetFactor(userContext, FactorId.RedlistCriteriaString));
                searchCriteria.Add(CoreData.FactorManager.GetFactor(userContext, FactorId.Redlist_OrganismLabel1));
                searchCriteria.Add(_period);
                searchCriteria.AddTaxon(_taxon);
                searchCriteria.IncludeNotValidHosts = true;
                searchCriteria.IncludeNotValidTaxa  = true;
                speciesFacts = CoreData.SpeciesFactManager.GetSpeciesFacts(userContext, searchCriteria);
                if (speciesFacts.IsNotEmpty())
                {
                    foreach (ISpeciesFact speciesFact in speciesFacts)
                    {
                        switch (speciesFact.Factor.Id)
                        {
                        case (Int32)FactorId.RedlistCategory:
                            if (speciesFact.HasField1)
                            {
                                _redlistCategoryName = speciesFact.Field1.EnumValue.OriginalLabel;
                                _redlistCategoryName = _redlistCategoryName.Remove(_redlistCategoryName.Length - 5);
                            }
                            if (speciesFact.HasField4)
                            {
                                _redlistCategoryShortString = speciesFact.Field4.StringValue;
                            }
                            break;

                        case (Int32)FactorId.RedlistCriteriaString:
                            if (speciesFact.HasField4 &&
                                speciesFact.Field4.StringValue.IsNotEmpty())
                            {
                                _redlistCriteria = speciesFact.Field4.StringValue.Trim();
                            }
                            break;

                        case (Int32)FactorId.Redlist_OrganismLabel1:
                            if (speciesFact.MainField.HasValue)
                            {
                                _organismGroupName = speciesFact.MainField.EnumValue.OriginalLabel;
                            }
                            break;
                        }
                    }
                }
            }
        }
コード例 #9
0
        /// <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);
        }
コード例 #10
0
        public void RemoveSpeciesFactsWithBadQuality()
        {
            Int32                      countWithBadQuality, countWithoutBadQuality;
            SpeciesFactList            speciesFacts;
            ISpeciesFactSearchCriteria searchCriteria;

            searchCriteria = new SpeciesFactSearchCriteria();
            searchCriteria.Add(CoreData.FactorManager.GetFactor(GetUserContext(), 779));
            speciesFacts = CoreData.SpeciesFactManager.GetSpeciesFacts(GetUserContext(), searchCriteria);
            Assert.IsTrue(speciesFacts.IsNotEmpty());
            countWithBadQuality = speciesFacts.Count;
            speciesFacts.RemoveSpeciesFactsWithBadQuality();
            Assert.IsTrue(speciesFacts.IsNotEmpty());
            countWithoutBadQuality = speciesFacts.Count;
            Assert.IsTrue(countWithoutBadQuality < countWithBadQuality);
        }
コード例 #11
0
        /// <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>
        /// Initiate the cache with species fact information.
        /// </summary>
        /// <param name="userContext">The user context.</param>
        public void Init(IUserContext userContext)
        {
            FactorList                 factors;
            ISpeciesFactDataSource     speciesFactDataSource;
            ISpeciesFactSearchCriteria searchCriteria;
            SpeciesFactList            speciesFacts;

            speciesFactDataSource = new RedListSpeciesFactDataSource();
            searchCriteria        = new SpeciesFactSearchCriteria();
            searchCriteria.IndividualCategories = new IndividualCategoryList();
            searchCriteria.IndividualCategories.Add(CoreData.FactorManager.GetDefaultIndividualCategory(userContext));
            searchCriteria.Periods = new PeriodList();
            searchCriteria.Periods.Add(CoreData.FactorManager.GetCurrentRedListPeriod(userContext));
            factors = GetFactors(userContext);
            searchCriteria.Factors = new FactorList();
            searchCriteria.Factors.AddRange(factors);
            speciesFacts = speciesFactDataSource.GetSpeciesFacts(userContext, searchCriteria);
            foreach (ISpeciesFact speciesFact in speciesFacts)
            {
                if (speciesFact.IsRedlistCategorySpecified())
                {
                    if (speciesFact.Field1.EnumValue.KeyText.IsEmpty())
                    {
                        var ex = new Exception("Must be an error in the database for speciesFact.Field1.EnumValue.KeyText taxon =" + speciesFact.Taxon.Id);
                        throw ex;
                    }
                    if (speciesFact.Field1.EnumValue.KeyInt != null)
                    {
                        mCategories[(RedListCategory)speciesFact.Field1.EnumValue.KeyInt.Value].Add(new TaxonIdImplementation(speciesFact.Taxon.Id));
                    }
                }
            }

            foreach (var category in mCategories.Keys)
            {
                foreach (var taxon in mCategories[category])
                {
                    if (mTaxonIdCategories.ContainsKey(taxon.Id))
                    {
                        throw new Exception();
                    }

                    mTaxonIdCategories.Add(taxon.Id, category);
                }
            }
        }
        public void GetSpeciesFactsBySearchCriteriaForestAgency()
        {
            SpeciesFactList            speciesFacts;
            ISpeciesFactSearchCriteria searchCriteria;
            String text;

            // This test currently only works in production.
            searchCriteria = new SpeciesFactSearchCriteria();
            searchCriteria.Add(CoreData.FactorManager.GetFactor(GetUserContext(), 2682)); // Ekologi
            searchCriteria.Add(CoreData.FactorManager.GetFactor(GetUserContext(), 2683)); // Naturvård
            searchCriteria.Add(CoreData.FactorManager.GetFactor(GetUserContext(), 2684)); // Trädslag
            searchCriteria.Add(CoreData.FactorManager.GetDefaultIndividualCategory(GetUserContext()));
            searchCriteria.AddTaxon(CoreData.TaxonManager.GetTaxon(GetUserContext(), 256840));
            speciesFacts = CoreData.SpeciesFactManager.GetSpeciesFacts(GetUserContext(), searchCriteria);
            RemoveSpeciesFactsWithBadQuality(speciesFacts);
            Assert.IsTrue(speciesFacts.IsNotEmpty());
            text = speciesFacts[0].MainField.GetString();
            Assert.IsTrue(text.IsNotEmpty());
        }
コード例 #14
0
        /// <summary>
        /// Get all protected taxa
        /// </summary>
        /// <returns>A list of all protected taxa</returns>
        private TaxonList GetProtectedTaxa()
        {
            ISpeciesFactSearchCriteria searchCriteria = new SpeciesFactSearchCriteria();

            searchCriteria.Factors = new FactorList();
            searchCriteria.IndividualCategories = new IndividualCategoryList
            {
                CoreData.FactorManager.GetDefaultIndividualCategory(mContext)
            };
            searchCriteria.Factors.Add(CoreData.FactorManager.GetFactor(mContext, FactorId.ProtectionLevel));

            var speciesFactList = CoreData.SpeciesFactManager.GetSpeciesFacts(mContext, searchCriteria);

            var taxonList = new TaxonList(true);

            foreach (var speciesFact in speciesFactList)
            {
                if (speciesFact.MainField != null && speciesFact.MainField.HasValue &&
                    speciesFact.MainField.EnumValue != null && speciesFact.MainField.EnumValue.Enum != null)
                {
                    const int RedListProtectionLevel = 1;
                    if (speciesFact.MainField.EnumValue.KeyInt > RedListProtectionLevel)
                    {
                        taxonList.Add(speciesFact.Taxon);
                    }
                }
            }

            ITaxonTreeSearchCriteria taxonTreeSearchCriteria = new TaxonTreeSearchCriteria();

            taxonTreeSearchCriteria.TaxonIds        = taxonList.GetIds();
            taxonTreeSearchCriteria.Scope           = TaxonTreeSearchScope.AllChildTaxa;
            taxonTreeSearchCriteria.IsValidRequired = true;
            TaxonTreeNodeList taxonTreeNodeList = CoreData.TaxonManager.GetTaxonTrees(mContext, taxonTreeSearchCriteria);

            foreach (var taxonTreeNode in taxonTreeNodeList)
            {
                taxonList.Merge(taxonTreeNode.GetChildTaxa());
            }

            return(taxonList);
        }
コード例 #15
0
        /// <summary>
        /// Get list of protected taxons. List is cached.
        /// </summary>
        /// <returns>Protected taxons.</returns>
        public IEnumerable <ITaxon> GetProtectedTaxons()
        {
            const string CachedProtectedTaxons = "protectedTaxons";

            IEnumerable <ITaxon> protectedTaxons = (IEnumerable <ITaxon>)AspNetCache.GetCachedObject(CachedProtectedTaxons);

            if (protectedTaxons.IsNull())
            {
                ISpeciesFactSearchCriteria searchCriteria = new SpeciesFactSearchCriteria();

                searchCriteria.IncludeNotValidHosts = false;
                searchCriteria.IncludeNotValidTaxa  = false;
                searchCriteria.Factors = new FactorList();

                IFactor factor = CoreData.FactorManager.GetFactor(_user, FactorId.ProtectionLevel);

                searchCriteria.Factors.Add(factor);

                searchCriteria.FieldSearchCriteria = new SpeciesFactFieldSearchCriteriaList();

                ISpeciesFactFieldSearchCriteria fieldSearchCriteria = new SpeciesFactFieldSearchCriteria();
                fieldSearchCriteria.FactorField = factor.DataType.Field1;
                fieldSearchCriteria.Operator    = CompareOperator.Greater;
                fieldSearchCriteria.AddValue(1);

                searchCriteria.FieldSearchCriteria.Add(fieldSearchCriteria);

                // Get species facts related to protected taxons
                SpeciesFactList speciesFactList = CoreData.SpeciesFactManager.GetSpeciesFacts(_user, searchCriteria);

                // Get distinct list of taxons from list of species facts
                protectedTaxons = speciesFactList.Select(sf => sf.Taxon).Distinct();

                AspNetCache.AddCachedObject(
                    CachedProtectedTaxons,
                    protectedTaxons,
                    DateTime.Now.AddHours(6),
                    System.Web.Caching.CacheItemPriority.Normal);
            }

            return(protectedTaxons);
        }
        public void GetTaxaBySpeciesFactSearchCriteria()
        {
            TaxonList taxa;
            ISpeciesFactSearchCriteria searchCriteria;

            // Test String species fact field condition.
            searchCriteria = new SpeciesFactSearchCriteria();
            searchCriteria.IncludeNotValidHosts = true;
            searchCriteria.IncludeNotValidTaxa  = true;
            searchCriteria.Factors = new FactorList();
            searchCriteria.Factors.Add(CoreData.FactorManager.GetFactor(GetUserContext(), (Int32)(FactorId.RedlistCategory)));
            searchCriteria.FieldSearchCriteria = new SpeciesFactFieldSearchCriteriaList();
            searchCriteria.FieldSearchCriteria.Add(new SpeciesFactFieldSearchCriteria());
            searchCriteria.FieldSearchCriteria[0].FactorField = searchCriteria.Factors[0].DataType.Fields[2];
            searchCriteria.FieldSearchCriteria[0].Operator    = CompareOperator.Equal;
            searchCriteria.FieldSearchCriteria[0].AddValue("VU");
            taxa = GetSpeciesFactManager().GetTaxa(GetUserContext(), searchCriteria);
            Assert.IsTrue(taxa.IsNotEmpty());
            Assert.IsTrue(taxa.Count > 0);
        }
        public void GetSpeciesFactsBySearchCriteriaSpeciesFactFieldSearchCriteria()
        {
            SpeciesFactList            speciesFacts;
            ISpeciesFactSearchCriteria searchCriteria;

            // Test Int32 species fact field condition.
            searchCriteria = new SpeciesFactSearchCriteria();
            searchCriteria.IncludeNotValidHosts = true;
            searchCriteria.IncludeNotValidTaxa  = true;
            searchCriteria.Factors = new FactorList();
            searchCriteria.Factors.Add(CoreData.FactorManager.GetFactor(GetUserContext(), 830)); // Namn: Risädellövskog, FaktorId: 830
            searchCriteria.FieldSearchCriteria = new SpeciesFactFieldSearchCriteriaList();
            searchCriteria.FieldSearchCriteria.Add(new SpeciesFactFieldSearchCriteria());
            searchCriteria.FieldSearchCriteria[0].FactorField = searchCriteria.Factors[0].DataType.Fields[0];
            searchCriteria.FieldSearchCriteria[0].Operator    = CompareOperator.Equal;
            searchCriteria.FieldSearchCriteria[0].AddValue(1.WebToString()); // Betydelse: [1] Utnyttjas

            searchCriteria.FieldLogicalOperator = LogicalOperator.Or;
            speciesFacts = GetSpeciesFactManager().GetSpeciesFacts(GetUserContext(), searchCriteria);
            Assert.IsTrue(speciesFacts.IsNotEmpty());
        }
コード例 #18
0
        /// <summary>
        /// Get species facts with species document information.
        /// </summary>
        /// <param name="userContext">User context.</param>
        private void GetSpeciesFacts(IUserContext userContext)
        {
            FactorList                 factors;
            FactorSearchCriteria       factorSearchCriteria;
            ISpeciesFactSearchCriteria speciesFactSearchCriteria;

            // Get factors.
            factorSearchCriteria = new FactorSearchCriteria();
            factorSearchCriteria.RestrictSearchToFactorIds = new List <Int32>();
            factorSearchCriteria.RestrictSearchToFactorIds.Add((Int32)FactorId.SpeciesInformationDocumentGroup);
            factorSearchCriteria.RestrictReturnToScope = FactorSearchScope.LeafFactors;
            factors = CoreData.FactorManager.GetFactors(userContext, factorSearchCriteria);

            // Get species facts.
            speciesFactSearchCriteria = new SpeciesFactSearchCriteria();
            speciesFactSearchCriteria.AddTaxon(_taxon);
            speciesFactSearchCriteria.Factors = factors;
            speciesFactSearchCriteria.IncludeNotValidHosts = true;
            speciesFactSearchCriteria.IncludeNotValidTaxa  = true;
            _speciesFacts = CoreData.SpeciesFactManager.GetSpeciesFacts(userContext, speciesFactSearchCriteria);
        }
        /// <summary>
        /// Get previouly red list categories species facts.
        /// </summary>
        private void GetRedListOldCategorySpeciesFactsToCache()
        {
            ISpeciesFactSearchCriteria searchCriteria = new SpeciesFactSearchCriteria();

            searchCriteria.Factors = new FactorList();
            IFactor factor = CoreData.FactorManager.GetFactor(mContext, FactorId.RedlistCategory);

            searchCriteria.Factors.Add(factor);
            searchCriteria.IndividualCategories = new IndividualCategoryList
            {
                CoreData.FactorManager.GetDefaultIndividualCategory(mContext)
            };
            PeriodList periodsList   = CoreData.FactorManager.GetPublicPeriods(mContext);
            IPeriod    currentPeriod = CoreData.FactorManager.GetCurrentRedListPeriod(mContext);
            var        oldPeriods    = new PeriodList();

            foreach (IPeriod period in periodsList)
            {
                if (period.Id != currentPeriod.Id)
                {
                    oldPeriods.Add(period);
                }
            }
            searchCriteria.Periods = oldPeriods;
            ISpeciesFactDataSource speciesFactDataSource = new RedListSpeciesFactDataSource();
            SpeciesFactList        speciesFacts          = speciesFactDataSource.GetSpeciesFacts(mContext, searchCriteria);

            if (speciesFacts.IsNotEmpty())
            {
                foreach (ISpeciesFact speciesFact in speciesFacts)
                {
                    if (TaxonInformationCache.TaxonInformation.ContainsKey(speciesFact.Taxon.Id))
                    {
                        TaxonInformationCache.TaxonInformation[speciesFact.Taxon.Id].SetSpeciesFact(speciesFact, currentPeriod);
                    }
                }
            }
        }
コード例 #20
0
        /// <summary>
        /// Search for list of taxon by factor.
        /// </summary>
        /// <param name="taxonSearchFactorFieldViewModels"></param>
        /// <param name="factorId"></param>
        /// <param name="restrictToCurrentTaxonFilter"></param>
        /// <param name="settings"></param>
        /// <returns></returns>
        private List <ITaxon> SearchTaxonByFactor(List <TaxonSearchFactorFieldViewModel> taxonSearchFactorFieldViewModels, Int32 factorId, Boolean restrictToCurrentTaxonFilter, MySettings.MySettings settings)
        {
            if (taxonSearchFactorFieldViewModels == null)
            {
                taxonSearchFactorFieldViewModels = new List <TaxonSearchFactorFieldViewModel>();
            }

            TaxonList taxonList = new TaxonList();
            ISpeciesFactSearchCriteria searchCriteria = new SpeciesFactSearchCriteria();

            searchCriteria.IncludeNotValidHosts = false;
            searchCriteria.IncludeNotValidTaxa  = false;
            searchCriteria.FieldSearchCriteria  = new SpeciesFactFieldSearchCriteriaList();
            searchCriteria.Factors = new FactorList();
            ISpeciesFactFieldSearchCriteria fieldSearchCriteria;

            searchCriteria.FieldLogicalOperator = LogicalOperator.And;

            if (taxonSearchFactorFieldViewModels.Count > 0)
            {
                if (restrictToCurrentTaxonFilter)
                {
                    if (settings.Filter.Taxa.HasSettings)
                    {
                        searchCriteria.Taxa = CoreData.TaxonManager.GetTaxa(_user, settings.Filter.Taxa.TaxonIds.ToList());
                    }
                    else
                    {
                        return(new TaxonList());
                    }
                }

                IFactor factor = CoreData.FactorManager.GetFactor(_user, factorId);

                searchCriteria.Factors.Add(factor);

                // Add factor field to search criteria by list of factor field id
                foreach (var field in factor.DataType.Fields)
                {
                    if (field.Type.Id == (int)FactorFieldDataTypeId.Enum)
                    {
                        if (field.Enum != null && field.Enum.Values != null)
                        {
                            fieldSearchCriteria = new SpeciesFactFieldSearchCriteria();
                            // fieldSearchCriteria.IsEnumAsString = true;
                            fieldSearchCriteria.FactorField = field;
                            fieldSearchCriteria.Operator    = CompareOperator.Equal;
                            foreach (var val in field.Enum.Values)
                            {
                                if (val.KeyInt.HasValue && taxonSearchFactorFieldViewModels.Any(x => x.FactorFieldTypeId == val.Id))
                                {
                                    String factorValue = taxonSearchFactorFieldViewModels.First(x => x.FactorFieldTypeId == val.Id).FactorFieldTypeValue;
                                    fieldSearchCriteria.AddValue(factorValue);
                                }
                            }

                            if (fieldSearchCriteria.Values.IsNotEmpty())
                            {
                                searchCriteria.FieldSearchCriteria.Add(fieldSearchCriteria);
                            }
                        }
                    }
                    else if (field.Type.Id == (int)FactorFieldDataTypeId.Boolean)
                    {
                        if (field.Enum != null && field.Enum.Values != null)
                        {
                            fieldSearchCriteria = new SpeciesFactFieldSearchCriteria();
                            // fieldSearchCriteria.IsEnumAsString = true;
                            fieldSearchCriteria.FactorField = field;
                            fieldSearchCriteria.Operator    = CompareOperator.Equal;
                            foreach (var val in field.Enum.Values)
                            {
                                if (val.KeyInt.HasValue && taxonSearchFactorFieldViewModels.Any(x => x.FactorFieldTypeId == val.Id))
                                {
                                    String factorValue = taxonSearchFactorFieldViewModels.First(x => x.FactorFieldTypeId == val.Id).FactorFieldTypeValue;
                                    fieldSearchCriteria.AddValue(factorValue);
                                }
                            }

                            if (fieldSearchCriteria.Values.IsNotEmpty())
                            {
                                searchCriteria.FieldSearchCriteria.Add(fieldSearchCriteria);
                            }
                        }
                    }
                    else if (field.Type.Id == (int)FactorFieldDataTypeId.Double)
                    {
                        if (taxonSearchFactorFieldViewModels.Any(x => x.FactorFieldTypeId == field.Id))
                        {
                            TaxonSearchFactorFieldViewModel factorField = taxonSearchFactorFieldViewModels.First(x => x.FactorFieldTypeId == field.Id);
                            CompareOperator compareOperator             = factorField.CompareOperatorIsSpecified ? factorField.CompareOperator : CompareOperator.Equal;
                            String          factorValue = factorField.FactorFieldTypeValue;
                            fieldSearchCriteria             = new SpeciesFactFieldSearchCriteria();
                            fieldSearchCriteria.FactorField = field;
                            fieldSearchCriteria.Operator    = compareOperator;
                            fieldSearchCriteria.AddValue(factorValue.WebParseInt32());
                            searchCriteria.FieldSearchCriteria.Add(fieldSearchCriteria);
                        }
                    }
                    else if (field.Type.Id == (int)FactorFieldDataTypeId.Int32)
                    {
                        if (taxonSearchFactorFieldViewModels.Any(x => x.FactorFieldTypeId == field.Id))
                        {
                            TaxonSearchFactorFieldViewModel factorField = taxonSearchFactorFieldViewModels.First(x => x.FactorFieldTypeId == field.Id);
                            CompareOperator compareOperator             = factorField.CompareOperatorIsSpecified ? factorField.CompareOperator : CompareOperator.Equal;
                            String          factorValue = factorField.FactorFieldTypeValue;
                            fieldSearchCriteria             = new SpeciesFactFieldSearchCriteria();
                            fieldSearchCriteria.FactorField = field;
                            fieldSearchCriteria.Operator    = compareOperator;
                            fieldSearchCriteria.AddValue(factorValue.WebParseInt32());
                            searchCriteria.FieldSearchCriteria.Add(fieldSearchCriteria);
                        }
                    }
                    else if (field.Type.Id == (int)FactorFieldDataTypeId.String)
                    {
                        if (taxonSearchFactorFieldViewModels.Any(x => x.FactorFieldTypeId == field.Id))
                        {
                            TaxonSearchFactorFieldViewModel factorField = taxonSearchFactorFieldViewModels.First(x => x.FactorFieldTypeId == field.Id);
                            CompareOperator compareOperator             = factorField.CompareOperatorIsSpecified ? factorField.CompareOperator : CompareOperator.Equal;
                            String          factorValue = factorField.FactorFieldTypeValue;
                            fieldSearchCriteria             = new SpeciesFactFieldSearchCriteria();
                            fieldSearchCriteria.FactorField = field;
                            fieldSearchCriteria.Operator    = compareOperator;
                            fieldSearchCriteria.AddValue(factorValue);
                            searchCriteria.FieldSearchCriteria.Add(fieldSearchCriteria);
                        }
                    }
                }
            }
            else
            {
                return(new TaxonList());
            }

            // Get taxa.
            taxonList = CoreData.AnalysisManager.GetTaxa(_user, searchCriteria);

            return(taxonList);
        }
        /// <summary>
        /// Retrieves information about the specified taxon.
        /// </summary>
        /// <param name="taxonId">Id of the taxon.</param>
        /// <returns>Information about the specified taxon.</returns>
        public TaxonSpeciesFactViewModel GetTaxonSpeciesFact(int taxonId)
        {
            mTaxon            = CoreData.TaxonManager.GetTaxon(mUserContext, taxonId);
            mTaxonSpeciesFact = new TaxonSpeciesFactViewModel(mUserContext, mTaxon);

            IIndividualCategory individualCategory          = CoreData.FactorManager.GetDefaultIndividualCategory(mUserContext);
            IPeriod             period                      = CoreData.FactorManager.GetCurrentRedListPeriod(mUserContext);
            PeriodList          periods                     = CoreData.FactorManager.GetPublicPeriods(mUserContext);
            IFactor             categoryFactor              = CoreData.FactorManager.GetFactor(mUserContext, FactorId.RedlistCategory);
            IFactor             criteriaDocumentationFactor = CoreData.FactorManager.GetFactor(mUserContext, FactorId.RedlistCriteriaDocumentation);
            IFactor             criteriaFactor              = CoreData.FactorManager.GetFactor(mUserContext, FactorId.RedlistCriteriaString);
            IFactor             globalCategoryFactor        = CoreData.FactorManager.GetFactor(mUserContext, FactorId.GlobalRedlistCategory);
            //FactorList landscapeTypesFactors = LandscapeTypeCache.GetFactors(mUserContext);
            //FactorList lifeFormFactors = LifeFormCache.GetFactors(mUserContext);
            FactorList conventionFactors    = CoreData.FactorManager.GetFactorTree(mUserContext, FactorId.Conventions).GetAllLeafFactors();
            IFactor    organismGroup1Factor = CoreData.FactorManager.GetFactor(mUserContext, FactorId.Redlist_OrganismLabel1);
            IFactor    organismGroup2Factor = CoreData.FactorManager.GetFactor(mUserContext, FactorId.Redlist_OrganismLabel2);
            //FactorList countyOccurrenceFactors = CountyOccurrenceCache.GetFactors(mUserContext);
            //FactorList biotopeFactors = BiotopeCache.GetFactors(mUserContext);
            //FactorList substrateFactors = SubstrateCache.GetFactors(mUserContext);
            //FactorList impactFactors = ImpactCache.GetFactors(mUserContext);
            IFactor actionPlanFactor        = CoreData.FactorManager.GetFactor(mUserContext, FactorId.ActionPlan);
            IFactor protectedByLawFactor    = CoreData.FactorManager.GetFactor(mUserContext, FactorId.ProtectedByLaw);
            IFactor swedishOccurrenceFactor = CoreData.FactorManager.GetFactor(mUserContext, FactorId.SwedishOccurrence);
            //FactorList hostFactors = HostCache.GetFactors(mUserContext);

            // Get species facts.
            var          countyOccurrenceSpeciesFacts     = new SpeciesFactList();
            var          landscapeTypeSpeciesFacts        = new SpeciesFactList();
            var          biotopeSpeciesFacts              = new SpeciesFactList();
            var          lifeFormSpeciesFacts             = new SpeciesFactList();
            var          conventionSpeciesFacts           = new SpeciesFactList();
            var          previouslyCategorySpeciesFact    = new SpeciesFactList();
            ISpeciesFact categorySpeciesFact              = null;
            ISpeciesFact criteriaDocumentationSpeciesFact = null;
            ISpeciesFact criteriaSpeciesFact              = null;
            ISpeciesFact globalCategorySpeciesFact        = null;
            ISpeciesFact organismGroup1SpeciesFact        = null;
            ISpeciesFact organismGroup2SpeciesFact        = null;
            var          substrateSpeciesFacts            = new SpeciesFactList();
            var          impactSpeciesFacts           = new SpeciesFactList();
            ISpeciesFact actionPlanSpeciesFact        = null;
            ISpeciesFact protectedByLawSpeciesFact    = null;
            ISpeciesFact swedishOccurrenceSpeciesFact = null;
            var          hostSpeciesFacts             = new SpeciesFactList();
            ISpeciesFactSearchCriteria searchCriteria = new SpeciesFactSearchCriteria {
                Factors = new FactorList()
            };

            searchCriteria.AddTaxon(mTaxon);
            searchCriteria.Add(individualCategory);
            foreach (IPeriod tempPeriod in periods)
            {
                searchCriteria.Add(tempPeriod);
            }

            // Add current period if not exist.
            bool currentPeriodExist = periods.Any(tempPeriod => tempPeriod.Id == period.Id);

            if (!currentPeriodExist)
            {
                searchCriteria.Add(period);
            }

            searchCriteria.Add(categoryFactor);
            searchCriteria.Add(criteriaDocumentationFactor);
            searchCriteria.Add(criteriaFactor);
            searchCriteria.Add(globalCategoryFactor);
            //searchCriteria.Factors.AddRange(landscapeTypesFactors);
            //searchCriteria.Factors.AddRange(lifeFormFactors);
            searchCriteria.Factors.AddRange(conventionFactors);
            searchCriteria.Add(organismGroup1Factor);
            searchCriteria.Add(organismGroup2Factor);
            //searchCriteria.Factors.AddRange(countyOccurrenceFactors);
            //searchCriteria.Factors.AddRange(biotopeFactors);
            //searchCriteria.Factors.AddRange(substrateFactors);
            //searchCriteria.Factors.AddRange(impactFactors);
            searchCriteria.Add(actionPlanFactor);
            searchCriteria.Add(protectedByLawFactor);
            searchCriteria.Add(swedishOccurrenceFactor);
            //searchCriteria.Factors.AddRange(hostFactors);
            SpeciesFactList speciesFacts = CoreData.SpeciesFactManager.GetSpeciesFacts(mUserContext, searchCriteria);

            // Split species facts into information groups.
            if (speciesFacts.IsNotEmpty())
            {
                foreach (ISpeciesFact speciesFact in speciesFacts)
                {
                    //if (countyOccurrenceFactors.Exists(speciesFact.Factor))
                    //{
                    //    countyOccurrenceSpeciesFacts.Add(speciesFact);
                    //}
                    //else if (landscapeTypesFactors.Exists(speciesFact.Factor))
                    //{
                    //    landscapeTypeSpeciesFacts.Add(speciesFact);
                    //}
                    //else if (biotopeFactors.Exists(speciesFact.Factor))
                    //{
                    //    biotopeSpeciesFacts.Add(speciesFact);
                    //}
                    //else if (substrateFactors.Exists(speciesFact.Factor))
                    //{
                    //    substrateSpeciesFacts.Add(speciesFact);
                    //    if (hostFactors.Exists(speciesFact.Factor))
                    //    {
                    //        hostSpeciesFacts.Add(speciesFact);
                    //    }
                    //}
                    //else if (impactFactors.Exists(speciesFact.Factor))
                    //{
                    //    impactSpeciesFacts.Add(speciesFact);
                    //}
                    //else if (lifeFormFactors.Exists(speciesFact.Factor))
                    //{
                    //    lifeFormSpeciesFacts.Add(speciesFact);
                    //}
                    if (conventionFactors.Exists(speciesFact.Factor))
                    {
                        conventionSpeciesFacts.Add(speciesFact);
                    }
                    else if (speciesFact.Factor.Id == (int)FactorId.RedlistCategory && speciesFact.Period.Id != period.Id)
                    {
                        previouslyCategorySpeciesFact.Add(speciesFact);
                    }
                    else
                    {
                        switch (speciesFact.Factor.Id)
                        {
                        case (int)FactorId.ActionPlan:
                            actionPlanSpeciesFact = speciesFact;
                            break;

                        case (int)FactorId.GlobalRedlistCategory:
                            globalCategorySpeciesFact = speciesFact;
                            break;

                        case (int)FactorId.ProtectedByLaw:
                            protectedByLawSpeciesFact = speciesFact;
                            break;

                        case (int)FactorId.RedlistCategory:
                            categorySpeciesFact = speciesFact;
                            break;

                        case (int)FactorId.RedlistCriteriaDocumentation:
                            criteriaDocumentationSpeciesFact = speciesFact;
                            break;

                        case (int)FactorId.RedlistCriteriaString:
                            criteriaSpeciesFact = speciesFact;
                            break;

                        case (int)FactorId.Redlist_OrganismLabel1:
                            organismGroup1SpeciesFact = speciesFact;
                            break;

                        case (int)FactorId.Redlist_OrganismLabel2:
                            organismGroup2SpeciesFact = speciesFact;
                            break;

                        case (int)FactorId.SwedishOccurrence:
                            swedishOccurrenceSpeciesFact = speciesFact;
                            break;
                        }
                    }
                }
            }

            //mTaxonSpeciesFact.InitCountyOccurrenceInformation(countyOccurrenceSpeciesFacts);
            //mTaxonSpeciesFact.InitLandscapeTypeInformation(landscapeTypeSpeciesFacts);
            //mTaxonSpeciesFact.InitBiotopeInformation(biotopeSpeciesFacts);
            //mTaxonSpeciesFact.InitLifeFormInformation(lifeFormSpeciesFacts);
            //mTaxonSpeciesFact.InitConventionInformation(conventionSpeciesFacts);
            InitRedListInformation(
                mTaxonSpeciesFact,
                categorySpeciesFact,
                criteriaSpeciesFact,
                criteriaDocumentationSpeciesFact,
                globalCategorySpeciesFact,
                period);
            //mTaxonSpeciesFact.InitOrganismGroupInformation(organismGroup1SpeciesFact,
            //                                              organismGroup2SpeciesFact);
            //mTaxonSpeciesFact.InitSubstrateInformation(substrateSpeciesFacts);
            //mTaxonSpeciesFact.InitImpactInformation(impactSpeciesFacts);
            //mTaxonSpeciesFact.InitActionPlanInformation(actionPlanSpeciesFact);
            //mTaxonSpeciesFact.InitProtectedByLawInformation(protectedByLawSpeciesFact);
            //mTaxonSpeciesFact.InitHostInformation(hostSpeciesFacts, mUserContext);
            //mTaxonSpeciesFact.InitSwedishOccurrenceInformation(swedishOccurrenceSpeciesFact);
            //mTaxonSpeciesFact.InitPreviouslyRedListedCategories(previouslyCategorySpeciesFact);
            //GetSpeciesInformationDocument();
            //long pictureId;
            //mTaxonSpeciesFact.HasImage = !string.IsNullOrWhiteSpace(GetPictureByTaxon(mTaxon,
            //                                                       AppSettings.Default.PictureXtraLargeHeight,
            //                                                       AppSettings.Default.PictureXtraLargeWidth,
            //                                                       AppSettings.Default.PictureLargeSize,
            //                                                       true,
            //                                                       string.Empty,
            //                                                       out pictureId));
            //mTaxonSpeciesFact.ImageMetaData = GetPictureMetadataByPictureId(pictureId);
            //mTaxonSpeciesFact.HasCountyMap = GetCountyMap(mTaxon) != null;
            //mTaxonSpeciesFact.HasObservationMap = SpeciesFilter.IsTaxaSpeciesOrBelow(mTaxon) &&
            //    SpeciesFactCacheManager.Instance.GetObservationMap(mTaxon.Id.ToString(CultureInfo.InvariantCulture)) != null;

            mTaxonSpeciesFact.HasSpeciesFacts = HasSpeciesFacts(speciesFacts);
            mTaxonSpeciesFact.IsValid         = CheckIfTaxonValid();

            //mTaxonSpeciesFact.Synonyms = mTaxon.GetSynonymsViewModel(mUserContext);

            // Identify higher level taxa
            //mTaxonSpeciesFact.CategoryNameHighLevel = SpeciesFilter.IsTaxaSpeciesOrBelow(mTaxon) ? "" : mTaxon.Category.Name + " - ";

            //// Ignore if not higher taxa
            //if ((mTaxonSpeciesFact.IsHigherTaxa = !SpeciesFilter.IsTaxaSpeciesOrBelow(mTaxon)) == false)
            //{
            //    return mTaxonSpeciesFact;
            //}

            // Count all occurences for each category in underlying taxa
            //var taxonNameSearchInformation = TaxonNameSearchManager.Instance.GetInformation(this.mTaxon.Id);
            //foreach (var category in RedListedHelper.GetAllRedListCategories())
            //{
            //    mTaxonSpeciesFact.RedListCategoryTaxa[category] = new List<int>();
            //}

            //foreach (var taxonInfoType in taxonNameSearchInformation.AllChildTaxaIdsInScope)
            //{
            //    if (SpeciesFilter.IsTaxaSpeciesOrBelow(taxonInfoType.CategoryId, taxonInfoType.ParentCategoryId) && taxonInfoType.HasValidRedListCategory)
            //    {
            //        mTaxonSpeciesFact.RedListCategoryTaxa[taxonInfoType.RedListCategoryId].Add(taxonInfoType.TaxonId);
            //    }
            //}

            return(mTaxonSpeciesFact);
        }
コード例 #22
0
        public void GetSpeciesFactsBySearchCriteria()
        {
            SpeciesFactList            speciesFacts1, speciesFacts2;
            ISpeciesFactSearchCriteria searchCriteria;

            // Test factor data types.
            searchCriteria = new SpeciesFactSearchCriteria();
            searchCriteria.IncludeNotValidHosts = false;
            searchCriteria.IncludeNotValidTaxa  = false;
            searchCriteria.FactorDataTypes      = new FactorDataTypeList();
            searchCriteria.FactorDataTypes.Add(CoreData.FactorManager.GetFactorDataType(GetUserContext(), 5)); // EK-utbredning.
            speciesFacts1 = GetSpeciesFactDataSource(true).GetSpeciesFacts(GetUserContext(), searchCriteria);
            Assert.IsTrue(speciesFacts1.IsNotEmpty());

            searchCriteria.Factors = new FactorList();
            searchCriteria.Factors.Add(CoreData.FactorManager.GetFactor(GetUserContext(), 513)); // Fjällen
            speciesFacts2 = GetSpeciesFactDataSource().GetSpeciesFacts(GetUserContext(), searchCriteria);
            Assert.IsTrue(speciesFacts2.IsNotEmpty());
            Assert.IsTrue(speciesFacts1.Count > speciesFacts2.Count);

            // Test factors.
            searchCriteria = new SpeciesFactSearchCriteria();
            searchCriteria.IncludeNotValidHosts = false;
            searchCriteria.IncludeNotValidTaxa  = false;
            searchCriteria.Factors = new FactorList();
            searchCriteria.Factors.Add(CoreData.FactorManager.GetFactor(GetUserContext(), (Int32)(FactorId.RedlistCategory)));
            searchCriteria.Periods = new PeriodList();
            searchCriteria.Periods.Add(CoreData.FactorManager.GetPeriod(GetUserContext(), 3)); // 2010
            speciesFacts1 = GetSpeciesFactDataSource().GetSpeciesFacts(GetUserContext(), searchCriteria);
            Assert.IsTrue(speciesFacts1.IsNotEmpty());

            searchCriteria = new SpeciesFactSearchCriteria();
            searchCriteria.IncludeNotValidHosts = false;
            searchCriteria.IncludeNotValidTaxa  = false;
            searchCriteria.Hosts = new TaxonList();
            searchCriteria.Hosts.Add(CoreData.TaxonManager.GetTaxon(GetUserContext(), 102656)); // Hedsidenbi.
            speciesFacts1 = GetSpeciesFactDataSource().GetSpeciesFacts(GetUserContext(), searchCriteria);
            Assert.IsTrue(speciesFacts1.IsNotEmpty());

            // Test include not valid hosts.
            // Hard to test since there are no host values
            // in database that belongs to not valid taxa.
            searchCriteria         = new SpeciesFactSearchCriteria();
            searchCriteria.Factors = new FactorList();
            searchCriteria.Factors.Add(CoreData.FactorManager.GetFactor(GetUserContext(), 5));
            searchCriteria.IncludeNotValidHosts = false;
            speciesFacts1 = GetSpeciesFactDataSource().GetSpeciesFacts(GetUserContext(), searchCriteria);
            Assert.IsTrue(speciesFacts1.IsNotEmpty());

            searchCriteria         = new SpeciesFactSearchCriteria();
            searchCriteria.Factors = new FactorList();
            searchCriteria.Factors.Add(CoreData.FactorManager.GetFactor(GetUserContext(), 5));
            searchCriteria.IncludeNotValidHosts = true;
            speciesFacts2 = GetSpeciesFactDataSource().GetSpeciesFacts(GetUserContext(), searchCriteria);
            Assert.IsTrue(speciesFacts2.IsNotEmpty());
            Assert.IsTrue(speciesFacts2.Count >= speciesFacts1.Count);

            // Test include not valid taxa.
            searchCriteria         = new SpeciesFactSearchCriteria();
            searchCriteria.Factors = new FactorList();
            searchCriteria.Factors.Add(CoreData.FactorManager.GetFactor(GetUserContext(), 5));
            searchCriteria.IncludeNotValidTaxa = false;
            speciesFacts1 = GetSpeciesFactDataSource().GetSpeciesFacts(GetUserContext(), searchCriteria);
            Assert.IsTrue(speciesFacts1.IsNotEmpty());

            searchCriteria         = new SpeciesFactSearchCriteria();
            searchCriteria.Factors = new FactorList();
            searchCriteria.Factors.Add(CoreData.FactorManager.GetFactor(GetUserContext(), 5));
            searchCriteria.IncludeNotValidTaxa = true;
            speciesFacts2 = GetSpeciesFactDataSource().GetSpeciesFacts(GetUserContext(), searchCriteria);
            Assert.IsTrue(speciesFacts2.IsNotEmpty());
            Assert.IsTrue(speciesFacts2.Count > speciesFacts1.Count);

            searchCriteria = new SpeciesFactSearchCriteria();
            searchCriteria.IncludeNotValidHosts = false;
            searchCriteria.IncludeNotValidTaxa  = false;
            searchCriteria.IndividualCategories = new IndividualCategoryList();
            searchCriteria.IndividualCategories.Add(CoreData.FactorManager.GetIndividualCategory(GetUserContext(), 9)); // Ungar (juveniler)
            speciesFacts1 = GetSpeciesFactDataSource().GetSpeciesFacts(GetUserContext(), searchCriteria);
            Assert.IsTrue(speciesFacts1.IsNotEmpty());
            searchCriteria.IndividualCategories.Add(CoreData.FactorManager.GetIndividualCategory(GetUserContext(), 10)); // Vuxna (imago).
            speciesFacts1 = GetSpeciesFactDataSource().GetSpeciesFacts(GetUserContext(), searchCriteria);
            Assert.IsTrue(speciesFacts1.IsNotEmpty());

            searchCriteria = new SpeciesFactSearchCriteria();
            searchCriteria.IncludeNotValidHosts = false;
            searchCriteria.IncludeNotValidTaxa  = false;
            searchCriteria.Factors = new FactorList();
            searchCriteria.Factors.Add(CoreData.FactorManager.GetFactor(GetUserContext(), (Int32)(FactorId.RedlistCategory)));
            searchCriteria.Periods = new PeriodList();
            searchCriteria.Periods.Add(CoreData.FactorManager.GetPeriod(GetUserContext(), 3)); // 2010
            speciesFacts1 = GetSpeciesFactDataSource().GetSpeciesFacts(GetUserContext(), searchCriteria);
            Assert.IsTrue(speciesFacts1.IsNotEmpty());
            searchCriteria.Periods.Add(CoreData.FactorManager.GetPeriod(GetUserContext(), 5)); // 2013 HELCOM
            speciesFacts1 = GetSpeciesFactDataSource().GetSpeciesFacts(GetUserContext(), searchCriteria);
            Assert.IsTrue(speciesFacts1.IsNotEmpty());

            searchCriteria = new SpeciesFactSearchCriteria();
            searchCriteria.IncludeNotValidHosts = false;
            searchCriteria.IncludeNotValidTaxa  = false;
            searchCriteria.Factors = new FactorList();
            searchCriteria.Factors.Add(CoreData.FactorManager.GetFactor(GetUserContext(), (Int32)(FactorId.RedlistCategory)));
            searchCriteria.Periods = new PeriodList();
            searchCriteria.Periods.Add(CoreData.FactorManager.GetPeriod(GetUserContext(), 4));                           // 2015
            searchCriteria.IndividualCategories = new IndividualCategoryList();
            searchCriteria.IndividualCategories.Add(CoreData.FactorManager.GetIndividualCategory(GetUserContext(), 10)); // Vuxna (imago).
            speciesFacts1 = GetSpeciesFactDataSource().GetSpeciesFacts(GetUserContext(), searchCriteria);
            Assert.IsTrue(speciesFacts1.IsEmpty());

            searchCriteria = new SpeciesFactSearchCriteria();
            searchCriteria.IncludeNotValidHosts = false;
            searchCriteria.IncludeNotValidTaxa  = false;
            searchCriteria.Taxa = new TaxonList();
            searchCriteria.Taxa.Add(CoreData.TaxonManager.GetTaxon(GetUserContext(), TaxonId.DrumGrasshopper));
            speciesFacts1 = GetSpeciesFactDataSource().GetSpeciesFacts(GetUserContext(), searchCriteria);
            Assert.IsTrue(speciesFacts1.IsNotEmpty());

            // Test Boolean species fact field condition.
            searchCriteria = new SpeciesFactSearchCriteria();
            searchCriteria.IncludeNotValidHosts = false;
            searchCriteria.IncludeNotValidTaxa  = false;
            searchCriteria.Factors = new FactorList();
            searchCriteria.Factors.Add(CoreData.FactorManager.GetFactor(GetUserContext(), (Int32)(FactorId.RedlistCategory)));
            searchCriteria.FieldSearchCriteria = new SpeciesFactFieldSearchCriteriaList();
            searchCriteria.FieldSearchCriteria.Add(new SpeciesFactFieldSearchCriteria());
            searchCriteria.FieldSearchCriteria[0].FactorField = searchCriteria.Factors[0].DataType.Fields[1];
            searchCriteria.FieldSearchCriteria[0].Operator    = CompareOperator.Equal;
            searchCriteria.FieldSearchCriteria[0].AddValue(Boolean.TrueString);
            speciesFacts1 = GetSpeciesFactDataSource().GetSpeciesFacts(GetUserContext(), searchCriteria);
            Assert.IsTrue(speciesFacts1.IsNotEmpty());

            // Test Float64 species fact field condition.
            searchCriteria = new SpeciesFactSearchCriteria();
            searchCriteria.IncludeNotValidHosts = false;
            searchCriteria.IncludeNotValidTaxa  = false;
            searchCriteria.Factors = new FactorList();
            searchCriteria.Factors.Add(CoreData.FactorManager.GetFactor(GetUserContext(), 2547)); // 2:e gångbenparet lång relativt kroppslängden, ben/kroppslängd kvot = 2-8
            searchCriteria.FieldSearchCriteria = new SpeciesFactFieldSearchCriteriaList();
            searchCriteria.FieldSearchCriteria.Add(new SpeciesFactFieldSearchCriteria());
            searchCriteria.FieldSearchCriteria[0].FactorField = searchCriteria.Factors[0].DataType.Fields[0];
            searchCriteria.FieldSearchCriteria[0].Operator    = CompareOperator.Greater;
            searchCriteria.FieldSearchCriteria[0].AddValue("0");
            speciesFacts1 = GetSpeciesFactDataSource().GetSpeciesFacts(GetUserContext(), searchCriteria);
            Assert.IsTrue(speciesFacts1.IsNotEmpty());

            searchCriteria.FieldSearchCriteria[0].Operator = CompareOperator.Greater;
            searchCriteria.FieldSearchCriteria[0].Values   = new List <String>();
            searchCriteria.FieldSearchCriteria[0].AddValue("2");
            speciesFacts1 = GetSpeciesFactDataSource().GetSpeciesFacts(GetUserContext(), searchCriteria);
            Assert.IsTrue(speciesFacts1.IsEmpty());

            // Test Int32 species fact field condition.
            searchCriteria = new SpeciesFactSearchCriteria();
            searchCriteria.IncludeNotValidHosts = false;
            searchCriteria.IncludeNotValidTaxa  = false;
            searchCriteria.Factors = new FactorList();
            searchCriteria.Factors.Add(CoreData.FactorManager.GetFactor(GetUserContext(), (Int32)(FactorId.RedlistCategory)));
            searchCriteria.FieldSearchCriteria = new SpeciesFactFieldSearchCriteriaList();
            searchCriteria.FieldSearchCriteria.Add(new SpeciesFactFieldSearchCriteria());
            searchCriteria.FieldSearchCriteria[0].FactorField = searchCriteria.Factors[0].DataType.Fields[0];
            searchCriteria.FieldSearchCriteria[0].Operator    = CompareOperator.Equal;
            searchCriteria.FieldSearchCriteria[0].AddValue(2.WebToString()); // CR
            searchCriteria.FieldSearchCriteria.Add(new SpeciesFactFieldSearchCriteria());
            searchCriteria.FieldSearchCriteria[1].FactorField = searchCriteria.Factors[0].DataType.Fields[0];
            searchCriteria.FieldSearchCriteria[1].Operator    = CompareOperator.Equal;
            searchCriteria.FieldSearchCriteria[1].AddValue(3.WebToString()); // EN
            searchCriteria.FieldSearchCriteria.Add(new SpeciesFactFieldSearchCriteria());
            searchCriteria.FieldSearchCriteria[2].FactorField = searchCriteria.Factors[0].DataType.Fields[0];
            searchCriteria.FieldSearchCriteria[2].Operator    = CompareOperator.Equal;
            searchCriteria.FieldSearchCriteria[2].AddValue(4.WebToString()); // VU
            searchCriteria.FieldLogicalOperator = LogicalOperator.Or;
            speciesFacts1 = GetSpeciesFactDataSource().GetSpeciesFacts(GetUserContext(), searchCriteria);
            Assert.IsTrue(speciesFacts1.IsNotEmpty());

            // Test String species fact field condition.
            searchCriteria = new SpeciesFactSearchCriteria();
            searchCriteria.IncludeNotValidHosts = false;
            searchCriteria.IncludeNotValidTaxa  = false;
            searchCriteria.Factors = new FactorList();
            searchCriteria.Factors.Add(CoreData.FactorManager.GetFactor(GetUserContext(), (Int32)(FactorId.RedlistCategory)));
            searchCriteria.FieldSearchCriteria = new SpeciesFactFieldSearchCriteriaList();
            searchCriteria.FieldSearchCriteria.Add(new SpeciesFactFieldSearchCriteria());
            searchCriteria.FieldSearchCriteria[0].FactorField = searchCriteria.Factors[0].DataType.Fields[2];
            searchCriteria.FieldSearchCriteria[0].Operator    = CompareOperator.Equal;
            searchCriteria.FieldSearchCriteria[0].AddValue("VU");
            speciesFacts1 = GetSpeciesFactDataSource().GetSpeciesFacts(GetUserContext(), searchCriteria);
            Assert.IsTrue(speciesFacts1.IsNotEmpty());

            searchCriteria.FieldSearchCriteria[0].Operator = CompareOperator.Like;
            searchCriteria.FieldSearchCriteria[0].Values   = new List <String>();
            searchCriteria.FieldSearchCriteria[0].AddValue("%VU%");
            speciesFacts2 = GetSpeciesFactDataSource().GetSpeciesFacts(GetUserContext(), searchCriteria);
            Assert.IsTrue(speciesFacts2.IsNotEmpty());
            Assert.IsTrue(speciesFacts1.Count < speciesFacts2.Count);
        }