private async Task ListenForNotificationsAsync(Stream stream)
        {
            var socketState = new NotificationListenerSocketState();

            try
            {
                while (_clientSocket != null)
                {
                    var receivedDataLength =
                        await stream.ReadAsync(socketState.Buffer, 0, NotificationListenerSocketState.BufferSize);

                    var receivedDataJson = Encoding.UTF8.GetString(socketState.Buffer, 0, receivedDataLength);

                    socketState.Builder.Append(receivedDataJson);

                    if (TryParseObject(socketState.Builder.ToString(), out var jObject))
                    {
                        ParseNotification(jObject);

                        socketState = new NotificationListenerSocketState();
                    }
                    else
                    {
                        // Begin listening for remainder of announcement using same socket state
                    }
                }
            }
            catch (Exception)
            {
            }
        }
Exemple #2
0
        private async Task ListenForNotifications(Stream stream)
        {
            var socketState = new NotificationListenerSocketState();

            try
            {
                while (_clientSocket != null)
                {
                    var receivedDataLength =
                        await stream.ReadAsync(socketState.Buffer, 0, NotificationListenerSocketState.BufferSize);

                    var receivedDataJson = Encoding.UTF8.GetString(socketState.Buffer, 0, receivedDataLength);

                    socketState.Builder.Append(receivedDataJson);

                    JObject jObject;
                    if (TryParseObject(socketState.Builder.ToString(), out jObject))
                    {
                        ParseNotification(jObject);

                        socketState = new NotificationListenerSocketState();
                    }
                }
            }
            catch (Exception)
            {
            }
        }