ReadLine() public method

public ReadLine ( ) : string
return string
Exemplo n.º 1
0
            public void CanReadMultipleLines()
            {
                // Arrange
                var buffer = new ChunkBuffer();
                byte[] data = Encoding.UTF8.GetBytes("hel\nlo world\noy");

                // Act
                buffer.Add(data, data.Length);

                // Assert
                Assert.Equal("hel", buffer.ReadLine());
                Assert.Equal("lo world", buffer.ReadLine());
                Assert.Null(buffer.ReadLine());
            }
Exemplo n.º 2
0
        private void ProcessBuffer(int read)
        {
            lock (_lockObj)
            {
                _buffer.Add(_readBuffer, read);

                while (_buffer.HasChunks)
                {
                    string line = _buffer.ReadLine();

                    // No new lines in the buffer so stop processing
                    if (line == null)
                    {
                        break;
                    }

                    SseEvent sseEvent;
                    if (!SseEvent.TryParse(line, out sseEvent))
                    {
                        continue;
                    }

                    Debug.WriteLine("SSE READ: " + sseEvent);

                    OnMessage(sseEvent);
                }
            }
        }
Exemplo n.º 3
0
        private void ProcessBuffer(ArraySegment <byte> readBuffer)
        {
            lock (BufferLock)
            {
                _buffer.Add(readBuffer);

                while (_buffer.HasChunks)
                {
                    string line = _buffer.ReadLine();

                    // No new lines in the buffer so stop processing
                    if (line == null)
                    {
                        break;
                    }

                    SseEvent sseEvent;
                    if (!SseEvent.TryParse(line, out sseEvent))
                    {
                        continue;
                    }

                    _connection.Trace(TraceLevels.Messages, "SSE: OnMessage({0})", sseEvent);

                    OnMessage(sseEvent);
                }
            }
        }
Exemplo n.º 4
0
 public void WillCompleteNewLine()
 {
     // Arrange
     var buffer = new ChunkBuffer();
     byte[] data = Encoding.UTF8.GetBytes("hello");
     buffer.Add(data, data.Length);
     Assert.Null(buffer.ReadLine());
     data = Encoding.UTF8.GetBytes("\n");
     buffer.Add(data, data.Length);
     Assert.Equal("hello", buffer.ReadLine());
     data = Encoding.UTF8.GetBytes("Another line");
     buffer.Add(data, data.Length);
     Assert.Null(buffer.ReadLine());
     data = Encoding.UTF8.GetBytes("\nnext");
     buffer.Add(data, data.Length);
     Assert.Equal("Another line", buffer.ReadLine());
 }
Exemplo n.º 5
0
            public void ReturnsTextUpToNewLine()
            {
                // Arrange
                var buffer = new ChunkBuffer();
                byte[] data = Encoding.UTF8.GetBytes("hello world\noy");

                // Act
                buffer.Add(data, data.Length);

                // Assert
                Assert.Equal("hello world", buffer.ReadLine());
            }
Exemplo n.º 6
0
            public void ReturnsNullIfNoNewLineIfBuffer()
            {
                // Arrange
                var buffer = new ChunkBuffer();
                byte[] data = Encoding.UTF8.GetBytes("hello world");

                // Act
                buffer.Add(data, data.Length);

                // Assert
                Assert.Null(buffer.ReadLine());
            }