23 lines
886 B
C#
23 lines
886 B
C#
using System.Data;
|
|
using System.Data.Common;
|
|
using Abstractions;
|
|
using Microsoft.EntityFrameworkCore.Diagnostics;
|
|
|
|
namespace W542.GandalfReborn.Data.Database;
|
|
|
|
public class GrDbConnectionInterceptor(InvokerContext invokerContext) : IDbConnectionInterceptor
|
|
{
|
|
public const string CurrentSuspectKey = "gr.current.suspect";
|
|
public async Task ConnectionOpenedAsync(DbConnection connection, ConnectionEndEventData eventData, CancellationToken cancellationToken = new())
|
|
{
|
|
if (invokerContext.Invoker is null)
|
|
return;
|
|
|
|
var command = connection.CreateCommand();
|
|
command.CommandType = CommandType.Text;
|
|
command.CommandText = $"""
|
|
SET SESSION "{CurrentSuspectKey}" = {invokerContext.Invoker.SubjectId};
|
|
""";
|
|
await command.ExecuteNonQueryAsync(cancellationToken);
|
|
}
|
|
} |