private RESTCommand <NullType> SetServicePropertiesImpl(ServiceProperties properties, QueueRequestOptions requestOptions) { MultiBufferMemoryStream memoryStream = new MultiBufferMemoryStream(null /* bufferManager */, (int)(1 * Constants.KB)); try { properties.WriteServiceProperties(memoryStream); } catch (InvalidOperationException invalidOpException) { throw new ArgumentException(invalidOpException.Message, "properties"); } RESTCommand <NullType> retCmd = new RESTCommand <NullType>(this.Credentials, this.StorageUri); requestOptions.ApplyToStorageCommand(retCmd); retCmd.BuildRequest = (cmd, uri, builder, cnt, serverTimeout, ctx) => QueueHttpRequestMessageFactory.SetServiceProperties(uri, serverTimeout, cnt, ctx, this.GetCanonicalizer(), this.Credentials); retCmd.BuildContent = (cmd, ctx) => HttpContentFactory.BuildContentFromStream(memoryStream, 0, memoryStream.Length, null /* md5 */, cmd, ctx); retCmd.StreamToDispose = memoryStream; retCmd.PreProcessResponse = (cmd, resp, ex, ctx) => HttpResponseParsers.ProcessExpectedStatusCodeNoException(HttpStatusCode.Accepted, resp, null /* retVal */, cmd, ex); requestOptions.ApplyToStorageCommand(retCmd); return(retCmd); }
private RESTCommand <NullType> SetServicePropertiesImpl(ServiceProperties properties, QueueRequestOptions requestOptions) { MultiBufferMemoryStream str = new MultiBufferMemoryStream(null /* bufferManager */, (int)(1 * Constants.KB)); try { properties.WriteServiceProperties(str); } catch (InvalidOperationException invalidOpException) { throw new ArgumentException(invalidOpException.Message, "properties"); } str.Seek(0, SeekOrigin.Begin); RESTCommand <NullType> retCmd = new RESTCommand <NullType>(this.Credentials, this.StorageUri); retCmd.SendStream = str; retCmd.BuildRequestDelegate = QueueHttpWebRequestFactory.SetServiceProperties; retCmd.RecoveryAction = RecoveryActions.RewindStream; retCmd.SignRequest = this.AuthenticationHandler.SignRequest; retCmd.PreProcessResponse = (cmd, resp, ex, ctx) => HttpResponseParsers.ProcessExpectedStatusCodeNoException(HttpStatusCode.Accepted, resp, NullType.Value, cmd, ex); requestOptions.ApplyToStorageCommand(retCmd); return(retCmd); }
private RESTCommand <ServiceStats> GetServiceStatsImpl(QueueRequestOptions requestOptions) { RESTCommand <ServiceStats> retCmd = new RESTCommand <ServiceStats>(this.Credentials, this.StorageUri); requestOptions.ApplyToStorageCommand(retCmd); retCmd.CommandLocationMode = CommandLocationMode.PrimaryOrSecondary; retCmd.BuildRequest = (cmd, uri, builder, cnt, serverTimeout, ctx) => QueueHttpRequestMessageFactory.GetServiceStats(uri, serverTimeout, ctx, this.GetCanonicalizer(), this.Credentials); retCmd.RetrieveResponseStream = true; retCmd.PreProcessResponse = (cmd, resp, ex, ctx) => HttpResponseParsers.ProcessExpectedStatusCodeNoException(HttpStatusCode.OK, resp, null /* retVal */, cmd, ex); retCmd.PostProcessResponse = (cmd, resp, ctx) => Task.Factory.StartNew(() => QueueHttpResponseParsers.ReadServiceStats(cmd.ResponseStream)); return(retCmd); }
private RESTCommand <ServiceStats> GetServiceStatsImpl(QueueRequestOptions requestOptions) { RESTCommand <ServiceStats> retCmd = new RESTCommand <ServiceStats>(this.Credentials, this.StorageUri); requestOptions.ApplyToStorageCommand(retCmd); retCmd.CommandLocationMode = CommandLocationMode.PrimaryOrSecondary; retCmd.BuildRequestDelegate = QueueHttpWebRequestFactory.GetServiceStats; retCmd.SignRequest = this.AuthenticationHandler.SignRequest; retCmd.RetrieveResponseStream = true; retCmd.PreProcessResponse = (cmd, resp, ex, ctx) => HttpResponseParsers.ProcessExpectedStatusCodeNoException(HttpStatusCode.OK, resp, null /* retVal */, cmd, ex); retCmd.PostProcessResponse = (cmd, resp, ctx) => QueueHttpResponseParsers.ReadServiceStats(cmd.ResponseStream); return(retCmd); }
private RESTCommand <ServiceStats> GetServiceStatsImpl(QueueRequestOptions requestOptions) { if (RetryPolicies.LocationMode.PrimaryOnly == requestOptions.LocationMode) { throw new InvalidOperationException(SR.GetServiceStatsInvalidOperation); } RESTCommand <ServiceStats> retCmd = new RESTCommand <ServiceStats>(this.Credentials, this.StorageUri, this.HttpClient); requestOptions.ApplyToStorageCommand(retCmd); retCmd.CommandLocationMode = CommandLocationMode.PrimaryOrSecondary; retCmd.BuildRequest = (cmd, uri, builder, cnt, serverTimeout, ctx) => QueueHttpRequestMessageFactory.GetServiceStats(uri, serverTimeout, ctx, this.GetCanonicalizer(), this.Credentials); retCmd.RetrieveResponseStream = true; retCmd.PreProcessResponse = (cmd, resp, ex, ctx) => HttpResponseParsers.ProcessExpectedStatusCodeNoException(HttpStatusCode.OK, resp, null /* retVal */, cmd, ex); retCmd.PostProcessResponseAsync = (cmd, resp, ctx, ct) => QueueHttpResponseParsers.ReadServiceStatsAsync(cmd.ResponseStream, ct); return(retCmd); }
/// <summary> /// Core implementation for the ListQueues method. /// </summary> /// <param name="prefix">The queue prefix.</param> /// <param name="detailsIncluded">The details included.</param> /// <param name="currentToken">The continuation token.</param> /// <param name="maxResults">A non-negative integer value that indicates the maximum number of results to be returned at a time, up to the /// per-operation limit of 5000. If this value is <c>null</c>, the maximum possible number of results will be returned, up to 5000.</param> /// <returns>A <see cref="TaskSequence"/> that lists the queues.</returns> private RESTCommand <ResultSegment <CloudQueue> > ListQueuesImpl(string prefix, int?maxResults, QueueListingDetails detailsIncluded, QueueRequestOptions options, QueueContinuationToken currentToken) { ListingContext listingContext = new ListingContext(prefix, maxResults) { Marker = currentToken != null ? currentToken.NextMarker : null }; RESTCommand <ResultSegment <CloudQueue> > getCmd = new RESTCommand <ResultSegment <CloudQueue> >(this.Credentials, this.StorageUri); options.ApplyToStorageCommand(getCmd); getCmd.CommandLocationMode = CommonUtility.GetListingLocationMode(currentToken); getCmd.RetrieveResponseStream = true; getCmd.Handler = this.AuthenticationHandler; getCmd.BuildClient = HttpClientFactory.BuildHttpClient; getCmd.BuildRequest = (cmd, uri, builder, cnt, serverTimeout, ctx) => QueueHttpRequestMessageFactory.List(uri, serverTimeout, listingContext, detailsIncluded, cnt, ctx); getCmd.PreProcessResponse = (cmd, resp, ex, ctx) => HttpResponseParsers.ProcessExpectedStatusCodeNoException(HttpStatusCode.OK, resp, null /* retVal */, cmd, ex); getCmd.PostProcessResponse = (cmd, resp, ctx) => { return(Task.Factory.StartNew(() => { ListQueuesResponse listQueuesResponse = new ListQueuesResponse(cmd.ResponseStream); List <CloudQueue> queuesList = listQueuesResponse.Queues.Select(item => new CloudQueue(item.Metadata, item.Name, this)).ToList(); QueueContinuationToken continuationToken = null; if (listQueuesResponse.NextMarker != null) { continuationToken = new QueueContinuationToken() { NextMarker = listQueuesResponse.NextMarker, TargetLocation = cmd.CurrentResult.TargetLocation, }; } return new ResultSegment <CloudQueue>(queuesList) { ContinuationToken = continuationToken, }; })); }; return(getCmd); }
/// <summary> /// Core implementation of the ListQueues method. /// </summary> /// <param name="prefix">The queue name prefix.</param> /// <param name="maxResults">A non-negative integer value that indicates the maximum number of results to be returned at a time, up to the /// per-operation limit of 5000. If this value is <c>null</c>, the maximum possible number of results will be returned, up to 5000.</param> /// <param name="queueListingDetails">A <see cref="QueueListingDetails"/> enumeration describing which items to include in the listing.</param> /// <param name="options">An object that specifies any additional options for the request.</param> /// <param name="currentToken">The continuation token.</param> /// <returns>A <see cref="RESTCommand{T}"/> that lists the queues.</returns> private RESTCommand <ResultSegment <CloudQueue> > ListQueuesImpl(string prefix, int?maxResults, QueueListingDetails queueListingDetails, QueueRequestOptions options, QueueContinuationToken currentToken) { int?nullableMaxResults = (maxResults > 0) ? maxResults : null; QueueListingContext listingContext = new QueueListingContext(prefix, nullableMaxResults, queueListingDetails) { Marker = currentToken != null ? currentToken.NextMarker : null }; RESTCommand <ResultSegment <CloudQueue> > getCmd = new RESTCommand <ResultSegment <CloudQueue> >(this.Credentials, this.BaseUri); options.ApplyToStorageCommand(getCmd); getCmd.RetrieveResponseStream = true; getCmd.BuildRequestDelegate = (uri, builder, serverTimeout, ctx) => QueueHttpWebRequestFactory.List(uri, serverTimeout, listingContext, queueListingDetails, ctx); getCmd.SignRequest = this.AuthenticationHandler.SignRequest; getCmd.PreProcessResponse = (cmd, resp, ex, ctx) => HttpResponseParsers.ProcessExpectedStatusCodeNoException(HttpStatusCode.OK, resp, null /* retVal */, cmd, ex, ctx); getCmd.PostProcessResponse = (cmd, resp, ex, ctx) => { ListQueuesResponse listQueuesResponse = new ListQueuesResponse(cmd.ResponseStream); List <CloudQueue> queuesList = new List <CloudQueue>( listQueuesResponse.Queues.Select(item => new CloudQueue(item.Name, this))); QueueContinuationToken continuationToken = null; if (listQueuesResponse.NextMarker != null) { continuationToken = new QueueContinuationToken() { NextMarker = listQueuesResponse.NextMarker, }; } return(new ResultSegment <CloudQueue>(queuesList) { ContinuationToken = continuationToken, }); }; return(getCmd); }
/// <summary> /// Implementation for the PeekMessages method. /// </summary> /// <param name="messageCount">The message count.</param> /// <param name="options">A <see cref="QueueRequestOptions"/> object that specifies any additional options for the request.</param> /// <returns>A <see cref="RESTCommand"/> that gets the permissions.</returns> private RESTCommand<IEnumerable<CloudQueueMessage>> PeekMessagesImpl(int messageCount, QueueRequestOptions options) { RESTCommand<IEnumerable<CloudQueueMessage>> getCmd = new RESTCommand<IEnumerable<CloudQueueMessage>>(this.ServiceClient.Credentials, this.GetMessageRequestAddress()); options.ApplyToStorageCommand(getCmd); getCmd.Handler = this.ServiceClient.AuthenticationHandler; getCmd.BuildClient = HttpClientFactory.BuildHttpClient; getCmd.RetrieveResponseStream = true; getCmd.BuildRequest = (cmd, cnt, ctx) => QueueHttpRequestMessageFactory.PeekMessages(getCmd.Uri, getCmd.ServerTimeoutInSeconds, messageCount, cnt, ctx); getCmd.PreProcessResponse = (cmd, resp, ex, ctx) => HttpResponseParsers.ProcessExpectedStatusCodeNoException(HttpStatusCode.OK, resp, null, cmd, ex, ctx); getCmd.PostProcessResponse = (cmd, resp, ex, ctx) => { return Task.Factory.StartNew(() => { GetMessagesResponse getMessagesResponse = new GetMessagesResponse(cmd.ResponseStream); IEnumerable<CloudQueueMessage> messagesList = new List<CloudQueueMessage>( getMessagesResponse.Messages.Select(item => SelectPeekMessageResponse(item))); return messagesList; }); }; return getCmd; }
/// <summary> /// Implementation for the UpdateMessage method. /// </summary> /// <param name="message">The message to update.</param> /// <param name="visibilityTimeout">The visibility timeout interval.</param> /// <param name="updateFields">The message update fields.</param> /// <param name="options">A <see cref="QueueRequestOptions"/> object that specifies any additional options for the request.</param> /// <returns>A <see cref="RESTCommand"/> that sets the permissions.</returns> private RESTCommand<NullType> UpdateMessageImpl(CloudQueueMessage message, TimeSpan? visibilityTimeout, MessageUpdateFields updateFields, QueueRequestOptions options) { TimeSpan? effectiveVisibilityTimeout = visibilityTimeout; if ((updateFields & MessageUpdateFields.Visibility) != 0) { CommonUtils.AssertNotNull("visibilityTimeout", visibilityTimeout); } else { effectiveVisibilityTimeout = TimeSpan.FromSeconds(0); } Uri messageUri = this.GetIndividualMessageAddress(message.Id); RESTCommand<NullType> putCmd = new RESTCommand<NullType>(this.ServiceClient.Credentials, messageUri); options.ApplyToStorageCommand(putCmd); putCmd.Handler = this.ServiceClient.AuthenticationHandler; putCmd.BuildClient = HttpClientFactory.BuildHttpClient; putCmd.BuildRequest = (cmd, cnt, ctx) => QueueHttpRequestMessageFactory.UpdateMessage(cmd.Uri, cmd.ServerTimeoutInSeconds, message.PopReceipt, effectiveVisibilityTimeout, cnt, ctx); if ((updateFields & MessageUpdateFields.Content) != 0) { MemoryStream memoryStream = new MemoryStream(); QueueRequest.WriteMessageContent(message.GetMessageContentForTransfer(this.EncodeMessage), memoryStream); memoryStream.Seek(0, SeekOrigin.Begin); putCmd.BuildContent = (cmd, ctx) => HttpContentFactory.BuildContentFromStream(memoryStream, 0, memoryStream.Length, null, cmd, ctx); } putCmd.PreProcessResponse = (cmd, resp, ex, ctx) => { HttpResponseParsers.ProcessExpectedStatusCodeNoException(HttpStatusCode.NoContent, resp, NullType.Value, cmd, ex, ctx); GetPopReceiptAndNextVisibleTimeFromResponse(message, resp); return NullType.Value; }; return putCmd; }
/// <summary> /// Implementation for the GetPermissions method. /// </summary> /// <param name="options">A <see cref="QueueRequestOptions"/> object that specifies any additional options for the request.</param> /// <returns>A <see cref="RESTCommand"/> that gets the permissions.</returns> private RESTCommand<QueuePermissions> GetPermissionsImpl(QueueRequestOptions options) { RESTCommand<QueuePermissions> getCmd = new RESTCommand<QueuePermissions>(this.ServiceClient.Credentials, this.Uri); options.ApplyToStorageCommand(getCmd); getCmd.Handler = this.ServiceClient.AuthenticationHandler; getCmd.BuildClient = HttpClientFactory.BuildHttpClient; getCmd.RetrieveResponseStream = true; getCmd.BuildRequest = (cmd, cnt, ctx) => QueueHttpRequestMessageFactory.GetAcl(cmd.Uri, cmd.ServerTimeoutInSeconds, cnt, ctx); getCmd.PreProcessResponse = (cmd, resp, ex, ctx) => HttpResponseParsers.ProcessExpectedStatusCodeNoException(HttpStatusCode.OK, resp, null /* retVal */, cmd, ex, ctx); getCmd.PostProcessResponse = (cmd, resp, ex, ctx) => { this.GetMessageCountAndMetadataFromResponse(resp); return Task<QueuePermissions>.Factory.StartNew(() => { QueuePermissions queueAcl = new QueuePermissions(); QueueHttpResponseParsers.ReadSharedAccessIdentifiers(cmd.ResponseStream, queueAcl); return queueAcl; }); }; return getCmd; }
/// <summary> /// Implementation for the SetMetadata method. /// </summary> /// <param name="options">A <see cref="QueueRequestOptions"/> object that specifies any additional options for the request.</param> /// <returns>A <see cref="RESTCommand"/> that sets the metadata.</returns> private RESTCommand<NullType> SetMetadataImpl(QueueRequestOptions options) { RESTCommand<NullType> putCmd = new RESTCommand<NullType>(this.ServiceClient.Credentials, this.Uri); options.ApplyToStorageCommand(putCmd); putCmd.Handler = this.ServiceClient.AuthenticationHandler; putCmd.BuildClient = HttpClientFactory.BuildHttpClient; putCmd.BuildRequest = (cmd, cnt, ctx) => { HttpRequestMessage msg = QueueHttpRequestMessageFactory.SetMetadata(cmd.Uri, cmd.ServerTimeoutInSeconds, cnt, ctx); QueueHttpRequestMessageFactory.AddMetadata(msg, this.Metadata); return msg; }; putCmd.PreProcessResponse = (cmd, resp, ex, ctx) => { HttpResponseParsers.ProcessExpectedStatusCodeNoException(HttpStatusCode.NoContent, resp, NullType.Value, cmd, ex, ctx); GetMessageCountAndMetadataFromResponse(resp); return NullType.Value; }; return putCmd; }
/// <summary> /// Implementation for the FetchAttributes method. /// </summary> /// <param name="options">A <see cref="QueueRequestOptions"/> object that specifies any additional options for the request.</param> /// <returns>A <see cref="RESTCommand"/> that fetches the attributes.</returns> private RESTCommand<NullType> FetchAttributesImpl(QueueRequestOptions options) { RESTCommand<NullType> getCmd = new RESTCommand<NullType>(this.ServiceClient.Credentials, this.Uri); options.ApplyToStorageCommand(getCmd); getCmd.Handler = this.ServiceClient.AuthenticationHandler; getCmd.BuildClient = HttpClientFactory.BuildHttpClient; getCmd.BuildRequest = (cmd, cnt, ctx) => QueueHttpRequestMessageFactory.GetMetadata(cmd.Uri, cmd.ServerTimeoutInSeconds, cnt, ctx); getCmd.PreProcessResponse = (cmd, resp, ex, ctx) => { HttpResponseParsers.ProcessExpectedStatusCodeNoException(HttpStatusCode.OK, resp, NullType.Value, cmd, ex, ctx); GetMessageCountAndMetadataFromResponse(resp); return NullType.Value; }; return getCmd; }
/// <summary> /// Implementation for the UpdateMessage method. /// </summary> /// <param name="message">A queue message.</param> /// <param name="visibilityTimeout">The visibility timeout for the message.</param> /// <param name="updateFlags">Indicates whether to update the visibility delay, message contents, or both.</param> /// <param name="options">An <see cref="QueueRequestOptions"/> object that specifies any additional options for the request.</param> /// <returns>A <see cref="RESTCommand{T}"/> that sets the permissions.</returns> private RESTCommand<NullType> UpdateMessageImpl(CloudQueueMessage message, TimeSpan visibilityTimeout, MessageUpdateFields updateFlags, QueueRequestOptions options) { CommonUtils.AssertNotNull("message", message); CommonUtils.AssertNotNullOrEmpty("messageId", message.Id); CommonUtils.AssertNotNullOrEmpty("popReceipt", message.PopReceipt); CommonUtils.AssertInBounds<TimeSpan>("visibilityTimeout", visibilityTimeout, TimeSpan.Zero, CloudQueueMessage.MaxTimeToLive); if ((updateFlags & MessageUpdateFields.Visibility) == 0) { throw new ArgumentException("Calls to UpdateMessage must include the Visibility flag.", "updateFlags"); } Uri messageUri = this.GetIndividualMessageAddress(message.Id); RESTCommand<NullType> putCmd = new RESTCommand<NullType>(this.ServiceClient.Credentials, messageUri); options.ApplyToStorageCommand(putCmd); putCmd.BuildRequestDelegate = (uri, builder, serverTimeout, ctx) => QueueHttpWebRequestFactory.UpdateMessage(putCmd.Uri, serverTimeout, message.PopReceipt, visibilityTimeout.RoundUpToSeconds(), ctx); if ((updateFlags & MessageUpdateFields.Content) != 0) { MemoryStream memoryStream = new MemoryStream(); QueueRequest.WriteMessageContent(message.GetMessageContentForTransfer(this.EncodeMessage), memoryStream); memoryStream.Seek(0, SeekOrigin.Begin); putCmd.SendStream = memoryStream; putCmd.RecoveryAction = RecoveryActions.RewindStream; } else { putCmd.SetHeaders = (r, ctx) => { r.ContentLength = 0; }; } putCmd.SignRequest = this.ServiceClient.AuthenticationHandler.SignRequest; putCmd.PreProcessResponse = (cmd, resp, ex, ctx) => { HttpResponseParsers.ProcessExpectedStatusCodeNoException(HttpStatusCode.NoContent, resp, NullType.Value, cmd, ex, ctx); GetPopReceiptAndNextVisibleTimeFromResponse(message, resp); return NullType.Value; }; return putCmd; }
/// <summary> /// Implementation for the Exists method. /// </summary> /// <param name="options">A <see cref="QueueRequestOptions"/> object that specifies additional options for the request.</param> /// <param name="primaryOnly">If <c>true</c>, the command will be executed against the primary location.</param> /// <returns>A <see cref="RESTCommand"/> that checks existence.</returns> private RESTCommand<bool> ExistsImpl(QueueRequestOptions options, bool primaryOnly) { RESTCommand<bool> getCmd = new RESTCommand<bool>(this.ServiceClient.Credentials, this.StorageUri); options.ApplyToStorageCommand(getCmd); getCmd.CommandLocationMode = primaryOnly ? CommandLocationMode.PrimaryOnly : CommandLocationMode.PrimaryOrSecondary; getCmd.BuildRequest = (cmd, uri, builder, cnt, serverTimeout, ctx) => QueueHttpRequestMessageFactory.GetMetadata(uri, serverTimeout, cnt, ctx, this.ServiceClient.GetCanonicalizer(), this.ServiceClient.Credentials); getCmd.PreProcessResponse = (cmd, resp, ex, ctx) => { if (resp.StatusCode == HttpStatusCode.NotFound) { return false; } if (resp.StatusCode == HttpStatusCode.PreconditionFailed) { return true; } return HttpResponseParsers.ProcessExpectedStatusCodeNoException(HttpStatusCode.OK, resp, true, cmd, ex); }; return getCmd; }
/// <summary> /// Implementation for the FetchAttributes method. /// </summary> /// <param name="options">A <see cref="QueueRequestOptions"/> object that specifies additional options for the request.</param> /// <returns>A <see cref="RESTCommand"/> that fetches the attributes.</returns> private RESTCommand<NullType> FetchAttributesImpl(QueueRequestOptions options) { RESTCommand<NullType> getCmd = new RESTCommand<NullType>(this.ServiceClient.Credentials, this.StorageUri); options.ApplyToStorageCommand(getCmd); getCmd.CommandLocationMode = CommandLocationMode.PrimaryOrSecondary; getCmd.BuildRequest = (cmd, uri, builder, cnt, serverTimeout, ctx) => QueueHttpRequestMessageFactory.GetMetadata(uri, serverTimeout, cnt, ctx, this.ServiceClient.GetCanonicalizer(), this.ServiceClient.Credentials); getCmd.PreProcessResponse = (cmd, resp, ex, ctx) => { HttpResponseParsers.ProcessExpectedStatusCodeNoException(HttpStatusCode.OK, resp, NullType.Value, cmd, ex); GetMessageCountAndMetadataFromResponse(resp); return NullType.Value; }; return getCmd; }
/// <summary> /// Implementation for the Delete method. /// </summary> /// <param name="options">A <see cref="QueueRequestOptions"/> object that specifies additional options for the request.</param> /// <returns>A <see cref="RESTCommand"/> that deletes the queue.</returns> private RESTCommand<NullType> DeleteQueueImpl(QueueRequestOptions options) { RESTCommand<NullType> putCmd = new RESTCommand<NullType>(this.ServiceClient.Credentials, this.StorageUri); options.ApplyToStorageCommand(putCmd); putCmd.BuildRequest = (cmd, uri, builder, cnt, serverTimeout, ctx) => QueueHttpRequestMessageFactory.Delete(uri, serverTimeout, cnt, ctx, this.ServiceClient.GetCanonicalizer(), this.ServiceClient.Credentials); putCmd.PreProcessResponse = (cmd, resp, ex, ctx) => HttpResponseParsers.ProcessExpectedStatusCodeNoException(HttpStatusCode.NoContent, resp, NullType.Value, cmd, ex); return putCmd; }
/// <summary> /// Implementation for the Create method. /// </summary> /// <param name="options">A <see cref="QueueRequestOptions"/> object that specifies additional options for the request.</param> /// <returns>A <see cref="RESTCommand"/> that creates the queue.</returns> private RESTCommand<NullType> CreateQueueImpl(QueueRequestOptions options) { RESTCommand<NullType> putCmd = new RESTCommand<NullType>(this.ServiceClient.Credentials, this.StorageUri); options.ApplyToStorageCommand(putCmd); putCmd.BuildRequest = (cmd, uri, builder, cnt, serverTimeout, ctx) => { StorageRequestMessage msg = QueueHttpRequestMessageFactory.Create(uri, serverTimeout, cnt, ctx, this.ServiceClient.GetCanonicalizer(), this.ServiceClient.Credentials); QueueHttpRequestMessageFactory.AddMetadata(msg, this.Metadata); return msg; }; putCmd.PreProcessResponse = (cmd, resp, ex, ctx) => { HttpStatusCode[] expectedHttpStatusCodes = new HttpStatusCode[2]; expectedHttpStatusCodes[0] = HttpStatusCode.Created; expectedHttpStatusCodes[1] = HttpStatusCode.NoContent; HttpResponseParsers.ProcessExpectedStatusCodeNoException(expectedHttpStatusCodes, resp, NullType.Value, cmd, ex); GetMessageCountAndMetadataFromResponse(resp); return NullType.Value; }; return putCmd; }
/// <summary> /// Implementation for the PeekMessage method. /// </summary> /// <param name="options">A <see cref="QueueRequestOptions"/> object that specifies additional options for the request.</param> /// <returns>A <see cref="RESTCommand"/> that gets the permissions.</returns> private RESTCommand<CloudQueueMessage> PeekMessageImpl(QueueRequestOptions options) { RESTCommand<CloudQueueMessage> getCmd = new RESTCommand<CloudQueueMessage>(this.ServiceClient.Credentials, this.GetMessageRequestAddress()); options.ApplyToStorageCommand(getCmd); getCmd.RetrieveResponseStream = true; getCmd.BuildRequest = (cmd, uri, builder, cnt, serverTimeout, ctx) => QueueHttpRequestMessageFactory.PeekMessages(uri, serverTimeout, 1, cnt, ctx, this.ServiceClient.GetCanonicalizer(), this.ServiceClient.Credentials); getCmd.PreProcessResponse = (cmd, resp, ex, ctx) => HttpResponseParsers.ProcessExpectedStatusCodeNoException(HttpStatusCode.OK, resp, null /* retVal */, cmd, ex); getCmd.PostProcessResponse = (cmd, resp, ctx) => { return Task.Factory.StartNew(() => { using (IEnumerator<QueueMessage> enumerator = new GetMessagesResponse(cmd.ResponseStream).Messages.GetEnumerator()) { if (enumerator.MoveNext()) { return SelectPeekMessageResponse(enumerator.Current); } } return null; }); }; return getCmd; }
/// <summary> /// Implementation for the SetPermissions method. /// </summary> /// <param name="acl">The permissions to set.</param> /// <param name="options">A <see cref="QueueRequestOptions"/> object that specifies additional options for the request.</param> /// <returns>A <see cref="RESTCommand"/> that sets the permissions.</returns> private RESTCommand<NullType> SetPermissionsImpl(QueuePermissions acl, QueueRequestOptions options) { MultiBufferMemoryStream memoryStream = new MultiBufferMemoryStream(null /* bufferManager */, (int)(1 * Constants.KB)); QueueRequest.WriteSharedAccessIdentifiers(acl.SharedAccessPolicies, memoryStream); RESTCommand<NullType> putCmd = new RESTCommand<NullType>(this.ServiceClient.Credentials, this.StorageUri); options.ApplyToStorageCommand(putCmd); putCmd.BuildRequest = (cmd, uri, builder, cnt, serverTimeout, ctx) => QueueHttpRequestMessageFactory.SetAcl(uri, serverTimeout, cnt, ctx, this.ServiceClient.GetCanonicalizer(), this.ServiceClient.Credentials); putCmd.BuildContent = (cmd, ctx) => HttpContentFactory.BuildContentFromStream(memoryStream, 0, memoryStream.Length, null /* md5 */, cmd, ctx); putCmd.StreamToDispose = memoryStream; putCmd.PreProcessResponse = (cmd, resp, ex, ctx) => { HttpResponseParsers.ProcessExpectedStatusCodeNoException(HttpStatusCode.NoContent, resp, NullType.Value, cmd, ex); GetMessageCountAndMetadataFromResponse(resp); return NullType.Value; }; return putCmd; }
/// <summary> /// Implementation for the PeekMessages method. /// </summary> /// <param name="messageCount">The message count.</param> /// <param name="options">A <see cref="QueueRequestOptions"/> object that specifies additional options for the request.</param> /// <returns>A <see cref="RESTCommand"/> that gets the permissions.</returns> private RESTCommand<IEnumerable<CloudQueueMessage>> PeekMessagesImpl(int messageCount, QueueRequestOptions options) { RESTCommand<IEnumerable<CloudQueueMessage>> getCmd = new RESTCommand<IEnumerable<CloudQueueMessage>>(this.ServiceClient.Credentials, this.GetMessageRequestAddress()); options.ApplyToStorageCommand(getCmd); getCmd.CommandLocationMode = CommandLocationMode.PrimaryOrSecondary; getCmd.RetrieveResponseStream = true; getCmd.BuildRequest = (cmd, uri, builder, cnt, serverTimeout, ctx) => QueueHttpRequestMessageFactory.PeekMessages(uri, serverTimeout, messageCount, cnt, ctx, this.ServiceClient.GetCanonicalizer(), this.ServiceClient.Credentials); getCmd.PreProcessResponse = (cmd, resp, ex, ctx) => HttpResponseParsers.ProcessExpectedStatusCodeNoException(HttpStatusCode.OK, resp, null, cmd, ex); getCmd.PostProcessResponse = (cmd, resp, ctx) => { return Task.Factory.StartNew(() => { GetMessagesResponse getMessagesResponse = new GetMessagesResponse(cmd.ResponseStream); IEnumerable<CloudQueueMessage> messagesList = getMessagesResponse.Messages.Select(item => SelectPeekMessageResponse(item)).ToList(); return messagesList; }); }; return getCmd; }
/// <summary> /// Implementation for the Clear method. /// </summary> /// <param name="options">A <see cref="QueueRequestOptions"/> object that specifies additional options for the request.</param> /// <returns>A <see cref="RESTCommand"/> that deletes the queue.</returns> private RESTCommand<NullType> ClearImpl(QueueRequestOptions options) { RESTCommand<NullType> putCmd = new RESTCommand<NullType>(this.ServiceClient.Credentials, this.GetMessageRequestAddress()); options.ApplyToStorageCommand(putCmd); putCmd.Handler = this.ServiceClient.AuthenticationHandler; putCmd.BuildClient = HttpClientFactory.BuildHttpClient; putCmd.BuildRequest = (cmd, uri, builder, cnt, serverTimeout, ctx) => QueueHttpRequestMessageFactory.Delete(uri, serverTimeout, cnt, ctx); putCmd.PreProcessResponse = (cmd, resp, ex, ctx) => HttpResponseParsers.ProcessExpectedStatusCodeNoException(HttpStatusCode.NoContent, resp, NullType.Value, cmd, ex); return putCmd; }
/// <summary> /// Implementation for the PeekMessages method. /// </summary> /// <param name="messageCount">The number of messages to retrieve.</param> /// <param name="options">An <see cref="QueueRequestOptions"/> object that specifies any 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) { RESTCommand<IEnumerable<CloudQueueMessage>> getCmd = new RESTCommand<IEnumerable<CloudQueueMessage>>(this.ServiceClient.Credentials, this.GetMessageRequestAddress()); options.ApplyToStorageCommand(getCmd); getCmd.RetrieveResponseStream = true; getCmd.BuildRequestDelegate = (uri, builder, serverTimeout, ctx) => QueueHttpWebRequestFactory.PeekMessages(getCmd.Uri, serverTimeout, messageCount, ctx); getCmd.SignRequest = this.ServiceClient.AuthenticationHandler.SignRequest; getCmd.PreProcessResponse = (cmd, resp, ex, ctx) => HttpResponseParsers.ProcessExpectedStatusCodeNoException(HttpStatusCode.OK, resp, null /* retVal */, cmd, ex, ctx); getCmd.PostProcessResponse = (cmd, resp, ex, ctx) => { GetMessagesResponse getMessagesResponse = new GetMessagesResponse(cmd.ResponseStream); List<CloudQueueMessage> messagesList = new List<CloudQueueMessage>( getMessagesResponse.Messages.Select(item => SelectPeekMessageResponse(item))); return messagesList; }; return getCmd; }
/// <summary> /// Implementation for the UpdateMessage method. /// </summary> /// <param name="message">The message to update.</param> /// <param name="visibilityTimeout">The visibility timeout interval.</param> /// <param name="updateFields">The message update fields.</param> /// <param name="options">A <see cref="QueueRequestOptions"/> object that specifies additional options for the request.</param> /// <returns>A <see cref="RESTCommand"/> that sets the permissions.</returns> private RESTCommand<NullType> UpdateMessageImpl(CloudQueueMessage message, TimeSpan visibilityTimeout, MessageUpdateFields updateFields, QueueRequestOptions options) { CommonUtility.AssertNotNull("message", message); CommonUtility.AssertNotNullOrEmpty("messageId", message.Id); CommonUtility.AssertNotNullOrEmpty("popReceipt", message.PopReceipt); CommonUtility.AssertInBounds<TimeSpan>("visibilityTimeout", visibilityTimeout, TimeSpan.Zero, CloudQueueMessage.MaxTimeToLive); if ((updateFields & MessageUpdateFields.Visibility) == 0) { throw new ArgumentException(SR.UpdateMessageVisibilityRequired, "updateFlags"); } StorageUri messageUri = this.GetIndividualMessageAddress(message.Id); RESTCommand<NullType> putCmd = new RESTCommand<NullType>(this.ServiceClient.Credentials, messageUri); options.ApplyToStorageCommand(putCmd); putCmd.Handler = this.ServiceClient.AuthenticationHandler; putCmd.BuildClient = HttpClientFactory.BuildHttpClient; putCmd.BuildRequest = (cmd, uri, builder, cnt, serverTimeout, ctx) => QueueHttpRequestMessageFactory.UpdateMessage(uri, serverTimeout, message.PopReceipt, visibilityTimeout, cnt, ctx); if ((updateFields & MessageUpdateFields.Content) != 0) { MultiBufferMemoryStream memoryStream = new MultiBufferMemoryStream(null /* bufferManager */, (int)(1 * Constants.KB)); QueueRequest.WriteMessageContent(message.GetMessageContentForTransfer(this.EncodeMessage), memoryStream); memoryStream.Seek(0, SeekOrigin.Begin); putCmd.BuildContent = (cmd, ctx) => HttpContentFactory.BuildContentFromStream(memoryStream, 0, memoryStream.Length, null, cmd, ctx); } putCmd.PreProcessResponse = (cmd, resp, ex, ctx) => { HttpResponseParsers.ProcessExpectedStatusCodeNoException(HttpStatusCode.NoContent, resp, NullType.Value, cmd, ex); GetPopReceiptAndNextVisibleTimeFromResponse(message, resp); return NullType.Value; }; return putCmd; }
/// <summary> /// Implementation for the GetPermissions method. /// </summary> /// <param name="options">A <see cref="QueueRequestOptions"/> object that specifies additional options for the request.</param> /// <returns>A <see cref="RESTCommand"/> that gets the permissions.</returns> private RESTCommand<QueuePermissions> GetPermissionsImpl(QueueRequestOptions options) { RESTCommand<QueuePermissions> getCmd = new RESTCommand<QueuePermissions>(this.ServiceClient.Credentials, this.StorageUri); options.ApplyToStorageCommand(getCmd); getCmd.CommandLocationMode = CommandLocationMode.PrimaryOrSecondary; getCmd.RetrieveResponseStream = true; getCmd.BuildRequest = (cmd, uri, builder, cnt, serverTimeout, ctx) => QueueHttpRequestMessageFactory.GetAcl(uri, serverTimeout, cnt, ctx, this.ServiceClient.GetCanonicalizer(), this.ServiceClient.Credentials); getCmd.PreProcessResponse = (cmd, resp, ex, ctx) => HttpResponseParsers.ProcessExpectedStatusCodeNoException(HttpStatusCode.OK, resp, null /* retVal */, cmd, ex); getCmd.PostProcessResponse = (cmd, resp, ctx) => { this.GetMessageCountAndMetadataFromResponse(resp); return Task<QueuePermissions>.Factory.StartNew(() => { QueuePermissions queueAcl = new QueuePermissions(); QueueHttpResponseParsers.ReadSharedAccessIdentifiers(cmd.ResponseStream, queueAcl); return queueAcl; }); }; return getCmd; }
/// <summary> /// Core implementation of the ListQueues method. /// </summary> /// <param name="prefix">A string containing the queue name prefix.</param> /// <param name="maxResults">A non-negative integer value that indicates the maximum number of results to be returned at a time, up to the /// per-operation limit of 5000. If this value is <c>null</c>, the maximum possible number of results will be returned, up to 5000.</param> /// <param name="queueListingDetails">A <see cref="QueueListingDetails"/> enumeration describing which items to include in the listing.</param> /// <param name="options">A <see cref="QueueRequestOptions"/> object that specifies additional options for the request.</param> /// <param name="currentToken">The continuation token.</param> /// <returns>A <see cref="RESTCommand{T}"/> that lists the queues.</returns> private RESTCommand<ResultSegment<CloudQueue>> ListQueuesImpl(string prefix, int? maxResults, QueueListingDetails queueListingDetails, QueueRequestOptions options, QueueContinuationToken currentToken) { QueueListingContext listingContext = new QueueListingContext(prefix, maxResults, queueListingDetails) { Marker = currentToken != null ? currentToken.NextMarker : null }; RESTCommand<ResultSegment<CloudQueue>> getCmd = new RESTCommand<ResultSegment<CloudQueue>>(this.Credentials, this.StorageUri); options.ApplyToStorageCommand(getCmd); getCmd.CommandLocationMode = CommonUtility.GetListingLocationMode(currentToken); getCmd.RetrieveResponseStream = true; getCmd.BuildRequestDelegate = (uri, builder, serverTimeout, useVersionHeader, ctx) => QueueHttpWebRequestFactory.List(uri, serverTimeout, listingContext, queueListingDetails, useVersionHeader, ctx); getCmd.SignRequest = this.AuthenticationHandler.SignRequest; getCmd.PreProcessResponse = (cmd, resp, ex, ctx) => HttpResponseParsers.ProcessExpectedStatusCodeNoException(HttpStatusCode.OK, resp, null /* retVal */, cmd, ex); getCmd.PostProcessResponse = (cmd, resp, ctx) => { ListQueuesResponse listQueuesResponse = new ListQueuesResponse(cmd.ResponseStream); List<CloudQueue> queuesList = listQueuesResponse.Queues.Select(item => new CloudQueue(item.Metadata, item.Name, this)).ToList(); QueueContinuationToken continuationToken = null; if (listQueuesResponse.NextMarker != null) { continuationToken = new QueueContinuationToken() { NextMarker = listQueuesResponse.NextMarker, TargetLocation = cmd.CurrentResult.TargetLocation, }; } return new ResultSegment<CloudQueue>(queuesList) { ContinuationToken = continuationToken, }; }; return getCmd; }
/// <summary> /// Implementation for the Exists method. /// </summary> /// <param name="options">A <see cref="QueueRequestOptions"/> object that specifies any additional options for the request.</param> /// <returns>A <see cref="RESTCommand"/> that checks existence.</returns> private RESTCommand<bool> ExistsImpl(QueueRequestOptions options) { RESTCommand<bool> getCmd = new RESTCommand<bool>(this.ServiceClient.Credentials, this.Uri); options.ApplyToStorageCommand(getCmd); getCmd.Handler = this.ServiceClient.AuthenticationHandler; getCmd.BuildClient = HttpClientFactory.BuildHttpClient; getCmd.BuildRequest = (cmd, cnt, ctx) => QueueHttpRequestMessageFactory.GetMetadata(cmd.Uri, cmd.ServerTimeoutInSeconds, cnt, ctx); getCmd.PreProcessResponse = (cmd, resp, ex, ctx) => { if (resp.StatusCode == HttpStatusCode.NotFound) { return false; } if (resp.StatusCode == HttpStatusCode.PreconditionFailed) { return true; } return HttpResponseParsers.ProcessExpectedStatusCodeNoException(HttpStatusCode.OK, resp, true, cmd, ex, ctx); }; return getCmd; }
private RESTCommand<NullType> SetServicePropertiesImpl(ServiceProperties properties, QueueRequestOptions requestOptions) { MultiBufferMemoryStream str = new MultiBufferMemoryStream(null /* bufferManager */, (int)(1 * Constants.KB)); try { properties.WriteServiceProperties(str); } catch (InvalidOperationException invalidOpException) { str.Dispose(); throw new ArgumentException(invalidOpException.Message, "properties"); } str.Seek(0, SeekOrigin.Begin); RESTCommand<NullType> retCmd = new RESTCommand<NullType>(this.Credentials, this.StorageUri); retCmd.SendStream = str; retCmd.StreamToDispose = str; retCmd.BuildRequestDelegate = QueueHttpWebRequestFactory.SetServiceProperties; retCmd.RecoveryAction = RecoveryActions.RewindStream; retCmd.SignRequest = this.AuthenticationHandler.SignRequest; retCmd.PreProcessResponse = (cmd, resp, ex, ctx) => HttpResponseParsers.ProcessExpectedStatusCodeNoException(HttpStatusCode.Accepted, resp, NullType.Value, cmd, ex); requestOptions.ApplyToStorageCommand(retCmd); return retCmd; }
/// <summary> /// Implementation for the SetPermissions method. /// </summary> /// <param name="acl">The permissions to set.</param> /// <param name="options">A <see cref="QueueRequestOptions"/> object that specifies any additional options for the request.</param> /// <returns>A <see cref="RESTCommand"/> that sets the permissions.</returns> private RESTCommand<NullType> SetPermissionsImpl(QueuePermissions acl, QueueRequestOptions options) { MemoryStream memoryStream = new MemoryStream(); QueueRequest.WriteSharedAccessIdentifiers(acl.SharedAccessPolicies, memoryStream); RESTCommand<NullType> putCmd = new RESTCommand<NullType>(this.ServiceClient.Credentials, this.Uri); options.ApplyToStorageCommand(putCmd); putCmd.Handler = this.ServiceClient.AuthenticationHandler; putCmd.BuildClient = HttpClientFactory.BuildHttpClient; putCmd.BuildRequest = (cmd, cnt, ctx) => QueueHttpRequestMessageFactory.SetAcl(cmd.Uri, cmd.ServerTimeoutInSeconds, cnt, ctx); putCmd.BuildContent = (cmd, ctx) => HttpContentFactory.BuildContentFromStream(memoryStream, 0, memoryStream.Length, null, cmd, ctx); putCmd.PreProcessResponse = (cmd, resp, ex, ctx) => { HttpResponseParsers.ProcessExpectedStatusCodeNoException(HttpStatusCode.NoContent, resp, NullType.Value, cmd, ex, ctx); GetMessageCountAndMetadataFromResponse(resp); return NullType.Value; }; return putCmd; }
private RESTCommand<ServiceStats> GetServiceStatsImpl(QueueRequestOptions requestOptions) { if (RetryPolicies.LocationMode.PrimaryOnly == requestOptions.LocationMode) { throw new InvalidOperationException(SR.GetServiceStatsInvalidOperation); } RESTCommand<ServiceStats> retCmd = new RESTCommand<ServiceStats>(this.Credentials, this.StorageUri); requestOptions.ApplyToStorageCommand(retCmd); retCmd.CommandLocationMode = CommandLocationMode.PrimaryOrSecondary; retCmd.BuildRequestDelegate = QueueHttpWebRequestFactory.GetServiceStats; retCmd.SignRequest = this.AuthenticationHandler.SignRequest; retCmd.RetrieveResponseStream = true; retCmd.PreProcessResponse = (cmd, resp, ex, ctx) => HttpResponseParsers.ProcessExpectedStatusCodeNoException(HttpStatusCode.OK, resp, null /* retVal */, cmd, ex); retCmd.PostProcessResponse = (cmd, resp, ctx) => QueueHttpResponseParsers.ReadServiceStats(cmd.ResponseStream); return retCmd; }
/// <summary> /// Implementation for the AddMessageImpl method. /// </summary> /// <param name="message">The message.</param> /// <param name="timeToLive">The maximum time to allow the message to be in the queue, or null.</param> /// <param name="initialVisibilityDelay">The length of time from now during which the message will be invisible. /// If <c>null</c> then the message will be visible immediately.</param> /// <param name="options">A <see cref="QueueRequestOptions"/> object that specifies any additional options for the request.</param> /// <returns>A <see cref="RESTCommand"/> that sets the permissions.</returns> private RESTCommand<NullType> AddMessageImpl(CloudQueueMessage message, TimeSpan? timeToLive, TimeSpan? initialVisibilityDelay, QueueRequestOptions options) { MemoryStream memoryStream = new MemoryStream(); QueueRequest.WriteMessageContent(message.GetMessageContentForTransfer(this.EncodeMessage), memoryStream); memoryStream.Seek(0, SeekOrigin.Begin); RESTCommand<NullType> putCmd = new RESTCommand<NullType>(this.ServiceClient.Credentials, this.GetMessageRequestAddress()); options.ApplyToStorageCommand(putCmd); putCmd.Handler = this.ServiceClient.AuthenticationHandler; putCmd.BuildClient = HttpClientFactory.BuildHttpClient; putCmd.BuildRequest = (cmd, cnt, ctx) => QueueHttpRequestMessageFactory.AddMessage(cmd.Uri, cmd.ServerTimeoutInSeconds, timeToLive, initialVisibilityDelay, cnt, ctx); putCmd.BuildContent = (cmd, ctx) => HttpContentFactory.BuildContentFromStream(memoryStream, 0, memoryStream.Length, null, cmd, ctx); putCmd.PreProcessResponse = (cmd, resp, ex, ctx) => { HttpResponseParsers.ProcessExpectedStatusCodeNoException(HttpStatusCode.Created, resp, NullType.Value, cmd, ex, ctx); GetMessageCountAndMetadataFromResponse(resp); return NullType.Value; }; return putCmd; }
/// <summary> /// Implementation for the SetMetadata method. /// </summary> /// <param name="options">An <see cref="QueueRequestOptions"/> object that specifies any additional options for the request.</param> /// <returns>A <see cref="RESTCommand{T}"/> that sets the metadata.</returns> private RESTCommand<NullType> SetMetadataImpl(QueueRequestOptions options) { RESTCommand<NullType> putCmd = new RESTCommand<NullType>(this.ServiceClient.Credentials, this.Uri); options.ApplyToStorageCommand(putCmd); putCmd.BuildRequestDelegate = (uri, builder, serverTimeout, ctx) => QueueHttpWebRequestFactory.SetMetadata(uri, serverTimeout, ctx); putCmd.SetHeaders = (r, ctx) => QueueHttpWebRequestFactory.AddMetadata(r, this.Metadata); putCmd.SignRequest = this.ServiceClient.AuthenticationHandler.SignRequest; putCmd.PreProcessResponse = (cmd, resp, ex, ctx) => { HttpResponseParsers.ProcessExpectedStatusCodeNoException(HttpStatusCode.NoContent, resp, NullType.Value, cmd, ex, ctx); return NullType.Value; }; return putCmd; }
/// <summary> /// Implementation for the DeleteMessage method. /// </summary> /// <param name="messageId">The message ID.</param> /// <param name="popReceipt">The pop receipt value.</param> /// <param name="options">A <see cref="QueueRequestOptions"/> object that specifies any additional options for the request.</param> /// <returns>A <see cref="RESTCommand"/> that deletes the queue.</returns> private RESTCommand<NullType> DeleteMessageImpl(string messageId, string popReceipt, QueueRequestOptions options) { Uri messageUri = this.GetIndividualMessageAddress(messageId); RESTCommand<NullType> putCmd = new RESTCommand<NullType>(this.ServiceClient.Credentials, messageUri); options.ApplyToStorageCommand(putCmd); putCmd.Handler = this.ServiceClient.AuthenticationHandler; putCmd.BuildClient = HttpClientFactory.BuildHttpClient; putCmd.BuildRequest = (cmd, cnt, ctx) => QueueHttpRequestMessageFactory.DeleteMessage(cmd.Uri, cmd.ServerTimeoutInSeconds, popReceipt, cnt, ctx); putCmd.PreProcessResponse = (cmd, resp, ex, ctx) => HttpResponseParsers.ProcessExpectedStatusCodeNoException(HttpStatusCode.NoContent, resp, NullType.Value, cmd, ex, ctx); return putCmd; }
/// <summary> /// Implementation for the GetPermissions method. /// </summary> /// <param name="options">An <see cref="QueueRequestOptions"/> object that specifies any additional options for the request.</param> /// <returns>A <see cref="RESTCommand{T}"/> that gets the permissions.</returns> private RESTCommand<QueuePermissions> GetPermissionsImpl(QueueRequestOptions options) { RESTCommand<QueuePermissions> getCmd = new RESTCommand<QueuePermissions>(this.ServiceClient.Credentials, this.Uri); options.ApplyToStorageCommand(getCmd); getCmd.RetrieveResponseStream = true; getCmd.BuildRequestDelegate = (uri, builder, serverTimeout, ctx) => QueueHttpWebRequestFactory.GetAcl(uri, serverTimeout, ctx); getCmd.SignRequest = this.ServiceClient.AuthenticationHandler.SignRequest; getCmd.PreProcessResponse = (cmd, resp, ex, ctx) => HttpResponseParsers.ProcessExpectedStatusCodeNoException(HttpStatusCode.OK, resp, null /* retVal */, cmd, ex, ctx); getCmd.PostProcessResponse = (cmd, resp, ex, ctx) => { QueuePermissions queueAcl = new QueuePermissions(); QueueHttpResponseParsers.ReadSharedAccessIdentifiers(cmd.ResponseStream, queueAcl); return queueAcl; }; return getCmd; }
/// <summary> /// Implementation for the GetPermissions method. /// </summary> /// <param name="visibilityTimeout">The visibility timeout interval.</param> /// <param name="options">A <see cref="QueueRequestOptions"/> object that specifies any additional options for the request.</param> /// <returns>A <see cref="RESTCommand"/> that gets the permissions.</returns> private RESTCommand<CloudQueueMessage> GetMessageImpl(TimeSpan? visibilityTimeout, QueueRequestOptions options) { RESTCommand<CloudQueueMessage> getCmd = new RESTCommand<CloudQueueMessage>(this.ServiceClient.Credentials, this.GetMessageRequestAddress()); options.ApplyToStorageCommand(getCmd); getCmd.Handler = this.ServiceClient.AuthenticationHandler; getCmd.BuildClient = HttpClientFactory.BuildHttpClient; getCmd.RetrieveResponseStream = true; getCmd.BuildRequest = (cmd, cnt, ctx) => QueueHttpRequestMessageFactory.GetMessages(getCmd.Uri, getCmd.ServerTimeoutInSeconds, 1, visibilityTimeout, cnt, ctx); getCmd.PreProcessResponse = (cmd, resp, ex, ctx) => HttpResponseParsers.ProcessExpectedStatusCodeNoException(HttpStatusCode.OK, resp, null /* retVal */, cmd, ex, ctx); getCmd.PostProcessResponse = (cmd, resp, ex, ctx) => { return Task.Factory.StartNew(() => { using (IEnumerator<QueueMessage> enumerator = new GetMessagesResponse(cmd.ResponseStream).Messages.GetEnumerator()) { if (enumerator.MoveNext()) { return SelectGetMessageResponse(enumerator.Current); } } return null; }); }; return getCmd; }
/// <summary> /// Implementation for the AddMessageImpl method. /// </summary> /// <param name="message">A queue message.</param> /// <param name="timeToLive">A value indicating the message time-to-live.</param> /// <param name="initialVisibilityDelay">The visibility delay for the message.</param> /// <param name="options">An <see cref="QueueRequestOptions"/> object that specifies any additional options for the request.</param> /// <returns>A <see cref="RESTCommand{T}"/> that sets the permissions.</returns> private RESTCommand<NullType> AddMessageImpl(CloudQueueMessage message, TimeSpan? timeToLive, TimeSpan? initialVisibilityDelay, QueueRequestOptions options) { int? timeToLiveInSeconds = null; int? initialVisibilityDelayInSeconds = null; if (timeToLive != null) { CommonUtils.AssertInBounds<TimeSpan>("timeToLive", timeToLive.Value, TimeSpan.Zero, CloudQueueMessage.MaxTimeToLive); timeToLiveInSeconds = (int)timeToLive.Value.TotalSeconds; } if (initialVisibilityDelay != null) { CommonUtils.AssertInBounds<TimeSpan>("initialVisibilityDelay", initialVisibilityDelay.Value, TimeSpan.Zero, timeToLive ?? CloudQueueMessage.MaxTimeToLive); initialVisibilityDelayInSeconds = (int)initialVisibilityDelay.Value.TotalSeconds; } CommonUtils.AssertNotNull("message", message); CommonUtils.AssertNotNull("MessageContent", message.AsBytes); MemoryStream memoryStream = new MemoryStream(); QueueRequest.WriteMessageContent(message.GetMessageContentForTransfer(this.EncodeMessage), memoryStream); memoryStream.Seek(0, SeekOrigin.Begin); RESTCommand<NullType> putCmd = new RESTCommand<NullType>(this.ServiceClient.Credentials, this.GetMessageRequestAddress()); options.ApplyToStorageCommand(putCmd); putCmd.BuildRequestDelegate = (uri, builder, serverTimeout, ctx) => QueueHttpWebRequestFactory.AddMessage(putCmd.Uri, serverTimeout, timeToLiveInSeconds, initialVisibilityDelayInSeconds, ctx); putCmd.SendStream = memoryStream; putCmd.RecoveryAction = RecoveryActions.RewindStream; putCmd.SetHeaders = (r, ctx) => { if (timeToLive != null) { r.Headers.Set(Constants.QueryConstants.MessageTimeToLive, timeToLive.Value.TotalSeconds.ToString()); } if (initialVisibilityDelay != null) { r.Headers.Set(Constants.QueryConstants.VisibilityTimeout, initialVisibilityDelay.Value.TotalSeconds.ToString()); } }; putCmd.SignRequest = this.ServiceClient.AuthenticationHandler.SignRequest; putCmd.PreProcessResponse = (cmd, resp, ex, ctx) => { HttpResponseParsers.ProcessExpectedStatusCodeNoException(HttpStatusCode.Created, resp, NullType.Value, cmd, ex, ctx); return NullType.Value; }; return putCmd; }
/// <summary> /// Implementation for the SetPermissions method. /// </summary> /// <param name="acl">The permissions to set.</param> /// <param name="options">An <see cref="QueueRequestOptions"/> object that specifies any additional options for the request.</param> /// <returns>A <see cref="RESTCommand{T}"/> that sets the permissions.</returns> private RESTCommand<NullType> SetPermissionsImpl(QueuePermissions acl, QueueRequestOptions options) { MemoryStream memoryStream = new MemoryStream(); QueueRequest.WriteSharedAccessIdentifiers(acl.SharedAccessPolicies, memoryStream); memoryStream.Seek(0, SeekOrigin.Begin); RESTCommand<NullType> putCmd = new RESTCommand<NullType>(this.ServiceClient.Credentials, this.Uri); options.ApplyToStorageCommand(putCmd); putCmd.BuildRequestDelegate = (uri, builder, serverTimeout, ctx) => QueueHttpWebRequestFactory.SetAcl(uri, serverTimeout, ctx); putCmd.SendStream = memoryStream; putCmd.RecoveryAction = RecoveryActions.RewindStream; putCmd.SignRequest = this.ServiceClient.AuthenticationHandler.SignRequest; putCmd.PreProcessResponse = (cmd, resp, ex, ctx) => { HttpResponseParsers.ProcessExpectedStatusCodeNoException(HttpStatusCode.NoContent, resp, NullType.Value, cmd, ex, ctx); return NullType.Value; }; return putCmd; }
/// <summary> /// Implementation for the AddMessage method. /// </summary> /// <param name="message">The message.</param> /// <param name="timeToLive">The maximum time to allow the message to be in the queue, or null.</param> /// <param name="initialVisibilityDelay">The length of time from now during which the message will be invisible. /// If <c>null</c> then the message will be visible immediately.</param> /// <param name="options">A <see cref="QueueRequestOptions"/> object that specifies additional options for the request.</param> /// <returns>A <see cref="RESTCommand"/> that sets the permissions.</returns> private RESTCommand<NullType> AddMessageImpl(CloudQueueMessage message, TimeSpan? timeToLive, TimeSpan? initialVisibilityDelay, QueueRequestOptions options) { int? timeToLiveInSeconds = null; int? initialVisibilityDelayInSeconds = null; if (timeToLive.HasValue) { CommonUtility.AssertInBounds("timeToLive", timeToLive.Value, TimeSpan.Zero, CloudQueueMessage.MaxTimeToLive); timeToLiveInSeconds = (int)timeToLive.Value.TotalSeconds; } if (initialVisibilityDelay.HasValue) { CommonUtility.AssertInBounds("initialVisibilityDelay", initialVisibilityDelay.Value, TimeSpan.Zero, timeToLive ?? CloudQueueMessage.MaxTimeToLive); initialVisibilityDelayInSeconds = (int)initialVisibilityDelay.Value.TotalSeconds; } MultiBufferMemoryStream memoryStream = new MultiBufferMemoryStream(null /* bufferManager */, (int)(1 * Constants.KB)); QueueRequest.WriteMessageContent(message.GetMessageContentForTransfer(this.EncodeMessage), memoryStream); memoryStream.Seek(0, SeekOrigin.Begin); RESTCommand<NullType> putCmd = new RESTCommand<NullType>(this.ServiceClient.Credentials, this.GetMessageRequestAddress()); options.ApplyToStorageCommand(putCmd); putCmd.BuildRequest = (cmd, uri, builder, cnt, serverTimeout, ctx) => QueueHttpRequestMessageFactory.AddMessage(uri, serverTimeout, timeToLiveInSeconds, initialVisibilityDelayInSeconds, cnt, ctx, this.ServiceClient.GetCanonicalizer(), this.ServiceClient.Credentials); putCmd.BuildContent = (cmd, ctx) => HttpContentFactory.BuildContentFromStream(memoryStream, 0, memoryStream.Length, null, cmd, ctx); putCmd.StreamToDispose = memoryStream; putCmd.PreProcessResponse = (cmd, resp, ex, ctx) => { HttpResponseParsers.ProcessExpectedStatusCodeNoException(HttpStatusCode.Created, resp, NullType.Value, cmd, ex); GetMessageCountAndMetadataFromResponse(resp); return NullType.Value; }; return putCmd; }