private async void ReadFromClient() { try { while (this._client != null && this._client.Connected && this._stream != null) { var data = await this._stream.ReadRawMessageAsync(); if (data == null) { await this.DisconnectAsync(); break; } var message = AtomMessage.Incoming(data); await this._plugin.OnMessageReceivedAsync(message); this.MessageReceived?.Invoke(this, new AtomClientMessageReceivedEventArgs(message)); } } catch { await this.DisconnectAsync(); } }
private async void ReadFromChannel() { try { while (this._channel.Connected) { var data = await this._stream.ReadRawMessageAsync(); if (data == null) { await this.DisconnectAsync(); break; } var message = AtomMessage.Incoming(data); await this._parent.OnChannelMessageReceivedAsync(this, message); this.MessageReceived?.Invoke(this, new AtomChannelMessageReceivedEventArgs(message)); } } catch { await this.DisconnectAsync(); } }
public async Task SendMessageAsync(AtomMessage message) { Guard.NotNull(message, nameof(message)); await this._lock.WaitAsync(); try { await this._plugin.OnSendingMessageAsync(message); await this._stream.WriteRawMessageAsync(message.Data); } catch { await this.DisconnectAsync(); } finally { this._lock.Release(); } }
internal Task OnChannelMessageReceivedAsync(AtomChannel channel, AtomMessage message) { return(this._plugin.OnChannelMessageReceivedAsync(channel, message)); }
internal Task OnChannelSendingMessageAsync(AtomChannel channel, AtomMessage message) { return(this._plugin.OnChannelSendingMessageAsync(channel, message)); }
public AtomClientMessageReceivedEventArgs(AtomMessage message) { Guard.NotNull(message, nameof(message)); this.Message = message; }