namespace WatsonTcp
{
using System;
using System.Collections.Generic;
using System.Text;
///
/// Response to a synchronous request.
///
public class SyncResponse
{
#region Public-Members
///
/// Metadata to attach to the response.
///
public Dictionary Metadata { get; } = new Dictionary();
///
/// Data to attach to the response.
///
public byte[] Data { get; }
///
/// Conversation GUID.
///
public Guid ConversationGuid { get; } = Guid.NewGuid();
///
/// The time at which the request expires.
///
public DateTime ExpirationUtc { get; }
#endregion
#region Private-Members
#endregion
#region Constructors-and-Factories
///
/// Instantiate.
///
/// The synchronous request for which this response is intended.
/// Data to send as a response.
public SyncResponse(SyncRequest req, string data)
{
if (req == null) throw new ArgumentNullException(nameof(req));
ExpirationUtc = req.ExpirationUtc;
ConversationGuid = req.ConversationGuid;
if (String.IsNullOrEmpty(data)) Data = Array.Empty();
else Data = Encoding.UTF8.GetBytes(data);
}
///
/// Instantiate.
///
/// The synchronous request for which this response is intended.
/// Data to send as a response.
public SyncResponse(SyncRequest req, byte[] data)
{
if (req == null) throw new ArgumentNullException(nameof(req));
ExpirationUtc = req.ExpirationUtc;
ConversationGuid = req.ConversationGuid;
Data = data;
}
///
/// Instantiate.
///
/// The synchronous request for which this response is intended.
/// Metadata to attach to the response.
/// Data to send as a response.
public SyncResponse(SyncRequest req, Dictionary metadata, string data)
{
if (req == null) throw new ArgumentNullException(nameof(req));
ExpirationUtc = req.ExpirationUtc;
ConversationGuid = req.ConversationGuid;
Metadata = metadata;
if (String.IsNullOrEmpty(data))
{
Data = Array.Empty();
}
else
{
Data = Encoding.UTF8.GetBytes(data);
}
}
///
/// Instantiate.
///
/// The synchronous request for which this response is intended.
/// Metadata to attach to the response.
/// Data to send as a response.
public SyncResponse(SyncRequest req, Dictionary metadata, byte[] data)
{
if (req == null) throw new ArgumentNullException(nameof(req));
ExpirationUtc = req.ExpirationUtc;
ConversationGuid = req.ConversationGuid;
Metadata = metadata;
Data = data;
}
///
/// Instantiate.
///
///
///
///
///
public SyncResponse(Guid convGuid, DateTime expirationUtc, Dictionary metadata, byte[] data)
{
ConversationGuid = convGuid;
ExpirationUtc = expirationUtc;
Metadata = metadata;
Data = data;
}
#endregion
#region Public-Methods
#endregion
#region Private-Methods
#endregion
}
}