示例#1
0
        public virtual IMessage ToNmsMessage(Message message)
        {
            BaseMessage answer = CreateNmsMessage(message);
            // Get the NMS meta data from the extension area
            PrimitiveMap metaData = PrimitiveMap.Unmarshal(message.Extension);

            try
            {
                answer.NMSMessageId     = message.Id;
                answer.NMSCorrelationID = metaData.GetString("NMSCorrelationID");
                answer.NMSDeliveryMode  = (message.Recoverable ? MsgDeliveryMode.Persistent : MsgDeliveryMode.NonPersistent);
                answer.NMSDestination   = ToNmsDestination(message.DestinationQueue);
            }
            catch (InvalidOperationException)
            {
            }

            try
            {
                answer.NMSType       = message.Label;
                answer.NMSReplyTo    = ToNmsDestination(message.ResponseQueue);
                answer.NMSTimeToLive = message.TimeToBeReceived;
            }
            catch (InvalidOperationException)
            {
            }

            return(answer);
        }
示例#2
0
        /// <summary>
        /// Converts an MSMQ message body to the equivalent NMS map message
        /// body.
        /// </summary>
        /// <param name="message">Source MSMQ message.</param>
        /// <param name="answer">Target NMS map message.</param>
        public virtual void ConvertMapMessageBodyToNMS(Message message,
                                                       MapMessage answer)
        {
            byte[] buf = null;

            if (message.BodyStream != null && message.BodyStream.Length > 0)
            {
                buf = new byte[message.BodyStream.Length];
                message.BodyStream.Read(buf, 0, buf.Length);
            }

            answer.Body = PrimitiveMap.Unmarshal(buf);
        }
示例#3
0
        /// <summary>
        /// Converts the specified MSMQ message to an equivalent NMS message.
        /// </summary>
        /// <param name="message">MSMQ message to be converted.</param>
        /// <param name="convertBody">true if message body should be converted.</param>
        /// <result>Converted NMS message.</result>
        public virtual IMessage ToNmsMessage(Message message, bool convertBody)
        {
            BaseMessage answer = CreateNmsMessage(message, convertBody);

            // Get the NMS property data from the extension area
            PrimitiveMap propertyData = PrimitiveMap.Unmarshal(message.Extension);

            try
            {
                answer.NMSMessageId     = message.Id;
                answer.NMSCorrelationID = propertyData.GetString("NMSCorrelationID");
                answer.NMSDeliveryMode  = (message.Recoverable ? MsgDeliveryMode.Persistent : MsgDeliveryMode.NonPersistent);
                answer.NMSDestination   = ToNmsDestination(message.DestinationQueue);
            }
            catch (InvalidOperationException)
            {
            }

            try
            {
                answer.NMSReplyTo    = ToNmsDestination(message.ResponseQueue);
                answer.NMSTimeToLive = message.TimeToBeReceived;
                answer.NMSPriority   = ToNmsMsgPriority(message.Priority);
            }
            catch (InvalidOperationException)
            {
            }

            try
            {
                if (message.Label != null)
                {
                    if (SetLabelAsNMSType)
                    {
                        answer.NMSType = message.Label;
                    }
                    else
                    {
                        answer.Properties["Label"] = message.Label;
                    }
                }
                answer.Properties["LookupId"] = message.LookupId;
            }
            catch (InvalidOperationException)
            {
            }

            foreach (object keyObject in propertyData.Keys)
            {
                try
                {
                    string key = (keyObject as string);
                    if (string.Compare(key, "NMSType", true) == 0)
                    {
                        answer.NMSType = propertyData.GetString(key);
                    }
                    else if (string.Compare(key, "NMSCorrelationID", true) == 0)
                    {
                        answer.NMSCorrelationID = propertyData.GetString("NMSCorrelationID");
                    }
                    else
                    {
                        answer.Properties[key] = propertyData[key];
                    }
                }
                catch (InvalidOperationException)
                {
                }
            }
            return(answer);
        }
示例#4
0
        protected virtual BaseMessage CreateNmsMessage(Message message)
        {
            BaseMessage result = null;

            if ((int)NMSMessageType.TextMessage == message.AppSpecific)
            {
                TextMessage textMessage = new TextMessage();
                string      content     = String.Empty;

                if (message.BodyStream != null && message.BodyStream.Length > 0)
                {
                    byte[] buf = null;
                    buf = new byte[message.BodyStream.Length];
                    message.BodyStream.Read(buf, 0, buf.Length);
                    content = Encoding.UTF32.GetString(buf);
                }

                textMessage.Text = content;
                result           = textMessage;
            }
            else if ((int)NMSMessageType.BytesMessage == message.AppSpecific)
            {
                byte[] buf = null;

                if (message.BodyStream != null && message.BodyStream.Length > 0)
                {
                    buf = new byte[message.BodyStream.Length];
                    message.BodyStream.Read(buf, 0, buf.Length);
                }

                BytesMessage bytesMessage = new BytesMessage();
                bytesMessage.Content = buf;
                result = bytesMessage;
            }
            else if ((int)NMSMessageType.ObjectMessage == message.AppSpecific)
            {
                ObjectMessage objectMessage = new ObjectMessage();

                objectMessage.Body = message.Body;
                result             = objectMessage;
            }
            else if ((int)NMSMessageType.MapMessage == message.AppSpecific)
            {
                byte[] buf = null;

                if (message.BodyStream != null && message.BodyStream.Length > 0)
                {
                    buf = new byte[message.BodyStream.Length];
                    message.BodyStream.Read(buf, 0, buf.Length);
                }

                MapMessage mapMessage = new MapMessage();
                mapMessage.Body = PrimitiveMap.Unmarshal(buf);
                result          = mapMessage;
            }
            else if ((int)NMSMessageType.StreamMessage == message.AppSpecific)
            {
                StreamMessage streamMessage = new StreamMessage();

                // TODO: Implement
                result = streamMessage;
            }
            else
            {
                BaseMessage baseMessage = new BaseMessage();

                result = baseMessage;
            }

            return(result);
        }