當前位置: 首頁>>代碼示例>>C#>>正文


C# QueueRequestOptions.AssertPolicyIfRequired方法代碼示例

本文整理匯總了C#中Microsoft.WindowsAzure.Storage.Queue.QueueRequestOptions.AssertPolicyIfRequired方法的典型用法代碼示例。如果您正苦於以下問題:C# QueueRequestOptions.AssertPolicyIfRequired方法的具體用法?C# QueueRequestOptions.AssertPolicyIfRequired怎麽用?C# QueueRequestOptions.AssertPolicyIfRequired使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Microsoft.WindowsAzure.Storage.Queue.QueueRequestOptions的用法示例。


在下文中一共展示了QueueRequestOptions.AssertPolicyIfRequired方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: PeekMessagesImpl

        /// <summary>
        /// Implementation for the PeekMessages method.
        /// </summary>
        /// <param name="messageCount">The number of messages to retrieve.</param>
        /// <param name="options">A <see cref="QueueRequestOptions"/> object that specifies additional options for the request.</param>
        /// <returns>A <see cref="RESTCommand{T}"/> that gets the permissions.</returns>
        private RESTCommand<IEnumerable<CloudQueueMessage>> PeekMessagesImpl(int messageCount, QueueRequestOptions options)
        {
            options.AssertPolicyIfRequired();

            RESTCommand<IEnumerable<CloudQueueMessage>> getCmd = new RESTCommand<IEnumerable<CloudQueueMessage>>(this.ServiceClient.Credentials, this.GetMessageRequestAddress());

            options.ApplyToStorageCommand(getCmd);
            getCmd.CommandLocationMode = CommandLocationMode.PrimaryOrSecondary;
            getCmd.RetrieveResponseStream = true;
            getCmd.BuildRequestDelegate = (uri, builder, serverTimeout, useVersionHeader, ctx) => QueueHttpWebRequestFactory.PeekMessages(uri, serverTimeout, messageCount, useVersionHeader, ctx);
            getCmd.SignRequest = this.ServiceClient.AuthenticationHandler.SignRequest;
            getCmd.PreProcessResponse = (cmd, resp, ex, ctx) => HttpResponseParsers.ProcessExpectedStatusCodeNoException(HttpStatusCode.OK, resp, null /* retVal */, cmd, ex);
            getCmd.PostProcessResponse = (cmd, resp, ctx) =>
            {
                GetMessagesResponse getMessagesResponse = new GetMessagesResponse(cmd.ResponseStream);

                List<CloudQueueMessage> messagesList = getMessagesResponse.Messages.Select(item => SelectPeekMessageResponse(item, options)).ToList();

                return messagesList;
            };

            return getCmd;
        }
開發者ID:tamram,項目名稱:azure-storage-net,代碼行數:29,代碼來源:CloudQueue.cs

示例2: GetMessageContentForTransfer

        /// <summary>
        /// Gets the content of the message for transfer (internal use only).
        /// </summary>
        /// <param name="shouldEncodeMessage">Indicates if the message should be encoded.</param>
        /// <param name="options">A <see cref="QueueRequestOptions"/> object that specifies additional options for the request.</param>
        /// <returns>The message content as a string.</returns>
        internal string GetMessageContentForTransfer(bool shouldEncodeMessage, QueueRequestOptions options = null)
        {
            if (!shouldEncodeMessage && this.MessageType != QueueMessageType.RawString)
            {
                throw new ArgumentException(SR.BinaryMessageShouldUseBase64Encoding);
            }

            string outgoingMessageString = null;

#if !(WINDOWS_RT || ASPNET_K || PORTABLE)
            if (options != null)
            {
                options.AssertPolicyIfRequired();

                if (options.EncryptionPolicy != null)
                {
                    // Create an encrypted message that will hold the message contents along with encryption related metadata and return it.
                    // The encrypted message is already Base 64 encoded. So no need to process further in this method.
                    string encryptedMessageString = options.EncryptionPolicy.EncryptMessage(this.AsBytes);

                    // the size of Base64 encoded string is the number of bytes this message will take up on server.
                    if (encryptedMessageString.Length > CloudQueueMessage.MaxMessageSize)
                    {
                        throw new ArgumentException(string.Format(
                            CultureInfo.InvariantCulture,
                            SR.EncryptedMessageTooLarge,
                            CloudQueueMessage.MaxMessageSize));
                    }

                    return encryptedMessageString;
                }
            }
#endif

            if (this.MessageType != QueueMessageType.Base64Encoded)
            {
                if (shouldEncodeMessage)
                {
                    outgoingMessageString = Convert.ToBase64String(this.AsBytes);

                    // the size of Base64 encoded string is the number of bytes this message will take up on server.
                    if (outgoingMessageString.Length > CloudQueueMessage.MaxMessageSize)
                    {
                        throw new ArgumentException(string.Format(
                            CultureInfo.InvariantCulture,
                            SR.MessageTooLarge,
                            CloudQueueMessage.MaxMessageSize));
                    }
                }
                else
                {
                    outgoingMessageString = this.RawString;

                    // we need to calculate the size of its UTF8 byte array, as that will be the storage usage on server.
                    if (Encoding.UTF8.GetBytes(outgoingMessageString).Length > CloudQueueMessage.MaxMessageSize)
                    {
                        throw new ArgumentException(string.Format(
                            CultureInfo.InvariantCulture,
                            SR.MessageTooLarge,
                            CloudQueueMessage.MaxMessageSize));
                    }
                }
            }
            else
            {
                // at this point, this.EncodeMessage must be true
                outgoingMessageString = this.RawString;

                // the size of Base64 encoded string is the number of bytes this message will take up on server.
                if (outgoingMessageString.Length > CloudQueueMessage.MaxMessageSize)
                {
                    throw new ArgumentException(string.Format(
                        CultureInfo.InvariantCulture,
                        SR.MessageTooLarge,
                        CloudQueueMessage.MaxMessageSize));
                }
            }

            return outgoingMessageString;
        }
開發者ID:benaadams,項目名稱:azure-storage-net,代碼行數:86,代碼來源:CloudQueueMessage.Common.cs


注:本文中的Microsoft.WindowsAzure.Storage.Queue.QueueRequestOptions.AssertPolicyIfRequired方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。