public void Ping() { using (WebServiceDataServer database = new SpeciesObservationHarvestServer()) { Assert.IsTrue(database.Ping()); } }
public void Constructor() { using (WebServiceDataServer database = new SpeciesObservationHarvestServer()) { Assert.IsNotNull(database); } }
public void BeginTransaction() { using (DataServer database = new SpeciesObservationHarvestServer()) { database.BeginTransaction(); } }
public void GetSpeciesObservationChangesElasticsearch() { Int64 changeId = 77653355; using (SpeciesObservationHarvestServer database = new SpeciesObservationHarvestServer()) { using (DataReader reader = database.GetSpeciesObservationChangesElasticsearch(changeId, 1000, null)) { // Get DarwinCore information. Assert.IsTrue(reader.Read()); while (reader.Read()) { } // Get project parameters. Assert.IsTrue(reader.NextResultSet()); Assert.IsTrue(reader.Read()); while (reader.Read()) { } // Get deleted species observations. Assert.IsTrue(reader.NextResultSet()); Assert.IsFalse(reader.Read()); while (reader.Read()) { } // Get max change id. Assert.IsTrue(reader.NextResultSet()); Assert.IsTrue(reader.Read()); } } }
public void CommitTransactionNoTransactionError() { using (DataServer database = new SpeciesObservationHarvestServer()) { database.CommitTransaction(); } }
public void AddSpeciesObservationChangeForElasticSearchClientSide() { using (var database = new SpeciesObservationHarvestServer()) { Assert.IsNotNull(database);//? database.AddSpeciesObservationChangeForElasticSearch(100000, false); } }
public void DeleteUnnecessaryChanges() { using (SpeciesObservationHarvestServer database = new SpeciesObservationHarvestServer()) { Assert.IsNotNull(database); database.DeleteUnnecessaryChanges(); } }
public void EmptyTempElasticsearchTables() { using (SpeciesObservationHarvestServer database = new SpeciesObservationHarvestServer()) { Assert.IsNotNull(database); database.EmptyTempElasticsearchTables(); } }
public void HasPendingTransaction() { using (DataServer database = new SpeciesObservationHarvestServer()) { Assert.IsFalse(database.HasPendingTransaction()); database.BeginTransaction(); Assert.IsTrue(database.HasPendingTransaction()); } }
public void GetSpeciesObservationElasticsearch() { using (SpeciesObservationHarvestServer database = new SpeciesObservationHarvestServer()) { using (DataReader dataReader = database.GetSpeciesObservationElasticsearch()) { Assert.IsTrue(dataReader.Read()); } } }
public void Dispose() { using (DataServer database = new SpeciesObservationHarvestServer()) { database.Dispose(); // Should be ok to dispose an already disposed database. database.Dispose(); } }
/// <summary> /// Get status for database. /// </summary> /// <param name="status"> /// The status. /// </param> private void GetDatabaseStatus(Dictionary <Int32, List <WebResourceStatus> > status) { Boolean ping; String address, informationEnglish, informationSwedish; WebResourceStatus resourceStatus; address = null; try { address = HarvestBaseServer.GetAddress(); informationEnglish = null; informationSwedish = null; using (SpeciesObservationHarvestServer database = new SpeciesObservationHarvestServer()) { ping = database.Ping(); } if (!ping) { informationEnglish = WebService.Settings.Default.DatabaseStatusErrorEnglish; informationSwedish = WebService.Settings.Default.DatabaseStatusErrorSwedish; } } catch (Exception exception) { ping = false; informationEnglish = WebService.Settings.Default.DatabaseCommunicationFailureEnglish + " " + WebService.Settings.Default.ErrorMessageEnglish + " = " + exception.Message; informationSwedish = WebService.Settings.Default.DatabaseCommunicationFailureSwedish + " " + WebService.Settings.Default.ErrorMessageSwedish + " = " + exception.Message; } resourceStatus = new WebResourceStatus(); resourceStatus.AccessType = WebService.Settings.Default.ResourceAccessTypeReadAndWriteSwedish; resourceStatus.Address = address; resourceStatus.Information = informationSwedish; resourceStatus.Name = DatabaseName.SwedishSpeciesObservation.ToString(); resourceStatus.ResourceType = WebServiceBase.GetResourceType(ResourceTypeIdentifier.Database, (Int32)(LocaleId.sv_SE)); resourceStatus.Status = ping; resourceStatus.Time = DateTime.Now; status[(Int32)(LocaleId.sv_SE)].Add(resourceStatus); resourceStatus = new WebResourceStatus(); resourceStatus.AccessType = WebService.Settings.Default.ResourceAccessTypeReadAndWriteEnglish; resourceStatus.Address = address; resourceStatus.Information = informationEnglish; resourceStatus.Name = DatabaseName.SwedishSpeciesObservation.ToString(); resourceStatus.ResourceType = WebServiceBase.GetResourceType(ResourceTypeIdentifier.Database, (Int32)(LocaleId.en_GB)); resourceStatus.Status = ping; resourceStatus.Time = DateTime.Now; status[(Int32)(LocaleId.en_GB)].Add(resourceStatus); }
public void GetNextChangeId() { Int64 currentChangeId, nextChangeId; using (SpeciesObservationHarvestServer database = new SpeciesObservationHarvestServer()) { currentChangeId = 42; nextChangeId = database.GetNextChangeId(currentChangeId, null); Assert.IsTrue(currentChangeId < nextChangeId); } }
public void GetCountyFromCoordinates() { double coordinateX, coordinateY; String county; coordinateX = 1986116; coordinateY = 8146315; using (SpeciesObservationHarvestServer database = new SpeciesObservationHarvestServer()) { county = database.GetCountyFromCoordinates(coordinateX, coordinateY); Assert.IsTrue(county.IsNotEmpty()); } }
public void GetParishFromCoordinates() { double coordinateX, coordinateY; String parish; coordinateX = 1986116; coordinateY = 8146315; using (SpeciesObservationHarvestServer database = new SpeciesObservationHarvestServer()) { parish = database.GetParishFromCoordinates(coordinateX, coordinateY); Assert.IsTrue(parish.IsNotEmpty()); } }
public void GetStateProvinceFromCoordinates() { double coordinateX, coordinateY; String stateProvince; coordinateX = 1986116; coordinateY = 8146315; using (SpeciesObservationHarvestServer database = new SpeciesObservationHarvestServer()) { stateProvince = database.GetStateProvinceFromCoordinates(coordinateX, coordinateY); Assert.IsTrue(stateProvince.IsNotEmpty()); } }
public void GetLogUpdateErrorLog_ExpectsMaxTenRows() { using (SpeciesObservationHarvestServer database = new SpeciesObservationHarvestServer()) { using (DataReader reader = database.GetLogUpdateError(10)) { while (reader.Read()) { Debug.WriteLine(reader.GetDateTime(14) + " - " + reader.GetString(0) + " - " + reader.GetInt32(10) + " - " + reader.GetString(12)); } } } }
public void GetLogStatisticsLog_ExpectsMaxTenRows() { using (SpeciesObservationHarvestServer database = new SpeciesObservationHarvestServer()) { using (DataReader reader = database.GetLogStatistics(10)) { while (reader.Read()) { Debug.WriteLine(reader.GetDateTime(0) + " - " + reader.GetString(1) + " - " + reader.GetString(3)); } } } }
public void GetLatestLog() { using (SpeciesObservationHarvestServer database = new SpeciesObservationHarvestServer()) { using (DataReader reader = database.GetLatestLog()) { while (reader.Read()) { Debug.WriteLine(reader.GetDateTime(0) + " - " + reader.GetString(1)); } } } }
public void LoadData() { TaxonInformation taxonInformation; using (SpeciesObservationHarvestServer database = new SpeciesObservationHarvestServer()) { using (DataReader dataReader = database.GetTaxon()) { Assert.IsTrue(dataReader.Read()); taxonInformation = new TaxonInformation(); taxonInformation.LoadData(dataReader); Assert.IsNotNull(taxonInformation); } } }
public void GetWeekOfYear() { for (int i = 0; i < 10000; i++) { var date = new DateTime(2000, 1, 1).AddDays(i); using (SpeciesObservationHarvestServer database = new SpeciesObservationHarvestServer()) { using (var reader = database.GetWeekOfYear(date)) { if (reader.Read()) { var weeknumber = reader.GetInt32(0); var otherWeekNumber = CultureInfo.CurrentCulture.Calendar.GetWeekOfYear(date, CalendarWeekRule.FirstDay, DayOfWeek.Sunday); Debug.WriteLine(string.Format("{0} - {1} SQL {2} code {3}", date, date.DayOfWeek, weeknumber, otherWeekNumber)); Assert.IsTrue(weeknumber == otherWeekNumber); } } } } }
public void GetSpeciesObservationDatabase() { SpeciesObservationHarvestServer dataServer = GetContext().GetSpeciesObservationDatabase(); Assert.IsNotNull(dataServer); }
public void GetSpeciesObservationSynchronization() { var sightingIds = GetContext().GetSpeciesObservationDatabase().GetAllSourceSpeciesObservationIdsForInsert((int)SpeciesObservationDataProviderId.SpeciesGateway); var totalCount = sightingIds.Count; var pageSize = 10000; var pageCount = totalCount / pageSize + 1; var stopwatchM = Stopwatch.StartNew(); long stopwatchPrev = 0; var context = GetContext(); var connector = new ArtportalenConnector(); var webDarwinCoreFieldDescriptions = WebServiceData.MetadataManager.GetSpeciesObservationFieldDescriptionsExtended(context, true); context.GetSpeciesObservationDatabase().LogHarvestMove(context, "Harvest DB - OPERATIONS", 0, "webDarwinCoreFieldDescriptions."); // Get provider information var dataProvider = connector.GetSpeciesObservationDataProvider(context); context.GetSpeciesObservationDatabase().LogHarvestMove(context, "Harvest DB - OPERATIONS", 0, "GetSpeciesObservationDataProvider."); var providerName = dataProvider.Name; var dataProviderId = dataProvider.Id; var mappings = HarvestManager.CreateMappingList(webDarwinCoreFieldDescriptions, dataProviderId); //if (context.ClientToken.UserName != ApplicationIdentifier.SpeciesObservationHarvestService.ToString()) //{ // WebServiceData.AuthorizationManager.CheckAuthorization(context, AuthorityIdentifier.WebServiceAdministrator); //} for (var currentPage = 0; currentPage < pageCount; currentPage++) { var start = currentPage * pageSize + (currentPage == 0 ? 0 : 1); if ((start + pageSize) > totalCount) { pageSize = totalCount - start; } //Har byggt hela skördningen här och lämnat HarvestManager orörd!! try { // Make sure the temp tables in db are empty context.GetSpeciesObservationDatabase().EmptyTempTables(); context.GetSpeciesObservationDatabase().LogHarvestMove(context, "Harvest DB - OPERATIONS", 0, "Empty Temp tables before reading."); // Ready with provider information context.GetSpeciesObservationDatabase().Log(context, providerName, LogType.Information, string.Format("Start {0}, start:{1} pageSize:{2}", providerName, start, pageSize), String.Empty); connector.GetSpeciesObservationChange(sightingIds.GetRange(start, pageSize), mappings, context, new ConnectorServer()); //Add the deleted observations in the last loop if ((currentPage + 1) == pageCount) { context.GetSpeciesObservationDatabase().AddTempDeleteSpeciesObservation(dataProviderId); context.GetSpeciesObservationDatabase().LogHarvestMove(context, "Harvest SP - DELETE", stopwatchM.ElapsedMilliseconds, " AddTempDeleteSpeciesObservation: " + (stopwatchM.ElapsedMilliseconds - stopwatchPrev)); } // Log latest changed date (at data source), of modified information of harvested observations context.GetSpeciesObservationDatabase().SetDataProviderLatestChangedDate(dataProvider.Id); context.GetSpeciesObservationDatabase().UpdateTempObservationId(); context.GetSpeciesObservationDatabase().LogHarvestMove(context, "Harvest SP - Check", stopwatchM.ElapsedMilliseconds, " UpdateTempObservationId: " + (stopwatchM.ElapsedMilliseconds - stopwatchPrev)); stopwatchPrev = stopwatchM.ElapsedMilliseconds; context.GetSpeciesObservationDatabase().CheckTaxonIdOnTemp(); context.GetSpeciesObservationDatabase().LogHarvestMove(context, "Harvest SP - Check", stopwatchM.ElapsedMilliseconds, " CheckTaxonIdOnTemp: " + (stopwatchM.ElapsedMilliseconds - stopwatchPrev)); stopwatchPrev = stopwatchM.ElapsedMilliseconds; context.GetSpeciesObservationDatabase().CreatePointGoogleMercatorInTemp(); context.GetSpeciesObservationDatabase().LogHarvestMove(context, "Harvest SP - Calculate", stopwatchM.ElapsedMilliseconds, " CreatePointGoogleMercatorInTemp: " + (stopwatchM.ElapsedMilliseconds - stopwatchPrev)); stopwatchPrev = stopwatchM.ElapsedMilliseconds; context.GetSpeciesObservationDatabase().UpdateAccuracyAndDisturbanceRadius(); context.GetSpeciesObservationDatabase().LogHarvestMove(context, "Harvest SP - Calculate", stopwatchM.ElapsedMilliseconds, " UpdateAccuracyAndDisturbanceRadius: " + (stopwatchM.ElapsedMilliseconds - stopwatchPrev)); stopwatchPrev = stopwatchM.ElapsedMilliseconds; context.GetSpeciesObservationDatabase().MergeTempUpdateToPosition(); context.GetSpeciesObservationDatabase().LogHarvestMove(context, "Harvest SP - POSITION", stopwatchM.ElapsedMilliseconds, " MergeTempUpdateToPosition: " + (stopwatchM.ElapsedMilliseconds - stopwatchPrev)); stopwatchPrev = stopwatchM.ElapsedMilliseconds; context.GetSpeciesObservationDatabase().UpdateSpeciesObservationChange(); context.GetSpeciesObservationDatabase().LogHarvestMove(context, "Harvest SP - CREATE & UPDATE", stopwatchM.ElapsedMilliseconds, " UpdateSpeciesObservationChange: " + (stopwatchM.ElapsedMilliseconds - stopwatchPrev)); stopwatchPrev = stopwatchM.ElapsedMilliseconds; context.GetSpeciesObservationDatabase().MergeTempUpdateToDarwinCoreObservation(); context.GetSpeciesObservationDatabase().LogHarvestMove(context, "Harvest SP - CREATE & UPDATE", stopwatchM.ElapsedMilliseconds, " MergeTempUpdateToDarwinCoreObservation: " + (stopwatchM.ElapsedMilliseconds - stopwatchPrev)); stopwatchPrev = stopwatchM.ElapsedMilliseconds; context.GetSpeciesObservationDatabase().MergeTempUpdateToSpeciesObservationField(); context.GetSpeciesObservationDatabase().LogHarvestMove(context, "Harvest SP - CREATE & UPDATE", stopwatchM.ElapsedMilliseconds, " MergeTempUpdateToSpeciesObservationField: " + (stopwatchM.ElapsedMilliseconds - stopwatchPrev)); stopwatchPrev = stopwatchM.ElapsedMilliseconds; context.GetSpeciesObservationDatabase().CopyDeleteToSpeciesObservation(); context.GetSpeciesObservationDatabase().LogHarvestMove(context, "Harvest SP - DELETE", stopwatchM.ElapsedMilliseconds, " CopyDeleteToSpeciesObservation: " + (stopwatchM.ElapsedMilliseconds - stopwatchPrev)); stopwatchPrev = stopwatchM.ElapsedMilliseconds; context.GetSpeciesObservationDatabase().UpdateStatistics(); context.GetSpeciesObservationDatabase().LogHarvestMove(context, "Harvest DB - OPERATIONS", stopwatchM.ElapsedMilliseconds, " UpdateStatistics:" + (stopwatchM.ElapsedMilliseconds - stopwatchPrev)); stopwatchPrev = stopwatchM.ElapsedMilliseconds; context.GetSpeciesObservationDatabase().EmptyTempTables(); context.GetSpeciesObservationDatabase().LogHarvestMove(context, "Harvest DB - OPERATIONS", stopwatchM.ElapsedMilliseconds, " EmptyTempTables: " + (stopwatchM.ElapsedMilliseconds - stopwatchPrev)); stopwatchPrev = stopwatchM.ElapsedMilliseconds; context.GetSpeciesObservationDatabase().CleanLogUpdateError(); context.GetSpeciesObservationDatabase().LogHarvestMove(context, "Harvest DB - OPERATIONS", stopwatchM.ElapsedMilliseconds, " CleanLogUpdateError: " + (stopwatchM.ElapsedMilliseconds - stopwatchPrev)); stopwatchPrev = stopwatchM.ElapsedMilliseconds; context.GetSpeciesObservationDatabase().CleanLogUpdateErrorDuplicates(); context.GetSpeciesObservationDatabase().LogHarvestMove(context, "Harvest DB - OPERATIONS", stopwatchM.ElapsedMilliseconds, " CleanLogUpdateErrorDuplicates: " + (stopwatchM.ElapsedMilliseconds - stopwatchPrev)); stopwatchPrev = stopwatchM.ElapsedMilliseconds; //if (SpeciesObservationConfiguration.IsElasticsearchUsed) //{ // HarvestManager.UpdateSpeciesObservationsElasticsearchCurrentIndex(context); // context.GetSpeciesObservationDatabase().LogHarvestMove(context, "Harvest DB - OPERATIONS", stopwatchM.ElapsedMilliseconds, " UpdateSpeciesObservationsElasticsearchCurrentIndex: " + (stopwatchM.ElapsedMilliseconds - stopwatchPrev)); //} stopwatchM.Stop(); } catch (Exception exception) { WebServiceData.LogManager.LogError(context, exception); } finally { try { // Clean up. using (SpeciesObservationHarvestServer database = (SpeciesObservationHarvestServer)(WebServiceData.DatabaseManager.GetDatabase(context))) { database.EmptyTempTables(); } } catch (Exception) { } } } context.GetSpeciesObservationDatabase().CleanLogUpdateError(); context.GetSpeciesObservationDatabase().LogHarvestMove(context, "Harvest DB - OPERATIONS", stopwatchM.ElapsedMilliseconds, " CleanLogUpdateError: " + (stopwatchM.ElapsedMilliseconds - stopwatchPrev)); stopwatchPrev = stopwatchM.ElapsedMilliseconds; context.GetSpeciesObservationDatabase().CleanLogUpdateErrorDuplicates(); context.GetSpeciesObservationDatabase().LogHarvestMove(context, "Harvest DB - OPERATIONS", stopwatchM.ElapsedMilliseconds, " CleanLogUpdateErrorDuplicates: " + (stopwatchM.ElapsedMilliseconds - stopwatchPrev)); }