/// <summary> /// Test if organism as substrate is specified in species fact. /// </summary> /// <param name="speciesFact">Species fact with substrate information.</param> /// <returns>True if organism as substrate is specified.</returns> public static bool IsOrganismAsSubstrateSpecified(this ISpeciesFact speciesFact) { return(speciesFact.IsNotNull() && speciesFact.HasHost && (speciesFact.Host.Id != (int)TaxonId.Life) && speciesFact.MainField.IsNotNull() && speciesFact.MainField.HasValue && (speciesFact.MainField.EnumValue.KeyInt >= (int)OrganismAsSubstrateImportanceEnum.HasImportance) && (speciesFact.MainField.EnumValue.KeyInt <= (int)OrganismAsSubstrateImportanceEnum.VeryImportant)); }
/// <summary> /// Init red list information. /// </summary> /// <param name="taxonSpeciesFact">Taxon species fact view model.</param> /// <param name="categorySpeciesFact">Red list category species fact.</param> /// <param name="criteriaSpeciesFact">Red list criteria species fact.</param> /// <param name="criteriaDocumentationSpeciesFact">Red list criteria documentation species fact.</param> /// <param name="globalCategorySpeciesFact">Global red list category species fact.</param> /// <param name="period">Red list period.</param> public static void InitRedListInformation( TaxonSpeciesFactViewModel taxonSpeciesFact, ISpeciesFact categorySpeciesFact, ISpeciesFact criteriaSpeciesFact, ISpeciesFact criteriaDocumentationSpeciesFact, ISpeciesFact globalCategorySpeciesFact, IPeriod period) { if (categorySpeciesFact.IsRedlistCategorySpecified()) { taxonSpeciesFact.RedListCategory = categorySpeciesFact.Field1.EnumValue.OriginalLabel.Substring(0, categorySpeciesFact.Field1.EnumValue.OriginalLabel.Length - 4) + "(" + categorySpeciesFact.MainField.StringValue + ")"; taxonSpeciesFact.IsRedListed = categorySpeciesFact.Field1.EnumValue.KeyInt >= (int)RedListCategory.DD && categorySpeciesFact.Field1.EnumValue.KeyInt < (int)RedListCategory.LC; taxonSpeciesFact.IsRedListCriteriaAvailable = (categorySpeciesFact.Field1.EnumValue.KeyInt >= (int)RedListCategory.CR) && (categorySpeciesFact.Field1.EnumValue.KeyInt <= (int)RedListCategory.VU); } if (taxonSpeciesFact.IsRedListCriteriaAvailable && criteriaSpeciesFact.IsRedlistCriteriaSpecified()) { taxonSpeciesFact.RedListCriteria = criteriaSpeciesFact.MainField.StringValue; } if (globalCategorySpeciesFact.IsGlobalRedlistCategorySpecified()) { taxonSpeciesFact.GlobalRedListCategory = globalCategorySpeciesFact.MainField.StringValue; } if (criteriaDocumentationSpeciesFact.IsRedlistDocumentationSpecified()) { taxonSpeciesFact.RedListDocumentationQuality = criteriaDocumentationSpeciesFact.Quality.Id; taxonSpeciesFact.RedListDocumentationText = criteriaDocumentationSpeciesFact.MainField.StringValue; } taxonSpeciesFact.Period = period.Year; }
/// <summary> /// Test if continuous decline is specified in species fact. /// </summary> /// <param name="speciesFact">Species fact with continuous decline information.</param> /// <param name="period">Redlisting period.</param> /// <returns>True if continuous decline is specified.</returns> public static bool IsContinuousDeclineSpecified(this ISpeciesFact speciesFact, IPeriod period) { return(speciesFact.IsNotNull() && speciesFact.MainField.IsNotNull() && speciesFact.MainField.HasValue && speciesFact.MainField.EnumValue.IsNotNull() && (speciesFact.MainField.EnumValue.KeyInt >= (int)ContinuousDeclineEnum.GoesOn) && (speciesFact.MainField.EnumValue.KeyInt <= (int)ContinuousDeclineEnum.DeclinesMoreThan25) && speciesFact.HasPeriod && speciesFact.Period.Year == period.Year); }
/// <summary> /// Test if redlist criteria is specified in species fact. /// </summary> /// <param name="speciesFact">Species fact with redlist criteria information.</param> /// <param name="period">Redlisting period.</param> /// <returns>True if redlist criteria is specified.</returns> public static bool IsSmallPopulationOrDistributionSpecified(this ISpeciesFact speciesFact, IPeriod period) { return(speciesFact.IsNotNull() && speciesFact.MainField.IsNotNull() && speciesFact.MainField.HasValue && (speciesFact.MainField.StringValue.Contains("B") || speciesFact.MainField.StringValue.Contains("C") || speciesFact.MainField.StringValue.Contains("D")) && speciesFact.HasPeriod && speciesFact.Period.Year == period.Year); }
/// <summary> /// Determines whether status identifier has changed. /// </summary> /// <param name="speciesFact">The species fact.</param> /// <returns>true if status id has changed; othwerwise null.</returns> public static bool HasStatusIdChanged(this ISpeciesFact speciesFact) { if (speciesFact == null) { return(false); } return(speciesFact.MainField.HasChanged); }
/// <summary> /// Create a SpeciesFactField instance. /// </summary> /// <param name="speciesFact">The SpeciesFact that this SpeciesFactField belongs to.</param> /// <param name="factorField">Factor field for the species fact field.</param> /// <param name="hasValue">Indication whether or not a value is initially specified.</param> /// <param name="value">The value of the species fact field.</param> public SpeciesFactField(ISpeciesFact speciesFact, IFactorField factorField, Boolean hasValue, Object value) { FactorField = factorField; Id = factorField.Id; SpeciesFact = speciesFact; this.Update(hasValue, value); }
/// <summary> /// Gets the description. /// </summary> /// <param name="speciesFact">The species fact.</param> /// <returns>Species fact description; othwerwise null.</returns> public static string GetDescription(this ISpeciesFact speciesFact) { string val = speciesFact == null || speciesFact.Field5 == null ? null : speciesFact.Field5.StringValue; if (val != null) { return(val); } return(string.Empty); }
/// <summary> /// Sets comment value for a species fact. /// </summary> /// <param name="speciesFact">The species fact.</param> /// <param name="comment">The comment.</param> public static void SetDescription(this ISpeciesFact speciesFact, string comment) { string currentComment = GetDescription(speciesFact); if (currentComment == comment) { return; } speciesFact.Field5.StringValue = comment; }
/// <summary> /// Get picture relations related to specified species fact. /// </summary> /// <param name="userContext"> /// Information about the user that makes this method call. /// </param> /// <param name="speciesFact">Species fact that may be related to pictures.</param> /// <returns>Picture relations related to specified species fact.</returns> public virtual PictureRelationList GetPictureRelations(IUserContext userContext, ISpeciesFact speciesFact) { IPictureRelationType pictureRelationType; pictureRelationType = GetPictureRelationType(userContext, PictureRelationTypeIdentifier.SpeciesFact); return(DataSource.GetPictureRelations(userContext, speciesFact.Identifier, pictureRelationType)); }
/// <summary> /// Update species facts in RAM memory /// with latest information from data source. /// This method works on species facts both with and without id. /// </summary> /// <param name="userContext"> /// Information about the user that makes this method call. /// </param> /// <param name="speciesFacts">Species facts to update.</param> public virtual void UpdateSpeciesFacts(IUserContext userContext, SpeciesFactList speciesFacts) { SpeciesFactList speciesFactsFromDataSource, updatedSpeciesFacts; // Get updated data from web service. speciesFactsFromDataSource = GetSpeciesFacts(userContext, speciesFacts); // Update species facts. updatedSpeciesFacts = new SpeciesFactList(); if (speciesFactsFromDataSource.IsNotEmpty()) { foreach (ISpeciesFact speciesFactFromDataSource in speciesFactsFromDataSource) { // Get species fact. ISpeciesFact speciesFact = speciesFacts.Get(speciesFactFromDataSource.Identifier); // Update species fact. speciesFact.Update(speciesFactFromDataSource.Id, speciesFactFromDataSource.Reference, speciesFactFromDataSource.ModifiedDate, speciesFactFromDataSource.ModifiedBy, speciesFactFromDataSource.HasField1, speciesFactFromDataSource.HasField1 ? speciesFactFromDataSource.Field1.GetDoubleValue() : 0, speciesFactFromDataSource.HasField2, speciesFactFromDataSource.HasField2 ? speciesFactFromDataSource.Field2.GetDoubleValue() : 0, speciesFactFromDataSource.HasField3, speciesFactFromDataSource.HasField3 ? speciesFactFromDataSource.Field3.GetDoubleValue() : 0, speciesFactFromDataSource.HasField4, speciesFactFromDataSource.HasField4 ? speciesFactFromDataSource.Field4.GetStringValue() : null, speciesFactFromDataSource.HasField5, speciesFactFromDataSource.HasField5 ? speciesFactFromDataSource.Field5.GetStringValue() : null, speciesFactFromDataSource.Quality); updatedSpeciesFacts.Add(speciesFact); } } // Update species facts that has been deleted. foreach (ISpeciesFact speciesFact in speciesFacts) { if (speciesFact.HasId && !updatedSpeciesFacts.Exists(speciesFact.Identifier)) { speciesFact.Reset(userContext); } } }
/// <summary> /// Gets the name of the quality. /// </summary> /// <param name="speciesFact">The species fact.</param> /// <returns>Species fact quality name; otherwise null.</returns> public static String GetQualityName(this ISpeciesFact speciesFact) { if (speciesFact == null) { return(null); } ISpeciesFactQuality val = speciesFact.Quality; if (val != null) { return(val.Name); } return(null); }
/// <summary> /// Gets the status identifier. /// </summary> /// <param name="speciesFact">The species fact.</param> /// <returns>Species fact status id; otherwise null.</returns> public static Int32?GetStatusId(this ISpeciesFact speciesFact) { if (speciesFact == null) { return(null); } FactorFieldEnumValue val = speciesFact.MainField.Value as FactorFieldEnumValue; if (val != null) { return(val.Id); } return(null); }
/// <summary> /// Gets the reference identifier. /// </summary> /// <param name="speciesFact">The species fact.</param> /// <returns>Species fact reference id; otherwise null</returns> public static Int32?GetReferenceId(this ISpeciesFact speciesFact) { if (speciesFact == null) { return(null); } IReference val = speciesFact.Reference; if (val != null) { return(val.Id); } return(null); }
/// <summary> /// Gets the status original label. /// </summary> /// <param name="speciesFact">The species fact.</param> /// <returns>Species fact status original label; otherwise null.</returns> public static String GetStatusOriginalLabel(this ISpeciesFact speciesFact) { if (speciesFact == null) { return(null); } FactorFieldEnumValue val = speciesFact.MainField.Value as FactorFieldEnumValue; if (val != null) { return(val.OriginalLabel); } return(null); }
/// <summary> /// Gets the name of the reference. /// </summary> /// <param name="speciesFact">The species fact.</param> /// <returns>Species fact reference name; otherwise null</returns> public static String GetReferenceName(this ISpeciesFact speciesFact) { if (speciesFact == null) { return(null); } IReference val = speciesFact.Reference; if (val != null) { return(val.Name); } return(null); }
/// <summary> /// Sets the status for a species fact. /// </summary> /// <param name="speciesFact">The species fact to change.</param> /// <param name="statusId">The new status Id.</param> public static void SetStatus(this ISpeciesFact speciesFact, int?statusId) { int?currentStatusId = GetStatusId(speciesFact); if (currentStatusId.HasValue && currentStatusId.Value == statusId) { return; } IFactorFieldEnumValue factorFieldEnumValue = speciesFact.MainField.FactorFieldEnum.Values.FirstOrDefault(enumValue => statusId == enumValue.Id); if (factorFieldEnumValue != null) { speciesFact.MainField.Value = factorFieldEnumValue; } }
/// <summary> /// Sets reference for a species fact. /// </summary> /// <param name="speciesFact">The species fact.</param> /// <param name="userContext">The user context.</param> /// <param name="referenceId">The reference id.</param> public static void SetReference(this ISpeciesFact speciesFact, IUserContext userContext, int?referenceId) { int?currentReferenceId = GetReferenceId(speciesFact); if (currentReferenceId.HasValue && currentReferenceId.Value == referenceId) { return; } if (!referenceId.HasValue) { speciesFact.Reference = null; return; } speciesFact.Reference = CoreData.ReferenceManager.GetReference(userContext, referenceId.Value); }
/// <summary> /// Set species fact information about this taxon regarding previously red listed facts. /// </summary> /// <param name="speciesFact">Species fact with red list information.</param> /// <param name="currentPeriod">Actual red list period.</param> public void SetSpeciesFact(ISpeciesFact speciesFact, IPeriod currentPeriod) { if (speciesFact.Factor.Id == (int)FactorId.RedlistCategory && speciesFact.Period.Id != currentPeriod.Id) { if (speciesFact.IsOldRedlistCategorySpecified()) { if (PreviousRedListCriteria.IsNull()) { PreviousRedListCriteria = new Dictionary <string, string>(); } var redListCategory = speciesFact.Field1.EnumValue.OriginalLabel.Substring(0, speciesFact.Field1.EnumValue.OriginalLabel.Length - 4) + "(" + speciesFact.MainField.StringValue + ")"; PreviousRedListCriteria.Add(speciesFact.Period.Name, redListCategory); } } }
/// <summary> /// Gets the quality identifier. /// </summary> /// <param name="speciesFact">The species fact.</param> /// <returns>Species fact quality identifier; otherwise null.</returns> public static Int32?GetQualityId(this ISpeciesFact speciesFact) { if (speciesFact == null) { return(null); } ISpeciesFactQuality val = speciesFact.Quality; if (val != null) { return(val.Id); } return(null); }
/// <summary> /// Sets quality for a species fact. /// </summary> /// <param name="speciesFact">The species fact.</param> /// <param name="userContext">The user context.</param> /// <param name="qualityId">The quality id.</param> public static void SetQuality(this ISpeciesFact speciesFact, IUserContext userContext, int?qualityId) { int?currentQualityId = GetQualityId(speciesFact); if (currentQualityId.HasValue && currentQualityId.Value == qualityId) { return; } if (!qualityId.HasValue) { speciesFact.Quality = null; return; } ISpeciesFactQuality speciesFactQuality = CoreData.SpeciesFactManager.GetSpeciesFactQuality(userContext, qualityId.Value); if (speciesFactQuality != null) { speciesFact.Quality = speciesFactQuality; } }
/// <summary> /// Set species fact information about this taxon. /// </summary> /// <param name="speciesFact">Species fact with red list information.</param> public void SetSpeciesFact(ISpeciesFact speciesFact) { if (LandscapeTypeManager.LandscapeTypeFactors.IsNotNull() && LandscapeTypeManager.LandscapeTypeFactors.Exists(speciesFact.Factor)) { if (speciesFact.IsLandscapeTypeOccurrenceSpecified()) { string landscapeTypeOccurrence = speciesFact.Factor.Label; landscapeTypeOccurrence = landscapeTypeOccurrence.Substring(landscapeTypeOccurrence.Length - 2, 1); switch (speciesFact.MainField.EnumValue.KeyInt) { case (int)LandscapeTypeImportanceEnum.HasImportance: LandscapeTypeOccurrence += landscapeTypeOccurrence.ToLower(); break; case (int)LandscapeTypeImportanceEnum.VeryImportant: LandscapeTypeOccurrence += landscapeTypeOccurrence.ToUpper(); break; } } } else { switch (speciesFact.Factor.Id) { case (int)FactorId.RedlistCategory: if (speciesFact.IsRedlistCategorySpecified()) { RedListCategory = speciesFact.Field1.EnumValue.OriginalLabel.Substring(0, speciesFact.Field1.EnumValue.OriginalLabel.Length - 4) + "(" + speciesFact.MainField.StringValue + ")"; var category = (RedListCategory)Enum.Parse(typeof(RedListCategory), RedListCategory.Substring(RedListCategory.IndexOf("(", StringComparison.Ordinal) + 1, 2)); IsRedListed = RedListedHelper.IsRedListedDdToNt((int)category); IsRedListedEnsured = RedListedHelper.IsRedListedDdToNe((int)category); RedListCategoryId = Convert.ToInt32(speciesFact.Field1.EnumValue.KeyInt); } break; case (int)FactorId.RedlistCriteriaString: if (speciesFact.IsRedlistCriteriaSpecified()) { RedListCriteria = speciesFact.MainField.StringValue; } break; case (int)FactorId.Redlist_OrganismLabel1: if (speciesFact.IsOrganismGroupSpecified()) { if (OrganismGroup.IsEmpty()) { OrganismGroup = speciesFact.MainField.EnumValue.OriginalLabel; } else { if (OrganismGroup != speciesFact.MainField.EnumValue.OriginalLabel) { OrganismGroup = speciesFact.MainField.EnumValue.OriginalLabel + ", " + OrganismGroup; } } } break; case (int)FactorId.SwedishOccurrence: if (speciesFact.IsSwedishOccurrenceSpecified()) { SwedishOccurrence = speciesFact.MainField.EnumValue.OriginalLabel; SwedishOccurrenceId = Convert.ToInt32(speciesFact.MainField.EnumValue.KeyInt); } break; } } }
/// <summary> /// Test if species information document threats is specified. /// </summary> /// <param name="speciesFact">Species fact with species information document threats information.</param> /// <returns>True if species information document threats is specified.</returns> public static bool IsSpeciesInformationDocumentThreatsSpecified(this ISpeciesFact speciesFact) { return(speciesFact.IsNotNull() && speciesFact.MainField.IsNotNull() && speciesFact.MainField.HasValue); }
/// <summary> /// Test if substrate is specified in species fact. /// </summary> /// <param name="speciesFact">Species fact with substrate information.</param> /// <returns>True if substrate is specified.</returns> public static bool IsSubstrateSpecified(this ISpeciesFact speciesFact) { return(speciesFact.IsNotNull() && speciesFact.MainField.IsNotNull() && speciesFact.MainField.HasValue && (speciesFact.MainField.EnumValue.KeyInt >= (int)SubstrateImportanceEnum.HasImportance) && (speciesFact.MainField.EnumValue.KeyInt <= (int)SubstrateImportanceEnum.VeryImportant)); }
/// <summary> /// Test if swedish occurence is specified in species fact. /// </summary> /// <param name="speciesFact">Species fact with swedish occurence information.</param> /// <returns>True if swedish occurrence is specified.</returns> public static bool IsSwedishOccurrenceSpecified(this ISpeciesFact speciesFact) { return(speciesFact.IsNotNull() && speciesFact.MainField.IsNotNull() && speciesFact.MainField.HasValue); }
/// <summary> /// Test if extreme fluctuations is specified in species fact. /// </summary> /// <param name="speciesFact">Species fact with extreme fluctuations information.</param> /// <param name="period">Redlisting period.</param> /// <returns>True if extreme fluctuations is specified.</returns> public static bool IsExtremeFluctuationsSpecified(this ISpeciesFact speciesFact, IPeriod period) { return(speciesFact.IsNotNull() && speciesFact.MainField.IsNotNull() && speciesFact.MainField.HasValue && speciesFact.MainField.EnumValue.KeyInt >= (int)ExtremeFluctuationsEnum.CanOccur && speciesFact.HasPeriod && speciesFact.Period.Year == period.Year); }
/// <summary> /// Test if swedish occurence is specified in species fact. /// </summary> /// <param name="speciesFact">Species fact with swedish occurence information.</param> /// <returns>True if swedish occurence is specified.</returns> public static bool IsOldRedlistCategorySpecified(this ISpeciesFact speciesFact) { return(speciesFact.IsNotNull() && speciesFact.Field1.IsNotNull() && speciesFact.Field1.HasValue && RedListedHelper.IsRedListedDdToNe(speciesFact.Field1.EnumValue.KeyInt) && speciesFact.MainField.IsNotNull() && speciesFact.MainField.HasValue); }
/// <summary> /// Test if impact is specified in species fact. /// </summary> /// <param name="speciesFact">Species fact with impact information.</param> /// <returns>True if impact is specified.</returns> public static bool IsImpactSpecified(this ISpeciesFact speciesFact) { return(speciesFact.IsNotNull() && speciesFact.MainField.IsNotNull() && speciesFact.MainField.HasValue); }
public static bool IsGlobalRedlistCategorySpecified(this ISpeciesFact speciesFact) { return(speciesFact.IsNotNull() && speciesFact.MainField.IsNotNull() && speciesFact.MainField.HasValue); }
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> /// Test if county occurrence is specified in species fact. /// </summary> /// <param name="speciesFact">Species fact with county occurrence information.</param> /// <returns>True if county occurrence is specified.</returns> public static bool IsCountyOccurrenceSpecified(this ISpeciesFact speciesFact) { return(speciesFact.IsNotNull() && speciesFact.Field1.IsNotNull() && speciesFact.Field1.HasValue); }