示例#1
0
        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();
            }
        }
示例#2
0
        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();
            }
        }
示例#3
0
        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();
            }
        }
示例#4
0
 internal Task OnChannelMessageReceivedAsync(AtomChannel channel, AtomMessage message)
 {
     return(this._plugin.OnChannelMessageReceivedAsync(channel, message));
 }
示例#5
0
 internal Task OnChannelSendingMessageAsync(AtomChannel channel, AtomMessage message)
 {
     return(this._plugin.OnChannelSendingMessageAsync(channel, message));
 }
示例#6
0
        public AtomClientMessageReceivedEventArgs(AtomMessage message)
        {
            Guard.NotNull(message, nameof(message));

            this.Message = message;
        }