Holds the new chunk of the console ANSI stream.
Inheritance: System.EventArgs
示例#1
0
        /// <summary>
        /// A function which processes the part of the stream which gets available (or does the rest of it at the end).
        /// </summary>
        public void PumpStream()
        {
            if (_isDisposed)
            {
                return;                 // Nonfiring, yep
            }
            // Try acquiring the stream if not yet
            _fstream = _fstream ?? FindAnsiLogFile();

            // No ANSI stream file (yet?)
            if (_fstream == null)
            {
                return;
            }

            // Read the available chunk
            long length = _fstream.Length;             // Take the length and keep it for the rest of the iteration, might change right as we're reading

            if (_fstream.Position >= length)
            {
                return;                                        // Nothing new
            }
            var buffer = new byte[length - _fstream.Position]; // TODO: buffer pooling to save mem traffic
            int nRead  = _fstream.Read(buffer, 0, buffer.Length);

            if (nRead <= 0)
            {
                return;                 // Hmm should have succeeded, but anyway
            }
            // Make a smaller buffer if we got less data (unlikely)
            AnsiStreamChunkEventArgs args;

            if (nRead < buffer.Length)
            {
                var subbuffer = new byte[nRead];
                Buffer.BlockCopy(buffer, 0, subbuffer, 0, nRead);
                args = new AnsiStreamChunkEventArgs(subbuffer);
            }
            else
            {
                args = new AnsiStreamChunkEventArgs(buffer);
            }

            // Fire
            AnsiStreamChunkReceived?.Invoke(this, args);
        }
示例#2
0
        /// <summary>
        /// A function which processes the part of the stream which gets available (or does the rest of it at the end).
        /// </summary>
        public void PumpStream()
        {
            if(_isDisposed)
                return; // Nonfiring, yep

            // Try acquiring the stream if not yet
            _fstream = _fstream ?? FindAnsiLogFile();

            // No ANSI stream file (yet?)
            if(_fstream == null)
                return;

            // Read the available chunk
            long length = _fstream.Length; // Take the length and keep it for the rest of the iteration, might change right as we're reading
            if(_fstream.Position >= length)
                return; // Nothing new
            var buffer = new byte[length - _fstream.Position]; // TODO: buffer pooling to save mem traffic
            int nRead = _fstream.Read(buffer, 0, buffer.Length);
            if(nRead <= 0)
                return; // Hmm should have succeeded, but anyway

            // Make a smaller buffer if we got less data (unlikely)
            AnsiStreamChunkEventArgs args;
            if(nRead < buffer.Length)
            {
                var subbuffer = new byte[nRead];
                Buffer.BlockCopy(buffer, 0, subbuffer, 0, nRead);
                args = new AnsiStreamChunkEventArgs(subbuffer);
            }
            else
                args = new AnsiStreamChunkEventArgs(buffer);

            // Fire
            AnsiStreamChunkReceived?.Invoke(this, args);
        }