Working on tenants and config
This commit is contained in:
parent
c10de11bbe
commit
f3352318f5
12 changed files with 309 additions and 19 deletions
51
TestPostgresLISTEN/Program.cs
Normal file
51
TestPostgresLISTEN/Program.cs
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
using Npgsql;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
class Program
|
||||
{
|
||||
static async Task Main(string[] args)
|
||||
{
|
||||
// Tilpas connection string til dine behov
|
||||
var connectionString = "Host=192.168.1.57;Database=ptdb01;Username=postgres;Password=3911";
|
||||
|
||||
try
|
||||
{
|
||||
await using NpgsqlConnection conn = new NpgsqlConnection(connectionString);
|
||||
await conn.OpenAsync();
|
||||
|
||||
Console.WriteLine("Forbundet til databasen. Lytter efter notifikationer...");
|
||||
|
||||
// Opsæt notification handling
|
||||
conn.Notification += (o, e) =>
|
||||
{
|
||||
Console.WriteLine($"Notifikation modtaget:");
|
||||
Console.WriteLine($" PID: {e.PID}");
|
||||
Console.WriteLine($" Kanal: {e.Channel}");
|
||||
Console.WriteLine($" Payload: {e.Payload}");
|
||||
Console.WriteLine("------------------------");
|
||||
};
|
||||
|
||||
// Start lytning
|
||||
await using (var cmd = new NpgsqlCommand("LISTEN config_changes;", conn))
|
||||
{
|
||||
await cmd.ExecuteNonQueryAsync();
|
||||
}
|
||||
|
||||
// Hold programmet kørende og lyt efter notifikationer
|
||||
Console.WriteLine("Tryk på en tast for at stoppe...");
|
||||
|
||||
// Mens vi venter på input, skal vi huske at wait for notifikationer
|
||||
while (!Console.KeyAvailable)
|
||||
{
|
||||
// Wait for notification for 1 second, then continue loop
|
||||
await conn.WaitAsync();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"Der opstod en fejl: {ex.Message}");
|
||||
Console.WriteLine($"Stack trace: {ex.StackTrace}");
|
||||
}
|
||||
}
|
||||
}
|
||||
13
TestPostgresLISTEN/TestPostgresLISTEN.csproj
Normal file
13
TestPostgresLISTEN/TestPostgresLISTEN.csproj
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Core\Core.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
Loading…
Add table
Add a link
Reference in a new issue