From 1fb3d2bb8b72a7e5f7760e784a61ffc6b6cd2687 Mon Sep 17 00:00:00 2001 From: GyroGearl00se Date: Tue, 17 Sep 2024 01:26:35 +0200 Subject: [PATCH] Reapply "return whole class MessageDetails instead of messageContent to enrich DataGrid with more details." This reverts commit df34f9991762d0b39c74177b2c70bc0244cdc1be. --- Services/SolaceSubscribeService.cs | 85 +++++++++++++++++++++++++++--- wwwroot/app.css | 16 ++++++ 2 files changed, 93 insertions(+), 8 deletions(-) diff --git a/Services/SolaceSubscribeService.cs b/Services/SolaceSubscribeService.cs index dd92490..23cd09d 100644 --- a/Services/SolaceSubscribeService.cs +++ b/Services/SolaceSubscribeService.cs @@ -1,5 +1,6 @@ using Microsoft.Extensions.Logging; using SolaceSystems.Solclient.Messaging; +using SolaceSystems.Solclient.Messaging.SDT; using System; using System.Text; using System.Threading.Tasks; @@ -19,7 +20,7 @@ public SolaceSubscribeService(ILogger logger) } - public void SubscribeToTopic(string host, string vpnName, string username, string password, string topic, bool sslVerify, Action messageHandler) + public void SubscribeToTopic(string host, string vpnName, string username, string password, string topic, bool sslVerify, Action messageHandler) { try { @@ -61,23 +62,91 @@ public void SubscribeToTopic(string host, string vpnName, string username, strin } } - public void HandleMessage(object source, MessageEventArgs args, Action messageHandler) + public void HandleMessage(object source, MessageEventArgs args, Action messageHandler) { try { using (IMessage message = args.Message) { + string formattedDateTime; + + if (message.SenderTimestamp == -1) + { + formattedDateTime = ""; + } + else + { + DateTimeOffset dateTimeOffset = DateTimeOffset.FromUnixTimeMilliseconds(message.SenderTimestamp); + formattedDateTime = dateTimeOffset.ToString("yyyy-MM-dd HH:mm:ss"); + } + + Dictionary keyValuePairs = new Dictionary(); + + var userPropertyMap = message.UserPropertyMap; + if (userPropertyMap != null) + { + while (true) + { + var nextKeyValuePair = userPropertyMap.GetNext(); + if (nextKeyValuePair.Key == null) + { + break; + } + var key = nextKeyValuePair.Key; + var valueObject = nextKeyValuePair.Value; + var value = ((ISDTField)valueObject).Value; + 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 = ""; + } + } - byte[] binaryAttachment = message.BinaryAttachment; - if (binaryAttachment != null && binaryAttachment.Length > 0) + int messageSize = 0; + if (message.BinaryAttachment != null) { - messageContent = Encoding.UTF8.GetString(binaryAttachment); - messageHandler(messageContent); - } else + byte[] binaryAttachment = message.BinaryAttachment; + messageSize = binaryAttachment.Length; + } + else if (message.XmlContent != null) { - messageHandler("Message without payload"); + messageSize = message.XmlContent.Length; } + else if (SDTUtils.GetText(message) != null) + { + messageSize = SDTUtils.GetText(message).Length; + } + + messageHandler(new MessageDetails + { + DestinationName = message.Destination.Name != null ? message.Destination.Name : "", + ApplicationMessageType = message.ApplicationMessageType != null ? message.ApplicationMessageType : "", + ApplicationMessageId = message.ApplicationMessageId != null ? message.ApplicationMessageId : "", + SenderId = message.SenderId != null ? message.SenderId : "", + MessageContent = messageContent, + MessageContentXML = message.XmlContent != null ? System.Text.Encoding.ASCII.GetString(message.XmlContent) : "", + CorrelationId = message.CorrelationId != null ? message.CorrelationId : "", + ADMessageId = message.ADMessageId != 0 ? message.ADMessageId : 0, + FormattedDateTime = formattedDateTime, + UserProperties = keyValuePairs, + DeliveryMode = message.DeliveryMode.ToString(), + Size = messageSize + }); } } catch (OperationErrorException ex) diff --git a/wwwroot/app.css b/wwwroot/app.css index 5a38e43..cc4778b 100644 --- a/wwwroot/app.css +++ b/wwwroot/app.css @@ -201,4 +201,20 @@ h1:focus { .modal-content { background-color: #303030; +} + +.datagrid tbody tr:hover { + color: #00C895; +} + +.detail-row-user-properties { + color: #e0e0e0; +} + +.detail-row-message-content { + color: #e0e0e0; + max-width: 90em; + overflow: clip; + border: 1px solid #ccc; + padding: 10px; } \ No newline at end of file