Exemplo n.º 1
0
        public override WebServiceResponse Unmarshall(XmlUnmarshallerContext context)
        {
            XmlTextReader reader = new XmlTextReader(context.ResponseStream);
            ChangeMessageVisibilityResponse response = new ChangeMessageVisibilityResponse();

            while (reader.Read())
            {
                switch (reader.NodeType)
                {
                case XmlNodeType.Element:
                    switch (reader.LocalName)
                    {
                    case MNSConstants.XML_ELEMENT_RECEIPT_HANDLE:
                        reader.Read();
                        response.ReceiptHandle = reader.Value;
                        break;

                    case MNSConstants.XML_ELEMENT_NEXT_VISIBLE_TIME:
                        reader.Read();
                        response.NextVisibleTime = AliyunSDKUtils.ConvertFromUnixEpochSeconds(long.Parse(reader.Value));
                        break;
                    }
                    break;
                }
            }
            reader.Close();
            return(response);
        }
        public override WebServiceResponse Unmarshall(XmlUnmarshallerContext context)
        {
            XmlTextReader   reader     = new XmlTextReader(context.ResponseStream);
            TopicAttributes attributes = new TopicAttributes();

            while (reader.Read())
            {
                switch (reader.NodeType)
                {
                case XmlNodeType.Element:
                    switch (reader.LocalName)
                    {
                    case MNSConstants.XML_ELEMENT_TOPIC_NAME:
                        reader.Read();
                        attributes.TopicName = reader.Value;
                        break;

                    case MNSConstants.XML_ELEMENT_CREATE_TIME:
                        reader.Read();
                        attributes.CreateTime = AliyunSDKUtils.ConvertFromUnixEpochSeconds(long.Parse(reader.Value) * 1000);
                        break;

                    case MNSConstants.XML_ELEMENT_LAST_MODIFY_TIME:
                        reader.Read();
                        attributes.LastModifyTime = AliyunSDKUtils.ConvertFromUnixEpochSeconds(long.Parse(reader.Value) * 1000);
                        break;

                    case MNSConstants.XML_ELEMENT_MAXIMUM_MESSAGE_SIZE:
                        reader.Read();
                        attributes.MaximumMessageSize = uint.Parse(reader.Value);
                        break;

                    case MNSConstants.XML_ELEMENT_MESSAGE_RETENTION_PERIOD:
                        reader.Read();
                        attributes.MessageRetentionPeriod = uint.Parse(reader.Value);
                        break;

                    case MNSConstants.XML_ELEMENT_MESSAGE_COUNT:
                        reader.Read();
                        attributes.MessageCount = uint.Parse(reader.Value);
                        break;

                    case MNSConstants.XML_ELEMENT_LOGGING_ENABLED:
                        reader.Read();
                        attributes.LoggingEnabled = bool.Parse(reader.Value);
                        break;
                    }
                    break;
                }
            }
            reader.Close();
            return(new GetTopicAttributesResponse()
            {
                Attributes = attributes
            });
        }
        public override WebServiceResponse Unmarshall(XmlUnmarshallerContext context)
        {
            XmlTextReader reader  = new XmlTextReader(context.ResponseStream);
            Message       message = new Message();

            while (reader.Read())
            {
                switch (reader.NodeType)
                {
                case XmlNodeType.Element:
                    switch (reader.LocalName)
                    {
                    case MNSConstants.XML_ELEMENT_MESSAGE_ID:
                        reader.Read();
                        message.Id = reader.Value;
                        break;

                    case MNSConstants.XML_ELEMENT_MESSAGE_BODY_MD5:
                        reader.Read();
                        message.BodyMD5 = reader.Value;
                        break;

                    case MNSConstants.XML_ELEMENT_MESSAGE_BODY:
                        reader.Read();
                        message.Body = reader.Value;
                        break;

                    case MNSConstants.XML_ELEMENT_ENQUEUE_TIME:
                        reader.Read();
                        message.EnqueueTime = AliyunSDKUtils.ConvertFromUnixEpochSeconds(long.Parse(reader.Value));
                        break;

                    case MNSConstants.XML_ELEMENT_FIRST_DEQUEUE_TIME:
                        reader.Read();
                        message.FirstDequeueTime = AliyunSDKUtils.ConvertFromUnixEpochSeconds(long.Parse(reader.Value));
                        break;

                    case MNSConstants.XML_ELEMENT_DEQUEUE_COUNT:
                        reader.Read();
                        message.DequeueCount = uint.Parse(reader.Value);
                        break;

                    case MNSConstants.XML_ELEMENT_PRIORITY:
                        reader.Read();
                        message.Priority = uint.Parse(reader.Value);
                        break;
                    }
                    break;
                }
            }
            reader.Close();
            return(new PeekMessageResponse()
            {
                Message = message
            });
        }
Exemplo n.º 4
0
        public void UnmarshallTest()
        {
            string       xml    = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><Message xmlns = \"http://mns.aliyuncs.com/doc/v1/\">\n<MessageId>5F290C926D472878-2-14D9529A8FA-200000001</MessageId><ReceiptHandle>1-ODU4OTkzNDU5My0xNDMyNzI3ODI3LTItOA==</ReceiptHandle><MessageBodyMD5>C5DD56A39F5F7BB8B3337C6D11B6D8C7</MessageBodyMD5><MessageBody>This is a test message</MessageBody><EnqueueTime>1250700979248</EnqueueTime><NextVisibleTime>1250700799348</NextVisibleTime><FirstDequeueTime>1250700779318</FirstDequeueTime><DequeueCount>1</DequeueCount><Priority>8</Priority></Message>";
            MemoryStream stream = new MemoryStream(System.Text.Encoding.UTF8.GetBytes(xml));

            XmlUnmarshallerContext context  = new XmlUnmarshallerContext(stream, null);
            ReceiveMessageResponse response = (ReceiveMessageResponse)ReceiveMessageResponseUnmarshaller.Instance.Unmarshall(context);

            Message message = response.Message;

            Assert.IsTrue(message.Id == "5F290C926D472878-2-14D9529A8FA-200000001");
            Assert.IsTrue(message.ReceiptHandle == "1-ODU4OTkzNDU5My0xNDMyNzI3ODI3LTItOA==");
            Assert.IsTrue(message.BodyMD5 == "C5DD56A39F5F7BB8B3337C6D11B6D8C7");
            Assert.IsTrue(message.Body == "This is a test message");
            Assert.IsTrue(message.EnqueueTime == AliyunSDKUtils.ConvertFromUnixEpochSeconds(1250700979248));
            Assert.IsTrue(message.NextVisibleTime == AliyunSDKUtils.ConvertFromUnixEpochSeconds(1250700799348));
            Assert.IsTrue(message.FirstDequeueTime == AliyunSDKUtils.ConvertFromUnixEpochSeconds(1250700779318));
            Assert.IsTrue(message.DequeueCount == 1);
            Assert.IsTrue(message.Priority == 8);
        }
        public override WebServiceResponse Unmarshall(XmlUnmarshallerContext context)
        {
            System.Xml.XmlTextReader    reader = new System.Xml.XmlTextReader(context.ResponseStream);
            BatchReceiveMessageResponse batchReceiveMessageResponse = new BatchReceiveMessageResponse();
            Message message = null;

            while (reader.Read())
            {
                switch (reader.NodeType)
                {
                case System.Xml.XmlNodeType.Element:
                    switch (reader.LocalName)
                    {
                    case MNSConstants.XML_ROOT_MESSAGE:
                        message = new Message();
                        break;

                    case MNSConstants.XML_ELEMENT_MESSAGE_ID:
                        reader.Read();
                        message.Id = reader.Value;
                        break;

                    case MNSConstants.XML_ELEMENT_RECEIPT_HANDLE:
                        reader.Read();
                        message.ReceiptHandle = reader.Value;
                        break;

                    case MNSConstants.XML_ELEMENT_MESSAGE_BODY_MD5:
                        reader.Read();
                        message.BodyMD5 = reader.Value;
                        break;

                    case MNSConstants.XML_ELEMENT_MESSAGE_BODY:
                        reader.Read();
                        message.Body = reader.Value;
                        break;

                    case MNSConstants.XML_ELEMENT_ENQUEUE_TIME:
                        reader.Read();
                        message.EnqueueTime = AliyunSDKUtils.ConvertFromUnixEpochSeconds(long.Parse(reader.Value));
                        break;

                    case MNSConstants.XML_ELEMENT_NEXT_VISIBLE_TIME:
                        reader.Read();
                        message.NextVisibleTime = AliyunSDKUtils.ConvertFromUnixEpochSeconds(long.Parse(reader.Value));
                        break;

                    case MNSConstants.XML_ELEMENT_FIRST_DEQUEUE_TIME:
                        reader.Read();
                        message.FirstDequeueTime = AliyunSDKUtils.ConvertFromUnixEpochSeconds(long.Parse(reader.Value));
                        break;

                    case MNSConstants.XML_ELEMENT_DEQUEUE_COUNT:
                        reader.Read();
                        message.DequeueCount = uint.Parse(reader.Value);
                        break;

                    case MNSConstants.XML_ELEMENT_PRIORITY:
                        reader.Read();
                        message.Priority = uint.Parse(reader.Value);
                        break;
                    }
                    break;

                case System.Xml.XmlNodeType.EndElement:
                    if (reader.LocalName == MNSConstants.XML_ROOT_MESSAGE)
                    {
                        batchReceiveMessageResponse.Messages.Add(message);
                    }
                    break;
                }
            }
            reader.Close();
            return(batchReceiveMessageResponse);
        }
        public override WebServiceResponse Unmarshall(XmlUnmarshallerContext context)
        {
            XmlTextReader          reader     = new XmlTextReader(context.ResponseStream);
            SubscriptionAttributes attributes = new SubscriptionAttributes();

            while (reader.Read())
            {
                switch (reader.NodeType)
                {
                case XmlNodeType.Element:
                    switch (reader.LocalName)
                    {
                    case MNSConstants.XML_ELEMENT_TOPIC_NAME:
                        reader.Read();
                        attributes.TopicName = reader.Value;
                        break;

                    case MNSConstants.XML_ELEMENT_CREATE_TIME:
                        reader.Read();
                        attributes.CreateTime = AliyunSDKUtils.ConvertFromUnixEpochSeconds(long.Parse(reader.Value) * 1000);
                        break;

                    case MNSConstants.XML_ELEMENT_LAST_MODIFY_TIME:
                        reader.Read();
                        attributes.LastModifyTime = AliyunSDKUtils.ConvertFromUnixEpochSeconds(long.Parse(reader.Value) * 1000);
                        break;

                    case MNSConstants.XML_ELEMENT_TOPIC_OWNER:
                        reader.Read();
                        attributes.TopicOwner = reader.Value;
                        break;

                    case MNSConstants.XML_ELEMENT_SUBSCRIPTION_NAME:
                        reader.Read();
                        attributes.SubscriptionName = reader.Value;
                        break;

                    case MNSConstants.XML_ELEMENT_ENDPOINT:
                        reader.Read();
                        attributes.EndPoint = reader.Value;
                        break;

                    case MNSConstants.XML_ELEMENT_NOTIFY_STRATEGY:
                        reader.Read();
                        string strategyStr = reader.Value;
                        attributes.Strategy = (SubscriptionAttributes.NotifyStrategy)
                                              Enum.Parse(typeof(SubscriptionAttributes.NotifyStrategy), strategyStr.ToUpper());
                        break;

                    case MNSConstants.XML_ELEMENT_NOTIFY_CONTENT_FORMAT:
                        reader.Read();
                        string contentFormatStr = reader.Value;
                        attributes.ContentFormat = (SubscriptionAttributes.NotifyContentFormat)
                                                   Enum.Parse(typeof(SubscriptionAttributes.NotifyContentFormat), contentFormatStr.ToUpper());
                        break;
                    }
                    break;
                }
            }
            reader.Close();
            return(new GetSubscriptionAttributeResponse()
            {
                Attributes = attributes
            });
        }
        public override WebServiceResponse Unmarshall(XmlUnmarshallerContext context)
        {
            XmlTextReader   reader     = new XmlTextReader(context.ResponseStream);
            QueueAttributes attributes = new QueueAttributes();

            while (reader.Read())
            {
                switch (reader.NodeType)
                {
                case XmlNodeType.Element:
                    switch (reader.LocalName)
                    {
                    case MNSConstants.XML_ELEMENT_QUEUE_NAME:
                        reader.Read();
                        attributes.QueueName = reader.Value;
                        break;

                    case MNSConstants.XML_ELEMENT_CREATE_TIME:
                        reader.Read();
                        attributes.CreateTime = AliyunSDKUtils.ConvertFromUnixEpochSeconds(long.Parse(reader.Value) * 1000);
                        break;

                    case MNSConstants.XML_ELEMENT_LAST_MODIFY_TIME:
                        reader.Read();
                        attributes.LastModifyTime = AliyunSDKUtils.ConvertFromUnixEpochSeconds(long.Parse(reader.Value) * 1000);
                        break;

                    case MNSConstants.XML_ELEMENT_VISIBILITY_TIMEOUT:
                        reader.Read();
                        attributes.VisibilityTimeout = uint.Parse(reader.Value);
                        break;

                    case MNSConstants.XML_ELEMENT_MAXIMUM_MESSAGE_SIZE:
                        reader.Read();
                        attributes.MaximumMessageSize = uint.Parse(reader.Value);
                        break;

                    case MNSConstants.XML_ELEMENT_MESSAGE_RETENTION_PERIOD:
                        reader.Read();
                        attributes.MessageRetentionPeriod = uint.Parse(reader.Value);
                        break;

                    case MNSConstants.XML_ELEMENT_DELAY_SECONDS:
                        reader.Read();
                        attributes.DelaySeconds = uint.Parse(reader.Value);
                        break;

                    case MNSConstants.XML_ELEMENT_POLLING_WAIT_SECONDS:
                        reader.Read();
                        attributes.PollingWaitSeconds = uint.Parse(reader.Value);
                        break;

                    case MNSConstants.XML_ELEMENT_INACTIVE_MESSAGES:
                        reader.Read();
                        attributes.InactiveMessages = uint.Parse(reader.Value);
                        break;

                    case MNSConstants.XML_ELEMENT_ACTIVE_MESSAGES:
                        reader.Read();
                        attributes.ActiveMessages = uint.Parse(reader.Value);
                        break;

                    case MNSConstants.ATTRIBUTE_DELAY_MESSAGES:
                        reader.Read();
                        attributes.DelayMessages = uint.Parse(reader.Value);
                        break;

                    case MNSConstants.XML_ELEMENT_LOGGING_ENABLED:
                        reader.Read();
                        attributes.LoggingEnabled = bool.Parse(reader.Value);
                        break;
                    }
                    break;
                }
            }
            reader.Close();
            return(new GetQueueAttributesResponse()
            {
                Attributes = attributes
            });
        }