public Task<bool> DeleteIfExists(QueueRequestOptions options = null, OperationContext operationContext = null, CancellationToken? cancellationToken = null) { return AsyncTaskUtil.RunAsyncCancellable<bool>( _inner.BeginDeleteIfExists(options, operationContext, null, null), _inner.EndDeleteIfExists, cancellationToken); }
public Task DeleteMessage(CloudQueueMessage message, QueueRequestOptions options = null, OperationContext operationContext = null, CancellationToken? cancellationToken = null) { return AsyncTaskUtil.RunAsyncCancellable( _inner.BeginDeleteMessage(message, options, operationContext, null, null), _inner.EndDeleteMessage, cancellationToken); }
public Task AddMessage(CloudQueueMessage message, TimeSpan? timeToLive = null, TimeSpan? initialVisibilityDelay = null, QueueRequestOptions options = null, OperationContext operationContext = null, CancellationToken? cancellationToken = null) { return AsyncTaskUtil.RunAsyncCancellable( _inner.BeginAddMessage(message, timeToLive, initialVisibilityDelay, options, operationContext, null, null), _inner.EndAddMessage, cancellationToken); }
public Task Create(QueueRequestOptions options = null, OperationContext operationContext = null, CancellationToken? cancellationToken = null) { return AsyncTaskUtil.RunAsyncCancellable( _inner.BeginCreate(options, operationContext, null, null), _inner.EndCreate, cancellationToken); }
/// <summary> /// Sends the given <see cref="TransportMessage"/> to the queue with the specified globally addressable name /// </summary> public async Task Send(string destinationAddress, TransportMessage message, ITransactionContext context) { context.OnCommitted(async () => { var headers = message.Headers.Clone(); var queue = GetQueue(destinationAddress); var messageId = Guid.NewGuid().ToString(); var popReceipt = Guid.NewGuid().ToString(); var timeToBeReceivedOrNull = GetTimeToBeReceivedOrNull(headers); var queueVisibilityDelayOrNull = GetQueueVisibilityDelayOrNull(headers); var cloudQueueMessage = Serialize(messageId, popReceipt, headers, message.Body); try { var options = new QueueRequestOptions {RetryPolicy = new ExponentialRetry()}; var operationContext = new OperationContext(); await queue.AddMessageAsync(cloudQueueMessage, timeToBeReceivedOrNull, queueVisibilityDelayOrNull, options, operationContext); } catch (Exception exception) { throw new RebusApplicationException(exception, $"Could not send message with ID {cloudQueueMessage.Id} to '{destinationAddress}'"); } }); }
/// <summary> /// Returns an enumerable collection of the queues in the storage account whose names begin with the specified prefix and that are retrieved lazily. /// </summary> /// <param name="prefix">The queue name prefix.</param> /// <param name="queueListingDetails">An enumeration value that indicates which details to include in the listing.</param> /// <param name="options">An object that specifies any additional options for the request.</param> /// <param name="operationContext">An <see cref="OperationContext"/> object that represents the context for the current operation. This object is used to track requests, and to provide additional runtime information about the operation.</param> /// <returns>An enumerable collection of objects that implement <see cref="CloudQueue"/> and are retrieved lazily.</returns> public IEnumerable<CloudQueue> ListQueues(string prefix, QueueListingDetails queueListingDetails = QueueListingDetails.None, QueueRequestOptions options = null, OperationContext operationContext = null) { QueueRequestOptions modifiedOptions = QueueRequestOptions.ApplyDefaults(options, this); operationContext = operationContext ?? new OperationContext(); return General.LazyEnumerable((token) => this.ListQueuesSegmentedCore(prefix, queueListingDetails, 0, token as QueueContinuationToken, modifiedOptions, operationContext), long.MaxValue, operationContext); }
static void Main(string[] args) { Console.WriteLine("Queue encryption sample"); // Retrieve storage account information from connection string // How to create a storage connection string - https://azure.microsoft.com/en-us/documentation/articles/storage-configure-connection-string/ CloudStorageAccount storageAccount = EncryptionShared.Utility.CreateStorageAccountFromConnectionString(); CloudQueueClient client = storageAccount.CreateCloudQueueClient(); CloudQueue queue = client.GetQueueReference(DemoQueue + Guid.NewGuid().ToString("N")); try { queue.Create(); // Create the IKey used for encryption. RsaKey key = new RsaKey("private:key1"); // Create the encryption policy to be used for insert and update. QueueEncryptionPolicy insertPolicy = new QueueEncryptionPolicy(key, null); // Set the encryption policy on the request options. QueueRequestOptions insertOptions = new QueueRequestOptions() { EncryptionPolicy = insertPolicy }; string messageStr = Guid.NewGuid().ToString(); CloudQueueMessage message = new CloudQueueMessage(messageStr); // Add message Console.WriteLine("Inserting the encrypted message."); queue.AddMessage(message, null, null, insertOptions, null); // For retrieves, a resolver can be set up that will help pick the key based on the key id. LocalResolver resolver = new LocalResolver(); resolver.Add(key); QueueEncryptionPolicy retrPolicy = new QueueEncryptionPolicy(null, resolver); QueueRequestOptions retrieveOptions = new QueueRequestOptions() { EncryptionPolicy = retrPolicy }; // Retrieve message Console.WriteLine("Retrieving the encrypted message."); CloudQueueMessage retrMessage = queue.GetMessage(null, retrieveOptions, null); // Update message Console.WriteLine("Updating the encrypted message."); string updatedMessage = Guid.NewGuid().ToString("N"); retrMessage.SetMessageContent(updatedMessage); queue.UpdateMessage(retrMessage, TimeSpan.FromSeconds(0), MessageUpdateFields.Content | MessageUpdateFields.Visibility, insertOptions, null); // Retrieve updated message Console.WriteLine("Retrieving the updated encrypted message."); retrMessage = queue.GetMessage(null, retrieveOptions, null); Console.WriteLine("Press enter key to exit"); Console.ReadLine(); } finally { queue.DeleteIfExists(); } }
public WorkerRole() { ocrMessageVisibilityTimeout = TimeSpan.FromMinutes(1); ocrQueueRequestOptions = new QueueRequestOptions { MaximumExecutionTime = TimeSpan.FromMinutes(15), RetryPolicy = new LinearRetry(TimeSpan.FromMinutes(1), 5) }; }
/// <summary> /// Creates the queue. /// </summary> /// <param name="options">An <see cref="QueueRequestOptions"/> object that specifies any additional options for the request.</param> /// <param name="operationContext">An <see cref="OperationContext"/> object that represents the context for the current operation. This object is used to track requests to the storage service, and to provide additional runtime information about the operation.</param> public void Create(QueueRequestOptions options = null, OperationContext operationContext = null) { QueueRequestOptions modifiedOptions = QueueRequestOptions.ApplyDefaults(options, this.ServiceClient); operationContext = operationContext ?? new OperationContext(); Executor.ExecuteSync( this.CreateQueueImpl(modifiedOptions), modifiedOptions.RetryPolicy, operationContext); }
internal static QueueRequestOptions ApplyDefaults(QueueRequestOptions options, CloudQueueClient serviceClient) { QueueRequestOptions modifiedOptions = new QueueRequestOptions(options); modifiedOptions.RetryPolicy = modifiedOptions.RetryPolicy ?? serviceClient.RetryPolicy; modifiedOptions.ServerTimeout = modifiedOptions.ServerTimeout ?? serviceClient.ServerTimeout; modifiedOptions.MaximumExecutionTime = modifiedOptions.MaximumExecutionTime ?? serviceClient.MaximumExecutionTime; return modifiedOptions; }
/// <summary> /// Clones an instance of QueueRequestOptions so that we can apply defaults. /// </summary> /// <param name="other">QueueRequestOptions instance to be cloned.</param> internal QueueRequestOptions(QueueRequestOptions other) : this() { if (other != null) { this.RetryPolicy = other.RetryPolicy; this.ServerTimeout = other.ServerTimeout; this.MaximumExecutionTime = other.MaximumExecutionTime; } }
public virtual Task CreateAsync(QueueRequestOptions options, OperationContext operationContext, CancellationToken cancellationToken) { QueueRequestOptions modifiedOptions = QueueRequestOptions.ApplyDefaults(options, this.ServiceClient); operationContext = operationContext ?? new OperationContext(); return Task.Run(async () => await Executor.ExecuteAsyncNullReturn( this.CreateQueueImpl(modifiedOptions), modifiedOptions.RetryPolicy, operationContext, cancellationToken), cancellationToken); }
/// <summary> /// Creates the queue. /// </summary> /// <param name="options">A <see cref="QueueRequestOptions"/> object that specifies any additional options for the request.</param> /// <param name="operationContext">An <see cref="OperationContext"/> object that represents the context for the current operation.</param> /// <returns>An <see cref="IAsyncAction"/> that represents an asynchronous action.</returns> public IAsyncAction CreateAsync(QueueRequestOptions options, OperationContext operationContext) { QueueRequestOptions modifiedOptions = QueueRequestOptions.ApplyDefaults(options, this.ServiceClient); operationContext = operationContext ?? new OperationContext(); return AsyncInfo.Run(async (token) => await Executor.ExecuteAsyncNullReturn( this.CreateQueueImpl(modifiedOptions), modifiedOptions.RetryPolicy, operationContext, token)); }
/// <summary> /// Delete the specified storage queue. /// </summary> /// <param name="queue">Cloud queue object</param> /// <param name="options">Queue request options</param> /// <param name="operationContext">Operation context</param> public void DeleteQueue(CloudQueue queue, QueueRequestOptions options, OperationContext operationContext) { foreach (CloudQueue queueRef in queueList) { if (queue.Name == queueRef.Name) { queueList.Remove(queueRef); return; } } }
/// <summary> /// Begins an asynchronous operation to create a queue. /// </summary> /// <param name="options">An <see cref="QueueRequestOptions"/> object that specifies any additional options for the request.</param> /// <param name="operationContext">An <see cref="OperationContext"/> object that represents the context for the current operation. This object is used to track requests to the storage service, and to provide additional runtime information about the operation.</param> /// <param name="callback">The callback delegate that will receive notification when the asynchronous operation completes.</param> /// <param name="state">A user-defined object that will be passed to the callback delegate.</param> /// <returns>An <see cref="ICancellableAsyncResult"/> that references the asynchronous operation.</returns> public ICancellableAsyncResult BeginCreate(QueueRequestOptions options, OperationContext operationContext, AsyncCallback callback, object state) { QueueRequestOptions modifiedOptions = QueueRequestOptions.ApplyDefaults(options, this.ServiceClient); operationContext = operationContext ?? new OperationContext(); return Executor.BeginExecuteAsync( this.CreateQueueImpl(modifiedOptions), modifiedOptions.RetryPolicy, operationContext, callback, state); }
/// <summary> /// Get an queue reference from azure server. /// </summary> /// <param name="name">Queue name</param> /// <param name="options">Queue request options</param> /// <param name="operationContext">Operation context</param> /// <returns>Cloud queue object if the specified queue exists, otherwise null.</returns> public CloudQueue GetQueueReferenceFromServer(string name, QueueRequestOptions options, OperationContext operationContext) { CloudQueue queue = queueClient.GetQueueReference(name); if (queue.Exists(options, operationContext)) { return queue; } else { return null; } }
/// <summary> /// Wrapper method that adds a message to the queue. Accepts all the same parameters that /// CloudQueue.AddMessage accepts and passes them through. /// /// Gets a message from the queue using the default request options. This operation marks /// the retrieved message as invisible in the queue for the default visibility timeout period. /// </summary> /// <param name="visibilityTimeout">The visibility timeout interval.</param> /// <param name="options">A <see cref="T:Microsoft.WindowsAzure.Storage.Queue.QueueRequestOptions"/> object /// that specifies any additional options for the request. Specifying null will use the default request /// options from the associated service client (<see cref="T:Microsoft.WindowsAzure.Storage.Queue.CloudQueueClient"/>).</param> /// <param name="operationContext">An <see cref="T:Microsoft.WindowsAzure.Storage.OperationContext"/> object that represents /// the context for the current operation. This object is used to track requests to the storage service, and to provide /// additional runtime information about the operation.</param> /// <returns> /// A message. /// </returns> public CloudQueueMessage GetMessage(TimeSpan? visibilityTimeout = null, QueueRequestOptions options = null, OperationContext operationContext = null) { try { var cloudQueueClient = new CloudQueueClient(BaseUri, StorageCredentials); var cloudQueue = cloudQueueClient.GetQueueReference(QueueName); return cloudQueue.GetMessage(visibilityTimeout, options, operationContext); } catch (StorageException ex) { System.Diagnostics.Trace.TraceError("Exception thrown: " + ex); // TODO: exception handling, dude throw; } }
internal static QueueRequestOptions ApplyDefaults(QueueRequestOptions options, CloudQueueClient serviceClient) { QueueRequestOptions modifiedOptions = new QueueRequestOptions(options); modifiedOptions.RetryPolicy = modifiedOptions.RetryPolicy ?? serviceClient.RetryPolicy; modifiedOptions.ServerTimeout = modifiedOptions.ServerTimeout ?? serviceClient.ServerTimeout; modifiedOptions.MaximumExecutionTime = modifiedOptions.MaximumExecutionTime ?? serviceClient.MaximumExecutionTime; if (!modifiedOptions.OperationExpiryTime.HasValue && modifiedOptions.MaximumExecutionTime.HasValue) { modifiedOptions.OperationExpiryTime = DateTime.Now + modifiedOptions.MaximumExecutionTime.Value; } return modifiedOptions; }
/// <summary> /// Create an cloud queue on azure if not exists. /// </summary> /// <param name="queue">Cloud queue object.</param> /// <param name="options">Queue request options</param> /// <param name="operationContext">Operation context</param> /// <returns>True if the queue did not already exist and was created; otherwise false.</returns> public bool CreateQueueIfNotExists(CloudQueue queue, QueueRequestOptions options, OperationContext operationContext) { CloudQueue queueRef = GetQueueReference(queue.Name); if (DoesQueueExist(queueRef, options, operationContext)) { return false; } else { queueRef = GetQueueReference(queue.Name); queueList.Add(queueRef); return true; } }
public void DeleteMessage(CloudQueueMessage message, QueueRequestOptions options = null, OperationContext operationContext = null) { try { var cloudQueueClient = new CloudQueueClient(BaseUri, StorageCredentials); var cloudQueue = cloudQueueClient.GetQueueReference(QueueName); cloudQueue.DeleteMessage(message, options, operationContext); } catch (StorageException ex) { System.Diagnostics.Trace.TraceError("Exception thrown: " + ex); // TODO: exception handling, dude throw; } }
public IAsyncOperation<bool> CreateIfNotExistsAsync(QueueRequestOptions options, OperationContext operationContext) { QueueRequestOptions modifiedOptions = QueueRequestOptions.ApplyDefaults(options, this.ServiceClient); operationContext = operationContext ?? new OperationContext(); return AsyncInfo.Run(async (token) => { bool exists = await this.ExistsAsync(true, modifiedOptions, operationContext).AsTask(token); if (exists) { return false; } try { await this.CreateAsync(modifiedOptions, operationContext).AsTask(token); if (operationContext.LastResult.HttpStatusCode == (int)HttpStatusCode.NoContent) { return false; } return true; } catch (Exception) { if (operationContext.LastResult.HttpStatusCode == (int)HttpStatusCode.Conflict) { StorageExtendedErrorInformation extendedInfo = operationContext.LastResult.ExtendedErrorInformation; if ((extendedInfo == null) || (extendedInfo.ErrorCode == QueueErrorCodeStrings.QueueAlreadyExists)) { return false; } else { throw; } } else { throw; } } }); }
/// <summary> /// Creates the queue if it does not already exist. /// </summary> /// <param name="options">A <see cref="QueueRequestOptions"/> object that specifies any additional options for the request.</param> /// <param name="operationContext">An <see cref="OperationContext"/> object that represents the context for the current operation.</param> /// <returns><c>true</c> if the queue did not already exist and was created; otherwise <c>false</c>.</returns> public IAsyncOperation<bool> CreateIfNotExistsAsync(QueueRequestOptions options, OperationContext operationContext) { QueueRequestOptions modifiedOptions = QueueRequestOptions.ApplyDefaults(options, this.ServiceClient); operationContext = operationContext ?? new OperationContext(); return AsyncInfo.Run(async (token) => { bool exists = await Executor.ExecuteAsync( this.ExistsImpl(modifiedOptions), modifiedOptions.RetryPolicy, operationContext, token); if (exists) { return false; } try { await Executor.ExecuteAsync( this.CreateQueueImpl(modifiedOptions), modifiedOptions.RetryPolicy, operationContext, token); if (operationContext.LastResult.HttpStatusCode == (int)HttpStatusCode.NoContent) { return false; } return true; } catch (StorageException e) { if (e.RequestInformation.HttpStatusCode == (int)HttpStatusCode.Conflict) { return false; } else { throw; } } }); }
/// <summary> /// PeekMessageAsync /// </summary> /// <param name="queue"></param> /// <returns></returns> public static async Task<CloudQueueMessage> PeekMessageAsync(this CloudQueue queue) { QueueRequestOptions options = new QueueRequestOptions { MaximumExecutionTime = TimeSpan.FromSeconds(1.0), ServerTimeout = TimeSpan.FromSeconds(1.0) }; var cAsyncR = queue.BeginPeekMessage(options, null, null, null); IAsyncResult asyncR = cAsyncR as IAsyncResult; CloudQueueMessage retVal = null; await Task.Factory.FromAsync(asyncR, (r) => { retVal = queue.EndPeekMessage(r); }); return retVal; }
/// <summary> /// List storage queues /// </summary> /// <param name="prefix">Queue name prefix</param> /// <param name="queueListingDetails">Queue listing details</param> /// <param name="options">Queue request options</param> /// <param name="operationContext">Operation context</param> /// <returns>An enumerable collection of the queues in the storage account.</returns> public IEnumerable<CloudQueue> ListQueues(string prefix, QueueListingDetails queueListingDetails, QueueRequestOptions options, OperationContext operationContext) { if(string.IsNullOrEmpty(prefix)) { return queueList; } else { List<CloudQueue> prefixQueues = new List<CloudQueue>(); foreach(CloudQueue queue in queueList) { if(queue.Name.StartsWith(prefix)) { prefixQueues.Add(queue); } } return prefixQueues; } }
/// <summary> /// Sends the given <see cref="TransportMessage"/> to the queue with the specified globally addressable name /// </summary> public async Task Send(string destinationAddress, TransportMessage message, ITransactionContext context) { context.OnCommitted(async () => { var queue = GetQueue(destinationAddress); var messageId = Guid.NewGuid().ToString(); var popReceipt = Guid.NewGuid().ToString(); var timeToBeReceived = GetTimeToBeReceivedOrNull(message); var cloudQueueMessage = Serialize(message, messageId, popReceipt); try { var options = new QueueRequestOptions {RetryPolicy = new ExponentialRetry()}; var operationContext = new OperationContext(); await queue.AddMessageAsync(cloudQueueMessage, timeToBeReceived, null, options, operationContext); } catch (Exception exception) { throw new RebusApplicationException(string.Format("Could not send message with ID {0} to '{1}'", cloudQueueMessage.Id, destinationAddress), exception); } }); }
public void CloudQueueAddUpdateEncryptedBinaryMessage() { // Create the Key to be used for wrapping. SymmetricKey aesKey = new SymmetricKey("symencryptionkey"); CloudQueueClient client = GenerateCloudQueueClient(); string name = GenerateNewQueueName(); CloudQueue queue = client.GetQueueReference(name); try { queue.CreateIfNotExists(); byte[] messageBytes = new byte[100]; Random rand = new Random(); rand.NextBytes(messageBytes); CloudQueueMessage message = new CloudQueueMessage(messageBytes); QueueEncryptionPolicy policy = new QueueEncryptionPolicy(aesKey, null); QueueRequestOptions options = new QueueRequestOptions() { EncryptionPolicy = policy }; // Add message queue.AddMessage(message, null, null, options, null); // Retrieve message CloudQueueMessage retrMessage = queue.GetMessage(null, options, null); TestHelper.AssertBuffersAreEqual(messageBytes, retrMessage.AsBytes); } finally { queue.DeleteIfExists(); } }
public void CloudQueueAddEncrypted64KMessage() { // Create the Key to be used for wrapping. SymmetricKey aesKey = new SymmetricKey("symencryptionkey"); CloudQueueClient client = GenerateCloudQueueClient(); string name = GenerateNewQueueName(); CloudQueue queue = client.GetQueueReference(name); try { queue.CreateIfNotExists(); string inputMessage = new string('a', 64 * 1024); CloudQueueMessage message = new CloudQueueMessage(inputMessage); queue.EncodeMessage = false; QueueEncryptionPolicy policy = new QueueEncryptionPolicy(aesKey, null); QueueRequestOptions options = new QueueRequestOptions() { EncryptionPolicy = policy }; // Add message queue.AddMessage(message, null, null, null, null); // Add encrypted Message TestHelper.ExpectedException <ArgumentException>( () => queue.AddMessage(message, null, null, options, null), "Adding an encrypted message that exceeds message limits should throw"); } finally { queue.DeleteIfExists(); } }
/// <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); }
/// <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; }
/// <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, 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); getCmd.PostProcessResponse = (cmd, resp, ctx) => { ListQueuesResponse listQueuesResponse = new ListQueuesResponse(cmd.ResponseStream); List <CloudQueue> queuesList = listQueuesResponse.Queues.Select(item => new CloudQueue(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); }
public Task SetServicePropertiesAsync(ServiceProperties properties, QueueRequestOptions options, OperationContext operationContext) { return(this.SetServicePropertiesAsync(properties, options, operationContext, CancellationToken.None)); }
/// <summary> /// Returns a result segment containing a collection of queues. /// </summary> /// <param name="prefix">A string containing the queue name prefix.</param> /// <param name="queueListingDetails">A <see cref="QueueListingDetails"/> enumeration describing which items to include in the listing.</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="currentToken">A <see cref="QueueContinuationToken"/> returned by a previous listing operation.</param> /// <param name="options">A <see cref="QueueRequestOptions"/> object that specifies additional options for the request.</param> /// <param name="operationContext">An <see cref="OperationContext"/> object that represents the context for the current operation.</param> /// <returns>A <see cref="ResultSegment{T}"/> of type <see cref="CloudQueue"/>.</returns> private ResultSegment <CloudQueue> ListQueuesSegmentedCore(string prefix, QueueListingDetails queueListingDetails, int?maxResults, QueueContinuationToken currentToken, QueueRequestOptions options, OperationContext operationContext) { return(Executor.ExecuteSync( this.ListQueuesImpl(prefix, maxResults, queueListingDetails, options, currentToken), options.RetryPolicy, operationContext)); }
public Task <QueueResultSegment> ListQueuesSegmentedAsync(string prefix, QueueListingDetails queueListingDetails, int?maxResults, QueueContinuationToken currentToken, QueueRequestOptions options, OperationContext operationContext) { return(this.ListQueuesSegmentedAsync(prefix, queueListingDetails, maxResults, currentToken, options, operationContext, CancellationToken.None)); }
public virtual Task <ServiceProperties> GetServicePropertiesAsync(QueueRequestOptions options, OperationContext operationContext) { return(this.GetServicePropertiesAsync(options, operationContext, CancellationToken.None)); }
/// <summary> /// Returns an enumerable collection of the queues in the storage account whose names begin with the specified prefix and that are retrieved lazily. /// </summary> /// <param name="prefix">A string containing the queue name prefix.</param> /// <param name="queueListingDetails">A <see cref="QueueListingDetails"/> enumeration value that indicates which details to include in the listing.</param> /// <param name="options">A <see cref="QueueRequestOptions"/> object that specifies additional options for the request. If <c>null</c>, default options are applied to the request.</param> /// <param name="operationContext">An <see cref="OperationContext"/> object that represents the context for the current operation.</param> /// <returns>An enumerable collection of objects of type <see cref="CloudQueue"/> that are retrieved lazily.</returns> public IEnumerable <CloudQueue> ListQueues(string prefix = null, QueueListingDetails queueListingDetails = QueueListingDetails.None, QueueRequestOptions options = null, OperationContext operationContext = null) { QueueRequestOptions modifiedOptions = QueueRequestOptions.ApplyDefaults(options, this); operationContext = operationContext ?? new OperationContext(); return(CommonUtility.LazyEnumerable( (token) => this.ListQueuesSegmentedCore(prefix, queueListingDetails, null, token as QueueContinuationToken, modifiedOptions, operationContext), long.MaxValue)); }
private RESTCommand <NullType> SetServicePropertiesImpl(ServiceProperties properties, QueueRequestOptions requestOptions) { throw new System.NotImplementedException(); }
public virtual async Task <QueueResultSegment> ListQueuesSegmentedAsync(string prefix, QueueListingDetails detailsIncluded, int?maxResults, QueueContinuationToken currentToken, QueueRequestOptions options, OperationContext operationContext, CancellationToken cancellationToken) { QueueRequestOptions modifiedOptions = QueueRequestOptions.ApplyDefaults(options, this); operationContext = operationContext ?? new OperationContext(); ResultSegment <CloudQueue> resultSegment = await Executor.ExecuteAsync( this.ListQueuesImpl(prefix, maxResults, detailsIncluded, modifiedOptions, currentToken), modifiedOptions.RetryPolicy, operationContext, cancellationToken).ConfigureAwait(false); return(new QueueResultSegment(resultSegment.Results, (QueueContinuationToken)resultSegment.ContinuationToken)); }
/// <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, this.HttpClient); options.ApplyToStorageCommand(getCmd); getCmd.CommandLocationMode = CommonUtility.GetListingLocationMode(currentToken); getCmd.RetrieveResponseStream = true; getCmd.BuildRequest = (cmd, uri, builder, cnt, serverTimeout, ctx) => QueueHttpRequestMessageFactory.List(uri, serverTimeout, listingContext, detailsIncluded, cnt, ctx, this.GetCanonicalizer(), this.Credentials); getCmd.PreProcessResponse = (cmd, resp, ex, ctx) => HttpResponseParsers.ProcessExpectedStatusCodeNoException(HttpStatusCode.OK, resp, null /* retVal */, cmd, ex); getCmd.PostProcessResponseAsync = async(cmd, resp, ctx, ct) => { ListQueuesResponse listQueuesResponse = await ListQueuesResponse.ParseAsync(cmd.ResponseStream, ct).ConfigureAwait(false); 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); }
public virtual Task <ServiceStats> GetServiceStatsAsync(QueueRequestOptions options, OperationContext operationContext, CancellationToken cancellationToken) { throw new System.NotImplementedException(); }
/// <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); }
public virtual Task <QueueResultSegment> ListQueuesSegmentedAsync(string prefix, QueueListingDetails detailsIncluded, int?maxResults, QueueContinuationToken currentToken, QueueRequestOptions options, OperationContext operationContext, CancellationToken cancellationToken) { throw new System.NotImplementedException(); }
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); }
/// <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; }
internal QueueRequestOptions(QueueRequestOptions other) : this() { throw new System.NotImplementedException(); }
/// <summary> /// Returns a result segment containing a collection of queues. /// </summary> /// <param name="prefix">A string containing the queue name prefix.</param> /// <param name="queueListingDetails">A <see cref="QueueListingDetails"/> enumeration describing which items to include in the listing.</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="currentToken">A <see cref="QueueContinuationToken"/> returned by a previous listing operation.</param> /// <param name="options">A <see cref="QueueRequestOptions"/> object that specifies additional options for the request. If <c>null</c>, default options are applied to the request.</param> /// <param name="operationContext">An <see cref="OperationContext"/> object that represents the context for the current operation.</param> /// <returns>A <see cref="QueueResultSegment"/> object.</returns> public QueueResultSegment ListQueuesSegmented(string prefix, QueueListingDetails queueListingDetails, int?maxResults, QueueContinuationToken currentToken, QueueRequestOptions options = null, OperationContext operationContext = null) { QueueRequestOptions modifiedOptions = QueueRequestOptions.ApplyDefaults(options, this); operationContext = operationContext ?? new OperationContext(); ResultSegment <CloudQueue> resultSegment = this.ListQueuesSegmentedCore(prefix, queueListingDetails, maxResults, currentToken, modifiedOptions, operationContext); return(new QueueResultSegment(resultSegment.Results, (QueueContinuationToken)resultSegment.ContinuationToken)); }
internal static QueueRequestOptions ApplyDefaults(QueueRequestOptions options, CloudQueueClient serviceClient) { throw new System.NotImplementedException(); }
/// <summary> /// Begins an asynchronous operation to return a result segment containing a collection of queues. /// </summary> /// <param name="prefix">A string containing the queue name prefix.</param> /// <param name="queueListingDetails">A <see cref="QueueListingDetails"/> enumeration describing which items to include in the listing.</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="currentToken">A <see cref="QueueContinuationToken"/> returned by a previous listing operation.</param> /// <param name="options">A <see cref="QueueRequestOptions"/> object that specifies additional options for the request.</param> /// <param name="operationContext">An <see cref="OperationContext"/> object that represents the context for the current operation.</param> /// <param name="callback">An <see cref="AsyncCallback"/> delegate that will receive notification when the asynchronous operation completes.</param> /// <param name="state">A user-defined object that will be passed to the callback delegate.</param> /// <returns>An <see cref="ICancellableAsyncResult"/> that references the asynchronous operation.</returns> public ICancellableAsyncResult BeginListQueuesSegmented(string prefix, QueueListingDetails queueListingDetails, int?maxResults, QueueContinuationToken currentToken, QueueRequestOptions options, OperationContext operationContext, AsyncCallback callback, object state) { QueueRequestOptions modifiedOptions = QueueRequestOptions.ApplyDefaults(options, this); operationContext = operationContext ?? new OperationContext(); return(Executor.BeginExecuteAsync( this.ListQueuesImpl(prefix, maxResults, queueListingDetails, modifiedOptions, currentToken), modifiedOptions.RetryPolicy, operationContext, callback, state)); }
public virtual Task SetServicePropertiesAsync(ServiceProperties properties, QueueRequestOptions requestOptions, OperationContext operationContext, CancellationToken cancellationToken) { throw new System.NotImplementedException(); }
public Task <QueueResultSegment> ListQueuesSegmentedAsync(string prefix, QueueListingDetails queueListingDetails, int?maxResults, QueueContinuationToken currentToken, QueueRequestOptions options, OperationContext operationContext, CancellationToken cancellationToken) { return(AsyncExtensions.TaskFromApm(this.BeginListQueuesSegmented, this.EndListQueuesSegmented, prefix, queueListingDetails, maxResults, currentToken, options, operationContext, cancellationToken)); }
public void SetServiceProperties(ServiceProperties properties, QueueRequestOptions requestOptions = null, OperationContext operationContext = null) { requestOptions = QueueRequestOptions.ApplyDefaults(requestOptions, this); operationContext = operationContext ?? new OperationContext(); Executor.ExecuteSync(this.SetServicePropertiesImpl(properties, requestOptions), requestOptions.RetryPolicy, operationContext); }
public ICancellableAsyncResult BeginSetServiceProperties(ServiceProperties properties, QueueRequestOptions requestOptions, OperationContext operationContext, AsyncCallback callback, object state) { requestOptions = QueueRequestOptions.ApplyDefaults(requestOptions, this); operationContext = operationContext ?? new OperationContext(); return(Executor.BeginExecuteAsync( this.SetServicePropertiesImpl(properties, requestOptions), requestOptions.RetryPolicy, operationContext, callback, state)); }
public Task <ServiceStats> GetServiceStatsAsync(QueueRequestOptions requestOptions, OperationContext operationContext, CancellationToken cancellationToken) { return(AsyncExtensions.TaskFromApm(this.BeginGetServiceStats, this.EndGetServiceStats, requestOptions, operationContext, cancellationToken)); }
public Task SetServicePropertiesAsync(ServiceProperties properties, QueueRequestOptions options, OperationContext operationContext, CancellationToken cancellationToken) { return(AsyncExtensions.TaskFromVoidApm(this.BeginSetServiceProperties, this.EndSetServiceProperties, properties, options, operationContext, cancellationToken)); }
private RESTCommand <ServiceStats> GetServiceStatsImpl(QueueRequestOptions requestOptions) { throw new System.NotImplementedException(); }
public Task <ServiceStats> GetServiceStatsAsync(QueueRequestOptions requestOptions, OperationContext operationContext) { return(this.GetServiceStatsAsync(requestOptions, operationContext, CancellationToken.None)); }
/// <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; }
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); }
/// <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> /// 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; }
private RESTCommand <ResultSegment <CloudQueue> > ListQueuesImpl(string prefix, int?maxResults, QueueListingDetails detailsIncluded, QueueRequestOptions options, QueueContinuationToken currentToken) { throw new System.NotImplementedException(); }