From 2a45024f09176b075cb6570ed4fe977caf546398 Mon Sep 17 00:00:00 2001 From: Florian Friedrich Date: Mon, 20 Nov 2023 10:42:43 +0100 Subject: [PATCH] Update to dotnet 8 --- Dockerfile | 4 ++-- .../SensorServer/Controllers/MeasurementsController.cs | 8 ++++++-- server/SensorServer/Helpers/HeatIndexCalculator.cs | 3 +-- .../Helpers/SimpleTokenAuthenticationHandler.cs | 7 +++---- server/SensorServer/Models/SortDirection.cs | 2 +- server/SensorServer/Program.cs | 2 +- server/SensorServer/SensorServer.csproj | 10 +++++----- 7 files changed, 19 insertions(+), 17 deletions(-) diff --git a/Dockerfile b/Dockerfile index 5d4d247..f629385 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM mcr.microsoft.com/dotnet/sdk:7.0-jammy as buildnode +FROM mcr.microsoft.com/dotnet/sdk:8.0-jammy as buildnode ARG VERSION @@ -26,7 +26,7 @@ RUN unset VERSION; \ -FROM mcr.microsoft.com/dotnet/aspnet:7.0-jammy +FROM mcr.microsoft.com/dotnet/aspnet:8.0-jammy ARG VERSION diff --git a/server/SensorServer/Controllers/MeasurementsController.cs b/server/SensorServer/Controllers/MeasurementsController.cs index e61f21d..b92d9c4 100644 --- a/server/SensorServer/Controllers/MeasurementsController.cs +++ b/server/SensorServer/Controllers/MeasurementsController.cs @@ -54,14 +54,18 @@ public async Task> GetLatestMeasurement([FromQuery] st [HttpGet] [Route("counts")] - public async Task GetMeasurementCounts([FromQuery] DateTime? start, [FromQuery] DateTime? stop) + public async Task GetMeasurementCounts( + [FromQuery] DateTime? start, + [FromQuery] DateTime? stop) { return await _measurementsRepository.GetMeasurementCounts(start, stop); } [HttpGet] [Route("statistics")] - public async Task GetMeasurementStatistics([FromQuery] string? location, [FromQuery] DateTime? start, + public async Task GetMeasurementStatistics( + [FromQuery] string? location, + [FromQuery] DateTime? start, [FromQuery] DateTime? stop) { return await _measurementsRepository.GetMeasurementStatistics(location, start, stop); diff --git a/server/SensorServer/Helpers/HeatIndexCalculator.cs b/server/SensorServer/Helpers/HeatIndexCalculator.cs index 553031a..c4e3796 100644 --- a/server/SensorServer/Helpers/HeatIndexCalculator.cs +++ b/server/SensorServer/Helpers/HeatIndexCalculator.cs @@ -24,8 +24,7 @@ public static double CalculateHeatIndexInFahrenheit(this Measurement measurement switch (humidityPercent) { case < 13 when fahrenheit is >= 80 and <= 112: - heatIndex -= (13 - humidityPercent) * 0.25 * - Math.Sqrt((17 - Math.Abs(fahrenheit - 95)) * 0.05882); + heatIndex -= (13 - humidityPercent) * 0.25 * Math.Sqrt((17 - Math.Abs(fahrenheit - 95)) * 0.05882); break; case > 85 when fahrenheit is >= 80 and <= 87: heatIndex += (humidityPercent - 85) * 0.1 * ((87 - fahrenheit) * 0.2); diff --git a/server/SensorServer/Helpers/SimpleTokenAuthenticationHandler.cs b/server/SensorServer/Helpers/SimpleTokenAuthenticationHandler.cs index f9872ac..4073eec 100644 --- a/server/SensorServer/Helpers/SimpleTokenAuthenticationHandler.cs +++ b/server/SensorServer/Helpers/SimpleTokenAuthenticationHandler.cs @@ -14,16 +14,15 @@ public class SimpleTokenAuthenticationHandler : AuthenticationHandler options, ILoggerFactory logger, - UrlEncoder encoder, - ISystemClock clock) : base(options, logger, encoder, clock) + UrlEncoder encoder) : base(options, logger, encoder) { } protected override Task HandleAuthenticateAsync() { - if (!Request.Headers.Authorization.Any()) return Task.FromResult(AuthenticateResult.NoResult()); + if (Request.Headers.Authorization.Count == 0) return Task.FromResult(AuthenticateResult.NoResult()); var authHeader = Request.Headers.Authorization[0]; - if (authHeader == null || !authHeader.ToLower().StartsWith("bearer ")) + if (authHeader == null || !authHeader.StartsWith("bearer ", StringComparison.CurrentCultureIgnoreCase)) return Task.FromResult(AuthenticateResult.Fail("Unauthorized")); var token = authHeader["bearer".Length..].Trim(); if (!Options.AllowedTokens.Contains(token)) diff --git a/server/SensorServer/Models/SortDirection.cs b/server/SensorServer/Models/SortDirection.cs index b708be9..0d20262 100644 --- a/server/SensorServer/Models/SortDirection.cs +++ b/server/SensorServer/Models/SortDirection.cs @@ -2,5 +2,5 @@ namespace SensorServer.Models; public enum SortDirection { - Ascending, Descending + Ascending, Descending, } diff --git a/server/SensorServer/Program.cs b/server/SensorServer/Program.cs index 6d10ea8..29ecab1 100644 --- a/server/SensorServer/Program.cs +++ b/server/SensorServer/Program.cs @@ -50,7 +50,7 @@ Id = "Bearer", }, }, - new string[] { } + Array.Empty() }, }); }); diff --git a/server/SensorServer/SensorServer.csproj b/server/SensorServer/SensorServer.csproj index 40adee2..618dc7c 100644 --- a/server/SensorServer/SensorServer.csproj +++ b/server/SensorServer/SensorServer.csproj @@ -1,19 +1,19 @@ - net7.0 + net8.0 enable enable - - - + + + all runtime; build; native; contentfiles; analyzers; buildtransitive - +