Initial commit: SWP.Core enterprise framework with multi-tenant architecture, configuration management, security, telemetry and comprehensive test suite

This commit is contained in:
Janus C. H. Knudsen 2025-08-02 22:16:39 +02:00
commit 5275a75502
87 changed files with 6140 additions and 0 deletions

View file

@ -0,0 +1,38 @@
using System.Data;
using System.Diagnostics;
using Microsoft.ApplicationInsights.DataContracts;
using Microsoft.ApplicationInsights.Extensibility;
namespace SWP.Core.Database;
public class DatabaseScope : IDisposable
{
internal readonly IOperationHolder<DependencyTelemetry> _operation;
private readonly Stopwatch _stopwatch;
public DatabaseScope(IDbConnection connection, IOperationHolder<DependencyTelemetry> operation)
{
Connection = connection;
_operation = operation;
_operation.Telemetry.Success = true;
_operation.Telemetry.Timestamp = DateTimeOffset.UtcNow;
_stopwatch = Stopwatch.StartNew();
}
public IDbConnection Connection { get; }
public void Dispose()
{
_stopwatch.Stop();
_operation.Telemetry.Duration = _stopwatch.Elapsed;
_operation.Dispose();
Connection.Dispose();
}
public void Error(Exception ex)
{
_operation.Telemetry.Success = false;
_operation.Telemetry.Properties["Error"] = ex.Message;
}
}