コード例 #1
0
 private void OnMessage(SseEvent sseEvent)
 {
     if (Message != null)
     {
         Message(sseEvent);
     }
 }
コード例 #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);
                }
            }
        }
コード例 #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);
                }
            }
        }
コード例 #4
0
 private void OnMessage(SseEvent sseEvent)
 {
     if (Message != null)
     {
         Message(sseEvent);
     }
 }
コード例 #5
0
        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);
        }
コード例 #6
0
ファイル: SseEvent.cs プロジェクト: Kazzje/SignalR
        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;
        }