diff --git a/FarmmapsApiSamples.sln b/FarmmapsApiSamples.sln index 8f35ae1..1183f84 100644 --- a/FarmmapsApiSamples.sln +++ b/FarmmapsApiSamples.sln @@ -29,8 +29,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FarmmapsBulkSatDownload", " EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Secrets", "Secrets\Secrets.csproj", "{C4EE5ECA-253A-4B71-9F67-D231AC4517D6}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FarmmapsCleanUp", "FarmmapsCleanUp\FarmmapsCleanUp.csproj", "{5E4387F9-5953-4A9B-BCA5-DF3964EED3CB}" -EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FarmmapsKPI", "FarmmapsKPI\FarmmapsKPI.csproj", "{14575235-9867-4CE5-A22F-3F9FE002FF42}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FarmmapsDownloadCL", "FarmmapsDownloadCL\FarmmapsDownloadCL.csproj", "{63E69101-D804-4DBC-B2E4-A33771CD5C5F}" @@ -123,14 +121,6 @@ Global {C4EE5ECA-253A-4B71-9F67-D231AC4517D6}.Release|Any CPU.Build.0 = Release|Any CPU {C4EE5ECA-253A-4B71-9F67-D231AC4517D6}.Release|x64.ActiveCfg = Release|x64 {C4EE5ECA-253A-4B71-9F67-D231AC4517D6}.Release|x64.Build.0 = Release|x64 - {5E4387F9-5953-4A9B-BCA5-DF3964EED3CB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {5E4387F9-5953-4A9B-BCA5-DF3964EED3CB}.Debug|Any CPU.Build.0 = Debug|Any CPU - {5E4387F9-5953-4A9B-BCA5-DF3964EED3CB}.Debug|x64.ActiveCfg = Debug|Any CPU - {5E4387F9-5953-4A9B-BCA5-DF3964EED3CB}.Debug|x64.Build.0 = Debug|Any CPU - {5E4387F9-5953-4A9B-BCA5-DF3964EED3CB}.Release|Any CPU.ActiveCfg = Release|Any CPU - {5E4387F9-5953-4A9B-BCA5-DF3964EED3CB}.Release|Any CPU.Build.0 = Release|Any CPU - {5E4387F9-5953-4A9B-BCA5-DF3964EED3CB}.Release|x64.ActiveCfg = Release|Any CPU - {5E4387F9-5953-4A9B-BCA5-DF3964EED3CB}.Release|x64.Build.0 = Release|Any CPU {14575235-9867-4CE5-A22F-3F9FE002FF42}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {14575235-9867-4CE5-A22F-3F9FE002FF42}.Debug|Any CPU.Build.0 = Debug|Any CPU {14575235-9867-4CE5-A22F-3F9FE002FF42}.Debug|x64.ActiveCfg = Debug|x64 diff --git a/FarmmapsCleanUp/CleanUpApplication.cs b/FarmmapsCleanUp/CleanUpApplication.cs deleted file mode 100644 index ab95e24..0000000 --- a/FarmmapsCleanUp/CleanUpApplication.cs +++ /dev/null @@ -1,143 +0,0 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.IO.Compression; -using System.Linq; -using System.Threading.Tasks; -using FarmmapsApi; -using FarmmapsApi.Models; -using FarmmapsApi.Services; -using FarmmapsBulkSatDownload.Models; -using Microsoft.Extensions.Logging; -using Newtonsoft.Json; -using Npgsql; -using Newtonsoft.Json.Linq; -using static FarmmapsApiSamples.Constants; - -namespace FarmmapsCleanup -{ - public class CleanupApplication : IApplication - { - private readonly ILogger _logger; - private readonly FarmmapsApiService _farmmapsApiService; - private readonly CleanupService _cleanupService; - private readonly GeneralService _generalService; - - public CleanupApplication(ILogger logger, FarmmapsApiService farmmapsApiService, - GeneralService generalService, CleanupService cleanupService) - { - _logger = logger; - _farmmapsApiService = farmmapsApiService; - _generalService = generalService; - _cleanupService = cleanupService; - } - - public async Task RunAsync() - { - // !! this call is needed the first time an api is called with a fresh clientid and secret !! - await _farmmapsApiService.GetCurrentUserCodeAsync(); - var roots = await _farmmapsApiService.GetCurrentUserRootsAsync(); - - //Establish a database connection. Expecting you are using same database server as in project FarmmapsBulkSatDownload - DB dbparcels = JsonConvert.DeserializeObject(File.ReadAllText("DBsettings.secrets.json")); - string schemaname = "bigdata"; - string parceltablename = "parcel_bollenrevolutie_tulips2020"; //"parcelsijbrandij" "parcel"; "parcel_flowerbulbs"; "parcel_disac"; ""parcel_bollenrevolutie_tulips2020"" - - //Query to get lists of items to delete from FarmmapsDatabase and from parceltablename - string cropfielditemcode; - string satellitetaskcode; - List cropfieldItemCodes = new List(); - List satellitetaskCodes = new List(); - string connectionString = dbparcels.GetConnectionString(); - string readSql = string.Format( -@" -SELECT pt.cropfielditemcode, pt.satellitetaskcode -FROM {0}.{1} pt -WHERE - pt.arbid IN(1,2) -ORDER BY pt.arbid -;", schemaname, parceltablename); - - string updateCropfieldItemCodesSql = string.Format( -@" -UPDATE {0}.{1} - SET cropfielditemcode=NULL - WHERE arbid IN(1,2) -;", schemaname, parceltablename); //Same WHERE AS above - string updateSatellitetaskCodesSql = string.Format( -@" -UPDATE {0}.{1} - SET satellitetaskcode=NULL - WHERE arbid IN(1,2) -;", schemaname, parceltablename); //Same WHERE AS above - - using (NpgsqlConnection connection = new NpgsqlConnection(connectionString)) - { - connection.Open(); - - // Read data (run query) = build a list of fields for which to download images - NpgsqlCommand command = connection.CreateCommand(); - command.CommandText = readSql; - NpgsqlDataReader dr = command.ExecuteReader(); - while (dr.Read()) - { - cropfielditemcode = dr.GetString(0); - satellitetaskcode = dr.GetString(1); - if(!string.IsNullOrEmpty(cropfielditemcode)) - cropfieldItemCodes.Add(cropfielditemcode); - if (!string.IsNullOrEmpty(satellitetaskcode)) - satellitetaskCodes.Add(satellitetaskcode); - } - connection.Close(); - } - _logger.LogWarning($"// FarmmapsCleanUp: WARNING: you are about to delete {cropfieldItemCodes.Count} cropfieldItemCodes and {satellitetaskCodes.Count} satellitetaskCodes from the FarmMaps database and your own table {schemaname}.{parceltablename}"); - _logger.LogInformation($"// Nice of you to clean up after the work is done. You would typically do this for cropfieldItemCodes used only once."); - _logger.LogInformation($"// You do NOT want to do this if you think you may later on still want to use these items."); - _logger.LogInformation($"// Please carefully check the SQL queries 'readSql' 'updateSql' in CleanUpApplication.cs before proceeding."); - - _logger.LogInformation($"// FarmmapsCleanUp: delete selected cropfieldItemCodes from FarmMaps database and table {schemaname}.{parceltablename}? 0 = no, 1 = yes"); - int i; - i = Int32.Parse(Console.ReadLine()); - if (i == 1) - { - await _farmmapsApiService.DeleteItemsAsync(cropfieldItemCodes); - //TODO _farmmapsApiService.DeleteItemsAsync throws an error: {StatusCode: 415, ReasonPhrase: 'Unsupported Media Type', Version: 1.1, Content: System.Net.Http.HttpConnectionResponseContent, Headers: {...}} - //what is wrong with cropfieldItemCodes? - //and shouldn't we be telling _farmmapsApiService.DeleteItemsAsync what item type to delete? - using (NpgsqlConnection connection = new NpgsqlConnection(connectionString)) - { - connection.Open(); - NpgsqlCommand updateCmd = connection.CreateCommand(); - updateCmd.CommandText = updateCropfieldItemCodesSql; - int r = updateCmd.ExecuteNonQuery(); - if (r == -1) - throw new Exception("// FarmmapsCleanUp: Update cropfielditemcode Failed"); - connection.Close(); - } - } - _logger.LogInformation($"// FarmmapsCleanUp: delete selected satellitetaskCodes from FarmMaps database and table {schemaname}.{parceltablename}? 0 = no, 1 = yes"); - i = Int32.Parse(Console.ReadLine()); - if (i == 1) - { - await _farmmapsApiService.DeleteItemsAsync(satellitetaskCodes); - //TODO _farmmapsApiService.DeleteItemsAsync throws an error: {StatusCode: 415, ReasonPhrase: 'Unsupported Media Type', Version: 1.1, Content: System.Net.Http.HttpConnectionResponseContent, Headers: {...}} - //what is wrong with satellitetaskCodes? - //and shouldn't we be telling _farmmapsApiService.DeleteItemsAsync what item type to delete? - using (NpgsqlConnection connection = new NpgsqlConnection(connectionString)) - { - connection.Open(); - NpgsqlCommand updateCmd = connection.CreateCommand(); - updateCmd.CommandText = updateSatellitetaskCodesSql; - int r = updateCmd.ExecuteNonQuery(); - if (r == -1) - throw new Exception("// FarmmapsCleanUp: Update cropfielditemcode Failed"); - connection.Close(); - } - } - _logger.LogInformation($"// FarmmapsCleanUp: done! Hit any key to exit ..."); - Console.ReadKey(); - - - } - } -} diff --git a/FarmmapsCleanUp/CleanUpService.cs b/FarmmapsCleanUp/CleanUpService.cs deleted file mode 100644 index b569e19..0000000 --- a/FarmmapsCleanUp/CleanUpService.cs +++ /dev/null @@ -1,28 +0,0 @@ -using System; -using System.Globalization; -using System.Threading.Tasks; -using FarmmapsApi.Models; -using FarmmapsApi.Services; -using Microsoft.Extensions.Logging; -using static FarmmapsApi.Extensions; -using static FarmmapsApiSamples.Constants; - -namespace FarmmapsCleanup -{ - public class CleanupService - { - private readonly ILogger _logger; - private readonly FarmmapsApiService _farmmapsApiService; - private readonly GeneralService _generalService; - - public CleanupService(ILogger logger, FarmmapsApiService farmmapsApiService, - GeneralService generalService) - { - _logger = logger; - _farmmapsApiService = farmmapsApiService; - _generalService = generalService; - } - - - } -} \ No newline at end of file diff --git a/FarmmapsCleanUp/FarmmapsCleanUp.csproj b/FarmmapsCleanUp/FarmmapsCleanUp.csproj deleted file mode 100644 index 74cf8ea..0000000 --- a/FarmmapsCleanUp/FarmmapsCleanUp.csproj +++ /dev/null @@ -1,23 +0,0 @@ - - - - Exe - netcoreapp3.1 - - - - - - - - - Always - - - - - - - - - diff --git a/FarmmapsCleanUp/Program.cs b/FarmmapsCleanUp/Program.cs deleted file mode 100644 index 182d69e..0000000 --- a/FarmmapsCleanUp/Program.cs +++ /dev/null @@ -1,21 +0,0 @@ -using System.Threading.Tasks; -using FarmmapsApi; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Logging; - -namespace FarmmapsCleanup -{ - class Program : FarmmapsProgram - { - private static async Task Main(string[] args) - { - await new Program().Start(args); - } - - protected override void Configure(IServiceCollection serviceCollection) - { - serviceCollection.AddLogging() - .AddTransient(); - } - } -} \ No newline at end of file