Skip to content

Commit

Permalink
Reapply "return whole class MessageDetails instead of messageContent …
Browse files Browse the repository at this point in the history
…to enrich DataGrid with more details."

This reverts commit df34f99.
  • Loading branch information
GyroGearl00se committed Sep 16, 2024
1 parent df34f99 commit 1fb3d2b
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 8 deletions.
85 changes: 77 additions & 8 deletions Services/SolaceSubscribeService.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -19,7 +20,7 @@ public SolaceSubscribeService(ILogger<SolaceSubscribeService> logger)

}

public void SubscribeToTopic(string host, string vpnName, string username, string password, string topic, bool sslVerify, Action<string> messageHandler)
public void SubscribeToTopic(string host, string vpnName, string username, string password, string topic, bool sslVerify, Action<MessageDetails> messageHandler)
{
try
{
Expand Down Expand Up @@ -61,23 +62,91 @@ public void SubscribeToTopic(string host, string vpnName, string username, strin
}
}

public void HandleMessage(object source, MessageEventArgs args, Action<string> messageHandler)
public void HandleMessage(object source, MessageEventArgs args, Action<MessageDetails> 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<string, object> keyValuePairs = new Dictionary<string, object>();

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)
Expand Down
16 changes: 16 additions & 0 deletions wwwroot/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

0 comments on commit 1fb3d2b

Please sign in to comment.