@@ -166,11 +166,6 @@ public int? MaxCount
166
166
[ ValidateNotNullOrEmpty ]
167
167
public override string TagCondition { get ; set ; }
168
168
169
- protected override bool UseTrack2Sdk ( )
170
- {
171
- return true ;
172
- }
173
-
174
169
/// <summary>
175
170
/// Initializes a new instance of the GetAzureStorageBlobCommand class.
176
171
/// </summary>
@@ -202,7 +197,6 @@ internal async Task ListBlobsByName(long taskId, IStorageBlobManagement localCha
202
197
{
203
198
CloudBlobContainer container = null ;
204
199
BlobRequestOptions requestOptions = RequestOptions ;
205
- AccessCondition accessCondition = null ;
206
200
207
201
string prefix = string . Empty ;
208
202
@@ -232,45 +226,30 @@ internal async Task ListBlobsByName(long taskId, IStorageBlobManagement localCha
232
226
}
233
227
234
228
BlobBaseClient blobClient = null ;
235
- if ( UseTrack2Sdk ( ) ) // User Track2 SDK
236
- {
237
- blobClient = Util . GetTrack2BlobClient ( track2container , blobName , localChannel . StorageContext , this . VersionId , false , this . SnapshotTime is null ? null : this . SnapshotTime . Value . ToUniversalTime ( ) . ToString ( "o" ) . Replace ( "+00:00" , "Z" ) , ClientOptions , shouldTrimSlash : false ) ;
238
- global ::Azure . Storage . Blobs . Models . BlobProperties blobProperties ;
239
- try
240
- {
241
- blobProperties = blobClient . GetProperties ( BlobRequestConditions , cancellationToken : CmdletCancellationToken ) ;
242
- }
243
- catch ( global ::Azure . RequestFailedException e ) when ( e . Status == 404 )
244
- {
245
- throw new ResourceNotFoundException ( String . Format ( Resources . BlobNotFound , blobName , containerName ) ) ;
246
- }
247
- blobClient = Util . GetTrack2BlobClient ( track2container , blobName , localChannel . StorageContext , this . VersionId , blobProperties . IsLatestVersion , this . SnapshotTime is null ? null : this . SnapshotTime . Value . ToUniversalTime ( ) . ToString ( "o" ) . Replace ( "+00:00" , "Z" ) , ClientOptions , blobProperties . BlobType , shouldTrimSlash : false ) ;
248
229
249
- AzureStorageBlob outputBlob = new AzureStorageBlob ( blobClient , localChannel . StorageContext , blobProperties , ClientOptions ) ;
250
- if ( this . IncludeTag . IsPresent )
251
- {
252
- IDictionary < string , string > tags = ( await blobClient . GetTagsAsync ( null , this . CmdletCancellationToken ) . ConfigureAwait ( false ) ) . Value . Tags ;
253
- if ( tags != null )
254
- {
255
- outputBlob . Tags = tags . ToHashtable ( ) ;
256
- outputBlob . TagCount = tags . Count ;
257
- }
258
- }
259
- OutputStream . WriteObject ( taskId , outputBlob ) ;
230
+ blobClient = Util . GetTrack2BlobClient ( track2container , blobName , localChannel . StorageContext , this . VersionId , false , this . SnapshotTime is null ? null : this . SnapshotTime . Value . ToUniversalTime ( ) . ToString ( "o" ) . Replace ( "+00:00" , "Z" ) , ClientOptions , shouldTrimSlash : false ) ;
231
+ global ::Azure . Storage . Blobs . Models . BlobProperties blobProperties ;
232
+ try
233
+ {
234
+ blobProperties = blobClient . GetProperties ( BlobRequestConditions , cancellationToken : CmdletCancellationToken ) ;
260
235
}
261
- else // Use Track1 SDK
236
+ catch ( global :: Azure . RequestFailedException e ) when ( e . Status == 404 )
262
237
{
263
- CloudBlob blob = await localChannel . GetBlobReferenceFromServerAsync ( container , blobName , this . SnapshotTime , accessCondition , requestOptions , OperationContext , CmdletCancellationToken ) . ConfigureAwait ( false ) ;
238
+ throw new ResourceNotFoundException ( String . Format ( Resources . BlobNotFound , blobName , containerName ) ) ;
239
+ }
240
+ blobClient = Util . GetTrack2BlobClient ( track2container , blobName , localChannel . StorageContext , this . VersionId , blobProperties . IsLatestVersion , this . SnapshotTime is null ? null : this . SnapshotTime . Value . ToUniversalTime ( ) . ToString ( "o" ) . Replace ( "+00:00" , "Z" ) , ClientOptions , blobProperties . BlobType , shouldTrimSlash : false ) ;
264
241
265
- if ( null == blob )
266
- {
267
- throw new ResourceNotFoundException ( String . Format ( Resources . BlobNotFound , blobName , containerName ) ) ;
268
- }
269
- else
242
+ AzureStorageBlob outputBlob = new AzureStorageBlob ( blobClient , localChannel . StorageContext , blobProperties , ClientOptions ) ;
243
+ if ( this . IncludeTag . IsPresent )
244
+ {
245
+ IDictionary < string , string > tags = ( await blobClient . GetTagsAsync ( null , this . CmdletCancellationToken ) . ConfigureAwait ( false ) ) . Value . Tags ;
246
+ if ( tags != null )
270
247
{
271
- OutputStream . WriteObject ( taskId , new AzureStorageBlob ( blob , localChannel . StorageContext , ClientOptions ) ) ;
248
+ outputBlob . Tags = tags . ToHashtable ( ) ;
249
+ outputBlob . TagCount = tags . Count ;
272
250
}
273
251
}
252
+ OutputStream . WriteObject ( taskId , outputBlob ) ;
274
253
}
275
254
}
276
255
@@ -297,93 +276,48 @@ internal async Task ListBlobsByPrefix(long taskId, IStorageBlobManagement localC
297
276
BlobContinuationToken continuationToken = ContinuationToken ;
298
277
string track2ContinuationToken = this . ContinuationToken is null ? null : this . ContinuationToken . NextMarker ;
299
278
300
- if ( UseTrack2Sdk ( ) ) // For new feature only available on Track2 SDK, need list with Track2 SDK.
279
+ BlobTraits blobTraits = BlobTraits . Metadata | BlobTraits . CopyStatus ; // | BlobTraits.Tags;
280
+ BlobStates blobStates = BlobStates . Snapshots ;
281
+ if ( includeDeleted )
301
282
{
302
- BlobTraits blobTraits = BlobTraits . Metadata | BlobTraits . CopyStatus ; // | BlobTraits.Tags;
303
- BlobStates blobStates = BlobStates . Snapshots ;
304
- if ( includeDeleted )
305
- {
306
- blobStates = blobStates | BlobStates . Deleted ;
307
- }
308
- if ( includeVersion )
309
- {
310
- blobStates = blobStates | BlobStates . Version ;
311
- }
312
- if ( IncludeTag . IsPresent )
313
- {
314
- blobTraits = blobTraits | BlobTraits . Tags ;
315
- }
316
-
317
- do
318
- {
319
- requestCount = Math . Min ( listCount , MaxListCount ) ;
320
- realListCount = 0 ;
321
- IEnumerator < Page < BlobItem > > enumerator = track2container . GetBlobs ( blobTraits , blobStates , prefix , CmdletCancellationToken )
322
- . AsPages ( track2ContinuationToken , requestCount )
323
- . GetEnumerator ( ) ;
324
-
325
- Page < BlobItem > page ;
326
- enumerator . MoveNext ( ) ;
327
- page = enumerator . Current ;
328
- foreach ( BlobItem item in page . Values )
329
- {
330
- if ( blobFilter == null || blobFilter ( item . Name ) )
331
- {
332
- ClientOptions . TrimBlobNameSlashes = false ;
333
- OutputStream . WriteObject ( taskId , GetAzureStorageBlob ( item , track2container , localChannel . StorageContext , page . ContinuationToken , ClientOptions ) ) ;
334
- }
335
- realListCount ++ ;
336
- }
337
- track2ContinuationToken = page . ContinuationToken ;
338
-
339
- if ( InternalMaxCount != int . MaxValue )
340
- {
341
- listCount -= realListCount ;
342
- }
343
- } while ( listCount > 0 && ! string . IsNullOrEmpty ( track2ContinuationToken ) ) ;
283
+ blobStates = blobStates | BlobStates . Deleted ;
344
284
}
345
- else
285
+ if ( includeVersion )
346
286
{
347
- BlobRequestOptions requestOptions = RequestOptions ;
348
- bool useFlatBlobListing = true ;
349
- BlobListingDetails details = BlobListingDetails . Snapshots | BlobListingDetails . Metadata | BlobListingDetails . Copy ;
350
- if ( includeDeleted )
351
- {
352
- details = details | BlobListingDetails . Deleted ;
353
- }
287
+ blobStates = blobStates | BlobStates . Version ;
288
+ }
289
+ if ( IncludeTag . IsPresent )
290
+ {
291
+ blobTraits = blobTraits | BlobTraits . Tags ;
292
+ }
354
293
355
- do
294
+ do
295
+ {
296
+ requestCount = Math . Min ( listCount , MaxListCount ) ;
297
+ realListCount = 0 ;
298
+ IEnumerator < Page < BlobItem > > enumerator = track2container . GetBlobs ( blobTraits , blobStates , prefix , CmdletCancellationToken )
299
+ . AsPages ( track2ContinuationToken , requestCount )
300
+ . GetEnumerator ( ) ;
301
+
302
+ Page < BlobItem > page ;
303
+ enumerator . MoveNext ( ) ;
304
+ page = enumerator . Current ;
305
+ foreach ( BlobItem item in page . Values )
356
306
{
357
- requestCount = Math . Min ( listCount , MaxListCount ) ;
358
- realListCount = 0 ;
359
- BlobResultSegment blobResult = await localChannel . ListBlobsSegmentedAsync ( container , prefix , useFlatBlobListing ,
360
- details , requestCount , continuationToken , requestOptions , OperationContext , CmdletCancellationToken ) . ConfigureAwait ( false ) ;
361
-
362
- foreach ( IListBlobItem blobItem in blobResult . Results )
363
- {
364
- CloudBlob blob = blobItem as CloudBlob ;
365
-
366
- if ( blob == null )
367
- {
368
- continue ;
369
- }
370
-
371
- if ( blobFilter == null || blobFilter ( blob . Name ) )
372
- {
373
- WriteCloudBlobObject ( taskId , localChannel , blob , blobResult . ContinuationToken ) ;
374
- realListCount ++ ;
375
- }
376
- }
377
-
378
- if ( InternalMaxCount != int . MaxValue )
307
+ if ( blobFilter == null || blobFilter ( item . Name ) )
379
308
{
380
- listCount -= realListCount ;
309
+ ClientOptions . TrimBlobNameSlashes = false ;
310
+ OutputStream . WriteObject ( taskId , GetAzureStorageBlob ( item , track2container , localChannel . StorageContext , page . ContinuationToken , ClientOptions ) ) ;
381
311
}
312
+ realListCount ++ ;
313
+ }
314
+ track2ContinuationToken = page . ContinuationToken ;
382
315
383
- continuationToken = blobResult . ContinuationToken ;
316
+ if ( InternalMaxCount != int . MaxValue )
317
+ {
318
+ listCount -= realListCount ;
384
319
}
385
- while ( listCount > 0 && continuationToken != null ) ;
386
- }
320
+ } while ( listCount > 0 && ! string . IsNullOrEmpty ( track2ContinuationToken ) ) ;
387
321
}
388
322
389
323
public static AzureStorageBlob GetAzureStorageBlob ( BlobItem blobItem , BlobContainerClient track2container , AzureStorageContext context , string continuationToken = null , BlobClientOptions options = null )
0 commit comments