From b62f4fc9344fa2d75601dc9070250404024a3c28 Mon Sep 17 00:00:00 2001 From: GyroGearl00se Date: Thu, 20 Jun 2024 01:36:02 +0200 Subject: [PATCH] - check if message is a text message or binary byte message - check if SenderTimestamp not present --- Services/QueueBrowserService.cs | 34 ++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/Services/QueueBrowserService.cs b/Services/QueueBrowserService.cs index f12a232..e48bfe9 100644 --- a/Services/QueueBrowserService.cs +++ b/Services/QueueBrowserService.cs @@ -95,8 +95,17 @@ public async Task> 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 keyValuePairs = new Dictionary(); @@ -116,13 +125,32 @@ public async Task> 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,