本文整理匯總了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;
}
示例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;
}