mirror of
https://github.com/ckaczor/HomeMonitor.git
synced 2026-01-13 17:22:54 -05:00
Update to .NET Core 3.1 and apply Roslyn suggestions
This commit is contained in:
@@ -38,7 +38,7 @@ namespace ChrisKaczor.HomeMonitor.Power.Service.Data
|
||||
var databaseExists = (bool?)command.ExecuteScalar();
|
||||
|
||||
// Create database if needed
|
||||
if (!databaseExists.GetValueOrDefault(false))
|
||||
if (!(databaseExists ?? false))
|
||||
{
|
||||
command.CommandText = $"CREATE DATABASE {_configuration["Power:Database:Name"]}";
|
||||
command.ExecuteNonQuery();
|
||||
|
||||
@@ -49,8 +49,8 @@ namespace ChrisKaczor.HomeMonitor.Power.Service
|
||||
|
||||
var sample = JsonSerializer.Deserialize<PowerSample>(response.Content);
|
||||
|
||||
var generation = sample.Channels.FirstOrDefault(c => c.Type == "GENERATION");
|
||||
var consumption = sample.Channels.FirstOrDefault(c => c.Type == "CONSUMPTION");
|
||||
var generation = Array.Find(sample.Channels, c => c.Type == "GENERATION");
|
||||
var consumption = Array.Find(sample.Channels, c => c.Type == "CONSUMPTION");
|
||||
|
||||
if (generation == null || consumption == null)
|
||||
return;
|
||||
|
||||
@@ -13,10 +13,7 @@ namespace ChrisKaczor.HomeMonitor.Power.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>();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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.Power.Service</AssemblyName>
|
||||
<RootNamespace>ChrisKaczor.HomeMonitor.Power.Service</RootNamespace>
|
||||
<CodeAnalysisRuleSet>../../ChrisKaczor.ruleset</CodeAnalysisRuleSet>
|
||||
<GenerateTargetFrameworkAttribute>false</GenerateTargetFrameworkAttribute>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -17,10 +17,7 @@ namespace ChrisKaczor.HomeMonitor.Power.Service
|
||||
|
||||
services.AddHostedService<PowerReader>();
|
||||
|
||||
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.Power.Service
|
||||
|
||||
applicationBuilder.UseRouting();
|
||||
|
||||
applicationBuilder.UseEndpoints(endpoints =>
|
||||
{
|
||||
endpoints.MapDefaultControllerRoute();
|
||||
});
|
||||
applicationBuilder.UseEndpoints(endpoints => endpoints.MapDefaultControllerRoute());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user