Skip to content

Commit a484727

Browse files
DataMovement StorageResource construction refactor | Part 4 (Azure#38534)
* hid implementation classes * exportapi | updatesnippets
1 parent d722905 commit a484727

13 files changed

+98
-238
lines changed

sdk/storage/Azure.Storage.DataMovement.Blobs/README.md

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -148,10 +148,11 @@ await tranfer.WaitForCompletionAsync();
148148
Azure.Storage.DataMovement.Blobs exposes a `StorageResource` for each type of blob (block, page, append) as well as a blob container. Storage resources are initialized with the appropriate client object from Azure.Storage.Blobs.
149149

150150
```C# Snippet:ResourceConstruction_Blobs
151-
StorageResource containerResource = new BlobStorageResourceContainer(blobContainerClient);
152-
StorageResource blockBlobResource = new BlockBlobStorageResource(blockBlobClient);
153-
StorageResource pageBlobResource = new PageBlobStorageResource(pageBlobClient);
154-
StorageResource appendBlobResource = new AppendBlobStorageResource(appendBlobClient);
151+
BlobsStorageResourceProvider blobs = new();
152+
StorageResource containerResource = blobs.FromClient(blobContainerClient);
153+
StorageResource blockBlobResource = blobs.FromClient(blockBlobClient);
154+
StorageResource pageBlobResource = blobs.FromClient(pageBlobClient);
155+
StorageResource appendBlobResource = blobs.FromClient(appendBlobClient);
155156
```
156157

157158
Blob `StorageResource` objects can be constructed with optional "options" arguments specific to the type of resource.
@@ -162,7 +163,7 @@ BlobStorageResourceContainerOptions virtualDirectoryOptions = new()
162163
BlobDirectoryPrefix = "blob/directory/prefix"
163164
};
164165

165-
StorageResource virtualDirectoryResource = new BlobStorageResourceContainer(
166+
StorageResource virtualDirectoryResource = blobs.FromClient(
166167
blobContainerClient,
167168
virtualDirectoryOptions);
168169
```
@@ -175,7 +176,7 @@ BlockBlobStorageResourceOptions leasedResourceOptions = new()
175176
LeaseId = leaseId
176177
}
177178
};
178-
StorageResource leasedBlockBlobResource = new BlockBlobStorageResource(
179+
StorageResource leasedBlockBlobResource = blobs.FromClient(
179180
blockBlobClient,
180181
leasedResourceOptions);
181182
```
@@ -190,17 +191,17 @@ Upload a block blob.
190191

191192
```C# Snippet:SimpleBlobUpload
192193
DataTransfer dataTransfer = await transferManager.StartTransferAsync(
193-
sourceResource: new LocalFileStorageResource(sourceLocalPath),
194-
destinationResource: new BlockBlobStorageResource(destinationBlob));
194+
sourceResource: files.FromPath(sourceLocalPath),
195+
destinationResource: blobs.FromClient(destinationBlob));
195196
await dataTransfer.WaitForCompletionAsync();
196197
```
197198

198199
Upload a directory as a specific blob type.
199200

200201
```C# Snippet:SimpleDirectoryUpload
201202
DataTransfer dataTransfer = await transferManager.StartTransferAsync(
202-
sourceResource: new LocalDirectoryStorageResourceContainer(sourcePath),
203-
destinationResource: new BlobStorageResourceContainer(
203+
sourceResource: files.FromPath(sourcePath),
204+
destinationResource: blobs.FromClient(
204205
blobContainerClient,
205206
new BlobStorageResourceContainerOptions()
206207
{
@@ -219,23 +220,25 @@ A download takes place between a blob `StorageResource` as source and local file
219220
Download a block blob.
220221

221222
```C# Snippet:SimpleBlockBlobDownload
223+
BlobsStorageResourceProvider blobs = new();
224+
LocalFilesStorageResourceProvider files = new();
222225
DataTransfer dataTransfer = await transferManager.StartTransferAsync(
223-
sourceResource: new BlockBlobStorageResource(sourceBlobClient),
224-
destinationResource: new LocalFileStorageResource(downloadPath));
226+
sourceResource: blobs.FromClient(sourceBlobClient),
227+
destinationResource: files.FromPath(downloadPath));
225228
await dataTransfer.WaitForCompletionAsync();
226229
```
227230

228231
Download a container which may contain a mix of blob types.
229232

230233
```C# Snippet:SimpleDirectoryDownload_Blob
231234
DataTransfer dataTransfer = await transferManager.StartTransferAsync(
232-
sourceResource: new BlobStorageResourceContainer(
235+
sourceResource: blobs.FromClient(
233236
blobContainerClient,
234237
new BlobStorageResourceContainerOptions()
235238
{
236239
BlobDirectoryPrefix = optionalSourcePrefix
237240
}),
238-
destinationResource: new LocalDirectoryStorageResourceContainer(downloadPath));
241+
destinationResource: files.FromPath(downloadPath));
239242
await dataTransfer.WaitForCompletionAsync();
240243
```
241244

@@ -246,23 +249,25 @@ A copy takes place between two blob `StorageResource` instances. Copying between
246249
Copy a single blob. Note the change in blob type on this copy from block to append.
247250

248251
```C# Snippet:s2sCopyBlob
252+
BlobsStorageResourceProvider blobs = new();
253+
LocalFilesStorageResourceProvider files = new();
249254
DataTransfer dataTransfer = await transferManager.StartTransferAsync(
250-
sourceResource: new BlockBlobStorageResource(sourceBlockBlobClient),
251-
destinationResource: new AppendBlobStorageResource(destinationAppendBlobClient));
255+
sourceResource: blobs.FromClient(sourceBlockBlobClient),
256+
destinationResource: blobs.FromClient(destinationAppendBlobClient));
252257
await dataTransfer.WaitForCompletionAsync();
253258
```
254259

255260
Copy a blob container.
256261

257262
```C# Snippet:s2sCopyBlobContainer
258263
DataTransfer dataTransfer = await transferManager.StartTransferAsync(
259-
sourceResource: new BlobStorageResourceContainer(
264+
sourceResource: blobs.FromClient(
260265
sourceContainer,
261266
new BlobStorageResourceContainerOptions()
262267
{
263268
BlobDirectoryPrefix = sourceDirectoryName
264269
}),
265-
destinationResource: new BlobStorageResourceContainer(
270+
destinationResource: blobs.FromClient(
266271
destinationContainer,
267272
new BlobStorageResourceContainerOptions()
268273
{

sdk/storage/Azure.Storage.DataMovement.Blobs/api/Azure.Storage.DataMovement.Blobs.net6.0.cs

Lines changed: 0 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,6 @@ public static partial class BlobContainerClientExtensions
1010
}
1111
namespace Azure.Storage.DataMovement.Blobs
1212
{
13-
public partial class AppendBlobStorageResource : Azure.Storage.DataMovement.StorageResourceItem
14-
{
15-
public AppendBlobStorageResource(Azure.Storage.Blobs.Specialized.AppendBlobClient blobClient, Azure.Storage.DataMovement.Blobs.AppendBlobStorageResourceOptions options = null) { }
16-
protected override long? Length { get { throw null; } }
17-
protected override long MaxChunkSize { get { throw null; } }
18-
protected override string ResourceId { get { throw null; } }
19-
protected override Azure.Storage.DataMovement.DataTransferOrder TransferType { get { throw null; } }
20-
public override System.Uri Uri { get { throw null; } }
21-
protected override System.Threading.Tasks.Task CompleteTransferAsync(bool overwrite, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
22-
protected override System.Threading.Tasks.Task CopyBlockFromUriAsync(Azure.Storage.DataMovement.StorageResourceItem sourceResource, Azure.HttpRange range, bool overwrite, long completeLength, Azure.Storage.DataMovement.StorageResourceCopyFromUriOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
23-
protected override System.Threading.Tasks.Task CopyFromStreamAsync(System.IO.Stream stream, long streamLength, bool overwrite, long completeLength, Azure.Storage.DataMovement.StorageResourceWriteToOffsetOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
24-
protected override System.Threading.Tasks.Task CopyFromUriAsync(Azure.Storage.DataMovement.StorageResourceItem sourceResource, bool overwrite, long completeLength, Azure.Storage.DataMovement.StorageResourceCopyFromUriOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
25-
protected override System.Threading.Tasks.Task<bool> DeleteIfExistsAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
26-
protected override System.Threading.Tasks.Task<Azure.HttpAuthorization> GetCopyAuthorizationHeaderAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
27-
protected override System.Threading.Tasks.Task<Azure.Storage.DataMovement.StorageResourceProperties> GetPropertiesAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
28-
protected override System.Threading.Tasks.Task<Azure.Storage.DataMovement.StorageResourceReadStreamResult> ReadStreamAsync(long position = (long)0, long? length = default(long?), System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
29-
}
3013
public partial class AppendBlobStorageResourceOptions : Azure.Storage.DataMovement.Blobs.BlobStorageResourceOptions
3114
{
3215
public AppendBlobStorageResourceOptions() { }
@@ -61,13 +44,6 @@ public BlobsStorageResourceProvider(Azure.Storage.StorageSharedKeyCredential cre
6144
public delegate Azure.Storage.StorageSharedKeyCredential GetStorageSharedKeyCredential(string uri, bool readOnly);
6245
public delegate Azure.Core.TokenCredential GetTokenCredential(string uri, bool readOnly);
6346
}
64-
public partial class BlobStorageResourceContainer : Azure.Storage.DataMovement.StorageResourceContainer
65-
{
66-
public BlobStorageResourceContainer(Azure.Storage.Blobs.BlobContainerClient blobContainerClient, Azure.Storage.DataMovement.Blobs.BlobStorageResourceContainerOptions options = null) { }
67-
public override System.Uri Uri { get { throw null; } }
68-
protected override Azure.Storage.DataMovement.StorageResourceItem GetStorageResourceReference(string path) { throw null; }
69-
protected override System.Collections.Generic.IAsyncEnumerable<Azure.Storage.DataMovement.StorageResource> GetStorageResourcesAsync([System.Runtime.CompilerServices.EnumeratorCancellationAttribute] System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
70-
}
7147
public partial class BlobStorageResourceContainerOptions
7248
{
7349
public BlobStorageResourceContainerOptions() { }
@@ -87,46 +63,12 @@ public BlobStorageResourceOptions() { }
8763
public System.Collections.Generic.IDictionary<string, string> Tags { get { throw null; } set { } }
8864
public Azure.Storage.UploadTransferValidationOptions UploadTransferValidationOptions { get { throw null; } set { } }
8965
}
90-
public partial class BlockBlobStorageResource : Azure.Storage.DataMovement.StorageResourceItem
91-
{
92-
public BlockBlobStorageResource(Azure.Storage.Blobs.Specialized.BlockBlobClient blobClient, Azure.Storage.DataMovement.Blobs.BlockBlobStorageResourceOptions options = null) { }
93-
protected override long? Length { get { throw null; } }
94-
protected override long MaxChunkSize { get { throw null; } }
95-
protected override string ResourceId { get { throw null; } }
96-
protected override Azure.Storage.DataMovement.DataTransferOrder TransferType { get { throw null; } }
97-
public override System.Uri Uri { get { throw null; } }
98-
protected override System.Threading.Tasks.Task CompleteTransferAsync(bool overwrite, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
99-
protected override System.Threading.Tasks.Task CopyBlockFromUriAsync(Azure.Storage.DataMovement.StorageResourceItem sourceResource, Azure.HttpRange range, bool overwrite, long completeLength, Azure.Storage.DataMovement.StorageResourceCopyFromUriOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
100-
protected override System.Threading.Tasks.Task CopyFromStreamAsync(System.IO.Stream stream, long streamLength, bool overwrite, long completeLength, Azure.Storage.DataMovement.StorageResourceWriteToOffsetOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
101-
protected override System.Threading.Tasks.Task CopyFromUriAsync(Azure.Storage.DataMovement.StorageResourceItem sourceResource, bool overwrite, long completeLength, Azure.Storage.DataMovement.StorageResourceCopyFromUriOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
102-
protected override System.Threading.Tasks.Task<bool> DeleteIfExistsAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
103-
protected override System.Threading.Tasks.Task<Azure.HttpAuthorization> GetCopyAuthorizationHeaderAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
104-
protected override System.Threading.Tasks.Task<Azure.Storage.DataMovement.StorageResourceProperties> GetPropertiesAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
105-
protected override System.Threading.Tasks.Task<Azure.Storage.DataMovement.StorageResourceReadStreamResult> ReadStreamAsync(long position = (long)0, long? length = default(long?), System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
106-
}
10766
public partial class BlockBlobStorageResourceOptions : Azure.Storage.DataMovement.Blobs.BlobStorageResourceOptions
10867
{
10968
public BlockBlobStorageResourceOptions() { }
11069
public Azure.Storage.Blobs.Models.BlobRequestConditions DestinationConditions { get { throw null; } set { } }
11170
public Azure.Storage.Blobs.Models.BlobRequestConditions SourceConditions { get { throw null; } set { } }
11271
}
113-
public partial class PageBlobStorageResource : Azure.Storage.DataMovement.StorageResourceItem
114-
{
115-
public PageBlobStorageResource(Azure.Storage.Blobs.Specialized.PageBlobClient blobClient, Azure.Storage.DataMovement.Blobs.PageBlobStorageResourceOptions options = null) { }
116-
protected override long? Length { get { throw null; } }
117-
protected override long MaxChunkSize { get { throw null; } }
118-
protected override string ResourceId { get { throw null; } }
119-
protected override Azure.Storage.DataMovement.DataTransferOrder TransferType { get { throw null; } }
120-
public override System.Uri Uri { get { throw null; } }
121-
protected override System.Threading.Tasks.Task CompleteTransferAsync(bool overwrite, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
122-
protected override System.Threading.Tasks.Task CopyBlockFromUriAsync(Azure.Storage.DataMovement.StorageResourceItem sourceResource, Azure.HttpRange range, bool overwrite, long completeLength, Azure.Storage.DataMovement.StorageResourceCopyFromUriOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
123-
protected override System.Threading.Tasks.Task CopyFromStreamAsync(System.IO.Stream stream, long streamLength, bool overwrite, long completeLength, Azure.Storage.DataMovement.StorageResourceWriteToOffsetOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
124-
protected override System.Threading.Tasks.Task CopyFromUriAsync(Azure.Storage.DataMovement.StorageResourceItem sourceResource, bool overwrite, long completeLength, Azure.Storage.DataMovement.StorageResourceCopyFromUriOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
125-
protected override System.Threading.Tasks.Task<bool> DeleteIfExistsAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
126-
protected override System.Threading.Tasks.Task<Azure.HttpAuthorization> GetCopyAuthorizationHeaderAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
127-
protected override System.Threading.Tasks.Task<Azure.Storage.DataMovement.StorageResourceProperties> GetPropertiesAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
128-
protected override System.Threading.Tasks.Task<Azure.Storage.DataMovement.StorageResourceReadStreamResult> ReadStreamAsync(long position = (long)0, long? length = default(long?), System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
129-
}
13072
public partial class PageBlobStorageResourceOptions : Azure.Storage.DataMovement.Blobs.BlobStorageResourceOptions
13173
{
13274
public PageBlobStorageResourceOptions() { }

0 commit comments

Comments
 (0)