Skip to content

Commit

Permalink
- check if message is a text message or binary byte message
Browse files Browse the repository at this point in the history
- check if SenderTimestamp not present
  • Loading branch information
GyroGearl00se committed Jun 19, 2024
1 parent 115f010 commit b62f4fc
Showing 1 changed file with 31 additions and 3 deletions.
34 changes: 31 additions & 3 deletions Services/QueueBrowserService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,17 @@ public async Task<List<MessageDetails>> BrowseQueueAsync(string host, string vpn
while ((message = await Task.Run(() => browser.GetNext())) != null && messageCount < maxMessages)
{
//_logger.LogInformation("Message received: {message}", Encoding.UTF8.GetString(message.BinaryAttachment));
DateTimeOffset dateTimeOffset = DateTimeOffset.FromUnixTimeMilliseconds(message.SenderTimestamp);
string formattedDateTime = dateTimeOffset.ToString("yyyy-MM-dd HH:mm:ss");

string formattedDateTime;

if (message.SenderTimestamp == -1)
{
formattedDateTime = "N/A";
} else
{
DateTimeOffset dateTimeOffset = DateTimeOffset.FromUnixTimeMilliseconds(message.SenderTimestamp);
formattedDateTime = dateTimeOffset.ToString("yyyy-MM-dd HH:mm:ss");
}

Dictionary<string, object> keyValuePairs = new Dictionary<string, object>();

Expand All @@ -116,13 +125,32 @@ public async Task<List<MessageDetails>> BrowseQueueAsync(string host, string vpn
keyValuePairs.Add(key, value);
}
}

string messageContent;
if (SDTUtils.GetText(message) != null)
{
messageContent = SDTUtils.GetText(message);
}
else
{
byte[] binaryAttachment = message.BinaryAttachment;
if (binaryAttachment != null && binaryAttachment.Length > 0)
{
messageContent = Encoding.UTF8.GetString(binaryAttachment);
}
else
{
messageContent = "";
}
}

messages.Add(new MessageDetails
{
DestinationName = message.Destination.Name != null ? message.Destination.Name : "N/A",
ApplicationMessageType = message.ApplicationMessageType != null ? message.ApplicationMessageType : "N/A",
ApplicationMessageId = message.ApplicationMessageId != null ? message.ApplicationMessageId : "N/A",
SenderId = message.SenderId != null ? message.SenderId : "N/A",
MessageContent = message.BinaryAttachment != null ? System.Text.Encoding.ASCII.GetString(message.BinaryAttachment) : "",
MessageContent = messageContent,
MessageContentXML = message.XmlContent != null ? System.Text.Encoding.ASCII.GetString(message.XmlContent) : "",
CorrelationId = message.CorrelationId != null ? message.CorrelationId : "N/A",
ADMessageId = message.ADMessageId != 0 ? message.ADMessageId : 0,
Expand Down

0 comments on commit b62f4fc

Please sign in to comment.