本文整理汇总了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;
}