diff --git a/ChrisKaczor.ruleset b/ChrisKaczor.ruleset
new file mode 100644
index 0000000..9d2e7ad
--- /dev/null
+++ b/ChrisKaczor.ruleset
@@ -0,0 +1,34 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Hub/Service/.vscode/launch.json b/Hub/Service/.vscode/launch.json
index f45784f..e1c1bf8 100644
--- a/Hub/Service/.vscode/launch.json
+++ b/Hub/Service/.vscode/launch.json
@@ -9,13 +9,10 @@
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
- "program": "${workspaceFolder}/bin/Debug/netcoreapp3.0/Service.dll",
+ "program": "${workspaceFolder}/bin/Debug/netcoreapp3.1/ChrisKaczor.HomeMonitor.Hub.Service.dll",
"args": [],
"cwd": "${workspaceFolder}",
"stopAtEntry": false,
- "launchBrowser": {
- "enabled": false
- },
"env": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
diff --git a/Hub/Service/.vscode/tasks.json b/Hub/Service/.vscode/tasks.json
index e872c92..0b3548f 100644
--- a/Hub/Service/.vscode/tasks.json
+++ b/Hub/Service/.vscode/tasks.json
@@ -7,29 +7,54 @@
"type": "process",
"args": [
"build",
- "${workspaceFolder}/Service.csproj"
+ "${workspaceFolder}/Service.csproj",
+ "/property:GenerateFullPaths=true",
+ "/consoleloggerparameters:NoSummary"
],
- "problemMatcher": "$msCompile",
- "group": {
- "kind": "build",
- "isDefault": true
- }
+ "problemMatcher": "$msCompile"
},
{
"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",
+ "args": [
+ "build",
+ "/property:GenerateFullPaths=true",
+ "/consoleloggerparameters:NoSummary"
+ ],
+ "group": {
+ "kind": "build",
+ "isDefault": true
+ },
"presentation": {
- "reveal": "always",
- "panel": "shared"
+ "reveal": "silent"
},
- "options": {
- "cwd": "${workspaceFolder}"
- },
- "windows": {
- "command": "${cwd}\\publish.bat"
- },
- "problemMatcher": [],
- "group": "build"
+ "problemMatcher": "$msCompile"
}
]
}
\ No newline at end of file
diff --git a/Hub/Service/Service.csproj b/Hub/Service/Service.csproj
index 6eade61..355d4ed 100644
--- a/Hub/Service/Service.csproj
+++ b/Hub/Service/Service.csproj
@@ -1,10 +1,12 @@
- netcoreapp3.0
+ netcoreapp3.1
InProcess
ChrisKaczor.HomeMonitor.Hub.Service
ChrisKaczor.HomeMonitor.Hub.Service
+ ../../ChrisKaczor.ruleset
+ false
diff --git a/Hub/Service/Startup.cs b/Hub/Service/Startup.cs
index 80cb2d1..78b6e9c 100644
--- a/Hub/Service/Startup.cs
+++ b/Hub/Service/Startup.cs
@@ -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.AddSignalR().AddJsonProtocol(options => { options.PayloadSerializerOptions.WriteIndented = false; });
+ services.AddSignalR().AddJsonProtocol(options => options.PayloadSerializerOptions.WriteIndented = false);
}
public void Configure(IApplicationBuilder applicationBuilder, IWebHostEnvironment environment)
diff --git a/Power/Service/Data/Database.cs b/Power/Service/Data/Database.cs
index a61c187..df03bab 100644
--- a/Power/Service/Data/Database.cs
+++ b/Power/Service/Data/Database.cs
@@ -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();
diff --git a/Power/Service/PowerReader.cs b/Power/Service/PowerReader.cs
index 6af3ced..f618591 100644
--- a/Power/Service/PowerReader.cs
+++ b/Power/Service/PowerReader.cs
@@ -49,8 +49,8 @@ namespace ChrisKaczor.HomeMonitor.Power.Service
var sample = JsonSerializer.Deserialize(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;
diff --git a/Power/Service/Program.cs b/Power/Service/Program.cs
index ec72b77..e29ce87 100644
--- a/Power/Service/Program.cs
+++ b/Power/Service/Program.cs
@@ -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();
+ return WebHost.CreateDefaultBuilder(args).ConfigureAppConfiguration((_, config) => config.AddEnvironmentVariables()).UseStartup();
}
}
}
\ No newline at end of file
diff --git a/Power/Service/Service.csproj b/Power/Service/Service.csproj
index 3d6f70e..dff332c 100644
--- a/Power/Service/Service.csproj
+++ b/Power/Service/Service.csproj
@@ -1,10 +1,12 @@
- netcoreapp3.0
+ netcoreapp3.1
InProcess
ChrisKaczor.HomeMonitor.Power.Service
ChrisKaczor.HomeMonitor.Power.Service
+ ../../ChrisKaczor.ruleset
+ false
diff --git a/Power/Service/Startup.cs b/Power/Service/Startup.cs
index 3a1ecd8..1533359 100644
--- a/Power/Service/Startup.cs
+++ b/Power/Service/Startup.cs
@@ -17,10 +17,7 @@ namespace ChrisKaczor.HomeMonitor.Power.Service
services.AddHostedService();
- services.Configure(options =>
- {
- options.Level = CompressionLevel.Optimal;
- });
+ services.Configure(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());
}
}
}
\ No newline at end of file
diff --git a/Weather/SerialReader/.vscode/launch.json b/Weather/SerialReader/.vscode/launch.json
index 991d6c7..5951ca3 100644
--- a/Weather/SerialReader/.vscode/launch.json
+++ b/Weather/SerialReader/.vscode/launch.json
@@ -1,30 +1,30 @@
{
- // Use IntelliSense to find out which attributes exist for C# debugging
- // Use hover for the description of the existing attributes
- // For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
+ // Use IntelliSense to learn about possible attributes.
+ // Hover to view descriptions of existing attributes.
+ // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
- "name": ".NET Core Launch (remote console)",
+ "name": ".NET Core Launch (web)",
"type": "coreclr",
"request": "launch",
- "preLaunchTask": "publish",
- "program": "dotnet",
- "args": [
- "/home/ckaczor/Weather/SerialReader/SerialReader.dll"
- ],
- "cwd": "/home/ckaczor/Weather/SerialReader",
+ "preLaunchTask": "build",
+ "program": "${workspaceFolder}/bin/Debug/netcoreapp3.1/ChrisKaczor.HomeMonitor.Weather.SerialReader.dll",
+ "args": [],
+ "cwd": "${workspaceFolder}",
"stopAtEntry": false,
- "console": "internalConsole",
- "pipeTransport": {
- "pipeCwd": "${workspaceFolder}",
- "pipeProgram": "C:\\Program Files (x86)\\PuTTY\\PLINK.EXE",
- "pipeArgs": [
- "root@172.23.10.6"
- ],
- "debuggerPath": "/home/ckaczor/vsdbg/vsdbg"
+ "env": {
+ "ASPNETCORE_ENVIRONMENT": "Development"
},
- "internalConsoleOptions": "openOnSessionStart"
+ "sourceFileMap": {
+ "/Views": "${workspaceFolder}/Views"
+ }
+ },
+ {
+ "name": ".NET Core Attach",
+ "type": "coreclr",
+ "request": "attach",
+ "processId": "${command:pickProcess}"
}
]
}
\ No newline at end of file
diff --git a/Weather/SerialReader/.vscode/tasks.json b/Weather/SerialReader/.vscode/tasks.json
index ea611cb..4e3e09c 100644
--- a/Weather/SerialReader/.vscode/tasks.json
+++ b/Weather/SerialReader/.vscode/tasks.json
@@ -7,29 +7,54 @@
"type": "process",
"args": [
"build",
- "${workspaceFolder}/SerialReader.csproj"
+ "${workspaceFolder}/SerialReader.csproj",
+ "/property:GenerateFullPaths=true",
+ "/consoleloggerparameters:NoSummary"
],
- "problemMatcher": "$msCompile",
- "group": {
- "kind": "build",
- "isDefault": true
- }
+ "problemMatcher": "$msCompile"
},
{
"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",
+ "args": [
+ "build",
+ "/property:GenerateFullPaths=true",
+ "/consoleloggerparameters:NoSummary"
+ ],
+ "group": {
+ "kind": "build",
+ "isDefault": true
+ },
"presentation": {
- "reveal": "always",
- "panel": "shared"
+ "reveal": "silent"
},
- "options": {
- "cwd": "${workspaceFolder}"
- },
- "windows": {
- "command": "${cwd}\\publish.bat"
- },
- "problemMatcher": [],
- "group": "build"
+ "problemMatcher": "$msCompile"
}
]
}
\ No newline at end of file
diff --git a/Weather/SerialReader/Program.cs b/Weather/SerialReader/Program.cs
index 32e483c..940b1a4 100644
--- a/Weather/SerialReader/Program.cs
+++ b/Weather/SerialReader/Program.cs
@@ -139,7 +139,7 @@ namespace ChrisKaczor.HomeMonitor.Weather.SerialReader
var ports = SerialPort.GetPortNames();
- var port = ports.FirstOrDefault(p => p.StartsWith(portPrefix));
+ var port = Array.Find(ports, p => p.StartsWith(portPrefix));
if (port != null)
{
diff --git a/Weather/SerialReader/SerialReader.csproj b/Weather/SerialReader/SerialReader.csproj
index 66856e1..8f9e7f6 100644
--- a/Weather/SerialReader/SerialReader.csproj
+++ b/Weather/SerialReader/SerialReader.csproj
@@ -2,7 +2,9 @@
Exe
- netcoreapp3.0
+ netcoreapp3.1
+ ../../ChrisKaczor.ruleset
+ false
diff --git a/Weather/Service/Data/Database.cs b/Weather/Service/Data/Database.cs
index a876b7e..0479398 100644
--- a/Weather/Service/Data/Database.cs
+++ b/Weather/Service/Data/Database.cs
@@ -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(query);
+ return await connection.QueryFirstOrDefaultAsync(query).ConfigureAwait(false);
}
public async Task> GetReadingHistory(DateTimeOffset start, DateTimeOffset end)
diff --git a/Weather/Service/Models/WeatherUpdate.cs b/Weather/Service/Models/WeatherUpdate.cs
index 788841c..4680d4f 100644
--- a/Weather/Service/Models/WeatherUpdate.cs
+++ b/Weather/Service/Models/WeatherUpdate.cs
@@ -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; }
diff --git a/Weather/Service/Program.cs b/Weather/Service/Program.cs
index a48d607..6ac3aa9 100644
--- a/Weather/Service/Program.cs
+++ b/Weather/Service/Program.cs
@@ -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();
+ return WebHost.CreateDefaultBuilder(args).ConfigureAppConfiguration((_, config) => config.AddEnvironmentVariables()).UseStartup();
}
}
}
\ No newline at end of file
diff --git a/Weather/Service/ResourceReader.cs b/Weather/Service/ResourceReader.cs
index 89d0ab8..9e25616 100644
--- a/Weather/Service/ResourceReader.cs
+++ b/Weather/Service/ResourceReader.cs
@@ -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();
}
}
}
\ No newline at end of file
diff --git a/Weather/Service/Service.csproj b/Weather/Service/Service.csproj
index df80e15..c24eecc 100644
--- a/Weather/Service/Service.csproj
+++ b/Weather/Service/Service.csproj
@@ -1,10 +1,12 @@
- netcoreapp3.0
+ netcoreapp3.1
InProcess
ChrisKaczor.HomeMonitor.Weather.Service
ChrisKaczor.HomeMonitor.Weather.Service
+ ../../ChrisKaczor.ruleset
+ false
diff --git a/Weather/Service/Startup.cs b/Weather/Service/Startup.cs
index 1f6599f..c2b6b95 100644
--- a/Weather/Service/Startup.cs
+++ b/Weather/Service/Startup.cs
@@ -17,10 +17,7 @@ namespace ChrisKaczor.HomeMonitor.Weather.Service
services.AddHostedService();
- services.Configure(options =>
- {
- options.Level = CompressionLevel.Optimal;
- });
+ services.Configure(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());
}
}
}
\ No newline at end of file