From 3dc91c2fe8fc7fa7f42a6abc4c0f4df20ab9393e Mon Sep 17 00:00:00 2001 From: whitlocktech Date: Fri, 28 Nov 2025 15:11:41 -0600 Subject: [PATCH] Lesson 1 with .net .gitignore and clean repo --- .gitignore | 133 ++++++++++++++++++ NetPulse.sln | 39 +++++ src/NetPulse.Core/EngineLoop.cs | 45 ++++++ src/NetPulse.Core/NetPulse.Core.csproj | 13 ++ src/NetPulse.Core/Program.cs | 33 +++++ .../Properties/launchSettings.json | 12 ++ .../appsettings.Development.json | 8 ++ src/NetPulse.Core/appsettings.json | 8 ++ 8 files changed, 291 insertions(+) create mode 100644 .gitignore create mode 100644 NetPulse.sln create mode 100644 src/NetPulse.Core/EngineLoop.cs create mode 100644 src/NetPulse.Core/NetPulse.Core.csproj create mode 100644 src/NetPulse.Core/Program.cs create mode 100644 src/NetPulse.Core/Properties/launchSettings.json create mode 100644 src/NetPulse.Core/appsettings.Development.json create mode 100644 src/NetPulse.Core/appsettings.json diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8962f82 --- /dev/null +++ b/.gitignore @@ -0,0 +1,133 @@ +## ----------------------------- +## .NET build artifacts +## ----------------------------- + +# Build output +bin/ +obj/ + +# Publish output +*.publish/ +publish/ + +# NuGet packages +*.nupkg +*.snupkg +packages/ + +# For local NuGet sources +*.nuspec + +## ----------------------------- +## IDE / Editor Specific +## ----------------------------- + +# Visual Studio (Windows) +.vs/ + +# Rider (JetBrains) +.idea/ +*.sln.iml + +# VS Code +.vscode/ +*.code-workspace + +# OmniSharp & Roslyn temp cache +.omnisharp/ +.vscode-test/ + +## ----------------------------- +## OS-specific junk +## ----------------------------- + +# Windows Explorer +Thumbs.db +Desktop.ini + +# macOS Finder +.DS_Store + +# Linux temp files +*~ + +## ----------------------------- +## Logs / Temp / Runtime +## ----------------------------- + +# Logs +*.log + +# DotNet watcher temp +.dotnet/ + +# User-specific config/generated files +*.user +*.userosscache +*.suo + +# Auto-generated by Visual Studio +*.cache/ +*.pdb +*.mdb + +## ----------------------------- +## Test / Coverage tools +## ----------------------------- + +# Coverlet +coverage.json +coverage.opencover.xml +coverage.cobertura.xml + +# Test results +TestResults/ +*.trx + +# NCrunch +_NCrunch_* +*ncrunchsolution* + +## ----------------------------- +## Build system artifacts +## ----------------------------- + +# MSBuild artifacts +*.obj +*.cache +*.tlog + +# Rider MSBuild artifacts +riderModule.iml + +## ----------------------------- +## Secret or runtime config +## ----------------------------- + +# DO NOT COMMIT real secrets automatically +# (user credentials, API keys, etc) +secrets.json + +# Local environment files +.env +.env.*.local + +## ----------------------------- +## Misc things we also don't want +## ----------------------------- + +# Local tools +tools/ + +# Artifacts folders +artifacts/ +dist/ +out/ + +# Crash dumps +*.dmp +*.stackdump + +# Package restore metadata +project.lock.json +project.fragment.lock.json diff --git a/NetPulse.sln b/NetPulse.sln new file mode 100644 index 0000000..db27ce3 --- /dev/null +++ b/NetPulse.sln @@ -0,0 +1,39 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.0.31903.59 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{827E0CD3-B72D-47B6-A68D-7590B98EB39B}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NetPulse.Core", "src\NetPulse.Core\NetPulse.Core.csproj", "{B996D138-9747-4AE9-9FEB-586D6F9CD97E}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|Any CPU = Release|Any CPU + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {B996D138-9747-4AE9-9FEB-586D6F9CD97E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B996D138-9747-4AE9-9FEB-586D6F9CD97E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B996D138-9747-4AE9-9FEB-586D6F9CD97E}.Debug|x64.ActiveCfg = Debug|Any CPU + {B996D138-9747-4AE9-9FEB-586D6F9CD97E}.Debug|x64.Build.0 = Debug|Any CPU + {B996D138-9747-4AE9-9FEB-586D6F9CD97E}.Debug|x86.ActiveCfg = Debug|Any CPU + {B996D138-9747-4AE9-9FEB-586D6F9CD97E}.Debug|x86.Build.0 = Debug|Any CPU + {B996D138-9747-4AE9-9FEB-586D6F9CD97E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B996D138-9747-4AE9-9FEB-586D6F9CD97E}.Release|Any CPU.Build.0 = Release|Any CPU + {B996D138-9747-4AE9-9FEB-586D6F9CD97E}.Release|x64.ActiveCfg = Release|Any CPU + {B996D138-9747-4AE9-9FEB-586D6F9CD97E}.Release|x64.Build.0 = Release|Any CPU + {B996D138-9747-4AE9-9FEB-586D6F9CD97E}.Release|x86.ActiveCfg = Release|Any CPU + {B996D138-9747-4AE9-9FEB-586D6F9CD97E}.Release|x86.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(NestedProjects) = preSolution + {B996D138-9747-4AE9-9FEB-586D6F9CD97E} = {827E0CD3-B72D-47B6-A68D-7590B98EB39B} + EndGlobalSection +EndGlobal diff --git a/src/NetPulse.Core/EngineLoop.cs b/src/NetPulse.Core/EngineLoop.cs new file mode 100644 index 0000000..e087518 --- /dev/null +++ b/src/NetPulse.Core/EngineLoop.cs @@ -0,0 +1,45 @@ +using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Logging; + +namespace NetPulse.Core; + +public class EngineLoop : BackgroundService +{ + private readonly ILogger _logger; + private readonly TimeSpan _interval = TimeSpan.FromSeconds(2); + + public EngineLoop(ILogger logger) + { + _logger = logger; + } + + protected override async Task ExecuteAsync(CancellationToken stoppingToken) + { + _logger.LogInformation("EngineLoop started."); + + while(!stoppingToken.IsCancellationRequested) + { + try + { + // ===== Core Heartbeat ===== + _logger.LogInformation("Hearbeat at {time}", DateTime.UtcNow); + + // Future: metrics Collection + // Future: dispatch events + // Future: run modules + + await Task.Delay(_interval, stoppingToken); + } + catch (TaskCanceledException) + { + break; + } + catch (Exception ex) + { + _logger.LogError(ex, "Unexpected Engine error."); + } + } + + _logger.LogInformation("EngineLoop Stopping"); + } +} \ No newline at end of file diff --git a/src/NetPulse.Core/NetPulse.Core.csproj b/src/NetPulse.Core/NetPulse.Core.csproj new file mode 100644 index 0000000..df8d51f --- /dev/null +++ b/src/NetPulse.Core/NetPulse.Core.csproj @@ -0,0 +1,13 @@ + + + + net9.0 + enable + enable + dotnet-NetPulse.Core-d06ed89e-b585-4482-b09d-8e11e4e6f936 + + + + + + diff --git a/src/NetPulse.Core/Program.cs b/src/NetPulse.Core/Program.cs new file mode 100644 index 0000000..5e2eef8 --- /dev/null +++ b/src/NetPulse.Core/Program.cs @@ -0,0 +1,33 @@ +using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Configuration; + +namespace NetPulse.Core; + +public class Program +{ + public static async Task Main(string[] args) + { + using IHost host = Host.CreateDefaultBuilder(args) + .ConfigureAppConfiguration(config => + { + config.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true); + }) + .ConfigureLogging(logging => + { + logging.ClearProviders(); + logging.AddSimpleConsole(options => + { + options.TimestampFormat = "HH:MM:SS"; + options.IncludeScopes = true; + }); + + }) + .ConfigureServices((context, services) => + { + services.AddHostedService(); + }) + .Build(); + await host.RunAsync(); + } +} \ No newline at end of file diff --git a/src/NetPulse.Core/Properties/launchSettings.json b/src/NetPulse.Core/Properties/launchSettings.json new file mode 100644 index 0000000..75cae9e --- /dev/null +++ b/src/NetPulse.Core/Properties/launchSettings.json @@ -0,0 +1,12 @@ +{ + "$schema": "https://json.schemastore.org/launchsettings.json", + "profiles": { + "NetPulse.Core": { + "commandName": "Project", + "dotnetRunMessages": true, + "environmentVariables": { + "DOTNET_ENVIRONMENT": "Development" + } + } + } +} diff --git a/src/NetPulse.Core/appsettings.Development.json b/src/NetPulse.Core/appsettings.Development.json new file mode 100644 index 0000000..b2dcdb6 --- /dev/null +++ b/src/NetPulse.Core/appsettings.Development.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.Hosting.Lifetime": "Information" + } + } +} diff --git a/src/NetPulse.Core/appsettings.json b/src/NetPulse.Core/appsettings.json new file mode 100644 index 0000000..b2dcdb6 --- /dev/null +++ b/src/NetPulse.Core/appsettings.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.Hosting.Lifetime": "Information" + } + } +}