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:
34
ChrisKaczor.ruleset
Normal file
34
ChrisKaczor.ruleset
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!--
|
||||||
|
|
||||||
|
This rule set can be used to:
|
||||||
|
|
||||||
|
1) Enable/disable analyzer(s) by DEFAULT.
|
||||||
|
2) Change DEFAULT severity (action) of the analyzer(s).
|
||||||
|
|
||||||
|
Default configuration is applied once when analyzers are loaded.
|
||||||
|
Therefore, it may be neccessary to restart IDE for changes to take effect.
|
||||||
|
|
||||||
|
Although it is possible to edit ruleset manually, Visual Studio has built-in support for editing ruleset.
|
||||||
|
Just add ruleset file to a solution and open it.
|
||||||
|
|
||||||
|
-->
|
||||||
|
<RuleSet Name="ChrisKaczor.ruleset" ToolsVersion="16.0">
|
||||||
|
|
||||||
|
<!-- Specify default action that should be applied to all analyzers except those explicitly specified. -->
|
||||||
|
<!-- <IncludeAll Action="None,Hidden,Info,Warning,Error" /> -->
|
||||||
|
|
||||||
|
<!-- Specify zero or more paths to other rulesets that should be included. -->
|
||||||
|
<!-- <Include Path="" Action="Default,None,Hidden,Info,Warning,Error" /> -->
|
||||||
|
|
||||||
|
<Rules AnalyzerId="Roslynator.CSharp.Analyzers" RuleNamespace="Roslynator.CSharp.Analyzers">
|
||||||
|
|
||||||
|
<!-- Specify default action that should be applied to a specified analyzer. -->
|
||||||
|
<!-- <Rule Id="RCS...." Action="None,Hidden,Info,Warning,Error" /> -->
|
||||||
|
|
||||||
|
<Rule Id="RCS1090" Action="None" />
|
||||||
|
<Rule Id="RCS1123" Action="None" />
|
||||||
|
<Rule Id="IDE0066" Action="None" />
|
||||||
|
</Rules>
|
||||||
|
|
||||||
|
</RuleSet>
|
||||||
5
Hub/Service/.vscode/launch.json
vendored
5
Hub/Service/.vscode/launch.json
vendored
@@ -9,13 +9,10 @@
|
|||||||
"type": "coreclr",
|
"type": "coreclr",
|
||||||
"request": "launch",
|
"request": "launch",
|
||||||
"preLaunchTask": "build",
|
"preLaunchTask": "build",
|
||||||
"program": "${workspaceFolder}/bin/Debug/netcoreapp3.0/Service.dll",
|
"program": "${workspaceFolder}/bin/Debug/netcoreapp3.1/ChrisKaczor.HomeMonitor.Hub.Service.dll",
|
||||||
"args": [],
|
"args": [],
|
||||||
"cwd": "${workspaceFolder}",
|
"cwd": "${workspaceFolder}",
|
||||||
"stopAtEntry": false,
|
"stopAtEntry": false,
|
||||||
"launchBrowser": {
|
|
||||||
"enabled": false
|
|
||||||
},
|
|
||||||
"env": {
|
"env": {
|
||||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||||
},
|
},
|
||||||
|
|||||||
57
Hub/Service/.vscode/tasks.json
vendored
57
Hub/Service/.vscode/tasks.json
vendored
@@ -7,29 +7,54 @@
|
|||||||
"type": "process",
|
"type": "process",
|
||||||
"args": [
|
"args": [
|
||||||
"build",
|
"build",
|
||||||
"${workspaceFolder}/Service.csproj"
|
"${workspaceFolder}/Service.csproj",
|
||||||
|
"/property:GenerateFullPaths=true",
|
||||||
|
"/consoleloggerparameters:NoSummary"
|
||||||
],
|
],
|
||||||
"problemMatcher": "$msCompile",
|
"problemMatcher": "$msCompile"
|
||||||
"group": {
|
|
||||||
"kind": "build",
|
|
||||||
"isDefault": true
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"label": "publish",
|
"label": "publish",
|
||||||
|
"command": "dotnet",
|
||||||
|
"type": "process",
|
||||||
|
"args": [
|
||||||
|
"publish",
|
||||||
|
"${workspaceFolder}/Service.csproj",
|
||||||
|
"/property:GenerateFullPaths=true",
|
||||||
|
"/consoleloggerparameters:NoSummary"
|
||||||
|
],
|
||||||
|
"problemMatcher": "$msCompile"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "watch",
|
||||||
|
"command": "dotnet",
|
||||||
|
"type": "process",
|
||||||
|
"args": [
|
||||||
|
"watch",
|
||||||
|
"run",
|
||||||
|
"${workspaceFolder}/Service.csproj",
|
||||||
|
"/property:GenerateFullPaths=true",
|
||||||
|
"/consoleloggerparameters:NoSummary"
|
||||||
|
],
|
||||||
|
"problemMatcher": "$msCompile"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "build",
|
||||||
|
"command": "dotnet",
|
||||||
"type": "shell",
|
"type": "shell",
|
||||||
|
"args": [
|
||||||
|
"build",
|
||||||
|
"/property:GenerateFullPaths=true",
|
||||||
|
"/consoleloggerparameters:NoSummary"
|
||||||
|
],
|
||||||
|
"group": {
|
||||||
|
"kind": "build",
|
||||||
|
"isDefault": true
|
||||||
|
},
|
||||||
"presentation": {
|
"presentation": {
|
||||||
"reveal": "always",
|
"reveal": "silent"
|
||||||
"panel": "shared"
|
|
||||||
},
|
},
|
||||||
"options": {
|
"problemMatcher": "$msCompile"
|
||||||
"cwd": "${workspaceFolder}"
|
|
||||||
},
|
|
||||||
"windows": {
|
|
||||||
"command": "${cwd}\\publish.bat"
|
|
||||||
},
|
|
||||||
"problemMatcher": [],
|
|
||||||
"group": "build"
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
@@ -1,10 +1,12 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>netcoreapp3.0</TargetFramework>
|
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||||
<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
|
<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
|
||||||
<AssemblyName>ChrisKaczor.HomeMonitor.Hub.Service</AssemblyName>
|
<AssemblyName>ChrisKaczor.HomeMonitor.Hub.Service</AssemblyName>
|
||||||
<RootNamespace>ChrisKaczor.HomeMonitor.Hub.Service</RootNamespace>
|
<RootNamespace>ChrisKaczor.HomeMonitor.Hub.Service</RootNamespace>
|
||||||
|
<CodeAnalysisRuleSet>../../ChrisKaczor.ruleset</CodeAnalysisRuleSet>
|
||||||
|
<GenerateTargetFrameworkAttribute>false</GenerateTargetFrameworkAttribute>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ namespace ChrisKaczor.HomeMonitor.Hub.Service
|
|||||||
|
|
||||||
services.AddCors(o => o.AddPolicy("CorsPolicy", builder => builder.AllowAnyMethod().AllowAnyHeader().AllowCredentials().WithOrigins("http://localhost:4200")));
|
services.AddCors(o => o.AddPolicy("CorsPolicy", builder => builder.AllowAnyMethod().AllowAnyHeader().AllowCredentials().WithOrigins("http://localhost:4200")));
|
||||||
|
|
||||||
services.AddSignalR().AddJsonProtocol(options => { options.PayloadSerializerOptions.WriteIndented = false; });
|
services.AddSignalR().AddJsonProtocol(options => options.PayloadSerializerOptions.WriteIndented = false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Configure(IApplicationBuilder applicationBuilder, IWebHostEnvironment environment)
|
public void Configure(IApplicationBuilder applicationBuilder, IWebHostEnvironment environment)
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ namespace ChrisKaczor.HomeMonitor.Power.Service.Data
|
|||||||
var databaseExists = (bool?)command.ExecuteScalar();
|
var databaseExists = (bool?)command.ExecuteScalar();
|
||||||
|
|
||||||
// Create database if needed
|
// Create database if needed
|
||||||
if (!databaseExists.GetValueOrDefault(false))
|
if (!(databaseExists ?? false))
|
||||||
{
|
{
|
||||||
command.CommandText = $"CREATE DATABASE {_configuration["Power:Database:Name"]}";
|
command.CommandText = $"CREATE DATABASE {_configuration["Power:Database:Name"]}";
|
||||||
command.ExecuteNonQuery();
|
command.ExecuteNonQuery();
|
||||||
|
|||||||
@@ -49,8 +49,8 @@ namespace ChrisKaczor.HomeMonitor.Power.Service
|
|||||||
|
|
||||||
var sample = JsonSerializer.Deserialize<PowerSample>(response.Content);
|
var sample = JsonSerializer.Deserialize<PowerSample>(response.Content);
|
||||||
|
|
||||||
var generation = sample.Channels.FirstOrDefault(c => c.Type == "GENERATION");
|
var generation = Array.Find(sample.Channels, c => c.Type == "GENERATION");
|
||||||
var consumption = sample.Channels.FirstOrDefault(c => c.Type == "CONSUMPTION");
|
var consumption = Array.Find(sample.Channels, c => c.Type == "CONSUMPTION");
|
||||||
|
|
||||||
if (generation == null || consumption == null)
|
if (generation == null || consumption == null)
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -13,10 +13,7 @@ namespace ChrisKaczor.HomeMonitor.Power.Service
|
|||||||
|
|
||||||
private static IWebHostBuilder CreateWebHostBuilder(string[] args)
|
private static IWebHostBuilder CreateWebHostBuilder(string[] args)
|
||||||
{
|
{
|
||||||
return WebHost.CreateDefaultBuilder(args).ConfigureAppConfiguration((hostingContext, config) =>
|
return WebHost.CreateDefaultBuilder(args).ConfigureAppConfiguration((_, config) => config.AddEnvironmentVariables()).UseStartup<Startup>();
|
||||||
{
|
|
||||||
config.AddEnvironmentVariables();
|
|
||||||
}).UseStartup<Startup>();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,10 +1,12 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>netcoreapp3.0</TargetFramework>
|
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||||
<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
|
<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
|
||||||
<AssemblyName>ChrisKaczor.HomeMonitor.Power.Service</AssemblyName>
|
<AssemblyName>ChrisKaczor.HomeMonitor.Power.Service</AssemblyName>
|
||||||
<RootNamespace>ChrisKaczor.HomeMonitor.Power.Service</RootNamespace>
|
<RootNamespace>ChrisKaczor.HomeMonitor.Power.Service</RootNamespace>
|
||||||
|
<CodeAnalysisRuleSet>../../ChrisKaczor.ruleset</CodeAnalysisRuleSet>
|
||||||
|
<GenerateTargetFrameworkAttribute>false</GenerateTargetFrameworkAttribute>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@@ -17,10 +17,7 @@ namespace ChrisKaczor.HomeMonitor.Power.Service
|
|||||||
|
|
||||||
services.AddHostedService<PowerReader>();
|
services.AddHostedService<PowerReader>();
|
||||||
|
|
||||||
services.Configure<GzipCompressionProviderOptions>(options =>
|
services.Configure<GzipCompressionProviderOptions>(options => options.Level = CompressionLevel.Optimal);
|
||||||
{
|
|
||||||
options.Level = CompressionLevel.Optimal;
|
|
||||||
});
|
|
||||||
|
|
||||||
services.AddResponseCompression(options =>
|
services.AddResponseCompression(options =>
|
||||||
{
|
{
|
||||||
@@ -47,10 +44,7 @@ namespace ChrisKaczor.HomeMonitor.Power.Service
|
|||||||
|
|
||||||
applicationBuilder.UseRouting();
|
applicationBuilder.UseRouting();
|
||||||
|
|
||||||
applicationBuilder.UseEndpoints(endpoints =>
|
applicationBuilder.UseEndpoints(endpoints => endpoints.MapDefaultControllerRoute());
|
||||||
{
|
|
||||||
endpoints.MapDefaultControllerRoute();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
38
Weather/SerialReader/.vscode/launch.json
vendored
38
Weather/SerialReader/.vscode/launch.json
vendored
@@ -1,30 +1,30 @@
|
|||||||
{
|
{
|
||||||
// Use IntelliSense to find out which attributes exist for C# debugging
|
// Use IntelliSense to learn about possible attributes.
|
||||||
// Use hover for the description of the existing attributes
|
// Hover to view descriptions of existing attributes.
|
||||||
// For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
|
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||||
"version": "0.2.0",
|
"version": "0.2.0",
|
||||||
"configurations": [
|
"configurations": [
|
||||||
{
|
{
|
||||||
"name": ".NET Core Launch (remote console)",
|
"name": ".NET Core Launch (web)",
|
||||||
"type": "coreclr",
|
"type": "coreclr",
|
||||||
"request": "launch",
|
"request": "launch",
|
||||||
"preLaunchTask": "publish",
|
"preLaunchTask": "build",
|
||||||
"program": "dotnet",
|
"program": "${workspaceFolder}/bin/Debug/netcoreapp3.1/ChrisKaczor.HomeMonitor.Weather.SerialReader.dll",
|
||||||
"args": [
|
"args": [],
|
||||||
"/home/ckaczor/Weather/SerialReader/SerialReader.dll"
|
"cwd": "${workspaceFolder}",
|
||||||
],
|
|
||||||
"cwd": "/home/ckaczor/Weather/SerialReader",
|
|
||||||
"stopAtEntry": false,
|
"stopAtEntry": false,
|
||||||
"console": "internalConsole",
|
"env": {
|
||||||
"pipeTransport": {
|
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||||
"pipeCwd": "${workspaceFolder}",
|
|
||||||
"pipeProgram": "C:\\Program Files (x86)\\PuTTY\\PLINK.EXE",
|
|
||||||
"pipeArgs": [
|
|
||||||
"root@172.23.10.6"
|
|
||||||
],
|
|
||||||
"debuggerPath": "/home/ckaczor/vsdbg/vsdbg"
|
|
||||||
},
|
},
|
||||||
"internalConsoleOptions": "openOnSessionStart"
|
"sourceFileMap": {
|
||||||
|
"/Views": "${workspaceFolder}/Views"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": ".NET Core Attach",
|
||||||
|
"type": "coreclr",
|
||||||
|
"request": "attach",
|
||||||
|
"processId": "${command:pickProcess}"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
57
Weather/SerialReader/.vscode/tasks.json
vendored
57
Weather/SerialReader/.vscode/tasks.json
vendored
@@ -7,29 +7,54 @@
|
|||||||
"type": "process",
|
"type": "process",
|
||||||
"args": [
|
"args": [
|
||||||
"build",
|
"build",
|
||||||
"${workspaceFolder}/SerialReader.csproj"
|
"${workspaceFolder}/SerialReader.csproj",
|
||||||
|
"/property:GenerateFullPaths=true",
|
||||||
|
"/consoleloggerparameters:NoSummary"
|
||||||
],
|
],
|
||||||
"problemMatcher": "$msCompile",
|
"problemMatcher": "$msCompile"
|
||||||
"group": {
|
|
||||||
"kind": "build",
|
|
||||||
"isDefault": true
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"label": "publish",
|
"label": "publish",
|
||||||
|
"command": "dotnet",
|
||||||
|
"type": "process",
|
||||||
|
"args": [
|
||||||
|
"publish",
|
||||||
|
"${workspaceFolder}/SerialReader.csproj",
|
||||||
|
"/property:GenerateFullPaths=true",
|
||||||
|
"/consoleloggerparameters:NoSummary"
|
||||||
|
],
|
||||||
|
"problemMatcher": "$msCompile"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "watch",
|
||||||
|
"command": "dotnet",
|
||||||
|
"type": "process",
|
||||||
|
"args": [
|
||||||
|
"watch",
|
||||||
|
"run",
|
||||||
|
"${workspaceFolder}/SerialReader.csproj",
|
||||||
|
"/property:GenerateFullPaths=true",
|
||||||
|
"/consoleloggerparameters:NoSummary"
|
||||||
|
],
|
||||||
|
"problemMatcher": "$msCompile"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "build",
|
||||||
|
"command": "dotnet",
|
||||||
"type": "shell",
|
"type": "shell",
|
||||||
|
"args": [
|
||||||
|
"build",
|
||||||
|
"/property:GenerateFullPaths=true",
|
||||||
|
"/consoleloggerparameters:NoSummary"
|
||||||
|
],
|
||||||
|
"group": {
|
||||||
|
"kind": "build",
|
||||||
|
"isDefault": true
|
||||||
|
},
|
||||||
"presentation": {
|
"presentation": {
|
||||||
"reveal": "always",
|
"reveal": "silent"
|
||||||
"panel": "shared"
|
|
||||||
},
|
},
|
||||||
"options": {
|
"problemMatcher": "$msCompile"
|
||||||
"cwd": "${workspaceFolder}"
|
|
||||||
},
|
|
||||||
"windows": {
|
|
||||||
"command": "${cwd}\\publish.bat"
|
|
||||||
},
|
|
||||||
"problemMatcher": [],
|
|
||||||
"group": "build"
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
@@ -139,7 +139,7 @@ namespace ChrisKaczor.HomeMonitor.Weather.SerialReader
|
|||||||
|
|
||||||
var ports = SerialPort.GetPortNames();
|
var ports = SerialPort.GetPortNames();
|
||||||
|
|
||||||
var port = ports.FirstOrDefault(p => p.StartsWith(portPrefix));
|
var port = Array.Find(ports, p => p.StartsWith(portPrefix));
|
||||||
|
|
||||||
if (port != null)
|
if (port != null)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -2,7 +2,9 @@
|
|||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<OutputType>Exe</OutputType>
|
<OutputType>Exe</OutputType>
|
||||||
<TargetFramework>netcoreapp3.0</TargetFramework>
|
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||||
|
<CodeAnalysisRuleSet>../../ChrisKaczor.ruleset</CodeAnalysisRuleSet>
|
||||||
|
<GenerateTargetFrameworkAttribute>false</GenerateTargetFrameworkAttribute>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ namespace ChrisKaczor.HomeMonitor.Weather.Service.Data
|
|||||||
var databaseExists = (bool?)command.ExecuteScalar();
|
var databaseExists = (bool?)command.ExecuteScalar();
|
||||||
|
|
||||||
// Create database if needed
|
// Create database if needed
|
||||||
if (!databaseExists.GetValueOrDefault(false))
|
if (!(databaseExists ?? false))
|
||||||
{
|
{
|
||||||
command.CommandText = $"CREATE DATABASE {_configuration["Weather:Database:Name"]}";
|
command.CommandText = $"CREATE DATABASE {_configuration["Weather:Database:Name"]}";
|
||||||
command.ExecuteNonQuery();
|
command.ExecuteNonQuery();
|
||||||
@@ -86,7 +86,7 @@ namespace ChrisKaczor.HomeMonitor.Weather.Service.Data
|
|||||||
|
|
||||||
var query = ResourceReader.GetString("ChrisKaczor.HomeMonitor.Weather.Service.Data.Resources.GetRecentReading.sql");
|
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)
|
public async Task<IEnumerable<WeatherReading>> GetReadingHistory(DateTimeOffset start, DateTimeOffset end)
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ namespace ChrisKaczor.HomeMonitor.Weather.Service.Models
|
|||||||
[PublicAPI]
|
[PublicAPI]
|
||||||
public class WeatherUpdate : WeatherMessage
|
public class WeatherUpdate : WeatherMessage
|
||||||
{
|
{
|
||||||
private Database _database;
|
private readonly Database _database;
|
||||||
|
|
||||||
public decimal? WindChill { get; set; }
|
public decimal? WindChill { get; set; }
|
||||||
|
|
||||||
|
|||||||
@@ -13,10 +13,7 @@ namespace ChrisKaczor.HomeMonitor.Weather.Service
|
|||||||
|
|
||||||
private static IWebHostBuilder CreateWebHostBuilder(string[] args)
|
private static IWebHostBuilder CreateWebHostBuilder(string[] args)
|
||||||
{
|
{
|
||||||
return WebHost.CreateDefaultBuilder(args).ConfigureAppConfiguration((hostingContext, config) =>
|
return WebHost.CreateDefaultBuilder(args).ConfigureAppConfiguration((_, config) => config.AddEnvironmentVariables()).UseStartup<Startup>();
|
||||||
{
|
|
||||||
config.AddEnvironmentVariables();
|
|
||||||
}).UseStartup<Startup>();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -9,18 +9,14 @@ namespace ChrisKaczor.HomeMonitor.Weather.Service
|
|||||||
public static string GetString(string resourceName)
|
public static string GetString(string resourceName)
|
||||||
{
|
{
|
||||||
var assembly = Assembly.GetExecutingAssembly();
|
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))
|
using var stream = assembly.GetManifestResourceStream(resourceName);
|
||||||
{
|
|
||||||
return reader.ReadToEnd();
|
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">
|
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>netcoreapp3.0</TargetFramework>
|
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||||
<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
|
<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
|
||||||
<AssemblyName>ChrisKaczor.HomeMonitor.Weather.Service</AssemblyName>
|
<AssemblyName>ChrisKaczor.HomeMonitor.Weather.Service</AssemblyName>
|
||||||
<RootNamespace>ChrisKaczor.HomeMonitor.Weather.Service</RootNamespace>
|
<RootNamespace>ChrisKaczor.HomeMonitor.Weather.Service</RootNamespace>
|
||||||
|
<CodeAnalysisRuleSet>../../ChrisKaczor.ruleset</CodeAnalysisRuleSet>
|
||||||
|
<GenerateTargetFrameworkAttribute>false</GenerateTargetFrameworkAttribute>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@@ -17,10 +17,7 @@ namespace ChrisKaczor.HomeMonitor.Weather.Service
|
|||||||
|
|
||||||
services.AddHostedService<MessageHandler>();
|
services.AddHostedService<MessageHandler>();
|
||||||
|
|
||||||
services.Configure<GzipCompressionProviderOptions>(options =>
|
services.Configure<GzipCompressionProviderOptions>(options => options.Level = CompressionLevel.Optimal);
|
||||||
{
|
|
||||||
options.Level = CompressionLevel.Optimal;
|
|
||||||
});
|
|
||||||
|
|
||||||
services.AddResponseCompression(options =>
|
services.AddResponseCompression(options =>
|
||||||
{
|
{
|
||||||
@@ -47,10 +44,7 @@ namespace ChrisKaczor.HomeMonitor.Weather.Service
|
|||||||
|
|
||||||
applicationBuilder.UseRouting();
|
applicationBuilder.UseRouting();
|
||||||
|
|
||||||
applicationBuilder.UseEndpoints(endpoints =>
|
applicationBuilder.UseEndpoints(endpoints => endpoints.MapDefaultControllerRoute());
|
||||||
{
|
|
||||||
endpoints.MapDefaultControllerRoute();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user