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