Пример #1
0
        public void TestSpeciesFactsWithIncludeMissingSpeciesFacts()
        {
            IUserContext    userContext = GetUserContext();
            List <FactorId> factorIds   = new List <FactorId> {
                FactorId.SwedishOccurrence, FactorId.SwedishHistory
            };
            List <int> taxonIds = new List <int>();

            taxonIds.Add(237935);  //Amphora Veneta
            SpeciesFactList speciesFactList       = SpeciesFactModelManager.GetSpeciesFactListByTaxaAndFactors(userContext, factorIds, taxonIds, true);
            var             speciesFactDictionary = speciesFactList.ToDictionaryGroupedByTaxonIdThenFactorId();

            Assert.IsTrue(speciesFactDictionary[237935][FactorId.SwedishOccurrence].GetStatusId().HasValue);
            Assert.IsFalse(speciesFactDictionary[237935][FactorId.SwedishHistory].GetStatusId().HasValue);

            var occurrenceStatusId    = speciesFactDictionary[237935][FactorId.SwedishOccurrence].GetStatusId();
            var occurrenceQualityId   = speciesFactDictionary[237935][FactorId.SwedishOccurrence].GetQualityId();
            var occurrenceReferenceId = speciesFactDictionary[237935][FactorId.SwedishOccurrence].GetReferenceId();
            var occurrenceComment     = speciesFactDictionary[237935][FactorId.SwedishOccurrence].GetDescription();

            var historyStatusId    = speciesFactDictionary[237935][FactorId.SwedishHistory].GetStatusId();
            var historyQualityId   = speciesFactDictionary[237935][FactorId.SwedishHistory].GetQualityId();
            var historyReferenceId = speciesFactDictionary[237935][FactorId.SwedishHistory].GetReferenceId();
            var historyComment     = speciesFactDictionary[237935][FactorId.SwedishHistory].GetDescription();

            Assert.IsNotNull(speciesFactList);
        }
        /// <summary>
        /// Convert a list of WebSpeciesFact instances
        /// to a SpeciesFactList.
        /// </summary>
        /// <param name="userContext">
        /// Information about the user that makes this method call.
        /// </param>
        /// <param name="webSpeciesFacts">List of WebSpeciesFact instances.</param>
        /// <returns>List of SpeciesFact instances.</returns>
        protected override SpeciesFactList GetSpeciesFacts(
            IUserContext userContext,
            List <WebSpeciesFact> webSpeciesFacts)
        {
            SpeciesFactList        speciesFacts;
            FactorList             factors = CoreData.FactorManager.GetFactors(userContext);
            IndividualCategoryList individualCategories = CoreData.FactorManager.GetIndividualCategories(userContext);
            PeriodList             periods = CoreData.FactorManager.GetPeriods(userContext);

            speciesFacts = null;
            if (webSpeciesFacts.IsNotEmpty())
            {
                speciesFacts = new SpeciesFactList();
                foreach (WebSpeciesFact webSpeciesFact in webSpeciesFacts)
                {
                    if (webSpeciesFact.QualityId <= (int)SpeciesFactQualityId.Acceptable)
                    {
                        speciesFacts.Add(GetSpeciesFact(webSpeciesFact, factors, individualCategories, periods));
                    }
                    // else: Bad quality, do not use this species fact.
                }
            }

            return(speciesFacts);
        }
 /// <summary>
 /// Expands a Species Fact List with empty species facts so that every combination from the user parameter selection is represented.
 /// Factor Headers are excluded.
 /// Periodic factors are not expanded to individual categories other than the default.
 /// </summary>
 /// <param name="userContext">The user context.</param>
 /// <param name="taxon">Taxon object of the species fact.</param>
 /// <param name="individualCategory">Individual category object of the species fact.</param>
 /// <param name="factor">Factor object of the species fact.</param>
 /// <param name="host">Host taxon object of the species fact.</param>
 /// <param name="period">Period object of the species fact.</param>
 /// <param name="speciesFacts">Species fact list to be expanded.</param>
 private static void ExpandSpeciesFactListWithEmptySpeciesFact(
     IUserContext userContext,
     ITaxon taxon,
     IIndividualCategory individualCategory,
     IFactor factor,
     ITaxon host,
     IPeriod period,
     SpeciesFactList speciesFacts)
 {
     if (!speciesFacts.Exists(CoreData.SpeciesFactManager.GetSpeciesFactIdentifier(
                                  taxon,
                                  individualCategory,
                                  factor,
                                  host,
                                  period)))
     {
         speciesFacts.Add(CoreData.SpeciesFactManager.GetSpeciesFact(
                              userContext,
                              taxon,
                              individualCategory,
                              factor,
                              host,
                              period));
     }
 }
Пример #4
0
        /// <summary>
        /// Convert a list of WebSpeciesFact instances
        /// to a SpeciesFactList.
        /// </summary>
        /// <param name="userContext">
        /// Information about the user that makes this method call.
        /// </param>
        /// <param name="webSpeciesFacts">List of WebSpeciesFact instances.</param>
        /// <returns>List of SpeciesFact instances.</returns>
        protected virtual SpeciesFactList GetSpeciesFacts(IUserContext userContext, List <WebSpeciesFact> webSpeciesFacts)
        {
            SpeciesFactList        speciesFacts;
            FactorList             factors = CoreData.FactorManager.GetFactors(userContext);
            IndividualCategoryList individualCategories = CoreData.FactorManager.GetIndividualCategories(userContext);
            PeriodList             periods = CoreData.FactorManager.GetPeriods(userContext);
            ReferenceList          references;
            SpeciesFactQualityList speciesFactQualities = CoreData.SpeciesFactManager.GetSpeciesFactQualities(userContext);
            List <Int32>           referenceIds, taxonIds;
            TaxonList taxa;

            speciesFacts = null;
            if (webSpeciesFacts.IsNotEmpty())
            {
                referenceIds = GetReferenceIds(webSpeciesFacts);
                references   = CoreData.ReferenceManager.GetReferences(userContext, referenceIds);
                taxonIds     = GetTaxonIds(webSpeciesFacts);
                taxa         = CoreData.TaxonManager.GetTaxa(userContext, taxonIds);
                speciesFacts = new SpeciesFactList();
                foreach (WebSpeciesFact webSpeciesFact in webSpeciesFacts)
                {
                    speciesFacts.Add(GetSpeciesFact(userContext, webSpeciesFact, factors, individualCategories, periods, references, speciesFactQualities, taxa));
                }
            }

            return(speciesFacts);
        }
        /// <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);
        }
        ///// <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());
        }
        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);
        }
Пример #8
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 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);
                    }
                }
            }
        }
        /// <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);
                    }
                }
            }
        }
Пример #11
0
        /// <summary>
        /// Get species facts with specified identifiers.
        /// Only existing species facts are returned,
        /// e.g. species fact identifiers that does not
        /// match existing species fact does not affect
        /// the returned species facts.
        /// </summary>
        /// <param name="userContext">
        /// Information about the user that makes this method call.
        /// </param>
        /// <param name="speciesFactIdentifiers">
        /// Species facts identifiers. E.g. ISpeciesFact
        /// instances where id for requested combination of
        /// factor, host, individual category, period and taxon
        /// has been set.
        /// Host id is only used together with taxonomic factors.
        /// Period id is only used together with periodic factors.
        /// </param>
        /// <returns>
        /// Existing species facts among the
        /// requested species facts.
        /// </returns>
        public virtual SpeciesFactList GetSpeciesFacts(IUserContext userContext,
                                                       SpeciesFactList speciesFactIdentifiers)
        {
            List <WebSpeciesFact> webSpeciesFactIdentifiers, webSpeciesFacts;

            CheckTransaction(userContext);
            webSpeciesFactIdentifiers = GetWebSpeciesFacts(speciesFactIdentifiers);
            webSpeciesFacts           = WebServiceProxy.TaxonAttributeService.GetSpeciesFactsByIdentifiers(GetClientInformation(userContext), webSpeciesFactIdentifiers);
            return(GetSpeciesFacts(userContext, webSpeciesFacts));
        }
Пример #12
0
        /// <summary>
        /// Update species facts.
        /// </summary>
        /// <param name="userContext">
        /// Information about the user that makes this method call.
        /// </param>
        /// <param name="updateSpeciesFacts">Existing species facts to update.</param>
        public virtual void UpdateSpeciesFacts(IUserContext userContext,
                                               SpeciesFactList updateSpeciesFacts)
        {
            List <WebSpeciesFact> webUpdateSpeciesFacts;

            CheckTransaction(userContext);
            webUpdateSpeciesFacts = GetWebSpeciesFacts(updateSpeciesFacts);

            // Update species facts.
            WebServiceProxy.TaxonAttributeService.UpdateSpeciesFacts(GetClientInformation(userContext),
                                                                     webUpdateSpeciesFacts);
        }
Пример #13
0
        /// <summary>
        /// Create species facts.
        /// </summary>
        /// <param name="userContext">
        /// Information about the user that makes this method call.
        /// </param>
        /// <param name="createSpeciesFacts">New species facts to create.</param>
        /// <param name="defaultReference">Reference used if no reference is specified.</param>
        public virtual void CreateSpeciesFacts(IUserContext userContext,
                                               SpeciesFactList createSpeciesFacts,
                                               IReference defaultReference)
        {
            List <WebSpeciesFact> webCreateSpeciesFacts;

            CheckTransaction(userContext);
            webCreateSpeciesFacts = GetWebSpeciesFacts(createSpeciesFacts, defaultReference);

            // Create species facts.
            WebServiceProxy.TaxonAttributeService.CreateSpeciesFacts(GetClientInformation(userContext),
                                                                     webCreateSpeciesFacts);
        }
Пример #14
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);
        }
Пример #15
0
        /// <summary>
        /// The get species facts.
        /// </summary>
        /// <param name="userContext">
        /// The user context.
        /// </param>
        /// <param name="taxon">
        /// The taxon.
        /// </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 <FactorId, SpeciesFact> GetSpeciesFacts(
            IUserContext userContext,
            ITaxon taxon,
            IEnumerable <FactorId> factorIds,
            out SpeciesFactList speciesFactList)
        {
            var dic = GetSpeciesFacts(userContext, new[] { taxon }, factorIds, out speciesFactList);

            if (dic.Values.Count == 1)
            {
                return(dic.Values.First());
            }

            return(new Dictionary <FactorId, SpeciesFact>());
        }
Пример #16
0
        /// <summary>
        /// Converts a SpeciesFactList instance to a list of WebSpeciesFact instances.
        /// </summary>
        /// <param name="speciesFacts">List of SpeciesFact instances.</param>
        /// <returns>List of WebSpeciesFact instances.</returns>
        private List <WebSpeciesFact> GetWebSpeciesFacts(SpeciesFactList speciesFacts)
        {
            List <WebSpeciesFact> webSpeciesFacts = null;

            if (speciesFacts.IsNotEmpty())
            {
                webSpeciesFacts = new List <WebSpeciesFact>();
                foreach (ISpeciesFact speciesFact in speciesFacts)
                {
                    webSpeciesFacts.Add(GetWebSpeciesFact(speciesFact));
                }
            }

            return(webSpeciesFacts);
        }
Пример #17
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="countyOccurrences">Information about county occurrence.</param>
        public CountyOccurrenceMap(SpeciesFactList countyOccurrences)
        {
            FontName           = TEXT_FONT;
            _countyInformation = countyOccurrences;
            _counties          = new FactorList();
            if (_countyInformation.IsNotEmpty())
            {
                foreach (SpeciesFact fact in _countyInformation)
                {
                    _counties.Add(fact.Factor);
                }
            }

            UpdateInformation = null;
        }
        private void RemoveSpeciesFactsWithBadQuality(SpeciesFactList speciesFacts)
        {
            Int32 index;

            if (speciesFacts.IsNotEmpty())
            {
                for (index = speciesFacts.Count - 1; index >= 0; index--)
                {
                    if (speciesFacts[index].Quality.Id > ((Int32)(SpeciesFactQualityId.Acceptable)))
                    {
                        // Bad quality. Remove species fact from list.
                        speciesFacts.RemoveAt(index);
                    }
                }
            }
        }
Пример #19
0
        public void TestSpeciesFactsWithExcludeMissingSpeciesFacts()
        {
            IUserContext    userContext = GetUserContext();
            List <FactorId> factorIds   = new List <FactorId> {
                FactorId.SwedishOccurrence, FactorId.SwedishHistory
            };
            List <int> taxonIds = new List <int>();

            taxonIds.Add(237935);  //Amphora Veneta
            SpeciesFactList speciesFactList       = SpeciesFactModelManager.GetSpeciesFactListByTaxaAndFactors(userContext, factorIds, taxonIds, false);
            var             speciesFactDictionary = speciesFactList.ToDictionaryGroupedByTaxonIdThenFactorId();

            Assert.IsTrue(speciesFactDictionary.ContainsKey(237935));
            Assert.IsTrue(speciesFactDictionary[237935].ContainsKey(FactorId.SwedishOccurrence));
            Assert.IsFalse(speciesFactDictionary[237935].ContainsKey(FactorId.SwedishHistory));
        }
Пример #20
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>
        /// Get information about species facts that correspond to all the combinations of parameters in the user parameter selection.
        /// In case data values exists in database values are provided otherwise values is set to defaults
        /// When user parameter selection is incomplete, i.e. some parameter lists is empty, the user parameter selection is complemented.
        /// This method is equivalent to SpeciesFactManager.GetSpeciesFacts(...) but adjusted for use in Dyntaxa Web Application.
        /// </summary>
        /// <param name="manager">The SpeciesFactManager.</param>
        /// <param name="userContext">
        /// Information about the user that makes this method call.
        /// </param>
        /// <param name="searchCriteria">Species fact search criteria.</param>
        /// <returns>Species facts that matches search criteria.</returns>
        public static SpeciesFactList GetDyntaxaSpeciesFacts(
            this ISpeciesFactManager manager,
            IUserContext userContext,
            ISpeciesFactSearchCriteria searchCriteria)
        {
            SpeciesFactList speciesFactList = manager.GetSpeciesFacts(userContext, searchCriteria);

            if (speciesFactList.IsNull())
            {
                speciesFactList = new SpeciesFactList();
            }

            if (searchCriteria.Factors.IsNotEmpty())
            {
                ExpandSpeciesFactListWithEmptySpeciesFacts(userContext, searchCriteria, speciesFactList);
            }

            return(speciesFactList);
        }
Пример #22
0
        /// <summary>
        /// Creates a instance of a Species Information Document
        /// object based on a list of species facts.
        /// </summary>
        /// <param name="userContext">User context.</param>
        /// <param name="speciesFacts">The species facts related to species information document factors and a single taxon</param>
        /// <param name="period">Period for red list information.</param>
        public SpeciesInformationDocument(IUserContext userContext,
                                          SpeciesFactList speciesFacts,
                                          IPeriod period)
        {
            _period       = period;
            _speciesFacts = speciesFacts;
            if (_speciesFacts.IsEmpty())
            {
                _taxon = null;
            }
            else
            {
                _taxon = _speciesFacts[0].Taxon;
            }

            LoadTaxonInformation(userContext);
            LoadRedListInformation(userContext);
            SetParagraphSpeciesFacts();
        }
        /// <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 CountyMapNoDataTest()
        {
            SpeciesFactList     facts = new SpeciesFactList();
            CountyOccurrenceMap countyOccurenceMap = new CountyOccurrenceMap(facts);
            string shapeFileName = Path.Combine(AbsoluteResourceFolderPath, "Sverigekarta med län.shp");

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

            string imagePath1 = Path.Combine(AbsoluteTempFolderPath, "testNoDataMapWithLegend.png");

            Console.WriteLine("Generating image: {0}", imagePath1);
            countyOccurenceMap.Save(imagePath1, System.Drawing.Imaging.ImageFormat.Png);

            countyOccurenceMap.Height = 200;
            string imagePath2 = Path.Combine(AbsoluteTempFolderPath, "testHeight200MapWithLegend.png");

            Console.WriteLine("Generating image: {0}", imagePath2);
            countyOccurenceMap.Save(imagePath2, System.Drawing.Imaging.ImageFormat.Png);
        }
        /// <summary>
        /// Cache taxon list information about specified taxa.
        /// </summary>
        /// <param name="taxa">The taxa.</param>
        private void LoadTaxonListInformation(TaxonList taxa)
        {
            // Init new taxon information items.
            var tempTaxonInformation = new Dictionary <Int32, TaxonListInformation>();

            foreach (ITaxon taxon in taxa)
            {
                var taxonListInformation = new TaxonListInformation
                {
                    CommonName       = taxon.CommonName,
                    Id               = taxon.Id,
                    CategoryId       = taxon.Category.Id,
                    ParentCategoryId = taxon.Category.ParentId,
                    ScientificName   = taxon.ScientificName
                };
                tempTaxonInformation[taxon.Id] = taxonListInformation;
            }

            // Add species fact information.
            SpeciesFactList speciesFacts = GetSpeciesFacts(taxa);

            if (speciesFacts.IsNotEmpty())
            {
                foreach (ISpeciesFact speciesFact in speciesFacts)
                {
                    tempTaxonInformation[speciesFact.Taxon.Id].SetSpeciesFact(speciesFact);
                }
            }

            // Add new taxon information items
            lock (CacheLock)
            {
                foreach (ITaxon taxon in taxa)
                {
                    if (!TaxonInformationCache.TaxonInformation.ContainsKey(taxon.Id))
                    {
                        TaxonInformationCache.TaxonInformation[taxon.Id] = tempTaxonInformation[taxon.Id];
                    }
                }
            }
        }
Пример #26
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);
                    }
                }
            }
        }
Пример #28
0
        private Bitmap getBitmap()
        {
            Bitmap bitmap;
            float  xScale = 1.0F * _bitmapWidth / _width;
            float  yScale = 1.0F * _bitmapHeight / _height;

            if (xScale < yScale)
            {
                _scale = xScale;
            }
            else
            {
                _scale = yScale;
            }

            //_shapeTransform = new TransformGroup();
            bitmap = new Bitmap(_bitmapWidth + _legendBoxWidth - _legendBoxOffsetX, _bitmapHeight + 2, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
            using (Graphics canvas = Graphics.FromImage(bitmap))
            {
                using (Pen pen = new Pen(Color.Black, 1))
                {
                    using (Brush backgroundBrush = new SolidBrush(_colorBackground))
                    {
                        String countyCode         = "";
                        int    countyOccurenceKey = 0;

                        canvas.FillRectangle(backgroundBrush, 0, 0, _bitmapWidth + _legendBoxWidth - _legendBoxOffsetX, _bitmapHeight + 2);

                        for (int recordIndex = 0; recordIndex < _shapeFile.Records.Count; recordIndex++)
                        {
                            try
                            {
                                ShapeFileRecord record = _shapeFile.Records[recordIndex];

                                if (_countyInformation.IsNotEmpty())
                                {
                                    countyCode = record.Attributes[2].ToString();
                                    int countyId = getCountyId(countyCode);
                                    if (countyId > 0)
                                    {
                                        ISpeciesFact    fact  = null;
                                        SpeciesFactList facts = null;
                                        if (_counties.Exists(countyId))
                                        {
                                            try
                                            {
                                                facts = _countyInformation.GetSpeciesFacts(_counties.Get(countyId));
                                                if (facts.IsNotEmpty())
                                                {
                                                    fact = facts[0];
                                                }
                                            }
                                            catch (Exception)
                                            {
                                                throw;
                                            }

                                            if (fact.IsNotNull())
                                            {
                                                countyOccurenceKey = fact.MainField.EnumValue.KeyInt.GetValueOrDefault(0);
                                            }
                                            else
                                            {
                                                countyOccurenceKey = 0;
                                            }
                                        }
                                        else
                                        {
                                            countyOccurenceKey = 0;
                                        }
                                    }
                                }
                                else
                                {
                                    countyOccurenceKey = -1;
                                }

                                for (int i = 0; i < record.NumberOfParts; i++)
                                {
                                    List <Point> points = new List <Point>();

                                    // Determine the starting index and the end index
                                    // into the points array that defines the figure.
                                    int start = record.Parts[i];
                                    int end;
                                    if (record.NumberOfParts > 1 && i != (record.NumberOfParts - 1))
                                    {
                                        end = record.Parts[i + 1];
                                    }
                                    else
                                    {
                                        end = record.NumberOfPoints;
                                    }


                                    for (int j = start; j < end; j++)
                                    {
                                        System.Windows.Point pt = record.Points[j];

                                        // Transform from lon/lat to canvas coordinates.
                                        //pt = this._shapeTransform.Transform(pt);

                                        Point point = new Point(_legendBoxWidth - _legendBoxOffsetX + (int)((pt.X - _xMin) * _scale), _bitmapHeight - (int)((pt.Y - _yMin) * _scale));
                                        points.Add(point);
                                    }

                                    using (Brush countyOccurrenceBrush = getBrush(countyOccurenceKey))
                                    {
                                        canvas.FillPolygon(countyOccurrenceBrush, points.ToArray());
                                    }

                                    canvas.DrawPolygon(pen, points.ToArray());
                                }
                            }
                            catch (Exception)
                            {
                                throw;
                            }
                        }

                        if (_countyInformation.IsEmpty())
                        {
                            using (Font font = new Font("Arial", 24 * _bitmapHeight / 708))
                            {
                                using (Brush brush = new SolidBrush(Color.Red))
                                {
                                    canvas.DrawString("Information saknas", font, brush, _legendBoxWidth, _bitmapHeight / 2);
                                }
                            }
                        }

                        if (UpdateInformation.IsNotEmpty())
                        {
                            canvas.DrawImage(GetUpdateInformationBox(),
                                             0,
                                             0);
                            canvas.DrawImage(getLegendBox(), 0, _updateInformationBoxHeight);
                        }
                        else
                        {
                            canvas.DrawImage(getLegendBox(), 0, 0);
                        }
                    }
                }
            }

            return(bitmap);
        }
        /// <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);
        }
 /// <summary>
 /// Checs whether or not SpeciesFacts exist.
 /// </summary>
 /// <param name="speciesFactList">
 /// SpeciesFact lists.
 /// </param>
 public bool HasSpeciesFacts(SpeciesFactList speciesFactList)
 {
     return(speciesFactList.IsNotEmpty());
 }