SignalR.Client._20.Transports.ServerSentEventsTransport.AsyncStreamReader.ProcessChunks C# (CSharp) Method

ProcessChunks() private method

private ProcessChunks ( ) : void
return void
            private void ProcessChunks()
            {
                while (Reading && _buffer.HasChunks)
                {
                    string line = _buffer.ReadLine();

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

                    if (!Reading)
                    {
                        return;
                    }

                    // Try parsing the sseEvent
                    SseEvent sseEvent;
                    if (!TryParseEvent(line, out sseEvent))
                    {
                        continue;
                    }

                    if (!Reading)
                    {
                        return;
                    }

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

                    switch (sseEvent.Type)
                    {
                        case EventType.Id:
                            long id;
                            if (Int64.TryParse(sseEvent.Data, out id))
                            {
                                _connection.MessageId = id;
                            }
                            break;
                        case EventType.Data:
                            if (sseEvent.Data.Equals("initialized", StringComparison.OrdinalIgnoreCase))
                            {
                                if (_initializeCallback != null)
                                {
                                    // Mark the connection as started
                                    _initializeCallback();
                                }
                            }
                            else
                            {
                                if (Reading)
                                {
                                    // We don't care about timedout messages here since it will just reconnect
                                    // as part of being a long running request
                                    bool timedOutReceived;
                                    bool disconnectReceived;

                                    ProcessResponse(_connection, sseEvent.Data, out timedOutReceived, out disconnectReceived);

                                    if (disconnectReceived)
                                    {
                                        _connection.Stop();
                                    }

                                    if (timedOutReceived)
                                    {
                                        return;
                                    }
                                }
                            }
                            break;
                    }
                }
            }