private void OnMessage(SseEvent sseEvent) { if (Message != null) { Message(sseEvent); } }
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); } } }
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); } } }
public static bool TryParse(string line, out SseEvent sseEvent) { sseEvent = null; if (line.StartsWith("data:", StringComparison.OrdinalIgnoreCase)) { string data = line.Substring("data:".Length).Trim(); sseEvent = new SseEvent(EventType.Data, data); return(true); } else if (line.StartsWith("id:", StringComparison.OrdinalIgnoreCase)) { string data = line.Substring("id:".Length).Trim(); sseEvent = new SseEvent(EventType.Id, data); return(true); } return(false); }
public static bool TryParse(string line, out SseEvent sseEvent) { sseEvent = null; if (line.StartsWith("data:", StringComparison.OrdinalIgnoreCase)) { string data = line.Substring("data:".Length).Trim(); sseEvent = new SseEvent(EventType.Data, data); return true; } else if (line.StartsWith("id:", StringComparison.OrdinalIgnoreCase)) { string data = line.Substring("id:".Length).Trim(); sseEvent = new SseEvent(EventType.Id, data); return true; } return false; }