public void TestNotify(NpgsqlConnector context)
{
//ZA Hnotifytest CNOTIFY Z
//Qlisten notifytest;notify notifytest;
Stream stm = context.Stream;
// string uuidString = "uuid" + Guid.NewGuid().ToString("N");
string uuidString = string.Format("uuid{0:N}", Guid.NewGuid());
Queue<byte> buffer = new Queue<byte>();
byte[] convertBuffer = new byte[36];
PGUtil.WriteStringNullTerminated(stm, "Qlisten {0};notify {0};", uuidString);
for (;;)
{
int newByte = stm.ReadByte();
if (newByte == -1)
{
throw new EndOfStreamException();
}
buffer.Enqueue((byte) newByte);
if (buffer.Count > 35)
{
buffer.CopyTo(convertBuffer, 0);
if (BackendEncoding.UTF8Encoding.GetString(convertBuffer) == uuidString)
{
for (;;)
{
switch (stm.ReadByte())
{
case -1:
throw new EndOfStreamException();
case 'Z':
//context.Query(new NpgsqlCommand("UNLISTEN *", context));
NpgsqlCommand.ExecuteBlind(context, "UNLISTEN *");
return;
}
}
}
else
{
buffer.Dequeue();
}
}
}
}