Пример #1
0
        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);
                }
            }
        }
Пример #2
0
 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;
 }
Пример #3
0
 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;
 }
Пример #4
0
        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;
                }
            }
        }
Пример #5
0
 void ITailStreamListener.Listen(ITailStreamContext context, ITailCallback callback, WaitHandle abortSignal)
 {
     Listen((TContext)context, callback, abortSignal);
 }
Пример #6
0
 public abstract void Listen(TContext context, ITailCallback callback, WaitHandle abortSignal);
Пример #7
0
 public void Listen(ITailStreamContext context, ITailCallback callback, System.Threading.WaitHandle abortSignal)
 {
 }
Пример #8
0
 public void Listen(ITailStreamContext context, ITailCallback callback, System.Threading.WaitHandle abortSignal)
 {
 }