private CloudBlockBlob GetBlockBlob(StoreLocation location, string snapshot = null) { DateTime?snapshotDate = null; if (snapshot != null) { snapshotDate = new DateTime(long.Parse(snapshot, CultureInfo.InvariantCulture)); } var container = _blobStorage.GetContainerReference(SafeContainerName(location.Container)); var offset = snapshotDate.HasValue ? new DateTimeOffset(snapshotDate.Value, new TimeSpan(0)) : (DateTimeOffset?)null; CloudBlockBlob blob; if (location.Id.HasValue) { if (!string.IsNullOrEmpty(location.BasePath)) { var dir = container.GetDirectoryReference(SafePath.MakeSafeFilePath(location.BasePath)); blob = dir.GetBlockBlobReference(location.Id.ToString() + IdExtension, offset); } else { blob = container.GetBlockBlobReference(location.Id.ToString() + IdExtension, offset); } } else { blob = container.GetBlockBlobReference(SafePath.MakeSafeFilePath(location.BasePath), offset); } return(blob); }
private BlockBlobClient GetBlockBlob(StoreLocation location, string snapshot = null) { var container = _blobStorage.GetBlobContainerClient(SafeContainerName(location.Container)); BlockBlobClient blob; if (location.Id.HasValue) { if (!string.IsNullOrEmpty(location.BasePath)) { var path = Path.Combine(SafePath.MakeSafeFilePath(location.BasePath), location.Id.ToString() + IdExtension); blob = container.GetBlockBlobClient(path); } else { blob = container.GetBlockBlobClient(location.Id.ToString() + IdExtension); } } else { blob = container.GetBlockBlobClient(SafePath.MakeSafeFilePath(location.BasePath)); } return(string.IsNullOrWhiteSpace(snapshot) ? blob : blob.WithSnapshot(snapshot)); }
private IAsyncEnumerable <ICloudBlob> ListBlobs(CloudBlobContainer container, string prefix, BlobListingDetails options) { // Clean up the prefix if required prefix = prefix == null ? null : SafePath.MakeSafeFilePath(prefix); return(AsyncEnumerableEx.Create <ICloudBlob>(async(y) => { BlobContinuationToken token = new BlobContinuationToken(); try { do { var segment = await container.ListBlobsSegmentedAsync(prefix, true, options, null, token, null, null, y.CancellationToken).ConfigureAwait(false); LeoTrace.WriteLine("Listed blob segment for prefix: " + prefix); foreach (var blob in segment.Results.OfType <ICloudBlob>()) { await y.YieldReturn(blob).ConfigureAwait(false); } token = segment.ContinuationToken; }while (token != null && !y.CancellationToken.IsCancellationRequested); } catch (StorageException e) { if (e.RequestInformation.HttpStatusCode != 404) { throw e.Wrap(container.Name + "_" + (prefix ?? string.Empty) + "*"); } } })); }
private IAsyncEnumerable <BlobItem> ListBlobs(BlobContainerClient container, string prefix, BlobTraits traits, BlobStates states) { // Clean up the prefix if required prefix = prefix == null ? null : SafePath.MakeSafeFilePath(prefix); return(container.GetBlobsAsync(traits, states, prefix)); }