/// <summary>
        /// Selects the peek message response.
        /// </summary>
        /// <param name="protocolMessage">The protocol message.</param>
        /// <param name="options">A <see cref="QueueRequestOptions"/> object that specifies additional options for the request.</param>
        /// <returns>The parsed message.</returns>
        private CloudQueueMessage SelectPeekMessageResponse(QueueMessage protocolMessage, QueueRequestOptions options = null)
        {
            CloudQueueMessage message = null;
            byte[] dest = null;
#if !(WINDOWS_RT || ASPNET_K || PORTABLE)
            if (options != null && options.EncryptionPolicy != null)
            {
                // If EncryptionPolicy is set, decrypt the message and set it.
                dest = options.EncryptionPolicy.DecryptMessage(protocolMessage.Text, options.RequireEncryption);
            }
#endif

            if (this.EncodeMessage)
            {
                if (dest!= null)
                {
                    protocolMessage.Text = Convert.ToBase64String(dest, 0, dest.Length);
                }

                // if EncodeMessage is true, we assume the string returned from server is Base64 encoding of original message;
                // if this is not true, exception will likely be thrown.
                // it is user's responsibility to make sure EncodeMessage setting matches the queue that is being read.
                message = new CloudQueueMessage(protocolMessage.Text, true);
            }
            else
            {
#if !(WINDOWS_RT || ASPNET_K || PORTABLE)
                if (dest != null)
                {
                    message = new CloudQueueMessage(dest);
                }
                else
#endif
                {
                    message = new CloudQueueMessage(protocolMessage.Text);
                }
            }

            message.Id = protocolMessage.Id;
            message.InsertionTime = protocolMessage.InsertionTime;
            message.ExpirationTime = protocolMessage.ExpirationTime;
            message.DequeueCount = protocolMessage.DequeueCount;

            // PopReceipt and TimeNextVisible are not returned during peek
            return message;
        }
        /// <summary>
        /// Selects the get message response.
        /// </summary>
        /// <param name="protocolMessage">The protocol message.</param>
        /// <param name="options">A <see cref="QueueRequestOptions"/> object that specifies additional options for the request.</param>
        /// <returns>The parsed message.</returns>
        private CloudQueueMessage SelectGetMessageResponse(QueueMessage protocolMessage, QueueRequestOptions options = null)
        {
            CloudQueueMessage message = this.SelectPeekMessageResponse(protocolMessage, options);
            message.PopReceipt = protocolMessage.PopReceipt;

            if (protocolMessage.NextVisibleTime.HasValue)
            {
                message.NextVisibleTime = protocolMessage.NextVisibleTime.Value;
            }

            return message;
        }
Exemplo n.º 3
0
        /// <summary>
        /// Selects the get message response.
        /// </summary>
        /// <param name="protocolMessage">The protocol message.</param>
        /// <returns>The parsed message.</returns>
        private CloudQueueMessage SelectGetMessageResponse(QueueMessage protocolMessage)
        {
            var message = this.SelectPeekMessageResponse(protocolMessage);
            message.PopReceipt = protocolMessage.PopReceipt;

            if (protocolMessage.NextVisibleTime.HasValue)
            {
                message.NextVisibleTime = protocolMessage.NextVisibleTime.Value;
            }

            return message;
        }
        /// <summary>
        /// Selects the peek message response.
        /// </summary>
        /// <param name="protocolMessage">The protocol message.</param>
        /// <returns>The parsed message.</returns>
        private CloudQueueMessage SelectPeekMessageResponse(QueueMessage protocolMessage)
        {
            CloudQueueMessage message = null;
            if (this.EncodeMessage)
            {
                // if EncodeMessage is true, we assume the string returned from server is Base64 encoding of original message;
                // if this is not true, exception will likely be thrown.
                // it is user's responsibility to make sure EncodeMessage setting matches the queue that is being read.
                message = new CloudQueueMessage(protocolMessage.Text, true);
            }
            else
            {
                message = new CloudQueueMessage(protocolMessage.Text);
            }

            message.Id = protocolMessage.Id;
            message.InsertionTime = protocolMessage.InsertionTime;
            message.ExpirationTime = protocolMessage.ExpirationTime;
            message.DequeueCount = protocolMessage.DequeueCount;

            // PopReceipt and TimeNextVisible are not returned during peek
            return message;
        }
Exemplo n.º 5
0
        /// <summary>
        /// Parses a message entry in a queue get messages response.
        /// </summary>
        /// <returns>Message entry</returns>
        private static async Task <QueueMessage> ParseMessageEntryAsync(XmlReader reader, CancellationToken token)
        {
            token.ThrowIfCancellationRequested();

            QueueMessage   message         = null;
            string         id              = null;
            string         popReceipt      = null;
            DateTimeOffset?insertionTime   = null;
            DateTimeOffset?expirationTime  = null;
            DateTimeOffset?timeNextVisible = null;
            string         text            = null;
            int            dequeueCount    = 0;

            await reader.ReadStartElementAsync().ConfigureAwait(false);

            while (await reader.IsStartElementAsync().ConfigureAwait(false))
            {
                token.ThrowIfCancellationRequested();

                if (reader.IsEmptyElement)
                {
                    await reader.SkipAsync().ConfigureAwait(false);
                }
                else
                {
                    switch (reader.Name)
                    {
                    case Constants.MessageIdElement:
                        id = await reader.ReadElementContentAsStringAsync().ConfigureAwait(false);

                        break;

                    case Constants.PopReceiptElement:
                        popReceipt = await reader.ReadElementContentAsStringAsync().ConfigureAwait(false);

                        break;

                    case Constants.InsertionTimeElement:
                        insertionTime = await reader.ReadElementContentAsDateTimeOffsetAsync().ConfigureAwait(false);

                        break;

                    case Constants.ExpirationTimeElement:
                        expirationTime = await reader.ReadElementContentAsDateTimeOffsetAsync().ConfigureAwait(false);

                        break;

                    case Constants.TimeNextVisibleElement:
                        timeNextVisible = await reader.ReadElementContentAsDateTimeOffsetAsync().ConfigureAwait(false);

                        break;

                    case Constants.MessageTextElement:
                        text = await reader.ReadElementContentAsStringAsync().ConfigureAwait(false);

                        break;

                    case Constants.DequeueCountElement:
                        dequeueCount = await reader.ReadElementContentAsInt32Async().ConfigureAwait(false);

                        break;

                    default:
                        await reader.SkipAsync().ConfigureAwait(false);

                        break;
                    }
                }
            }

            await reader.ReadEndElementAsync().ConfigureAwait(false);

            message =
                new QueueMessage
            {
                Text         = text,
                Id           = id,
                PopReceipt   = popReceipt,
                DequeueCount = dequeueCount,
            };

            if (insertionTime != null)
            {
                message.InsertionTime = (DateTimeOffset)insertionTime;
            }

            if (expirationTime != null)
            {
                message.ExpirationTime = (DateTimeOffset)expirationTime;
            }

            if (timeNextVisible != null)
            {
                message.NextVisibleTime = (DateTimeOffset)timeNextVisible;
            }

            return(message);
        }