public void TestMessageSetToReadOnlyOnSend() { NmsMessage message = factory.CreateMessage(); Assert.False(message.IsReadOnly); Assert.False(message.IsReadOnlyProperties); message.OnSend(TimeSpan.Zero); Assert.True(message.IsReadOnly); }
public static NmsMessage TransformMessage(INmsMessageFactory factory, IMessage message) { NmsMessage nmsMessage = null; if (message is IBytesMessage bytesMessage) { bytesMessage.Reset(); NmsBytesMessage msg = factory.CreateBytesMessage(); try { while (true) { // Reads a byte from the message stream until the stream is empty msg.WriteByte(bytesMessage.ReadByte()); } } catch (MessageEOFException) { // Indicates all the bytes have been read from the source. } nmsMessage = msg; } else if (message is IMapMessage mapMessage) { NmsMapMessage msg = factory.CreateMapMessage(); CopyMap(mapMessage.Body, msg.Body); nmsMessage = msg; } else if (message is IObjectMessage objectMessage) { NmsObjectMessage msg = factory.CreateObjectMessage(); msg.Body = objectMessage.Body; nmsMessage = msg; } else if (message is IStreamMessage streamMessage) { streamMessage.Reset(); NmsStreamMessage msg = factory.CreateStreamMessage(); try { while (true) { // Reads a byte from the message stream until the stream is empty msg.WriteObject(streamMessage.ReadObject()); } } catch (MessageEOFException) { // Indicates all the stream have been read from the source. } nmsMessage = msg; } else if (message is ITextMessage textMessage) { NmsTextMessage msg = factory.CreateTextMessage(); msg.Text = textMessage.Text; nmsMessage = msg; } else { nmsMessage = factory.CreateMessage(); } CopyProperties(message, nmsMessage); return(nmsMessage); }