public static void CreateIfNotExists(this IStorageBlobContainer container) { if (container == null) { throw new ArgumentNullException("container"); } container.CreateIfNotExistsAsync(CancellationToken.None).GetAwaiter().GetResult(); }
/// <inheritdoc /> public async Task <string> EnqueueAsync(T message, CancellationToken cancellationToken) { await _blobContainer.CreateIfNotExistsAsync(cancellationToken); string blobName = BlobNames.GetConflictFreeDateTimeBasedBlobName(); IStorageBlockBlob blob = _blobContainer.GetBlockBlobReference(blobName); message.AddMetadata(blob.Metadata); string messageBody = JsonConvert.SerializeObject(message, JsonSerialization.Settings); await blob.UploadTextAsync(messageBody, cancellationToken : cancellationToken); return(blobName); }
public async Task <IValueProvider> BindAsync(BindingContext context) { BlobPath boundPath = _path.Bind(context.BindingData); IStorageBlobContainer container = _client.GetContainerReference(boundPath.ContainerName); if (_argumentBinding.Access != FileAccess.Read) { await container.CreateIfNotExistsAsync(context.CancellationToken); } Type argumentType = _argumentBinding.ValueType; string blobName = boundPath.BlobName; IStorageBlob blob = await container.GetBlobReferenceForArgumentTypeAsync(blobName, argumentType, context.CancellationToken); return(await BindBlobAsync(blob, context.ValueContext)); }
public async Task <IStorageBlob> ConvertAsync(string input, CancellationToken cancellationToken) { BlobPath path; // For convenience, treat an an empty string as a request for the default value. if (String.IsNullOrEmpty(input) && _defaultPath.IsBound) { path = _defaultPath.Bind(null); } else { path = BlobPath.ParseAndValidate(input); } IStorageBlobContainer container = _client.GetContainerReference(path.ContainerName); await container.CreateIfNotExistsAsync(cancellationToken); return(await container.GetBlobReferenceForArgumentTypeAsync(path.BlobName, _argumentType, cancellationToken)); }
private async Task <IStorageBlob> GetBlobAsync( BlobAttribute blobAttribute, CancellationToken cancellationToken, Type requestedType = null) { IStorageBlobClient client = await GetClientAsync(blobAttribute, cancellationToken); BlobPath boundPath = BlobPath.ParseAndValidate(blobAttribute.BlobPath); IStorageBlobContainer container = client.GetContainerReference(boundPath.ContainerName); if (blobAttribute.Access != FileAccess.Read) { await container.CreateIfNotExistsAsync(cancellationToken); } IStorageBlob blob = await container.GetBlobReferenceForArgumentTypeAsync( boundPath.BlobName, requestedType, cancellationToken); return(blob); }