Esempio n. 1
0
        public void Deserialize(IReceiveContext context)
        {
            try
            {
                object message = _serializer.Deserialize(context.BodyStream);

                if (message == null)
                {
                    throw new SerializationException("Could not deserialize message.");
                }

                context.SetContentType(ContentTypeHeaderValue);

                if (message is XmlMessageEnvelope)
                {
                    var envelope = message as XmlMessageEnvelope;

                    context.SetUsingMessageEnvelope(envelope);
                    context.SetMessageTypeConverter(new StaticMessageTypeConverter(envelope.Message));
                    return;
                }

                context.SetMessageTypeConverter(new StaticMessageTypeConverter(message));
            }
            catch (SerializationException)
            {
                throw;
            }
            catch (Exception ex)
            {
                throw new SerializationException("Failed to serialize message", ex);
            }
        }
Esempio n. 2
0
        public void Deserialize(IReceiveContext context)
        {
            object obj = _formatter.Deserialize(context.BodyStream,
                                                headers => DeserializeHeaderHandler(headers, context));

            context.SetContentType(ContentTypeHeaderValue);
            context.SetMessageTypeConverter(new StaticMessageTypeConverter(obj));
        }
Esempio n. 3
0
        protected bool EnumerateQueue(Func <IReceiveContext, Action <IReceiveContext> > receiver, TimeSpan timeout)
        {
            if (_disposed)
            {
                throw new ObjectDisposedException("The transport has been disposed: '{0}'".FormatWith(Address));
            }

            bool received = false;

            _connectionHandler.Use(connection =>
            {
                using (MessageEnumerator enumerator = connection.Queue.GetMessageEnumerator2())
                {
                    // if (_log.IsDebugEnabled)
                    // _log.DebugFormat("Enumerating endpoint: {0} ({1}ms)", Address, timeout);

                    while (enumerator.MoveNext(timeout))
                    {
                        if (enumerator.Current == null)
                        {
                            if (_log.IsDebugEnabled)
                            {
                                _log.DebugFormat("Current message was null while enumerating endpoint");
                            }

                            continue;
                        }

                        Message peekMessage = enumerator.Current;
                        using (peekMessage)
                        {
                            IReceiveContext context = ReceiveContext.FromBodyStream(peekMessage.BodyStream);
                            context.SetMessageId(peekMessage.Id);
                            context.SetInputAddress(_address);

                            byte[] extension = peekMessage.Extension;
                            if (extension.Length > 0)
                            {
                                TransportMessageHeaders headers = TransportMessageHeaders.Create(extension);

                                context.SetContentType(headers["Content-Type"]);
                            }

                            Action <IReceiveContext> receive = receiver(context);
                            if (receive == null)
                            {
                                if (_log.IsDebugEnabled)
                                {
                                    _log.DebugFormat("SKIP:{0}:{1}", Address, peekMessage.Id);
                                }

                                continue;
                            }

                            ReceiveMessage(enumerator, timeout, message =>
                            {
                                if (message == null)
                                {
                                    throw new TransportException(Address.Uri,
                                                                 "Unable to remove message from queue: " + context.MessageId);
                                }

                                if (message.Id != context.MessageId)
                                {
                                    throw new TransportException(Address.Uri,
                                                                 string.Format(
                                                                     "Received message does not match current message: ({0} != {1})",
                                                                     message.Id, context.MessageId));
                                }

                                if (_messageLog.IsDebugEnabled)
                                {
                                    _messageLog.DebugFormat("RECV:{0}:{1}:{2}", _address.InboundFormatName,
                                                            message.Label, message.Id);
                                }

                                receive(context);

                                received = true;
                            });
                        }
                    }
                }
            });

            return(received);
        }
Esempio n. 4
0
        protected void EnumerateQueue(Func <IReceiveContext, Action <IReceiveContext> > receiver, TimeSpan timeout)
        {
            if (_disposed)
            {
                throw new ObjectDisposedException("The transport has been disposed: '{0}'".FormatWith(Address));
            }

            _connectionHandler.Use(connection =>
            {
                try
                {
                    using (MessageEnumerator enumerator = connection.Queue.GetMessageEnumerator2())
                    {
                        while (enumerator.MoveNext(timeout))
                        {
                            if (enumerator.Current == null)
                            {
                                if (_log.IsDebugEnabled)
                                {
                                    _log.DebugFormat("Current message was null while enumerating endpoint");
                                }

                                continue;
                            }

                            Message peekMessage = enumerator.Current;
                            using (peekMessage)
                            {
                                IReceiveContext context = ReceiveContext.FromBodyStream(peekMessage.BodyStream,
                                                                                        _address.IsTransactional);
                                context.SetMessageId(peekMessage.Id);
                                context.SetInputAddress(_address);

                                byte[] extension = peekMessage.Extension;
                                if (extension.Length > 0)
                                {
                                    TransportMessageHeaders headers = TransportMessageHeaders.Create(extension);

                                    context.SetContentType(headers["Content-Type"]);
                                    context.SetOriginalMessageId(headers["Original-Message-Id"]);
                                }

                                Action <IReceiveContext> receive = receiver(context);
                                if (receive == null)
                                {
                                    continue;
                                }

                                ReceiveMessage(enumerator, timeout, message =>
                                {
                                    if (message == null)
                                    {
                                        throw new TransportException(Address.Uri,
                                                                     "Unable to remove message from queue: " + context.MessageId);
                                    }

                                    if (message.Id != context.MessageId)
                                    {
                                        throw new TransportException(Address.Uri,
                                                                     string.Format(
                                                                         "Received message does not match current message: ({0} != {1})",
                                                                         message.Id, context.MessageId));
                                    }

                                    receive(context);
                                });
                            }
                        }
                    }
                }
                catch (MessageQueueException ex)
                {
                    HandleInboundMessageQueueException(ex);
                }
            });
        }
Esempio n. 5
0
 public void SetContentType(string value)
 {
     _context.SetContentType(value);
 }