2025-03-04 23:54:55 +01:00
|
|
|
|
using System.Data;
|
|
|
|
|
|
using Microsoft.ApplicationInsights.DataContracts;
|
|
|
|
|
|
using Microsoft.ApplicationInsights.Extensibility;
|
|
|
|
|
|
|
2025-03-10 15:56:22 +01:00
|
|
|
|
namespace PlanTempus.Core.Database;
|
2025-03-04 23:54:55 +01:00
|
|
|
|
|
|
|
|
|
|
public class DatabaseScope : IDisposable
|
|
|
|
|
|
{
|
|
|
|
|
|
private readonly IOperationHolder<DependencyTelemetry> _operation;
|
|
|
|
|
|
|
|
|
|
|
|
public DatabaseScope(IDbConnection connection, IOperationHolder<DependencyTelemetry> operation)
|
|
|
|
|
|
{
|
|
|
|
|
|
Connection = connection;
|
|
|
|
|
|
_operation = operation;
|
2025-03-10 15:56:22 +01:00
|
|
|
|
_operation.Telemetry.Success = true;
|
2025-03-04 23:54:55 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public IDbConnection Connection { get; }
|
|
|
|
|
|
|
|
|
|
|
|
public void Dispose()
|
|
|
|
|
|
{
|
|
|
|
|
|
_operation.Dispose();
|
|
|
|
|
|
Connection.Dispose();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void Error(Exception ex)
|
|
|
|
|
|
{
|
|
|
|
|
|
_operation.Telemetry.Success = false;
|
|
|
|
|
|
_operation.Telemetry.Properties["Error"] = ex.Message;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|