private static void CopyProperties(IMessage source, NmsMessage target) { target.NMSMessageId = source.NMSMessageId; target.NMSCorrelationID = source.NMSCorrelationID; target.NMSDestination = source.NMSDestination; target.NMSReplyTo = source.NMSReplyTo; target.NMSDeliveryMode = source.NMSDeliveryMode; target.NMSRedelivered = source.NMSRedelivered; target.NMSType = source.NMSType; target.NMSPriority = source.NMSPriority; target.NMSTimestamp = source.NMSTimestamp; CopyMap(source.Properties, target.Properties); }
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); }