From 8a76681add8261364058fe09d0b46bd8e7635a13 Mon Sep 17 00:00:00 2001 From: Bjarne Pedersen Date: Sun, 21 Dec 2025 11:56:17 +0100 Subject: [PATCH 1/2] =?UTF-8?q?Projekt=20struktur=20er=20p=C3=A5=20plads.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SmartHouse.Services/SmartHouse.Services.Siemens/NLog.config | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 SmartHouse.Services/SmartHouse.Services.Siemens/NLog.config diff --git a/SmartHouse.Services/SmartHouse.Services.Siemens/NLog.config b/SmartHouse.Services/SmartHouse.Services.Siemens/NLog.config new file mode 100644 index 0000000..e69de29 From 09b0793a47e82530c8ae10b063e02b0d9f22257d Mon Sep 17 00:00:00 2001 From: Bjarne Pedersen Date: Sun, 21 Dec 2025 11:57:04 +0100 Subject: [PATCH 2/2] =?UTF-8?q?grundk=C3=A6ggende=20projekt=20struktur=20e?= =?UTF-8?q?r=20p=C3=A5=20plads?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/.gitignore | 15 +++ .idea/encodings.xml | 4 + .idea/indexLayout.xml | 8 ++ .idea/vcs.xml | 6 + .../.idea/.gitignore | 15 +++ .../.idea/encodings.xml | 4 + .../.idea/indexLayout.xml | 8 ++ .../.idea.SmartHouse.Services/.idea/vcs.xml | 6 + .../SmartHouse.Services.AppHost/AppHost.cs | 13 ++ .../Properties/launchSettings.json | 31 +++++ .../SmartHouse.Services.AppHost.csproj | 19 +++ .../appsettings.Development.json | 8 ++ .../appsettings.json | 9 ++ .../SmartHouse.Services.Database/Class1.cs | 5 + .../SmartHouse.Services.Database.csproj | 13 ++ .../SmartHouse.Services.EVCharging/Program.cs | 9 ++ .../Properties/launchSettings.json | 12 ++ .../SmartHouse.Services.EVCharging.csproj | 17 +++ .../SmartHouse.Services.EVCharging/Worker.cs | 17 +++ .../appsettings.Development.json | 8 ++ .../appsettings.json | 8 ++ .../SmartHouse.Services.Helper/IPerflog.cs | 27 ++++ .../SmartHouse.Services.Helper/PerfLog.cs | 24 ++++ .../SmartHouse.Services.Helper.csproj | 14 ++ .../Class1.cs | 5 + .../SmartHouse.Services.HomeAssistent.csproj | 13 ++ .../Extensions.cs | 127 ++++++++++++++++++ ...SmartHouse.Services.ServiceDefaults.csproj | 22 +++ .../SmartHouse.Services.Siemens/NLog.config | 90 +++++++++++++ .../SmartHouse.Services.Siemens/Program.cs | 56 ++++++++ .../Properties/launchSettings.json | 12 ++ .../SmartHouse.Services.Siemens.csproj | 20 +++ .../SmartHouse.Services.Siemens/Worker.cs | 17 +++ .../appsettings.Development.json | 8 ++ .../appsettings.json | 8 ++ .../SmartHouse.Services.SunCast/Program.cs | 9 ++ .../Properties/launchSettings.json | 12 ++ .../SmartHouse.Services.SunCast.csproj | 17 +++ .../SmartHouse.Services.SunCast/Worker.cs | 17 +++ .../appsettings.Development.json | 8 ++ .../appsettings.json | 8 ++ SmartHouse.Services/SmartHouse.Services.sln | 67 +++++++++ 42 files changed, 816 insertions(+) create mode 100644 .idea/.gitignore create mode 100644 .idea/encodings.xml create mode 100644 .idea/indexLayout.xml create mode 100644 .idea/vcs.xml create mode 100644 SmartHouse.Services/.idea/.idea.SmartHouse.Services/.idea/.gitignore create mode 100644 SmartHouse.Services/.idea/.idea.SmartHouse.Services/.idea/encodings.xml create mode 100644 SmartHouse.Services/.idea/.idea.SmartHouse.Services/.idea/indexLayout.xml create mode 100644 SmartHouse.Services/.idea/.idea.SmartHouse.Services/.idea/vcs.xml create mode 100644 SmartHouse.Services/SmartHouse.Services.AppHost/AppHost.cs create mode 100644 SmartHouse.Services/SmartHouse.Services.AppHost/Properties/launchSettings.json create mode 100644 SmartHouse.Services/SmartHouse.Services.AppHost/SmartHouse.Services.AppHost.csproj create mode 100644 SmartHouse.Services/SmartHouse.Services.AppHost/appsettings.Development.json create mode 100644 SmartHouse.Services/SmartHouse.Services.AppHost/appsettings.json create mode 100644 SmartHouse.Services/SmartHouse.Services.Database/Class1.cs create mode 100644 SmartHouse.Services/SmartHouse.Services.Database/SmartHouse.Services.Database.csproj create mode 100644 SmartHouse.Services/SmartHouse.Services.EVCharging/Program.cs create mode 100644 SmartHouse.Services/SmartHouse.Services.EVCharging/Properties/launchSettings.json create mode 100644 SmartHouse.Services/SmartHouse.Services.EVCharging/SmartHouse.Services.EVCharging.csproj create mode 100644 SmartHouse.Services/SmartHouse.Services.EVCharging/Worker.cs create mode 100644 SmartHouse.Services/SmartHouse.Services.EVCharging/appsettings.Development.json create mode 100644 SmartHouse.Services/SmartHouse.Services.EVCharging/appsettings.json create mode 100644 SmartHouse.Services/SmartHouse.Services.Helper/IPerflog.cs create mode 100644 SmartHouse.Services/SmartHouse.Services.Helper/PerfLog.cs create mode 100644 SmartHouse.Services/SmartHouse.Services.Helper/SmartHouse.Services.Helper.csproj create mode 100644 SmartHouse.Services/SmartHouse.Services.HomeAssistent/Class1.cs create mode 100644 SmartHouse.Services/SmartHouse.Services.HomeAssistent/SmartHouse.Services.HomeAssistent.csproj create mode 100644 SmartHouse.Services/SmartHouse.Services.ServiceDefaults/Extensions.cs create mode 100644 SmartHouse.Services/SmartHouse.Services.ServiceDefaults/SmartHouse.Services.ServiceDefaults.csproj create mode 100644 SmartHouse.Services/SmartHouse.Services.Siemens/Program.cs create mode 100644 SmartHouse.Services/SmartHouse.Services.Siemens/Properties/launchSettings.json create mode 100644 SmartHouse.Services/SmartHouse.Services.Siemens/SmartHouse.Services.Siemens.csproj create mode 100644 SmartHouse.Services/SmartHouse.Services.Siemens/Worker.cs create mode 100644 SmartHouse.Services/SmartHouse.Services.Siemens/appsettings.Development.json create mode 100644 SmartHouse.Services/SmartHouse.Services.Siemens/appsettings.json create mode 100644 SmartHouse.Services/SmartHouse.Services.SunCast/Program.cs create mode 100644 SmartHouse.Services/SmartHouse.Services.SunCast/Properties/launchSettings.json create mode 100644 SmartHouse.Services/SmartHouse.Services.SunCast/SmartHouse.Services.SunCast.csproj create mode 100644 SmartHouse.Services/SmartHouse.Services.SunCast/Worker.cs create mode 100644 SmartHouse.Services/SmartHouse.Services.SunCast/appsettings.Development.json create mode 100644 SmartHouse.Services/SmartHouse.Services.SunCast/appsettings.json create mode 100644 SmartHouse.Services/SmartHouse.Services.sln diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..0fc5941 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,15 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Rider ignored files +/contentModel.xml +/projectSettingsUpdater.xml +/.idea.SmartHouse.Services.iml +/modules.xml +# Ignored default folder with query files +/queries/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml +# Editor-based HTTP Client requests +/httpRequests/ diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..df87cf9 --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/indexLayout.xml b/.idea/indexLayout.xml new file mode 100644 index 0000000..7b08163 --- /dev/null +++ b/.idea/indexLayout.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/SmartHouse.Services/.idea/.idea.SmartHouse.Services/.idea/.gitignore b/SmartHouse.Services/.idea/.idea.SmartHouse.Services/.idea/.gitignore new file mode 100644 index 0000000..d59fd38 --- /dev/null +++ b/SmartHouse.Services/.idea/.idea.SmartHouse.Services/.idea/.gitignore @@ -0,0 +1,15 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Rider ignored files +/.idea.SmartHouse.Services.iml +/contentModel.xml +/modules.xml +/projectSettingsUpdater.xml +# Ignored default folder with query files +/queries/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml +# Editor-based HTTP Client requests +/httpRequests/ diff --git a/SmartHouse.Services/.idea/.idea.SmartHouse.Services/.idea/encodings.xml b/SmartHouse.Services/.idea/.idea.SmartHouse.Services/.idea/encodings.xml new file mode 100644 index 0000000..df87cf9 --- /dev/null +++ b/SmartHouse.Services/.idea/.idea.SmartHouse.Services/.idea/encodings.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/SmartHouse.Services/.idea/.idea.SmartHouse.Services/.idea/indexLayout.xml b/SmartHouse.Services/.idea/.idea.SmartHouse.Services/.idea/indexLayout.xml new file mode 100644 index 0000000..7b08163 --- /dev/null +++ b/SmartHouse.Services/.idea/.idea.SmartHouse.Services/.idea/indexLayout.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/SmartHouse.Services/.idea/.idea.SmartHouse.Services/.idea/vcs.xml b/SmartHouse.Services/.idea/.idea.SmartHouse.Services/.idea/vcs.xml new file mode 100644 index 0000000..6c0b863 --- /dev/null +++ b/SmartHouse.Services/.idea/.idea.SmartHouse.Services/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/SmartHouse.Services/SmartHouse.Services.AppHost/AppHost.cs b/SmartHouse.Services/SmartHouse.Services.AppHost/AppHost.cs new file mode 100644 index 0000000..e50addc --- /dev/null +++ b/SmartHouse.Services/SmartHouse.Services.AppHost/AppHost.cs @@ -0,0 +1,13 @@ +var builder = DistributedApplication.CreateBuilder(args); + +builder.AddProject("smarthouse-services-database"); + +builder.AddProject("smarthouse-services-evcharging"); + +builder.AddProject("smarthouse-services-homeassistent"); + +builder.AddProject("smarthouse-services-siemens"); + +builder.AddProject("smarthouse-services-suncast"); + +builder.Build().Run(); diff --git a/SmartHouse.Services/SmartHouse.Services.AppHost/Properties/launchSettings.json b/SmartHouse.Services/SmartHouse.Services.AppHost/Properties/launchSettings.json new file mode 100644 index 0000000..2acdd65 --- /dev/null +++ b/SmartHouse.Services/SmartHouse.Services.AppHost/Properties/launchSettings.json @@ -0,0 +1,31 @@ +{ + "$schema": "https://json.schemastore.org/launchsettings.json", + "profiles": { + "https": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "applicationUrl": "https://localhost:17223;http://localhost:15039", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development", + "DOTNET_ENVIRONMENT": "Development", + "ASPIRE_DASHBOARD_OTLP_ENDPOINT_URL": "https://localhost:21227", + "ASPIRE_DASHBOARD_MCP_ENDPOINT_URL": "https://localhost:23091", + "ASPIRE_RESOURCE_SERVICE_ENDPOINT_URL": "https://localhost:22221" + } + }, + "http": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "applicationUrl": "http://localhost:15039", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development", + "DOTNET_ENVIRONMENT": "Development", + "ASPIRE_DASHBOARD_OTLP_ENDPOINT_URL": "http://localhost:19207", + "ASPIRE_DASHBOARD_MCP_ENDPOINT_URL": "http://localhost:18000", + "ASPIRE_RESOURCE_SERVICE_ENDPOINT_URL": "http://localhost:20178" + } + } + } +} diff --git a/SmartHouse.Services/SmartHouse.Services.AppHost/SmartHouse.Services.AppHost.csproj b/SmartHouse.Services/SmartHouse.Services.AppHost/SmartHouse.Services.AppHost.csproj new file mode 100644 index 0000000..3ad7fef --- /dev/null +++ b/SmartHouse.Services/SmartHouse.Services.AppHost/SmartHouse.Services.AppHost.csproj @@ -0,0 +1,19 @@ + + + + Exe + net10.0 + enable + enable + 90b46a44-f221-4903-b340-6fee7c8848f2 + + + + + + + + + + + diff --git a/SmartHouse.Services/SmartHouse.Services.AppHost/appsettings.Development.json b/SmartHouse.Services/SmartHouse.Services.AppHost/appsettings.Development.json new file mode 100644 index 0000000..0c208ae --- /dev/null +++ b/SmartHouse.Services/SmartHouse.Services.AppHost/appsettings.Development.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + } +} diff --git a/SmartHouse.Services/SmartHouse.Services.AppHost/appsettings.json b/SmartHouse.Services/SmartHouse.Services.AppHost/appsettings.json new file mode 100644 index 0000000..31c092a --- /dev/null +++ b/SmartHouse.Services/SmartHouse.Services.AppHost/appsettings.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning", + "Aspire.Hosting.Dcp": "Warning" + } + } +} diff --git a/SmartHouse.Services/SmartHouse.Services.Database/Class1.cs b/SmartHouse.Services/SmartHouse.Services.Database/Class1.cs new file mode 100644 index 0000000..5a98860 --- /dev/null +++ b/SmartHouse.Services/SmartHouse.Services.Database/Class1.cs @@ -0,0 +1,5 @@ +namespace SmartHouse.Services.Database; + +public class Class1 +{ +} \ No newline at end of file diff --git a/SmartHouse.Services/SmartHouse.Services.Database/SmartHouse.Services.Database.csproj b/SmartHouse.Services/SmartHouse.Services.Database/SmartHouse.Services.Database.csproj new file mode 100644 index 0000000..ab2e61d --- /dev/null +++ b/SmartHouse.Services/SmartHouse.Services.Database/SmartHouse.Services.Database.csproj @@ -0,0 +1,13 @@ + + + + net10.0 + enable + enable + + + + + + + diff --git a/SmartHouse.Services/SmartHouse.Services.EVCharging/Program.cs b/SmartHouse.Services/SmartHouse.Services.EVCharging/Program.cs new file mode 100644 index 0000000..e177e87 --- /dev/null +++ b/SmartHouse.Services/SmartHouse.Services.EVCharging/Program.cs @@ -0,0 +1,9 @@ +using SmartHouse.Services.EVCharging; + +var builder = Host.CreateApplicationBuilder(args); + +builder.AddServiceDefaults(); +builder.Services.AddHostedService(); + +var host = builder.Build(); +host.Run(); \ No newline at end of file diff --git a/SmartHouse.Services/SmartHouse.Services.EVCharging/Properties/launchSettings.json b/SmartHouse.Services/SmartHouse.Services.EVCharging/Properties/launchSettings.json new file mode 100644 index 0000000..cd8e306 --- /dev/null +++ b/SmartHouse.Services/SmartHouse.Services.EVCharging/Properties/launchSettings.json @@ -0,0 +1,12 @@ +{ + "$schema": "https://json.schemastore.org/launchsettings.json", + "profiles": { + "SmartHouse.Services.EVCharging": { + "commandName": "Project", + "dotnetRunMessages": true, + "environmentVariables": { + "DOTNET_ENVIRONMENT": "Development" + } + } + } +} diff --git a/SmartHouse.Services/SmartHouse.Services.EVCharging/SmartHouse.Services.EVCharging.csproj b/SmartHouse.Services/SmartHouse.Services.EVCharging/SmartHouse.Services.EVCharging.csproj new file mode 100644 index 0000000..5539061 --- /dev/null +++ b/SmartHouse.Services/SmartHouse.Services.EVCharging/SmartHouse.Services.EVCharging.csproj @@ -0,0 +1,17 @@ + + + + net10.0 + enable + enable + dotnet-SmartHouse.Services.EVCharging-8f24ed80-dad3-439c-b4e6-c654b00d1ae2 + + + + + + + + + + diff --git a/SmartHouse.Services/SmartHouse.Services.EVCharging/Worker.cs b/SmartHouse.Services/SmartHouse.Services.EVCharging/Worker.cs new file mode 100644 index 0000000..e003e7b --- /dev/null +++ b/SmartHouse.Services/SmartHouse.Services.EVCharging/Worker.cs @@ -0,0 +1,17 @@ +namespace SmartHouse.Services.EVCharging; + +public class Worker(ILogger logger) : BackgroundService +{ + protected override async Task ExecuteAsync(CancellationToken stoppingToken) + { + while (!stoppingToken.IsCancellationRequested) + { + if (logger.IsEnabled(LogLevel.Information)) + { + logger.LogInformation("Worker running at: {time}", DateTimeOffset.Now); + } + + await Task.Delay(1000, stoppingToken); + } + } +} \ No newline at end of file diff --git a/SmartHouse.Services/SmartHouse.Services.EVCharging/appsettings.Development.json b/SmartHouse.Services/SmartHouse.Services.EVCharging/appsettings.Development.json new file mode 100644 index 0000000..b2dcdb6 --- /dev/null +++ b/SmartHouse.Services/SmartHouse.Services.EVCharging/appsettings.Development.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.Hosting.Lifetime": "Information" + } + } +} diff --git a/SmartHouse.Services/SmartHouse.Services.EVCharging/appsettings.json b/SmartHouse.Services/SmartHouse.Services.EVCharging/appsettings.json new file mode 100644 index 0000000..b2dcdb6 --- /dev/null +++ b/SmartHouse.Services/SmartHouse.Services.EVCharging/appsettings.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.Hosting.Lifetime": "Information" + } + } +} diff --git a/SmartHouse.Services/SmartHouse.Services.Helper/IPerflog.cs b/SmartHouse.Services/SmartHouse.Services.Helper/IPerflog.cs new file mode 100644 index 0000000..80f5f61 --- /dev/null +++ b/SmartHouse.Services/SmartHouse.Services.Helper/IPerflog.cs @@ -0,0 +1,27 @@ +using Microsoft.Extensions.Logging; + +namespace SmartHouse.Services.Helper +{ + public interface IPerfLog + { + void Info(string message, params object[] args); + void Warn(string message, params object[] args); + } + + public sealed class PerfLog : IPerfLog + { + private readonly ILogger _log; + + public PerfLog(ILoggerFactory factory) + { + // Matcher din rule: Performance.* -> perf.log + _log = factory.CreateLogger("Performance.Worker"); + } + + public void Info(string message, params object[] args) + => _log.LogInformation(message, args); + + public void Warn(string message, params object[] args) + => _log.LogWarning(message, args); + } +} diff --git a/SmartHouse.Services/SmartHouse.Services.Helper/PerfLog.cs b/SmartHouse.Services/SmartHouse.Services.Helper/PerfLog.cs new file mode 100644 index 0000000..1ea6b71 --- /dev/null +++ b/SmartHouse.Services/SmartHouse.Services.Helper/PerfLog.cs @@ -0,0 +1,24 @@ +using Microsoft.Extensions.Logging; + +public interface IPerfLog +{ + void Info(string message, params object[] args); + void Warn(string message, params object[] args); +} + +public sealed class PerfLog : IPerfLog +{ + private readonly ILogger _log; + + public PerfLog(ILoggerFactory factory) + { + // Matcher rule: Performance.* → perf.log + _log = factory.CreateLogger("Performance.Worker"); + } + + public void Info(string message, params object[] args) + => _log.LogInformation(message, args); + + public void Warn(string message, params object[] args) + => _log.LogWarning(message, args); +} diff --git a/SmartHouse.Services/SmartHouse.Services.Helper/SmartHouse.Services.Helper.csproj b/SmartHouse.Services/SmartHouse.Services.Helper/SmartHouse.Services.Helper.csproj new file mode 100644 index 0000000..8c73806 --- /dev/null +++ b/SmartHouse.Services/SmartHouse.Services.Helper/SmartHouse.Services.Helper.csproj @@ -0,0 +1,14 @@ + + + + net10.0 + enable + enable + + + + + + + + diff --git a/SmartHouse.Services/SmartHouse.Services.HomeAssistent/Class1.cs b/SmartHouse.Services/SmartHouse.Services.HomeAssistent/Class1.cs new file mode 100644 index 0000000..e54b0af --- /dev/null +++ b/SmartHouse.Services/SmartHouse.Services.HomeAssistent/Class1.cs @@ -0,0 +1,5 @@ +namespace SmartHouse.Services.HomeAssistent; + +public class Class1 +{ +} \ No newline at end of file diff --git a/SmartHouse.Services/SmartHouse.Services.HomeAssistent/SmartHouse.Services.HomeAssistent.csproj b/SmartHouse.Services/SmartHouse.Services.HomeAssistent/SmartHouse.Services.HomeAssistent.csproj new file mode 100644 index 0000000..ab2e61d --- /dev/null +++ b/SmartHouse.Services/SmartHouse.Services.HomeAssistent/SmartHouse.Services.HomeAssistent.csproj @@ -0,0 +1,13 @@ + + + + net10.0 + enable + enable + + + + + + + diff --git a/SmartHouse.Services/SmartHouse.Services.ServiceDefaults/Extensions.cs b/SmartHouse.Services/SmartHouse.Services.ServiceDefaults/Extensions.cs new file mode 100644 index 0000000..b72c875 --- /dev/null +++ b/SmartHouse.Services/SmartHouse.Services.ServiceDefaults/Extensions.cs @@ -0,0 +1,127 @@ +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Diagnostics.HealthChecks; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Diagnostics.HealthChecks; +using Microsoft.Extensions.Logging; +using Microsoft.Extensions.ServiceDiscovery; +using OpenTelemetry; +using OpenTelemetry.Metrics; +using OpenTelemetry.Trace; + +namespace Microsoft.Extensions.Hosting; + +// Adds common Aspire services: service discovery, resilience, health checks, and OpenTelemetry. +// This project should be referenced by each service project in your solution. +// To learn more about using this project, see https://aka.ms/dotnet/aspire/service-defaults +public static class Extensions +{ + private const string HealthEndpointPath = "/health"; + private const string AlivenessEndpointPath = "/alive"; + + public static TBuilder AddServiceDefaults(this TBuilder builder) where TBuilder : IHostApplicationBuilder + { + builder.ConfigureOpenTelemetry(); + + builder.AddDefaultHealthChecks(); + + builder.Services.AddServiceDiscovery(); + + builder.Services.ConfigureHttpClientDefaults(http => + { + // Turn on resilience by default + http.AddStandardResilienceHandler(); + + // Turn on service discovery by default + http.AddServiceDiscovery(); + }); + + // Uncomment the following to restrict the allowed schemes for service discovery. + // builder.Services.Configure(options => + // { + // options.AllowedSchemes = ["https"]; + // }); + + return builder; + } + + public static TBuilder ConfigureOpenTelemetry(this TBuilder builder) where TBuilder : IHostApplicationBuilder + { + builder.Logging.AddOpenTelemetry(logging => + { + logging.IncludeFormattedMessage = true; + logging.IncludeScopes = true; + }); + + builder.Services.AddOpenTelemetry() + .WithMetrics(metrics => + { + metrics.AddAspNetCoreInstrumentation() + .AddHttpClientInstrumentation() + .AddRuntimeInstrumentation(); + }) + .WithTracing(tracing => + { + tracing.AddSource(builder.Environment.ApplicationName) + .AddAspNetCoreInstrumentation(tracing => + // Exclude health check requests from tracing + tracing.Filter = context => + !context.Request.Path.StartsWithSegments(HealthEndpointPath) + && !context.Request.Path.StartsWithSegments(AlivenessEndpointPath) + ) + // Uncomment the following line to enable gRPC instrumentation (requires the OpenTelemetry.Instrumentation.GrpcNetClient package) + //.AddGrpcClientInstrumentation() + .AddHttpClientInstrumentation(); + }); + + builder.AddOpenTelemetryExporters(); + + return builder; + } + + private static TBuilder AddOpenTelemetryExporters(this TBuilder builder) where TBuilder : IHostApplicationBuilder + { + var useOtlpExporter = !string.IsNullOrWhiteSpace(builder.Configuration["OTEL_EXPORTER_OTLP_ENDPOINT"]); + + if (useOtlpExporter) + { + builder.Services.AddOpenTelemetry().UseOtlpExporter(); + } + + // Uncomment the following lines to enable the Azure Monitor exporter (requires the Azure.Monitor.OpenTelemetry.AspNetCore package) + //if (!string.IsNullOrEmpty(builder.Configuration["APPLICATIONINSIGHTS_CONNECTION_STRING"])) + //{ + // builder.Services.AddOpenTelemetry() + // .UseAzureMonitor(); + //} + + return builder; + } + + public static TBuilder AddDefaultHealthChecks(this TBuilder builder) where TBuilder : IHostApplicationBuilder + { + builder.Services.AddHealthChecks() + // Add a default liveness check to ensure app is responsive + .AddCheck("self", () => HealthCheckResult.Healthy(), ["live"]); + + return builder; + } + + public static WebApplication MapDefaultEndpoints(this WebApplication app) + { + // Adding health checks endpoints to applications in non-development environments has security implications. + // See https://aka.ms/dotnet/aspire/healthchecks for details before enabling these endpoints in non-development environments. + if (app.Environment.IsDevelopment()) + { + // All health checks must pass for app to be considered ready to accept traffic after starting + app.MapHealthChecks(HealthEndpointPath); + + // Only health checks tagged with the "live" tag must pass for app to be considered alive + app.MapHealthChecks(AlivenessEndpointPath, new HealthCheckOptions + { + Predicate = r => r.Tags.Contains("live") + }); + } + + return app; + } +} diff --git a/SmartHouse.Services/SmartHouse.Services.ServiceDefaults/SmartHouse.Services.ServiceDefaults.csproj b/SmartHouse.Services/SmartHouse.Services.ServiceDefaults/SmartHouse.Services.ServiceDefaults.csproj new file mode 100644 index 0000000..938db20 --- /dev/null +++ b/SmartHouse.Services/SmartHouse.Services.ServiceDefaults/SmartHouse.Services.ServiceDefaults.csproj @@ -0,0 +1,22 @@ + + + + net10.0 + enable + enable + true + + + + + + + + + + + + + + + diff --git a/SmartHouse.Services/SmartHouse.Services.Siemens/NLog.config b/SmartHouse.Services/SmartHouse.Services.Siemens/NLog.config index e69de29..960dcee 100644 --- a/SmartHouse.Services/SmartHouse.Services.Siemens/NLog.config +++ b/SmartHouse.Services/SmartHouse.Services.Siemens/NLog.config @@ -0,0 +1,90 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/SmartHouse.Services/SmartHouse.Services.Siemens/Program.cs b/SmartHouse.Services/SmartHouse.Services.Siemens/Program.cs new file mode 100644 index 0000000..8d19ec1 --- /dev/null +++ b/SmartHouse.Services/SmartHouse.Services.Siemens/Program.cs @@ -0,0 +1,56 @@ +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Logging; +using NLog; +using NLog.Extensions.Logging; +using SmartHouse.Services.Siemens; + +// NLog internal bootstrap logger (til hvis noget går galt før hosten er oppe) +var bootstrapLogger = LogManager.Setup() + .LoadConfigurationFromFile("NLog.config", optional: false) + .GetCurrentClassLogger(); + +try +{ + var builder = Host.CreateApplicationBuilder(args); + + // Aspire service defaults (behold den) + builder.AddServiceDefaults(); + + // 1) Fjern standard logging providers + builder.Logging.ClearProviders(); + + // 2) (Valgfrit men anbefalet) Brug scopes (CorrelationId m.m.) + builder.Logging.Configure(o => + { + o.ActivityTrackingOptions = + ActivityTrackingOptions.TraceId | + ActivityTrackingOptions.SpanId | + ActivityTrackingOptions.ParentId; + }); + + // 3) Tilføj NLog som provider (læser din NLog.config) + builder.Logging.AddNLog(new NLogProviderOptions + { + CaptureMessageTemplates = true, + CaptureMessageProperties = true, + IncludeScopes = true + }); + + // Perf logger wrapper (DI-friendly, uden NLog i din domænekode) + builder.Services.AddSingleton(); + + builder.Services.AddHostedService(); + + var host = builder.Build(); + host.Run(); +} +catch (Exception ex) +{ + bootstrapLogger.Error(ex, "Host terminated unexpectedly"); + throw; +} +finally +{ + LogManager.Shutdown(); +} \ No newline at end of file diff --git a/SmartHouse.Services/SmartHouse.Services.Siemens/Properties/launchSettings.json b/SmartHouse.Services/SmartHouse.Services.Siemens/Properties/launchSettings.json new file mode 100644 index 0000000..61a887e --- /dev/null +++ b/SmartHouse.Services/SmartHouse.Services.Siemens/Properties/launchSettings.json @@ -0,0 +1,12 @@ +{ + "$schema": "https://json.schemastore.org/launchsettings.json", + "profiles": { + "SmartHouse.Services.Siemens": { + "commandName": "Project", + "dotnetRunMessages": true, + "environmentVariables": { + "DOTNET_ENVIRONMENT": "Development" + } + } + } +} diff --git a/SmartHouse.Services/SmartHouse.Services.Siemens/SmartHouse.Services.Siemens.csproj b/SmartHouse.Services/SmartHouse.Services.Siemens/SmartHouse.Services.Siemens.csproj new file mode 100644 index 0000000..67b9b78 --- /dev/null +++ b/SmartHouse.Services/SmartHouse.Services.Siemens/SmartHouse.Services.Siemens.csproj @@ -0,0 +1,20 @@ + + + + net10.0 + enable + enable + dotnet-SmartHouse.Services.Siemens-09de8319-5d84-47b2-8d81-a7eec428f8da + + + + + + + + + + + + + diff --git a/SmartHouse.Services/SmartHouse.Services.Siemens/Worker.cs b/SmartHouse.Services/SmartHouse.Services.Siemens/Worker.cs new file mode 100644 index 0000000..f86bb69 --- /dev/null +++ b/SmartHouse.Services/SmartHouse.Services.Siemens/Worker.cs @@ -0,0 +1,17 @@ +namespace SmartHouse.Services.Siemens; + +public class Worker(ILogger logger) : BackgroundService +{ + protected override async Task ExecuteAsync(CancellationToken stoppingToken) + { + while (!stoppingToken.IsCancellationRequested) + { + if (logger.IsEnabled(LogLevel.Information)) + { + logger.LogInformation("Worker running at: {time}", DateTimeOffset.Now); + } + + await Task.Delay(1000, stoppingToken); + } + } +} \ No newline at end of file diff --git a/SmartHouse.Services/SmartHouse.Services.Siemens/appsettings.Development.json b/SmartHouse.Services/SmartHouse.Services.Siemens/appsettings.Development.json new file mode 100644 index 0000000..b2dcdb6 --- /dev/null +++ b/SmartHouse.Services/SmartHouse.Services.Siemens/appsettings.Development.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.Hosting.Lifetime": "Information" + } + } +} diff --git a/SmartHouse.Services/SmartHouse.Services.Siemens/appsettings.json b/SmartHouse.Services/SmartHouse.Services.Siemens/appsettings.json new file mode 100644 index 0000000..b2dcdb6 --- /dev/null +++ b/SmartHouse.Services/SmartHouse.Services.Siemens/appsettings.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.Hosting.Lifetime": "Information" + } + } +} diff --git a/SmartHouse.Services/SmartHouse.Services.SunCast/Program.cs b/SmartHouse.Services/SmartHouse.Services.SunCast/Program.cs new file mode 100644 index 0000000..316cac8 --- /dev/null +++ b/SmartHouse.Services/SmartHouse.Services.SunCast/Program.cs @@ -0,0 +1,9 @@ +using SmartHouse.Services.SunCast; + +var builder = Host.CreateApplicationBuilder(args); + +builder.AddServiceDefaults(); +builder.Services.AddHostedService(); + +var host = builder.Build(); +host.Run(); \ No newline at end of file diff --git a/SmartHouse.Services/SmartHouse.Services.SunCast/Properties/launchSettings.json b/SmartHouse.Services/SmartHouse.Services.SunCast/Properties/launchSettings.json new file mode 100644 index 0000000..90f9e0b --- /dev/null +++ b/SmartHouse.Services/SmartHouse.Services.SunCast/Properties/launchSettings.json @@ -0,0 +1,12 @@ +{ + "$schema": "https://json.schemastore.org/launchsettings.json", + "profiles": { + "SmartHouse.Services.SunCast": { + "commandName": "Project", + "dotnetRunMessages": true, + "environmentVariables": { + "DOTNET_ENVIRONMENT": "Development" + } + } + } +} diff --git a/SmartHouse.Services/SmartHouse.Services.SunCast/SmartHouse.Services.SunCast.csproj b/SmartHouse.Services/SmartHouse.Services.SunCast/SmartHouse.Services.SunCast.csproj new file mode 100644 index 0000000..c9a5e3c --- /dev/null +++ b/SmartHouse.Services/SmartHouse.Services.SunCast/SmartHouse.Services.SunCast.csproj @@ -0,0 +1,17 @@ + + + + net10.0 + enable + enable + dotnet-SmartHouse.Services.SunCast-5f688ae7-b693-4c9b-aa20-147fcd5c7b79 + + + + + + + + + + diff --git a/SmartHouse.Services/SmartHouse.Services.SunCast/Worker.cs b/SmartHouse.Services/SmartHouse.Services.SunCast/Worker.cs new file mode 100644 index 0000000..6d517d3 --- /dev/null +++ b/SmartHouse.Services/SmartHouse.Services.SunCast/Worker.cs @@ -0,0 +1,17 @@ +namespace SmartHouse.Services.SunCast; + +public class Worker(ILogger logger) : BackgroundService +{ + protected override async Task ExecuteAsync(CancellationToken stoppingToken) + { + while (!stoppingToken.IsCancellationRequested) + { + if (logger.IsEnabled(LogLevel.Information)) + { + logger.LogInformation("Worker running at: {time}", DateTimeOffset.Now); + } + + await Task.Delay(1000, stoppingToken); + } + } +} \ No newline at end of file diff --git a/SmartHouse.Services/SmartHouse.Services.SunCast/appsettings.Development.json b/SmartHouse.Services/SmartHouse.Services.SunCast/appsettings.Development.json new file mode 100644 index 0000000..b2dcdb6 --- /dev/null +++ b/SmartHouse.Services/SmartHouse.Services.SunCast/appsettings.Development.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.Hosting.Lifetime": "Information" + } + } +} diff --git a/SmartHouse.Services/SmartHouse.Services.SunCast/appsettings.json b/SmartHouse.Services/SmartHouse.Services.SunCast/appsettings.json new file mode 100644 index 0000000..b2dcdb6 --- /dev/null +++ b/SmartHouse.Services/SmartHouse.Services.SunCast/appsettings.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.Hosting.Lifetime": "Information" + } + } +} diff --git a/SmartHouse.Services/SmartHouse.Services.sln b/SmartHouse.Services/SmartHouse.Services.sln new file mode 100644 index 0000000..004dcf4 --- /dev/null +++ b/SmartHouse.Services/SmartHouse.Services.sln @@ -0,0 +1,67 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 18 +VisualStudioVersion = 18.1.11312.151 d18.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SmartHouse.Services.HomeAssistent", "SmartHouse.Services.HomeAssistent\SmartHouse.Services.HomeAssistent.csproj", "{5EE8D007-801D-4E7A-8F40-D89C7A61B5FD}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SmartHouse.Services.Database", "SmartHouse.Services.Database\SmartHouse.Services.Database.csproj", "{8430DCBF-8341-4F00-9017-035699B07FED}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SmartHouse.Services.Siemens", "SmartHouse.Services.Siemens\SmartHouse.Services.Siemens.csproj", "{158F4BB1-78CC-42FE-B712-5489F8626750}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SmartHouse.Services.SunCast", "SmartHouse.Services.SunCast\SmartHouse.Services.SunCast.csproj", "{02ADF617-BBE0-4681-ABAE-164A1BF43804}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SmartHouse.Services.EVCharging", "SmartHouse.Services.EVCharging\SmartHouse.Services.EVCharging.csproj", "{9C8B5C4D-0B34-4ACC-A5ED-8DE9705E3801}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SmartHouse.Services.AppHost", "SmartHouse.Services.AppHost\SmartHouse.Services.AppHost.csproj", "{966ADDAD-5DF9-4FC3-8ACC-D751EA633DF1}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SmartHouse.Services.ServiceDefaults", "SmartHouse.Services.ServiceDefaults\SmartHouse.Services.ServiceDefaults.csproj", "{980D4FF9-B1F4-4F5D-846F-38EE5E15CC0E}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SmartHouse.Services.Helper", "SmartHouse.Services.Helper\SmartHouse.Services.Helper.csproj", "{119F70AB-85D8-4715-A41D-AD8509CEC551}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {5EE8D007-801D-4E7A-8F40-D89C7A61B5FD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {5EE8D007-801D-4E7A-8F40-D89C7A61B5FD}.Debug|Any CPU.Build.0 = Debug|Any CPU + {5EE8D007-801D-4E7A-8F40-D89C7A61B5FD}.Release|Any CPU.ActiveCfg = Release|Any CPU + {5EE8D007-801D-4E7A-8F40-D89C7A61B5FD}.Release|Any CPU.Build.0 = Release|Any CPU + {8430DCBF-8341-4F00-9017-035699B07FED}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {8430DCBF-8341-4F00-9017-035699B07FED}.Debug|Any CPU.Build.0 = Debug|Any CPU + {8430DCBF-8341-4F00-9017-035699B07FED}.Release|Any CPU.ActiveCfg = Release|Any CPU + {8430DCBF-8341-4F00-9017-035699B07FED}.Release|Any CPU.Build.0 = Release|Any CPU + {158F4BB1-78CC-42FE-B712-5489F8626750}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {158F4BB1-78CC-42FE-B712-5489F8626750}.Debug|Any CPU.Build.0 = Debug|Any CPU + {158F4BB1-78CC-42FE-B712-5489F8626750}.Release|Any CPU.ActiveCfg = Release|Any CPU + {158F4BB1-78CC-42FE-B712-5489F8626750}.Release|Any CPU.Build.0 = Release|Any CPU + {02ADF617-BBE0-4681-ABAE-164A1BF43804}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {02ADF617-BBE0-4681-ABAE-164A1BF43804}.Debug|Any CPU.Build.0 = Debug|Any CPU + {02ADF617-BBE0-4681-ABAE-164A1BF43804}.Release|Any CPU.ActiveCfg = Release|Any CPU + {02ADF617-BBE0-4681-ABAE-164A1BF43804}.Release|Any CPU.Build.0 = Release|Any CPU + {9C8B5C4D-0B34-4ACC-A5ED-8DE9705E3801}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {9C8B5C4D-0B34-4ACC-A5ED-8DE9705E3801}.Debug|Any CPU.Build.0 = Debug|Any CPU + {9C8B5C4D-0B34-4ACC-A5ED-8DE9705E3801}.Release|Any CPU.ActiveCfg = Release|Any CPU + {9C8B5C4D-0B34-4ACC-A5ED-8DE9705E3801}.Release|Any CPU.Build.0 = Release|Any CPU + {966ADDAD-5DF9-4FC3-8ACC-D751EA633DF1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {966ADDAD-5DF9-4FC3-8ACC-D751EA633DF1}.Debug|Any CPU.Build.0 = Debug|Any CPU + {966ADDAD-5DF9-4FC3-8ACC-D751EA633DF1}.Release|Any CPU.ActiveCfg = Release|Any CPU + {966ADDAD-5DF9-4FC3-8ACC-D751EA633DF1}.Release|Any CPU.Build.0 = Release|Any CPU + {980D4FF9-B1F4-4F5D-846F-38EE5E15CC0E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {980D4FF9-B1F4-4F5D-846F-38EE5E15CC0E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {980D4FF9-B1F4-4F5D-846F-38EE5E15CC0E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {980D4FF9-B1F4-4F5D-846F-38EE5E15CC0E}.Release|Any CPU.Build.0 = Release|Any CPU + {119F70AB-85D8-4715-A41D-AD8509CEC551}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {119F70AB-85D8-4715-A41D-AD8509CEC551}.Debug|Any CPU.Build.0 = Debug|Any CPU + {119F70AB-85D8-4715-A41D-AD8509CEC551}.Release|Any CPU.ActiveCfg = Release|Any CPU + {119F70AB-85D8-4715-A41D-AD8509CEC551}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {6F06BFFD-CD82-4F8C-AB9B-D63797D89B84} + EndGlobalSection +EndGlobal