public override void Listen(DebugStreamContext context, ITailCallback callback, WaitHandle abortSignal) { // Everything after the first DWORD is our debugging text. bool isWow64 = Win32Native.IsWow64Process(); IntPtr pString = isWow64 ? new IntPtr(_sharedMemory.ToInt32() + Marshal.SizeOf(typeof(int))) : new IntPtr(_sharedMemory.ToInt64() + Marshal.SizeOf(typeof(int))); _logger.Information(isWow64 ? "Running in WOW64." : "Not running in WOW64."); while (!abortSignal.WaitOne(0)) { // We're ready to receive new buffer data. Win32Native.SetEvent(_bufferReadyEvent); int ret = Win32Native.WaitForSingleObject(_readyEvent, 500); if (ret == Win32Native.WAIT_OBJECT_0) { // Get the process ID and the message. Marshal.ReadInt32(_sharedMemory); var message = Marshal.PtrToStringAnsi(pString); // Publish the message. callback.Publish(message); } } }
public TailListenerThread(int id, ITailCallback callback, ITailStreamListener listener, ITailStreamContext context) { _id = id; _callback = callback; _listener = listener; _context = context; _stopSignal = new ManualResetEvent(false); _stoppedSignal = new ManualResetEvent(false); _thread = new Thread(Execute); _thread.IsBackground = true; }
public override void Listen(FileStreamContext context, ITailCallback callback, WaitHandle abortSignal) { // Wait for a file to be loaded. var file = new FileInfo(context.Path); if (!file.Exists) { return; } using (var reader = new StreamReader(file.Open(FileMode.Open, FileAccess.Read, FileShare.ReadWrite))) { long lastOffset = reader.BaseStream.Length; if (reader.BaseStream.Length > 0) { // Send the last 10 kb of text to the reader. lastOffset = Math.Max(0, reader.BaseStream.Length - (1024 * 10)); } while (!abortSignal.WaitOne(100)) { // Idle if file hasn't changed. if (reader.BaseStream.Length <= lastOffset) { if (reader.BaseStream.Length < lastOffset) { lastOffset = reader.BaseStream.Length; } continue; } // Read the data. reader.BaseStream.Seek(lastOffset, SeekOrigin.Begin); var delta = reader.BaseStream.Length - lastOffset; var buffer = new char[delta]; reader.ReadBlock(buffer, 0, buffer.Length); // Publish the data. callback.Publish(new string(buffer)); // Update the offset. lastOffset = reader.BaseStream.Position; } } }
void ITailStreamListener.Listen(ITailStreamContext context, ITailCallback callback, WaitHandle abortSignal) { Listen((TContext)context, callback, abortSignal); }
public abstract void Listen(TContext context, ITailCallback callback, WaitHandle abortSignal);
public void Listen(ITailStreamContext context, ITailCallback callback, System.Threading.WaitHandle abortSignal) { }