JD2022-TU1/main/tools/framework/JD.Remoting/MessageSenderExtensions.cs

27 lines
No EOL
1.1 KiB
C#

using System;
using JD.Interfaces.Remoting;
namespace JD.Remoting
{
/// <summary>
/// Adds behavior to the basic connection interface.
/// </summary>
public static class MessageSenderExtensions
{
/// <summary>
/// Sends a message to the host connected.
/// </summary>
/// <param name="messageSender"></param>
/// <param name="messageName">Name of the message to send.</param>
/// <param name="writeBlobAction">When provided, will be used to fill the content of the command.</param>
/// <returns>0 if operation succeeded, a non-zero value otherwise.
/// See Windows Sockets Error Codes page for more information on error codes. </returns>
/// <exception cref="System.ObjectDisposedException">The System.Net.Socket has been closed. </exception>
public static int Send(this IMessageSender messageSender, string messageName, Action<IBlob> writeBlobAction = null)
{
var message = new Message(messageName);
writeBlobAction?.Invoke(message.Content);
return messageSender.Send(message);
}
}
}