///// <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());
        }
예제 #2
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();
        }
예제 #3
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);
        }