/// <summary> /// Create a SpeciesObservationSearchCriteria instance. /// </summary> public SpeciesObservationSearchCriteria() { Accuracy = Int32.MinValue; BirdNestActivityLevel = Int32.MinValue; Counties = new CountyList(); DatabaseIds = new List <Int32>(); HasAccuracy = false; HasBirdNestActivityLevel = false; HasBoundingBox = false; IncludeNeverFoundObservations = false; IncludeNotRediscoveredObservations = false; IncludePositiveObservations = true; IncludeUncertainTaxonDetermination = true; LocalitySearchString = null; MaxEastCoordinate = Int32.MinValue; MaxWestCoordinate = Int32.MinValue; MaxNorthCoordinate = Int32.MinValue; MaxSouthCoordinate = Int32.MinValue; Provinces = new ProvinceList(); TaxonIds = new List <Int32>(); if (UserManager.IsUserLoggedIn()) { UserRoleId = UserManager.GetUser().Roles[0].Id; } else { UserRoleId = Int32.MinValue; } ObservationEndDate = DateTime.MinValue; ObservationStartDate = DateTime.MinValue; ObserverSearchString = null; UseOfObservationDate = WebUseOfDate.NotSet; RegistrationEndDate = DateTime.MinValue; RegistrationStartDate = DateTime.MinValue; UseOfRegistrationDate = WebUseOfDate.NotSet; }
/// <summary> /// Get information about species observations /// that has changed in the specified date range. /// Scope is restricted to those observations /// that the user has access rights to. /// Max 1000000 observations of each change type (deleted, new /// or updated), with GUIDs or ids, can be retrieved in one call. /// Parameters changedFrom and changedTo may be the same date. /// Parameter changedTo must not be today or in the future. /// If parameter changedTo is yesterday the method call /// must be made after the nightly update of the /// species observations have been performed. /// Currently it is ok to call this method after 05:00 /// if yesterdays species observations should be retrieved. /// Only date part of parameters changedFrom and changedTo /// are used. It does not matter what time of day that is set /// in parameters changedFrom and changedTo. /// </summary> /// <param name="changedFrom">Start date for changes.</param> /// <param name="changedTo">End date for changes.</param> /// <returns>Information about changed species observations.</returns> public static SpeciesObservationChange GetSpeciesObservationChange(DateTime changedFrom, DateTime changedTo) { Int32 index, speciesObservationIdsIndex; List <Int64> speciesObservationIds; SpeciesObservationChange change; WebSpeciesObservationChange webChange; WebSpeciesObservationInformation webInformation; // Check arguments. CheckChangedDates(changedFrom, changedTo); // Get data from web service. webChange = WebServiceClient.GetSpeciesObservationChange(changedFrom, changedTo); change = new SpeciesObservationChange(); if (webChange.IsNotNull()) { // Handle deleted species observations. change.DeletedSpeciesObservationGuids = webChange.DeletedSpeciesObservationGuids; // Handle new species observations. change.NewSpeciesObservations = new SpeciesObservationList(); if (webChange.NewSpeciesObservations.IsEmpty() && webChange.NewSpeciesObservationIds.IsNotEmpty()) { // Get species observations in parts. speciesObservationIds = new List <Int64>(); index = 0; if (Configuration.Debug) { webChange.MaxSpeciesObservationCount = Math.Min(20000, webChange.MaxSpeciesObservationCount); } for (speciesObservationIdsIndex = 0; speciesObservationIdsIndex < webChange.NewSpeciesObservationIds.Count; speciesObservationIdsIndex++) { speciesObservationIds.Add(webChange.NewSpeciesObservationIds[speciesObservationIdsIndex]); if (++index == webChange.MaxSpeciesObservationCount) { // Get one part of species observations. webInformation = WebServiceClient.GetSpeciesObservationsById( speciesObservationIds, UserManager.GetUser().Roles[0].Id); foreach (WebSpeciesObservation webSpeciesObservation in webInformation.SpeciesObservations) { change.NewSpeciesObservations.Add(GetSpeciesObservation(webSpeciesObservation)); } if ((webChange.NewSpeciesObservationIds.Count - 1 - speciesObservationIdsIndex) < webChange.MaxSpeciesObservationCount) { speciesObservationIds = new List <Int64>(); } index = 0; speciesObservationIds.Clear(); } } if (speciesObservationIds.IsNotEmpty()) { webInformation = WebServiceClient.GetSpeciesObservationsById( speciesObservationIds, UserManager.GetUser().Roles[0].Id); foreach (WebSpeciesObservation webSpeciesObservation in webInformation.SpeciesObservations) { change.NewSpeciesObservations.Add(GetSpeciesObservation(webSpeciesObservation)); } } } else if (webChange.NewSpeciesObservations.IsNotEmpty()) { foreach (WebSpeciesObservation webSpeciesObservation in webChange.NewSpeciesObservations) { change.NewSpeciesObservations.Add(GetSpeciesObservation(webSpeciesObservation)); } } // Handle updated species observations. change.UpdatedSpeciesObservations = new SpeciesObservationList(); if (webChange.UpdatedSpeciesObservations.IsEmpty() && webChange.UpdatedSpeciesObservationIds.IsNotEmpty()) { // Get species observations in parts. speciesObservationIds = new List <Int64>(); index = 0; for (speciesObservationIdsIndex = 0; speciesObservationIdsIndex < webChange.UpdatedSpeciesObservationIds.Count; speciesObservationIdsIndex++) { speciesObservationIds.Add(webChange.UpdatedSpeciesObservationIds[speciesObservationIdsIndex]); if (++index == webChange.MaxSpeciesObservationCount) { // Get one part of species observations. webInformation = WebServiceClient.GetSpeciesObservationsById( speciesObservationIds, UserManager.GetUser().Roles[0].Id); foreach (WebSpeciesObservation webSpeciesObservation in webInformation.SpeciesObservations) { change.UpdatedSpeciesObservations.Add(GetSpeciesObservation(webSpeciesObservation)); } if ((webChange.UpdatedSpeciesObservationIds.Count - 1 - speciesObservationIdsIndex) < webChange.MaxSpeciesObservationCount) { speciesObservationIds = new List <Int64>(); } index = 0; speciesObservationIds.Clear(); } } if (speciesObservationIds.IsNotEmpty()) { webInformation = WebServiceClient.GetSpeciesObservationsById( speciesObservationIds, UserManager.GetUser().Roles[0].Id); foreach (WebSpeciesObservation webSpeciesObservation in webInformation.SpeciesObservations) { change.UpdatedSpeciesObservations.Add(GetSpeciesObservation(webSpeciesObservation)); } } } else if (webChange.UpdatedSpeciesObservations.IsNotEmpty()) { foreach (WebSpeciesObservation webSpeciesObservation in webChange.UpdatedSpeciesObservations) { change.UpdatedSpeciesObservations.Add(GetSpeciesObservation(webSpeciesObservation)); } } } return(change); }