public async Task WriteAsync(string id, Stream sourceStream, bool append, CancellationToken cancellationToken) { GenericValidation.CheckBlobId(id); GenericValidation.CheckSourceStream(sourceStream); if (append) { CloudAppendBlob cab = _blobContainer.GetAppendBlobReference(StoragePath.Normalize(id, false)); if (!(await cab.ExistsAsync())) { await cab.CreateOrReplaceAsync(); } await cab.AppendFromStreamAsync(sourceStream); } else { CloudBlockBlob blob = _blobContainer.GetBlockBlobReference(StoragePath.Normalize(id, false)); await blob.UploadFromStreamAsync(sourceStream); } }
public async Task WriteAsync(string id, Stream sourceStream, bool append, CancellationToken cancellationToken) { GenericValidation.CheckBlobId(id); DataLakeStoreFileSystemManagementClient client = await GetFsClient(); if (append) { if ((await ExistsAsync(new[] { id }, cancellationToken)).First()) { await client.FileSystem.AppendAsync(_accountName, id, new NonCloseableStream(sourceStream)); } else { await client.FileSystem.CreateAsync(_accountName, id, new NonCloseableStream(sourceStream), true); } } else { await client.FileSystem.CreateAsync(_accountName, id, new NonCloseableStream(sourceStream), true); } }
public Task <IEnumerable <BlobMeta> > GetMetaAsync(IEnumerable <string> ids, CancellationToken cancellationToken) { GenericValidation.CheckBlobId(ids); var result = new List <BlobMeta>(); foreach (string id in ids) { if (!_idToData.TryGetValue(id, out Tag tag)) { result.Add(null); } else { var meta = new BlobMeta(tag.data.Length, tag.md5, tag.lastMod); result.Add(meta); } } return(Task.FromResult <IEnumerable <BlobMeta> >(result)); }
public async Task <string> GetSasUriAsync( string id, SharedAccessBlobPolicy sasConstraints, SharedAccessBlobHeaders headers, bool createContainer, CancellationToken cancellationToken) { GenericValidation.CheckBlobId(id); (CloudBlobContainer container, string path) = await GetPartsAsync(id, createContainer); if (container == null) { return(null); } CloudBlockBlob blob = container.GetBlockBlobReference(StoragePath.Normalize(path, false)); try { return($@"{blob.Uri}{blob.GetSharedAccessSignature(sasConstraints, headers)}"); } catch (AzureStorageException ex) { if (AzureStorageValidation.IsDoesntExist(ex)) { return(null); } if (!AzureStorageValidation.TryHandleStorageException(ex)) { throw; } } throw new InvalidOperationException("must not be here"); }
public async Task <IEnumerable <bool> > ExistsAsync(IEnumerable <string> ids, CancellationToken cancellationToken) { GenericValidation.CheckBlobId(ids); DataLakeStoreFileSystemManagementClient client = await GetFsClient(); var result = new List <bool>(); foreach (string id in ids) { try { await client.FileSystem.GetFileStatusAsync(_accountName, id); result.Add(true); } catch (AdlsErrorException ex) when(ex.Response.StatusCode == HttpStatusCode.NotFound) { result.Add(false); } } return(result); }
public Task <IEnumerable <BlobMeta> > GetMetaAsync(IEnumerable <string> ids, CancellationToken cancellationToken) { GenericValidation.CheckBlobId(ids); var result = new List <BlobMeta>(); foreach (string id in ids) { if (!_idToData.TryGetValue(id, out MemoryStream ms)) { result.Add(null); } else { ms.Seek(0, SeekOrigin.Begin); var meta = new BlobMeta(ms.Length, ms.GetHash(HashType.Md5)); result.Add(meta); } } return(Task.FromResult <IEnumerable <BlobMeta> >(result)); }
public async Task <IEnumerable <BlobMeta> > GetMetaAsync(IEnumerable <string> ids, CancellationToken cancellationToken) { GenericValidation.CheckBlobId(ids); return(await Task.WhenAll(ids.Select(id => GetMetaAsync(id)))); }
public async Task <IEnumerable <bool> > ExistsAsync(IEnumerable <string> ids, CancellationToken cancellationToken) { GenericValidation.CheckBlobId(ids); return(await Task.WhenAll(ids.Select(id => ExistsAsync(id, cancellationToken)))); }
public async Task DeleteAsync(IEnumerable <string> ids, CancellationToken cancellationToken) { GenericValidation.CheckBlobId(ids); await Task.WhenAll(ids.Select(id => _vaultClient.DeleteSecretAsync(_vaultUri, id))); }
private bool Exists(string id) { GenericValidation.CheckBlobId(id); return(_idToData.ContainsKey(id)); }
public async Task DeleteAsync(IEnumerable <string> ids, CancellationToken cancellationToken = default) { GenericValidation.CheckBlobId(ids); await Task.WhenAll(ids.Select(id => DeleteAsync(id, cancellationToken))); }