Skip to content
This repository was archived by the owner on Apr 1, 2025. It is now read-only.

Commit 0807545

Browse files
authored
Merge pull request #23 from Azure-Samples/xpouyat-nov2020
Package update. Moved to new storage SDK.
2 parents fb577c8 + ed273f5 commit 0807545

File tree

8 files changed

+88
-104
lines changed

8 files changed

+88
-104
lines changed

AMSV3Tutorials/AnalyzeVideos/AnalyzeVideos.csproj

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@
1212
</PropertyGroup>
1313

1414
<ItemGroup>
15-
<PackageReference Include="Microsoft.Azure.Management.Media" Version="2.0.5" />
16-
<PackageReference Include="Microsoft.Azure.Storage.Blob" Version="11.2.0" />
17-
<PackageReference Include="Microsoft.Extensions.Configuration" Version="3.1.6" />
18-
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="3.1.6" />
19-
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="3.1.6" />
15+
<PackageReference Include="Azure.Storage.Blobs" Version="12.7.0" />
16+
<PackageReference Include="Microsoft.Azure.Management.Media" Version="3.0.2" />
17+
<PackageReference Include="Microsoft.Extensions.Configuration" Version="5.0.0" />
18+
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="5.0.0" />
19+
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="5.0.0" />
2020
<PackageReference Include="Microsoft.Rest.ClientRuntime.Azure.Authentication" Version="2.4.1" />
2121
</ItemGroup>
2222

AMSV3Tutorials/AnalyzeVideos/Program.cs

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
using System.IO;
44
using System.Linq;
55
using System.Threading.Tasks;
6-
6+
using Azure.Storage.Blobs;
7+
using Azure.Storage.Blobs.Models;
78
using Microsoft.Azure.Management.Media;
89
using Microsoft.Azure.Management.Media.Models;
9-
using Microsoft.Azure.Storage.Blob;
1010
using Microsoft.Extensions.Configuration;
1111
using Microsoft.IdentityModel.Clients.ActiveDirectory;
1212
using Microsoft.Rest;
@@ -233,11 +233,11 @@ private static async Task<Asset> CreateInputAssetAsync(
233233

234234
// Use Storage API to get a reference to the Asset container
235235
// that was created by calling Asset's CreateOrUpdate method.
236-
CloudBlobContainer container = new CloudBlobContainer(sasUri);
237-
var blob = container.GetBlockBlobReference(Path.GetFileName(fileToUpload));
236+
BlobContainerClient container = new BlobContainerClient(sasUri);
237+
BlobClient blob = container.GetBlobClient(Path.GetFileName(fileToUpload));
238238

239-
// Use Strorage API to upload the file into the container in storage.
240-
await blob.UploadFromFileAsync(fileToUpload);
239+
// Use Storage API to upload the file into the container in storage.
240+
await blob.UploadAsync(fileToUpload);
241241

242242
return asset;
243243
}
@@ -395,38 +395,35 @@ private static async Task DownloadOutputAssetAsync(
395395
expiryTime: DateTime.UtcNow.AddHours(1).ToUniversalTime());
396396

397397
Uri containerSasUrl = new Uri(assetContainerSas.AssetContainerSasUrls.FirstOrDefault());
398-
CloudBlobContainer container = new CloudBlobContainer(containerSasUrl);
398+
BlobContainerClient container = new BlobContainerClient(containerSasUrl);
399399

400400
string directory = Path.Combine(outputFolderName, assetName);
401401
Directory.CreateDirectory(directory);
402402

403403
Console.WriteLine($"Downloading output results to '{directory}'...");
404404

405-
BlobContinuationToken continuationToken = null;
405+
string continuationToken = null;
406406
IList<Task> downloadTasks = new List<Task>();
407407

408408
do
409409
{
410-
// A non-negative integer value that indicates the maximum number of results to be returned at a time,
411-
// up to the per-operation limit of 5000. If this value is null, the maximum possible number of results
412-
// will be returned, up to 5000.
413-
int? ListBlobsSegmentMaxResult = null;
414-
415-
BlobResultSegment segment = await container.ListBlobsSegmentedAsync(null, true, BlobListingDetails.None, ListBlobsSegmentMaxResult, continuationToken, null, null);
410+
var resultSegment = container.GetBlobs().AsPages(continuationToken);
416411

417-
foreach (IListBlobItem blobItem in segment.Results)
412+
foreach (Azure.Page<BlobItem> blobPage in resultSegment)
418413
{
419-
if (blobItem is CloudBlockBlob blob)
414+
foreach (BlobItem blobItem in blobPage.Values)
420415
{
421-
string path = Path.Combine(directory, blob.Name);
416+
var blobClient = container.GetBlobClient(blobItem.Name);
417+
string filename = Path.Combine(directory, blobItem.Name);
422418

423-
downloadTasks.Add(blob.DownloadToFileAsync(path, FileMode.Create));
419+
downloadTasks.Add(blobClient.DownloadToAsync(filename));
424420
}
421+
// Get the continuation token and loop until it is empty.
422+
continuationToken = blobPage.ContinuationToken;
425423
}
426424

427-
continuationToken = segment.ContinuationToken;
428-
}
429-
while (continuationToken != null);
425+
426+
} while (continuationToken != "");
430427

431428
await Task.WhenAll(downloadTasks);
432429

AMSV3Tutorials/EncryptWithAES/EncryptWithAES.csproj

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@
1111
</PropertyGroup>
1212

1313
<ItemGroup>
14-
<PackageReference Include="Microsoft.Azure.Storage.Blob" Version="11.2.0" />
14+
<PackageReference Include="Azure.Storage.Blobs" Version="12.7.0" />
1515
<PackageReference Include="System.IdentityModel.Tokens.Jwt " Version="5.3.0" />
16-
<PackageReference Include="Microsoft.IdentityModel.Tokens" Version="6.7.1" />
17-
<PackageReference Include="Microsoft.Azure.Management.Media" Version="2.0.5" />
18-
<PackageReference Include="Microsoft.Extensions.Configuration" Version="3.1.6" />
19-
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="3.1.6" />
20-
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="3.1.6" />
16+
<PackageReference Include="Microsoft.IdentityModel.Tokens" Version="6.8.0" />
17+
<PackageReference Include="Microsoft.Azure.Management.Media" Version="3.0.2" />
18+
<PackageReference Include="Microsoft.Extensions.Configuration" Version="5.0.0" />
19+
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="5.0.0" />
20+
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="5.0.0" />
2121
<PackageReference Include="Microsoft.Rest.ClientRuntime.Azure.Authentication" Version="2.4.1" />
2222
<PackageReference Include="System.Security.Claims" Version="4.3.0" />
2323
</ItemGroup>
@@ -31,7 +31,7 @@
3131

3232

3333
<ItemGroup>
34-
<PackageReference Update="System.IdentityModel.Tokens.Jwt" Version="6.7.1" />
34+
<PackageReference Update="System.IdentityModel.Tokens.Jwt" Version="6.8.0" />
3535
</ItemGroup>
3636

3737
</Project>

AMSV3Tutorials/EncryptWithAES/Program.cs

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,11 @@
44
using System.IO;
55
using System.Linq;
66
using System.Security.Claims;
7-
using System.Security.Cryptography;
87
using System.Threading.Tasks;
9-
8+
using Azure.Storage.Blobs;
9+
using Azure.Storage.Blobs.Models;
1010
using Microsoft.Azure.Management.Media;
1111
using Microsoft.Azure.Management.Media.Models;
12-
using Microsoft.Azure.Storage.Blob;
1312
using Microsoft.Extensions.Configuration;
1413
using Microsoft.IdentityModel.Clients.ActiveDirectory;
1514
using Microsoft.IdentityModel.Tokens;
@@ -549,38 +548,34 @@ private static async Task DownloadOutputAssetAsync(
549548
expiryTime: DateTime.UtcNow.AddHours(1).ToUniversalTime());
550549

551550
Uri containerSasUrl = new Uri(assetContainerSas.AssetContainerSasUrls.FirstOrDefault());
552-
CloudBlobContainer container = new CloudBlobContainer(containerSasUrl);
551+
BlobContainerClient container = new BlobContainerClient(containerSasUrl);
553552

554553
string directory = Path.Combine(outputFolderName, assetName);
555554
Directory.CreateDirectory(directory);
556555

557556
Console.WriteLine($"Downloading output results to '{directory}'...");
558557

559-
BlobContinuationToken continuationToken = null;
558+
string continuationToken = null;
560559
IList<Task> downloadTasks = new List<Task>();
561560

562561
do
563562
{
564-
// A non-negative integer value that indicates the maximum number of results to be returned at a time,
565-
// up to the per-operation limit of 5000. If this value is null, the maximum possible number of results
566-
// will be returned, up to 5000.
567-
int? ListBlobsSegmentMaxResult = null;
568-
569-
BlobResultSegment segment = await container.ListBlobsSegmentedAsync(null, true, BlobListingDetails.None, ListBlobsSegmentMaxResult, continuationToken, null, null);
563+
var resultSegment = container.GetBlobs().AsPages(continuationToken);
570564

571-
foreach (IListBlobItem blobItem in segment.Results)
565+
foreach (Azure.Page<BlobItem> blobPage in resultSegment)
572566
{
573-
if (blobItem is CloudBlockBlob blob)
567+
foreach (BlobItem blobItem in blobPage.Values)
574568
{
575-
string path = Path.Combine(directory, blob.Name);
569+
var blobClient = container.GetBlobClient(blobItem.Name);
570+
string filename = Path.Combine(directory, blobItem.Name);
576571

577-
downloadTasks.Add(blob.DownloadToFileAsync(path, FileMode.Create));
572+
downloadTasks.Add(blobClient.DownloadToAsync(filename));
578573
}
574+
// Get the continuation token and loop until it is empty.
575+
continuationToken = blobPage.ContinuationToken;
579576
}
580577

581-
continuationToken = segment.ContinuationToken;
582-
}
583-
while (continuationToken != null);
578+
} while (continuationToken != "");
584579

585580
await Task.WhenAll(downloadTasks);
586581

AMSV3Tutorials/EncryptWithDRM/EncryptWithDRM.csproj

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@
1111
</PropertyGroup>
1212

1313
<ItemGroup>
14-
<PackageReference Include="Microsoft.Azure.Storage.Blob" Version="11.2.0" />
14+
<PackageReference Include="Azure.Storage.Blobs" Version="12.7.0" />
1515
<PackageReference Include="System.IdentityModel.Tokens.Jwt " Version="5.3.0" />
16-
<PackageReference Include="Microsoft.IdentityModel.Tokens" Version="6.7.1" />
17-
<PackageReference Include="Microsoft.Azure.Management.Media" Version="2.0.5" />
18-
<PackageReference Include="Microsoft.Extensions.Configuration" Version="3.1.6" />
19-
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="3.1.6" />
20-
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="3.1.6" />
16+
<PackageReference Include="Microsoft.IdentityModel.Tokens" Version="6.8.0" />
17+
<PackageReference Include="Microsoft.Azure.Management.Media" Version="3.0.2" />
18+
<PackageReference Include="Microsoft.Extensions.Configuration" Version="5.0.0" />
19+
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="5.0.0" />
20+
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="5.0.0" />
2121
<PackageReference Include="Microsoft.Rest.ClientRuntime.Azure.Authentication" Version="2.4.1" />
2222
<PackageReference Include="System.Security.Claims" Version="4.3.0" />
2323
</ItemGroup>
@@ -29,7 +29,7 @@
2929
</ItemGroup>
3030

3131
<ItemGroup>
32-
<PackageReference Update="System.IdentityModel.Tokens.Jwt" Version="6.7.1" />
32+
<PackageReference Update="System.IdentityModel.Tokens.Jwt" Version="6.8.0" />
3333
</ItemGroup>
3434

3535
</Project>

AMSV3Tutorials/EncryptWithDRM/Program.cs

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
using System.Security.Claims;
77
using System.Security.Cryptography.X509Certificates;
88
using System.Threading.Tasks;
9-
9+
using Azure.Storage.Blobs;
10+
using Azure.Storage.Blobs.Models;
1011
using Microsoft.Azure.Management.Media;
1112
using Microsoft.Azure.Management.Media.Models;
12-
using Microsoft.Azure.Storage.Blob;
1313
using Microsoft.Extensions.Configuration;
1414
using Microsoft.IdentityModel.Clients.ActiveDirectory;
1515
using Microsoft.IdentityModel.Tokens;
@@ -701,38 +701,34 @@ private static async Task DownloadOutputAssetAsync(
701701
expiryTime: DateTime.UtcNow.AddHours(1).ToUniversalTime());
702702

703703
Uri containerSasUrl = new Uri(assetContainerSas.AssetContainerSasUrls.FirstOrDefault());
704-
CloudBlobContainer container = new CloudBlobContainer(containerSasUrl);
704+
BlobContainerClient container = new BlobContainerClient(containerSasUrl);
705705

706706
string directory = Path.Combine(outputFolderName, assetName);
707707
Directory.CreateDirectory(directory);
708708

709709
Console.WriteLine($"Downloading output results to '{directory}'...");
710710

711-
BlobContinuationToken continuationToken = null;
711+
string continuationToken = null;
712712
IList<Task> downloadTasks = new List<Task>();
713713

714714
do
715715
{
716-
// A non-negative integer value that indicates the maximum number of results to be returned at a time,
717-
// up to the per-operation limit of 5000. If this value is null, the maximum possible number of results
718-
// will be returned, up to 5000.
719-
int? ListBlobsSegmentMaxResult = null;
720-
721-
BlobResultSegment segment = await container.ListBlobsSegmentedAsync(null, true, BlobListingDetails.None, ListBlobsSegmentMaxResult, continuationToken, null, null);
716+
var resultSegment = container.GetBlobs().AsPages(continuationToken);
722717

723-
foreach (IListBlobItem blobItem in segment.Results)
718+
foreach (Azure.Page<BlobItem> blobPage in resultSegment)
724719
{
725-
if (blobItem is CloudBlockBlob blob)
720+
foreach (BlobItem blobItem in blobPage.Values)
726721
{
727-
string path = Path.Combine(directory, blob.Name);
722+
var blobClient = container.GetBlobClient(blobItem.Name);
723+
string filename = Path.Combine(directory, blobItem.Name);
728724

729-
downloadTasks.Add(blob.DownloadToFileAsync(path, FileMode.Create));
725+
downloadTasks.Add(blobClient.DownloadToAsync(filename));
730726
}
727+
// Get the continuation token and loop until it is empty.
728+
continuationToken = blobPage.ContinuationToken;
731729
}
732730

733-
continuationToken = segment.ContinuationToken;
734-
}
735-
while (continuationToken != null);
731+
} while (continuationToken != "");
736732

737733
await Task.WhenAll(downloadTasks);
738734

AMSV3Tutorials/UploadEncodeAndStreamFiles/Program.cs

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
using System.IO;
44
using System.Linq;
55
using System.Threading.Tasks;
6-
6+
using Azure.Storage.Blobs;
7+
using Azure.Storage.Blobs.Models;
78
using Microsoft.Azure.Management.Media;
89
using Microsoft.Azure.Management.Media.Models;
9-
using Microsoft.Azure.Storage.Blob;
1010
using Microsoft.Extensions.Configuration;
1111
using Microsoft.IdentityModel.Clients.ActiveDirectory;
1212
using Microsoft.Rest;
@@ -36,7 +36,7 @@ public static async Task Main(string[] args)
3636
{
3737
if (exception.Source.Contains("ActiveDirectory"))
3838
{
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.");
4040
}
4141

4242
Console.Error.WriteLine($"{exception.Message}");
@@ -193,11 +193,11 @@ private static async Task<Asset> CreateInputAssetAsync(
193193

194194
// Use Storage API to get a reference to the Asset container
195195
// 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));
198198

199199
// Use Strorage API to upload the file into the container in storage.
200-
await blob.UploadFromFileAsync(fileToUpload);
200+
await blob.UploadAsync(fileToUpload);
201201

202202
return asset;
203203
}
@@ -226,9 +226,9 @@ private static async Task<Asset> CreateOutputAssetAsync(IAzureMediaServicesClien
226226
// You may want to update this part to throw an Exception instead, and handle name collisions differently.
227227
string uniqueness = $"-{Guid.NewGuid():N}";
228228
outputAssetName += uniqueness;
229-
229+
230230
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);
232232
}
233233

234234
return await client.Assets.CreateOrUpdateAsync(resourceGroupName, accountName, outputAssetName, asset);
@@ -485,38 +485,34 @@ private static async Task DownloadOutputAssetAsync(
485485
expiryTime: DateTime.UtcNow.AddHours(1).ToUniversalTime());
486486

487487
Uri containerSasUrl = new Uri(assetContainerSas.AssetContainerSasUrls.FirstOrDefault());
488-
CloudBlobContainer container = new CloudBlobContainer(containerSasUrl);
488+
BlobContainerClient container = new BlobContainerClient(containerSasUrl);
489489

490490
string directory = Path.Combine(outputFolderName, assetName);
491491
Directory.CreateDirectory(directory);
492492

493493
Console.WriteLine($"Downloading output results to '{directory}'...");
494494

495-
BlobContinuationToken continuationToken = null;
495+
string continuationToken = null;
496496
IList<Task> downloadTasks = new List<Task>();
497497

498498
do
499499
{
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)
508503
{
509-
if (blobItem is CloudBlockBlob blob)
504+
foreach (BlobItem blobItem in blobPage.Values)
510505
{
511-
string path = Path.Combine(directory, blob.Name);
506+
var blobClient = container.GetBlobClient(blobItem.Name);
507+
string filename = Path.Combine(directory, blobItem.Name);
512508

513-
downloadTasks.Add(blob.DownloadToFileAsync(path, FileMode.Create));
509+
downloadTasks.Add(blobClient.DownloadToAsync(filename));
514510
}
511+
// Get the continuation token and loop until it is empty.
512+
continuationToken = blobPage.ContinuationToken;
515513
}
516514

517-
continuationToken = segment.ContinuationToken;
518-
}
519-
while (continuationToken != null);
515+
} while (continuationToken != "");
520516

521517
await Task.WhenAll(downloadTasks);
522518

0 commit comments

Comments
 (0)