Esempio n. 1
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;
            }
        }
        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);
        }
        ///// <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());
        }
Esempio n. 4
0
        public void GetFactorsBySearchCriteria()
        {
            List <int> factorIds = new List <int> {
                1, 2, 3
            };
            IFactorSearchCriteria searchCriteria = new FactorSearchCriteria();
            FactorList            factors;

            searchCriteria.RestrictSearchToFactorIds = factorIds;
            searchCriteria.NameSearchString          = null;
            factors = GetFactorDataSource().GetFactors(GetUserContext(), searchCriteria);
            Assert.IsNotNull(factors);
            Assert.AreEqual(factorIds.Count, factors.Count);

            searchCriteria.RestrictReturnToScope = FactorSearchScope.AllChildFactors;
            factors = GetFactorDataSource().GetFactors(GetUserContext(), searchCriteria);
            Assert.IsNotNull(factors);
            Assert.IsTrue(factors.Count > 30);
        }
Esempio n. 5
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);
        }