mirror of
https://github.com/ckaczor/HomeMonitor.git
synced 2026-02-22 18:47:54 -05:00
Update to .NET Core 3.1 and apply Roslyn suggestions
This commit is contained in:
@@ -39,7 +39,7 @@ namespace ChrisKaczor.HomeMonitor.Weather.Service.Data
|
||||
var databaseExists = (bool?)command.ExecuteScalar();
|
||||
|
||||
// Create database if needed
|
||||
if (!databaseExists.GetValueOrDefault(false))
|
||||
if (!(databaseExists ?? false))
|
||||
{
|
||||
command.CommandText = $"CREATE DATABASE {_configuration["Weather:Database:Name"]}";
|
||||
command.ExecuteNonQuery();
|
||||
@@ -86,7 +86,7 @@ namespace ChrisKaczor.HomeMonitor.Weather.Service.Data
|
||||
|
||||
var query = ResourceReader.GetString("ChrisKaczor.HomeMonitor.Weather.Service.Data.Resources.GetRecentReading.sql");
|
||||
|
||||
return await connection.QueryFirstOrDefaultAsync<WeatherReading>(query);
|
||||
return await connection.QueryFirstOrDefaultAsync<WeatherReading>(query).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<WeatherReading>> GetReadingHistory(DateTimeOffset start, DateTimeOffset end)
|
||||
|
||||
@@ -10,7 +10,7 @@ namespace ChrisKaczor.HomeMonitor.Weather.Service.Models
|
||||
[PublicAPI]
|
||||
public class WeatherUpdate : WeatherMessage
|
||||
{
|
||||
private Database _database;
|
||||
private readonly Database _database;
|
||||
|
||||
public decimal? WindChill { get; set; }
|
||||
|
||||
|
||||
@@ -13,10 +13,7 @@ namespace ChrisKaczor.HomeMonitor.Weather.Service
|
||||
|
||||
private static IWebHostBuilder CreateWebHostBuilder(string[] args)
|
||||
{
|
||||
return WebHost.CreateDefaultBuilder(args).ConfigureAppConfiguration((hostingContext, config) =>
|
||||
{
|
||||
config.AddEnvironmentVariables();
|
||||
}).UseStartup<Startup>();
|
||||
return WebHost.CreateDefaultBuilder(args).ConfigureAppConfiguration((_, config) => config.AddEnvironmentVariables()).UseStartup<Startup>();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,18 +9,14 @@ namespace ChrisKaczor.HomeMonitor.Weather.Service
|
||||
public static string GetString(string resourceName)
|
||||
{
|
||||
var assembly = Assembly.GetExecutingAssembly();
|
||||
using (var stream = assembly.GetManifestResourceStream(resourceName))
|
||||
{
|
||||
if (stream == null)
|
||||
{
|
||||
throw new Exception($"Resource {resourceName} not found in {assembly.FullName}. Valid resources are: {string.Join(", ", assembly.GetManifestResourceNames())}.");
|
||||
}
|
||||
|
||||
using (var reader = new StreamReader(stream))
|
||||
{
|
||||
return reader.ReadToEnd();
|
||||
}
|
||||
}
|
||||
using var stream = assembly.GetManifestResourceStream(resourceName);
|
||||
|
||||
if (stream == null)
|
||||
throw new Exception($"Resource {resourceName} not found in {assembly.FullName}. Valid resources are: {string.Join(", ", assembly.GetManifestResourceNames())}.");
|
||||
|
||||
using var reader = new StreamReader(stream);
|
||||
return reader.ReadToEnd();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,12 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netcoreapp3.0</TargetFramework>
|
||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||
<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
|
||||
<AssemblyName>ChrisKaczor.HomeMonitor.Weather.Service</AssemblyName>
|
||||
<RootNamespace>ChrisKaczor.HomeMonitor.Weather.Service</RootNamespace>
|
||||
<CodeAnalysisRuleSet>../../ChrisKaczor.ruleset</CodeAnalysisRuleSet>
|
||||
<GenerateTargetFrameworkAttribute>false</GenerateTargetFrameworkAttribute>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -17,10 +17,7 @@ namespace ChrisKaczor.HomeMonitor.Weather.Service
|
||||
|
||||
services.AddHostedService<MessageHandler>();
|
||||
|
||||
services.Configure<GzipCompressionProviderOptions>(options =>
|
||||
{
|
||||
options.Level = CompressionLevel.Optimal;
|
||||
});
|
||||
services.Configure<GzipCompressionProviderOptions>(options => options.Level = CompressionLevel.Optimal);
|
||||
|
||||
services.AddResponseCompression(options =>
|
||||
{
|
||||
@@ -47,10 +44,7 @@ namespace ChrisKaczor.HomeMonitor.Weather.Service
|
||||
|
||||
applicationBuilder.UseRouting();
|
||||
|
||||
applicationBuilder.UseEndpoints(endpoints =>
|
||||
{
|
||||
endpoints.MapDefaultControllerRoute();
|
||||
});
|
||||
applicationBuilder.UseEndpoints(endpoints => endpoints.MapDefaultControllerRoute());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user