public static TransportMessage Convert(IBM.XMS.IMessage m)
        {
            var result = new TransportMessage();
            result.Id = GetRealMessageId(m);
            result.CorrelationId = m.JMSCorrelationID;
            result.Recoverable = m.JMSDeliveryMode == DeliveryMode.Persistent;
            result.IdForCorrelation = m.GetStringProperty(HEADER_IDFORCORRELATION);
            result.ReplyToAddress = m.GetStringProperty(HEADER_RETURNADDRESS).ToXmsAddress().ToNsbAddress();
            //result.WindowsIdentityName = m.GetStringProperty(HEADER_WINDOWSIDENTITYNAME);
            result.MessageIntent = (MessageIntentEnum)m.GetIntProperty(HEADER_MESSAGEINTENT);
            //result.TimeSent = baseDate.AddMilliseconds(m.JMSTimestamp);
            result.Headers = new Dictionary<string, string>();
            //TODO:
            //result.TimeToBeReceived = DateTime.UtcNow - baseDate.AddMilliseconds(m.JMSExpiration);
            if (m.GetStringProperty("NSBKeys") != null)
            {
                var keys = UnwrapKeys(m.GetStringProperty("NSBKeys"));

                result.Headers = (from k in keys
                                  select new {Key = k.FromXmsFriendly(), Value = m.GetStringProperty(k)})
                                  .ToDictionary(x=>x.Key,x=>x.Value);
            }

            //TODO:
            //TimeToBeReceived = baseDate.AddMilliseconds(m.JMSTimestamp),
            //ReplyToAddress = GetIndependentAddressForQueue(m.ResponseQueue),
            var byteMessage = m as IBytesMessage;
            if (byteMessage == null)
            {
                return null;
            }
            if (byteMessage.BodyLength > 0)
            {
                var body = new byte[byteMessage.BodyLength];
                byteMessage.ReadBytes(body);
                result.Body = body;
            }
            return result;

/*
            TransportMessage transportMessage = new TransportMessage()
            {
                Id = m.Id,
                CorrelationId = m.CorrelationId == "00000000-0000-0000-0000-000000000000\\0" ? (string)null : m.CorrelationId,
                Recoverable = m.Recoverable,
                TimeToBeReceived = m.TimeToBeReceived,
                TimeSent = m.SentTime,
                ReplyToAddress = MsmqUtilities.GetIndependentAddressForQueue(m.ResponseQueue),
                MessageIntent = Enum.IsDefined(typeof(MessageIntentEnum), (object)m.AppSpecific) ? (MessageIntentEnum)m.AppSpecific : MessageIntentEnum.Send
            };
            m.BodyStream.Position = 0L;
            transportMessage.Body = new byte[m.BodyStream.Length];
            m.BodyStream.Read(transportMessage.Body, 0, transportMessage.Body.Length);
            transportMessage.Headers = new Dictionary<string, string>();
            if (m.Extension.Length > 0)
            {
                MemoryStream memoryStream = new MemoryStream(m.Extension);
                foreach (HeaderInfo headerInfo in MsmqUtilities.headerSerializer.Deserialize((Stream)memoryStream) as List<HeaderInfo>)
                {
                    if (headerInfo.Key != null)
                        transportMessage.Headers.Add(headerInfo.Key, headerInfo.Value);
                }
            }
            transportMessage.Id = TransportHeaderKeys.GetOriginalId(transportMessage);
            if (transportMessage.Headers.ContainsKey("EnclosedMessageTypes"))
                MsmqUtilities.ExtractMsmqMessageLabelInformationForBackwardCompatibility(m, transportMessage);
            transportMessage.IdForCorrelation = TransportHeaderKeys.GetIdForCorrelation(transportMessage);
            return transportMessage;*/

        }
        public static TransportMessage Convert(IBM.XMS.IMessage m)
        {
            var result = new TransportMessage();
            result.Id = GetRealMessageId(m);
            result.CorrelationId = m.JMSCorrelationID;
            result.Recoverable = m.JMSDeliveryMode == DeliveryMode.Persistent;
            result.IdForCorrelation = m.GetStringProperty(HEADER_IDFORCORRELATION);
            result.ReturnAddress = m.GetStringProperty(HEADER_RETURNADDRESS);
            result.WindowsIdentityName = m.GetStringProperty(HEADER_WINDOWSIDENTITYNAME);
            result.MessageIntent = (MessageIntentEnum) m.GetIntProperty(HEADER_MESSAGEINTENT);
            result.TimeSent = baseDate.AddMilliseconds(m.JMSTimestamp);
            result.Headers = new List<HeaderInfo>();
            //TODO:
            //result.TimeToBeReceived = DateTime.UtcNow - baseDate.AddMilliseconds(m.JMSExpiration);
            if (m.GetStringProperty("NSBKeys") != null)
            {
                var keys = UnwrapKeys(m.GetStringProperty("NSBKeys"));

                result.Headers = (from k in keys
                                  select new HeaderInfo
                                             {
                                                 Key = k.FromXmsFriendly(),
                                                 Value = m.GetStringProperty(k)
                                             }).ToList();
            }

            //TODO:
            //TimeToBeReceived = baseDate.AddMilliseconds(m.JMSTimestamp),
            //ReplyToAddress = GetIndependentAddressForQueue(m.ResponseQueue),
            return result;
        }