namespace WatsonTcp
{
using System;
using System.Threading.Tasks;
///
/// Watson TCP client callbacks.
///
public class WatsonTcpClientCallbacks
{
#region Public-Members
///
/// Function called when authentication is requested from the server. Expects the 16-byte preshared key.
///
public Func AuthenticationRequested = null;
///
/// Callback to invoke when receiving a synchronous request that demands a response.
///
[Obsolete("Please migrate to async methods.")]
public Func SyncRequestReceived
{
get
{
return _SyncRequestReceived;
}
set
{
_SyncRequestReceived = value;
}
}
///
/// Callback to invoke when receiving a synchronous request that demands a response.
///
public Func> SyncRequestReceivedAsync
{
get
{
return _SyncRequestReceivedAsync;
}
set
{
_SyncRequestReceivedAsync = value;
}
}
#endregion
#region Private-Members
private Func _SyncRequestReceived = null;
private Func> _SyncRequestReceivedAsync = null;
#endregion
#region Constructors-and-Factories
///
/// Instantiate.
///
public WatsonTcpClientCallbacks()
{
}
#endregion
#region Public-Methods
#endregion
#region Internal-Methods
internal string HandleAuthenticationRequested()
{
string ret = null;
if (AuthenticationRequested != null)
{
try
{
ret = AuthenticationRequested();
}
catch (Exception)
{
}
}
return ret;
}
internal SyncResponse HandleSyncRequestReceived(SyncRequest req)
{
SyncResponse ret = null;
#pragma warning disable CS0618 // Type or member is obsolete
if (SyncRequestReceived != null)
{
try
{
ret = SyncRequestReceived(req);
}
catch (Exception)
{
}
}
#pragma warning restore CS0618 // Type or member is obsolete
return ret;
}
internal async Task HandleSyncRequestReceivedAsync(SyncRequest req)
{
SyncResponse ret = null;
if (SyncRequestReceivedAsync != null)
{
try
{
ret = await SyncRequestReceivedAsync(req);
}
catch (Exception)
{
}
}
return ret;
}
#endregion
#region Private-Methods
#endregion
}
}