internal async Task <bool> SendAsync(ServerSentEventBytes serverSentEvent, CancellationToken cancellationToken, LogLevel minLogLevel = LogLevel.Debug)
        {
            try {
                CheckIsConnected(); // it is up to the caller to first check IsConnected, this will throw if IsConnected == false
                if (MarkedForDisconnection)
                {
                    _logger.Log(minLogLevel, $"Client SendAsync: Client is Marked for Disconnection, event will not be sent to: {this.ToString()}");
                    return(false);
                }
                _logger.Log(minLogLevel, $"Client SendAsync: Sending Event to: {this.ToString()}");
                await _response.WriteAsync(serverSentEvent, cancellationToken);

                return(true);
            } catch (Exception ex) {
                if (_logger != null)
                {
                    _logger.LogError($"Client SendAsync: Error: {this.ToString()} Exception: {ex.Message}");
                }
                return(false);
            }
        }
Esempio n. 2
0
 internal static Task WriteAsync(this HttpResponse response, ServerSentEventBytes serverSentEvent, CancellationToken cancellationToken)
 {
     return(response.Body.WriteAsync(serverSentEvent.Bytes, 0, serverSentEvent.BytesCount, cancellationToken));
 }
Esempio n. 3
0
 internal static Task WriteAsync(this HttpResponse response, ServerSentEventBytes serverSentEvent)
 {
     return(response.Body.WriteAsync(serverSentEvent.Bytes, 0, serverSentEvent.BytesCount));
 }
        internal Task SendAsync(ServerSentEventBytes serverSentEvent)
        {
            CheckIsConnected();

            return(_response.WriteAsync(serverSentEvent));
        }
Esempio n. 5
0
        internal Task SendAsync(ServerSentEventBytes serverSentEvent, CancellationToken cancellationToken)
        {
            CheckIsConnected();

            return(_response.WriteAsync(serverSentEvent, cancellationToken));
        }