Пример #1
0
        async Task <IMessage> IMessageHandler.ReceiveMessage(IAddressee sender, IMessage message, object context)
        {
            Equal("Request", message.Name);
            Equal("text/plain", message.Type.MediaType);
            var text = await message.ReadAsTextAsync();

            Equal("Ping", text);
            return(new TextMessage("Pong", "Reply"));
        }
Пример #2
0
 /// <summary>
 /// Send one-way text message.
 /// </summary>
 /// <param name="messenger">The receiver of the message.</param>
 /// <param name="messageName">The name of the message.</param>
 /// <param name="text">The content of the message.</param>
 /// <param name="mediaType">The media type of the message content.</param>
 /// <param name="requiresConfirmation"><see langword="true"/> to wait for confirmation of delivery from receiver; otherwise, <see langword="false"/>.</param>
 /// <param name="token">The token that can be used to cancel asynchronous operation.</param>
 /// <returns>The task representing asynchronous execution of the method.</returns>
 public static Task SendTextSignalAsync(this IAddressee messenger, string messageName, string text, bool requiresConfirmation = true, string mediaType = null, CancellationToken token = default)
 => messenger.SendSignalAsync(new TextMessage(messageName, text, mediaType), requiresConfirmation, token);
Пример #3
0
 /// <summary>
 /// Send synchronous text message.
 /// </summary>
 /// <typeparam name="TResponse">The type of the parsed response message.</typeparam>
 /// <param name="messenger">The receiver of the message.</param>
 /// <param name="responseReader">The response reader.</param>
 /// <param name="messageName">The name of the message.</param>
 /// <param name="text">The content of the message.</param>
 /// <param name="mediaType">The media type of the message content.</param>
 /// <param name="token">The token that can be used to cancel asynchronous operation.</param>
 /// <returns>The reply message.</returns>
 public static Task <TResponse> SendTextMessageAsync <TResponse>(this IAddressee messenger, MessageReader <TResponse> responseReader, string messageName, string text, string mediaType = null, CancellationToken token = default)
 => messenger.SendMessageAsync(new TextMessage(messageName, text, mediaType), responseReader, token);
Пример #4
0
 async Task IMessageHandler.ReceiveSignal(IAddressee sender, IMessage signal, object context)
 => Enqueue(await StreamMessage.CreateBufferedMessageAsync(signal).ConfigureAwait(false));