Skip to content

Commit

Permalink
Read string messages using GetBody<string>() (#776)
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikMogensen authored Apr 23, 2024
1 parent 979cee5 commit 9990a4f
Showing 1 changed file with 33 additions and 19 deletions.
52 changes: 33 additions & 19 deletions src/ServiceBusExplorer/Forms/MessageForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,18 +97,18 @@ public partial class MessageForm : Form

static readonly List<string> Types = new List<string>
{
"Boolean",
"Byte",
"Int16",
"Int32",
"Int64",
"Single",
"Double",
"Decimal",
"Guid",
"DateTime",
"TimeSpan",
"String",
"Boolean",
"Byte",
"Int16",
"Int32",
"Int64",
"Single",
"Double",
"Decimal",
"Guid",
"DateTime",
"TimeSpan",
"String",
"Char",
"UInt64",
"UInt32",
Expand Down Expand Up @@ -221,7 +221,7 @@ public MessageForm(BrokeredMessage brokeredMessage, ServiceBusHelper serviceBusH
}
}

public MessageForm(QueueDescription queueDescription, QueueType queueType, BrokeredMessage brokeredMessage,
public MessageForm(QueueDescription queueDescription, QueueType queueType, BrokeredMessage brokeredMessage,
ServiceBusHelper serviceBusHelper, WriteToLogDelegate writeToLog) :
this(brokeredMessage, serviceBusHelper, writeToLog)
{
Expand Down Expand Up @@ -427,9 +427,23 @@ private async void btnSubmit_Click(object sender, EventArgs e)
MainForm.SingletonMainForm.UseAscii, out bodyType);

// For body type ByteArray cloning is not an option. When cloned, supplied body can be only of a string or stream types, but not byte array :(
outboundMessage = bodyType == BodyType.ByteArray ?
message.CloneWithByteArrayBodyType(messageText, messagesSplitContainer.Visible) :
message.Clone(message.GetBody<Stream>(), messagesSplitContainer.Visible);
switch (bodyType)
{
case BodyType.ByteArray:
outboundMessage = message.CloneWithByteArrayBodyType(messageText,
messagesSplitContainer.Visible);
break;

case BodyType.String:
outboundMessage = message.Clone(message.GetBody<string>(),
messagesSplitContainer.Visible);
break;

default:
outboundMessage = message.Clone(message.GetBody<Stream>(),
messagesSplitContainer.Visible);
break;
}
}

outboundMessage = serviceBusHelper.CreateMessageForApiReceiver(outboundMessage,
Expand Down Expand Up @@ -504,12 +518,12 @@ private async void btnSubmit_Click(object sender, EventArgs e)
var messageHandler = CreateDeadLetterMessageHandler();

var result = await messageHandler.MoveMessages(messageSender,
sequenceNumbers,
transferDLQ: queueType == QueueType.TransferDeadletter,
sequenceNumbers,
transferDLQ: queueType == QueueType.TransferDeadletter,
outboundMessages);

RemovedSequenceNumbers = result.DeletedSequenceNumbers;

stopwatch.Stop();

if (result.TimedOut)
Expand Down

0 comments on commit 9990a4f

Please sign in to comment.