diff --git a/FarmMapsBlight/BlightService.cs b/FarmMapsBlight/BlightService.cs index cead99f..dde77f7 100644 --- a/FarmMapsBlight/BlightService.cs +++ b/FarmMapsBlight/BlightService.cs @@ -40,9 +40,9 @@ namespace FarmMapsBlight var fungicide2 = "{\"ai1\": \"fluazinam\", \"ai2\": \"cymoxanil\", \"ai3\": null, \"code\": \"kunshi\", \"name\": \"kunshi\", \"maxdose\": \"0.5\", \"mindose\": \"0.4\", \"safedays\": \"1\", \"emergence\": false, \"newgrowth\": \"1\", \"contentai1\": \"375\", \"contentai2\": \"250\", \"contentai3\": \"0\", \"fastgrowth\": true, \"contentunit\": \"g/kg\", \"rainfastness\": \"2.5\", \"tuberfilling\": false, \"aidescription\": \"(fluazinam + cymoxanil) 0.5 kg/ha\", \"curativescore\": \"2\", \"dryingtimemax\": \"2\", \"dryingtimemin\": \"1\", \"vracompatible\": true, \"maxapplications\": \"5\", \"preventivescore\": \"2.9\", \"recommendeddose\": \"0.5\", \"tuberprotection\": \"3.3\", \"eradicativescore\": \"1\", \"earlytubersetting\": false, \"protectioncategory\": \"1\", \"applicationrateunit\": \"kg/ha\", \"ctgbregistrationnumber\": \"14371 n\"}"; List sprays = new List(); - sprays.Add(new Spray() { fungicide = JsonConvert.DeserializeObject(fungicide1), sprayTime = new DateTime(2020, 6, 24), dose = 0.6, isVRA = false }); - sprays.Add(new Spray() { fungicide = JsonConvert.DeserializeObject(fungicide2), sprayTime = new DateTime(2020, 7, 2), dose = 0.6, isVRA = false }); - //sprays.Add(new Spray() { fungicideCode = "FLEX", SprayTime = new DateTime(2020, 7, 1), dose = 0.6, isVRA = false }); + sprays.Add(new Spray() { fungicide = JsonConvert.DeserializeObject(fungicide1), sprayTime = new DateTime(2020, 9, 1), dose = 0.6, isVRA = false }); + sprays.Add(new Spray() { fungicide = JsonConvert.DeserializeObject(fungicide2), sprayTime = new DateTime(2020, 9, 1), dose = 0.6, isVRA = false }); + taskRequest.attributes["sprays"] = JsonConvert.SerializeObject(sprays); List irrigations = new List(); diff --git a/FarmMapsBlight/FarmMapsBlight.csproj b/FarmMapsBlight/FarmMapsBlight.csproj index 666c07d..dc870a8 100644 --- a/FarmMapsBlight/FarmMapsBlight.csproj +++ b/FarmMapsBlight/FarmMapsBlight.csproj @@ -11,7 +11,7 @@ - >always + PreserveNewest diff --git a/FarmMapsBlight/Models/Fungicide.cs b/FarmMapsBlight/Models/Fungicide.cs index 1ca71fe..a8076c1 100644 --- a/FarmMapsBlight/Models/Fungicide.cs +++ b/FarmMapsBlight/Models/Fungicide.cs @@ -2,8 +2,10 @@ using System.Collections.Generic; using System.Text; -namespace FarmMapsBlight.Models { - public class Fungicide { +namespace FarmMapsBlight.Models +{ + public class Fungicide + { public string code { get; set; } public string name { get; set; } public string ctgbregistrationnumber { get; set; } @@ -35,10 +37,12 @@ namespace FarmMapsBlight.Models { public bool earlytubersetting { get; set; } public bool tuberfilling { get; set; } public int? safedays { get; set; } - public double takeback { - get { + public double takeback + { + get + { return curativescore * 6; } } } -} \ No newline at end of file +} diff --git a/FarmMapsBlight/Models/Spray.cs b/FarmMapsBlight/Models/Spray.cs index 206b849..2bccac9 100644 --- a/FarmMapsBlight/Models/Spray.cs +++ b/FarmMapsBlight/Models/Spray.cs @@ -5,7 +5,6 @@ namespace FarmMapsBlight.Models public class Spray { public DateTime sprayTime { get; set; } - public string fungicideCode { get; set; } public Fungicide fungicide { get; set; } public double dose { get; set; } public bool isVRA { get; set; } diff --git a/FarmmapsApi/FarmmapsApi.csproj b/FarmmapsApi/FarmmapsApi.csproj index 8f133f8..46a26b6 100644 --- a/FarmmapsApi/FarmmapsApi.csproj +++ b/FarmmapsApi/FarmmapsApi.csproj @@ -6,13 +6,15 @@ - - - - - - + + + + + + + + diff --git a/FarmmapsApi/FarmmapsProgram.cs b/FarmmapsApi/FarmmapsProgram.cs index b1bc874..ea25201 100644 --- a/FarmmapsApi/FarmmapsProgram.cs +++ b/FarmmapsApi/FarmmapsProgram.cs @@ -1,3 +1,4 @@ +using System; using System.Net.Http; using System.Threading.Tasks; using FarmmapsApi.HttpMessageHandlers; @@ -6,6 +7,10 @@ using FarmmapsApi.Services; using IdentityModel.Client; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using Serilog; +using Serilog.Events; +using Serilog.Filters; namespace FarmmapsApi { @@ -36,11 +41,13 @@ namespace FarmmapsApi .AddHttpClient() .AddHttpMessageHandler() .Services; - Configure(serviceCollection); var serviceProvider = serviceCollection.BuildServiceProvider(); + + ConfigureLogger(serviceProvider); + await serviceProvider.GetService().AuthenticateAsync(); // await serviceProvider.GetService().StartEventHub(); @@ -48,5 +55,24 @@ namespace FarmmapsApi } protected abstract void Configure(IServiceCollection serviceCollection); + + private static void ConfigureLogger(IServiceProvider serviceProvider) + { + var isMicrosoftNamespace = Matching.FromSource("Microsoft"); + var isSystem = Matching.FromSource("System"); + + Log.Logger = new LoggerConfiguration() + .MinimumLevel.Verbose() + .WriteTo.Logger(l => + l.WriteTo.Logger(l2 => l2 + .Filter.ByExcluding(v => isMicrosoftNamespace(v) || isSystem(v)) + .WriteTo.Console()) + ) + .WriteTo.File(path: "Logs/log.log", rollingInterval: RollingInterval.Day) + .CreateLogger(); + + var loggerFactory = serviceProvider.GetRequiredService(); + loggerFactory.AddSerilog(); + } } } \ No newline at end of file diff --git a/FarmmapsApi/Services/FarmmapsApiService.cs b/FarmmapsApi/Services/FarmmapsApiService.cs index 2d6a7d7..6c18202 100644 --- a/FarmmapsApi/Services/FarmmapsApiService.cs +++ b/FarmmapsApi/Services/FarmmapsApiService.cs @@ -283,7 +283,8 @@ namespace FarmmapsApi.Services /// /// /// - public async Task UploadFile(string filePath, string parentItemCode, string geoJsonString, + public async Task UploadFile(string filePath, string parentItemCode, + string geoJsonString = null, Action progressCallback = null) { if (!File.Exists(filePath)) @@ -301,7 +302,7 @@ namespace FarmmapsApi.Services Name = Path.GetFileName(filePath), ParentCode = parentItemCode, Size = uploadStream.Length, - Geometry = JObject.Parse(geoJsonString) + Geometry = string.IsNullOrEmpty(geoJsonString) ? null : JObject.Parse(geoJsonString) }; using var httpClient = CreateConfigurableHttpClient(_httpClient); diff --git a/FarmmapsApi/Services/GeneralService.cs b/FarmmapsApi/Services/GeneralService.cs index ac0574a..61583e2 100644 --- a/FarmmapsApi/Services/GeneralService.cs +++ b/FarmmapsApi/Services/GeneralService.cs @@ -51,7 +51,8 @@ namespace FarmmapsApi.Services i.Name.ToLower().Contains(itemName.ToLower())); } - public async Task UploadZipWithShapeAsync(UserRoot root, string filePath, string itemName, string geoJsonString = null) { + public async Task UploadZipWithShapeAsync(UserRoot root, string filePath, string itemName, string geoJsonString = null) + { var startUpload = DateTime.UtcNow.AddSeconds(-3); var result = await _farmmapsApiService.UploadFile(filePath, root.Code, geoJsonString, progress => _logger.LogInformation($"Status: {progress.Status} - BytesSent: {progress.BytesSent}")); @@ -64,7 +65,8 @@ namespace FarmmapsApi.Services i.Name.ToLower().Contains(itemName.ToLower())); ; } - public async Task ShapeToGeotiff(Item shapeItem) { + public async Task ShapeToGeotiff(Item shapeItem) + { var startUpload = DateTime.UtcNow.AddSeconds(-3); await RunAndWaitForTask(shapeItem, "vnd.farmmaps.task.shapetogeotiff"); @@ -74,9 +76,9 @@ namespace FarmmapsApi.Services } - public async Task GeotiffToShape(Item tiffItem) { - var taskmapRequest = new TaskRequest { TaskType = TASKMAP_TASK }; - + public async Task GeotiffToShape(Item tiffItem) + { + var taskmapRequest = new TaskRequest {TaskType = TASKMAP_TASK}; taskmapRequest.attributes["cellWidth"] = "3"; taskmapRequest.attributes["cellHeight"] = "1"; taskmapRequest.attributes["angle"] = "0"; @@ -163,6 +165,7 @@ namespace FarmmapsApi.Services } else if (outputType== "shape") { taskMapItem = await FindChildItemAsync(tiffItem.ParentCode, + SHAPE_PROCESSED_ITEMTYPE, itemName); } else diff --git a/FarmmapsPoten/Program.cs b/FarmmapsPoten/Program.cs index a3fa657..f9bcb48 100644 --- a/FarmmapsPoten/Program.cs +++ b/FarmmapsPoten/Program.cs @@ -14,9 +14,7 @@ namespace FarmmapsVRApoten protected override void Configure(IServiceCollection serviceCollection) { - serviceCollection.AddLogging(opts => opts - .AddConsole() - .AddFilter("System.Net.Http", LogLevel.Warning)) + serviceCollection.AddLogging() .AddTransient(); } } diff --git a/FarmmapsZonering/FarmmapsZonering.csproj b/FarmmapsZonering/FarmmapsZonering.csproj index b1927c2..9244d42 100644 --- a/FarmmapsZonering/FarmmapsZonering.csproj +++ b/FarmmapsZonering/FarmmapsZonering.csproj @@ -27,5 +27,4 @@ -