|
3 | 3 | using System.IO; |
4 | 4 | using System.Linq; |
5 | 5 | using System.Threading.Tasks; |
6 | | - |
| 6 | +using Azure.Storage.Blobs; |
| 7 | +using Azure.Storage.Blobs.Models; |
7 | 8 | using Microsoft.Azure.Management.Media; |
8 | 9 | using Microsoft.Azure.Management.Media.Models; |
9 | | -using Microsoft.Azure.Storage.Blob; |
10 | 10 | using Microsoft.Extensions.Configuration; |
11 | 11 | using Microsoft.IdentityModel.Clients.ActiveDirectory; |
12 | 12 | using Microsoft.Rest; |
@@ -36,7 +36,7 @@ public static async Task Main(string[] args) |
36 | 36 | { |
37 | 37 | if (exception.Source.Contains("ActiveDirectory")) |
38 | 38 | { |
39 | | - Console.Error.WriteLine("TIP: Make sure that you have filled out the appsettings.json file before running this sample."); |
| 39 | + Console.Error.WriteLine("TIP: Make sure that you have filled out the appsettings.json file before running this sample."); |
40 | 40 | } |
41 | 41 |
|
42 | 42 | Console.Error.WriteLine($"{exception.Message}"); |
@@ -193,11 +193,11 @@ private static async Task<Asset> CreateInputAssetAsync( |
193 | 193 |
|
194 | 194 | // Use Storage API to get a reference to the Asset container |
195 | 195 | // that was created by calling Asset's CreateOrUpdate method. |
196 | | - CloudBlobContainer container = new CloudBlobContainer(sasUri); |
197 | | - var blob = container.GetBlockBlobReference(Path.GetFileName(fileToUpload)); |
| 196 | + BlobContainerClient container = new BlobContainerClient(sasUri); |
| 197 | + BlobClient blob = container.GetBlobClient(Path.GetFileName(fileToUpload)); |
198 | 198 |
|
199 | 199 | // Use Strorage API to upload the file into the container in storage. |
200 | | - await blob.UploadFromFileAsync(fileToUpload); |
| 200 | + await blob.UploadAsync(fileToUpload); |
201 | 201 |
|
202 | 202 | return asset; |
203 | 203 | } |
@@ -226,9 +226,9 @@ private static async Task<Asset> CreateOutputAssetAsync(IAzureMediaServicesClien |
226 | 226 | // You may want to update this part to throw an Exception instead, and handle name collisions differently. |
227 | 227 | string uniqueness = $"-{Guid.NewGuid():N}"; |
228 | 228 | outputAssetName += uniqueness; |
229 | | - |
| 229 | + |
230 | 230 | Console.WriteLine("Warning – found an existing Asset with name = " + assetName); |
231 | | - Console.WriteLine("Creating an Asset with this name instead: " + outputAssetName); |
| 231 | + Console.WriteLine("Creating an Asset with this name instead: " + outputAssetName); |
232 | 232 | } |
233 | 233 |
|
234 | 234 | return await client.Assets.CreateOrUpdateAsync(resourceGroupName, accountName, outputAssetName, asset); |
@@ -485,38 +485,34 @@ private static async Task DownloadOutputAssetAsync( |
485 | 485 | expiryTime: DateTime.UtcNow.AddHours(1).ToUniversalTime()); |
486 | 486 |
|
487 | 487 | Uri containerSasUrl = new Uri(assetContainerSas.AssetContainerSasUrls.FirstOrDefault()); |
488 | | - CloudBlobContainer container = new CloudBlobContainer(containerSasUrl); |
| 488 | + BlobContainerClient container = new BlobContainerClient(containerSasUrl); |
489 | 489 |
|
490 | 490 | string directory = Path.Combine(outputFolderName, assetName); |
491 | 491 | Directory.CreateDirectory(directory); |
492 | 492 |
|
493 | 493 | Console.WriteLine($"Downloading output results to '{directory}'..."); |
494 | 494 |
|
495 | | - BlobContinuationToken continuationToken = null; |
| 495 | + string continuationToken = null; |
496 | 496 | IList<Task> downloadTasks = new List<Task>(); |
497 | 497 |
|
498 | 498 | do |
499 | 499 | { |
500 | | - // A non-negative integer value that indicates the maximum number of results to be returned at a time, |
501 | | - // up to the per-operation limit of 5000. If this value is null, the maximum possible number of results |
502 | | - // will be returned, up to 5000. |
503 | | - int? ListBlobsSegmentMaxResult = null; |
504 | | - |
505 | | - BlobResultSegment segment = await container.ListBlobsSegmentedAsync(null, true, BlobListingDetails.None, ListBlobsSegmentMaxResult, continuationToken, null, null); |
506 | | - |
507 | | - foreach (IListBlobItem blobItem in segment.Results) |
| 500 | + var resultSegment = container.GetBlobs().AsPages(continuationToken); |
| 501 | + |
| 502 | + foreach (Azure.Page<BlobItem> blobPage in resultSegment) |
508 | 503 | { |
509 | | - if (blobItem is CloudBlockBlob blob) |
| 504 | + foreach (BlobItem blobItem in blobPage.Values) |
510 | 505 | { |
511 | | - string path = Path.Combine(directory, blob.Name); |
| 506 | + var blobClient = container.GetBlobClient(blobItem.Name); |
| 507 | + string filename = Path.Combine(directory, blobItem.Name); |
512 | 508 |
|
513 | | - downloadTasks.Add(blob.DownloadToFileAsync(path, FileMode.Create)); |
| 509 | + downloadTasks.Add(blobClient.DownloadToAsync(filename)); |
514 | 510 | } |
| 511 | + // Get the continuation token and loop until it is empty. |
| 512 | + continuationToken = blobPage.ContinuationToken; |
515 | 513 | } |
516 | 514 |
|
517 | | - continuationToken = segment.ContinuationToken; |
518 | | - } |
519 | | - while (continuationToken != null); |
| 515 | + } while (continuationToken != ""); |
520 | 516 |
|
521 | 517 | await Task.WhenAll(downloadTasks); |
522 | 518 |
|
|
0 commit comments