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

43 lines
1.4 KiB
C#

using System;
using JD.Interfaces.Remoting;
using JD.Remoting.Details;
namespace JD.Remoting
{
/// <summary>
/// The Message is the logical communication element, user can send a message by creating a new one or by simply using the "Send" method.
/// </summary>
public class Message : IMessage
{
/// <summary>
/// Gets the content of the message at the current read/write position.
/// </summary>
public IBlob Content { get; private set; }
/// <summary>
/// The command
/// </summary>
public string CommandName
{
get { return Header.CommandName; }
}
/// <summary>
/// The parsed header from the engine message
/// </summary>
internal MessageHeader Header { get; set; }
/// <summary>
/// Builds a message either to read from or to write into.
/// </summary>
/// <remarks>When the plugin name is not specified, it is automatically filled with the appropriate value.</remarks>
public Message(string commandName, IBlob content = null)
{
if (string.IsNullOrEmpty(commandName))
throw new ArgumentException("CommandName cannot be left empty");
Content = content ?? new Blob(allowRead: true);
Header = new MessageHeader { CommandName = commandName };
}
}
}