public void SendActionableResponse(ClientRequestInfo requestInfo, bool success, object attachment = null, string status = null, params object[] args)
{
try
{
string responseType = requestInfo.Request.Command + (success ? ":Success" : ":Failure");
string message = "";
if (!string.IsNullOrWhiteSpace(status))
{
if (args.Length == 0)
message = status + "\r\n\r\n";
else
message = string.Format(status, args) + "\r\n\r\n";
}
ServiceResponse response = new ServiceResponse(responseType, CurtailMessageLength(message));
// Add any specified attachment to the service response
if ((object)attachment != null)
response.Attachments.Add(attachment);
// Add original command arguments as an attachment
response.Attachments.Add(requestInfo.Request.Arguments);
// Send response to service
SendResponse(requestInfo.Sender.ClientID, response);
OnUpdatedStatus(requestInfo.Sender.ClientID, response.Message, success ? UpdateType.Information : UpdateType.Alarm);
}
catch (Exception ex)
{
ErrorLogger.Log(ex);
UpdateStatus(UpdateType.Alarm, "Failed to send actionable client response with attachment due to an exception: " + ex.Message + "\r\n\r\n");
}
}