Skip to content

Commit

Permalink
Merge pull request #21 from Azure-Samples/xpouyat/july2020-update3
Browse files Browse the repository at this point in the history
Update to nugget packages, resolved information messages in VS.
  • Loading branch information
xpouyat authored Jul 31, 2020
2 parents c994c92 + 31f4762 commit 4ff2680
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 80 deletions.
8 changes: 4 additions & 4 deletions AMSV3Tutorials/AnalyzeVideos/AnalyzeVideos.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@

<ItemGroup>
<PackageReference Include="Microsoft.Azure.Management.Media" Version="2.0.5" />
<PackageReference Include="Microsoft.Azure.Storage.Blob" Version="11.1.7" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="3.1.5" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="3.1.5" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="3.1.5" />
<PackageReference Include="Microsoft.Azure.Storage.Blob" Version="11.2.0" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="3.1.6" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="3.1.6" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="3.1.6" />
<PackageReference Include="Microsoft.Rest.ClientRuntime.Azure.Authentication" Version="2.4.1" />
</ItemGroup>

Expand Down
19 changes: 8 additions & 11 deletions AMSV3Tutorials/AnalyzeVideos/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ public static async Task Main(string[] args)

Console.Error.WriteLine($"{exception.Message}");

ApiErrorException apiException = exception.GetBaseException() as ApiErrorException;
if (apiException != null)
if (exception.GetBaseException() is ApiErrorException apiException)
{
Console.Error.WriteLine(
$"ERROR: API call failed with error code '{apiException.Body.Error.Code}' and message '{apiException.Body.Error.Message}'.");
Expand Down Expand Up @@ -81,7 +80,7 @@ private static async Task RunAsync(ConfigWrapper config)
// This preset enables you to extract multiple audio and video insights from a video.
// In the example, the language ("en-US") is passed to its constructor.
// You can also specify what insights you want to extract by passing InsightsToExtract to the constructor.
Transform videoAnalyzerTransform = await GetOrCreateTransformAsync(client, config.ResourceGroup, config.AccountName, VideoAnalyzerTransformName, new VideoAnalyzerPreset("en-US"));
_ = await GetOrCreateTransformAsync(client, config.ResourceGroup, config.AccountName, VideoAnalyzerTransformName, new VideoAnalyzerPreset("en-US"));

// Create a new input Asset and upload the specified local video file into it.
await CreateInputAssetAsync(client, config.ResourceGroup, config.AccountName, inputAssetName, InputMP4FileName);
Expand All @@ -92,12 +91,12 @@ private static async Task RunAsync(ConfigWrapper config)
// Output from the encoding Job must be written to an Asset, so let's create one
Asset outputAsset = await CreateOutputAssetAsync(client, config.ResourceGroup, config.AccountName, outputAssetName);

Job job = await SubmitJobAsync(client, config.ResourceGroup, config.AccountName, VideoAnalyzerTransformName, jobName, jobInput, outputAsset.Name);
_ = await SubmitJobAsync(client, config.ResourceGroup, config.AccountName, VideoAnalyzerTransformName, jobName, jobInput, outputAsset.Name);

// In this demo code, we will poll for Job status
// Polling is not a recommended best practice for production applications because of the latency it introduces.
// Overuse of this API may trigger throttling. Developers should instead use Event Grid.
job = await WaitForJobToFinishAsync(client, config.ResourceGroup, config.AccountName, VideoAnalyzerTransformName, jobName);
Job job = await WaitForJobToFinishAsync(client, config.ResourceGroup, config.AccountName, VideoAnalyzerTransformName, jobName);

if (job.State == JobState.Finished)
{
Expand Down Expand Up @@ -265,7 +264,7 @@ private static async Task<Asset> CreateOutputAssetAsync(IAzureMediaServicesClien
// Name collision! In order to get the sample to work, let's just go ahead and create a unique asset name
// Note that the returned Asset can have a different name than the one specified as an input parameter.
// You may want to update this part to throw an Exception instead, and handle name collisions differently.
string uniqueness = $"-{Guid.NewGuid().ToString("N")}";
string uniqueness = $"-{Guid.NewGuid():N}";
outputAssetName += uniqueness;

Console.WriteLine("Warning – found an existing Asset with name = " + assetName);
Expand Down Expand Up @@ -338,8 +337,7 @@ private static async Task<Job> WaitForJobToFinishAsync(IAzureMediaServicesClient
{
const int SleepIntervalMs = 20 * 1000;

Job job = null;

Job job;
do
{
job = await client.Jobs.GetAsync(resourceGroupName, accountName, transformName, jobName);
Expand All @@ -351,7 +349,7 @@ private static async Task<Job> WaitForJobToFinishAsync(IAzureMediaServicesClient
Console.Write($"\tJobOutput[{i}] is '{output.State}'.");
if (output.State == JobState.Processing)
{
Console.Write($" Progress: '{output.Progress}'.");
Console.Write($" Progress (%): '{output.Progress}'.");
}

Console.WriteLine();
Expand Down Expand Up @@ -418,8 +416,7 @@ private static async Task DownloadOutputAssetAsync(

foreach (IListBlobItem blobItem in segment.Results)
{
CloudBlockBlob blob = blobItem as CloudBlockBlob;
if (blob != null)
if (blobItem is CloudBlockBlob blob)
{
string path = Path.Combine(directory, blob.Name);

Expand Down
15 changes: 10 additions & 5 deletions AMSV3Tutorials/EncryptWithAES/EncryptWithAES.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Azure.Storage.Blob" Version="11.1.7" />
<PackageReference Include="Microsoft.Azure.Storage.Blob" Version="11.2.0" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt " Version="5.3.0" />
<PackageReference Include="Microsoft.IdentityModel.Tokens" Version="5.3.0" />
<PackageReference Include="Microsoft.IdentityModel.Tokens" Version="6.7.1" />
<PackageReference Include="Microsoft.Azure.Management.Media" Version="2.0.5" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="3.1.5" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="3.1.5" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="3.1.5" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="3.1.6" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="3.1.6" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="3.1.6" />
<PackageReference Include="Microsoft.Rest.ClientRuntime.Azure.Authentication" Version="2.4.1" />
<PackageReference Include="System.Security.Claims" Version="4.3.0" />
</ItemGroup>
Expand All @@ -29,4 +29,9 @@
</None>
</ItemGroup>


<ItemGroup>
<PackageReference Update="System.IdentityModel.Tokens.Jwt" Version="6.7.1" />
</ItemGroup>

</Project>
37 changes: 18 additions & 19 deletions AMSV3Tutorials/EncryptWithAES/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ class Program
private const string AdaptiveStreamingTransformName = "MyTransformWithAdaptiveStreamingPreset";
private const string OutputFolderName = @"Output";

private static string Issuer = "myIssuer";
private static string Audience = "myAudience";
private static readonly string Issuer = "myIssuer";
private static readonly string Audience = "myAudience";
private static byte[] TokenSigningKey = new byte[40];
private static string ContentKeyPolicyName = "SharedContentKeyPolicyUsedByAllAssets";
private static readonly string ContentKeyPolicyName = "SharedContentKeyPolicyUsedByAllAssets";

public static async Task Main(string[] args)
{
Expand All @@ -44,8 +44,7 @@ public static async Task Main(string[] args)
{
Console.Error.WriteLine($"{exception.Message}");

ApiErrorException apiException = exception.GetBaseException() as ApiErrorException;
if (apiException != null)
if (exception.GetBaseException() is ApiErrorException apiException)
{
Console.Error.WriteLine(
$"ERROR: API call failed with error code '{apiException.Body.Error.Code}' and message '{apiException.Body.Error.Message}'.");
Expand Down Expand Up @@ -78,17 +77,17 @@ private static async Task RunAsync(ConfigWrapper config)
string outputAssetName = $"output-{uniqueness}";

// Ensure that you have the desired encoding Transform. This is really a one time setup operation.
Transform transform = await GetOrCreateTransformAsync(client, config.ResourceGroup, config.AccountName, AdaptiveStreamingTransformName);
_ = await GetOrCreateTransformAsync(client, config.ResourceGroup, config.AccountName, AdaptiveStreamingTransformName);

// Output from the encoding Job must be written to an Asset, so let's create one
Asset outputAsset = await CreateOutputAssetAsync(client, config.ResourceGroup, config.AccountName, outputAssetName);

Job job = await SubmitJobAsync(client, config.ResourceGroup, config.AccountName, AdaptiveStreamingTransformName, outputAsset.Name, jobName);
_ = await SubmitJobAsync(client, config.ResourceGroup, config.AccountName, AdaptiveStreamingTransformName, outputAsset.Name, jobName);

// In this demo code, we will poll for Job status
// Polling is not a recommended best practice for production applications because of the latency it introduces.
// Overuse of this API may trigger throttling. Developers should instead use Event Grid.
job = await WaitForJobToFinishAsync(client, config.ResourceGroup, config.AccountName, AdaptiveStreamingTransformName, jobName);
Job job = await WaitForJobToFinishAsync(client, config.ResourceGroup, config.AccountName, AdaptiveStreamingTransformName, jobName);

if (job.State == JobState.Finished)
{
Expand All @@ -99,9 +98,9 @@ private static async Task RunAsync(ConfigWrapper config)
// Set a token signing key that you want to use
TokenSigningKey = Convert.FromBase64String(config.SymmetricKey);

//Create the content key policy that configures how the content key is delivered to end clients
// Create the content key policy that configures how the content key is delivered to end clients
// via the Key Delivery component of Azure Media Services.
ContentKeyPolicy policy = await GetOrCreateContentKeyPolicyAsync(client, config.ResourceGroup, config.AccountName, ContentKeyPolicyName);
_ = await GetOrCreateContentKeyPolicyAsync(client, config.ResourceGroup, config.AccountName, ContentKeyPolicyName);

StreamingLocator locator = await CreateStreamingLocatorAsync(client, config.ResourceGroup, config.AccountName, outputAsset.Name, locatorName, ContentKeyPolicyName);

Expand Down Expand Up @@ -284,7 +283,7 @@ private static async Task<Asset> CreateOutputAssetAsync(IAzureMediaServicesClien
// Name collision! In order to get the sample to work, let's just go ahead and create a unique asset name
// Note that the returned Asset can have a different name than the one specified as an input parameter.
// You may want to update this part to throw an Exception instead, and handle name collisions differently.
string uniqueness = $"-{Guid.NewGuid().ToString("N")}";
string uniqueness = $"-{Guid.NewGuid():N}";
outputAssetName += uniqueness;

Console.WriteLine("Warning – found an existing Asset with name = " + assetName);
Expand Down Expand Up @@ -362,8 +361,7 @@ private static async Task<Job> WaitForJobToFinishAsync(IAzureMediaServicesClient
{
const int SleepIntervalMs = 20 * 1000;

Job job = null;

Job job;
do
{
job = await client.Jobs.GetAsync(resourceGroupName, accountName, transformName, jobName);
Expand All @@ -375,7 +373,7 @@ private static async Task<Job> WaitForJobToFinishAsync(IAzureMediaServicesClient
Console.Write($"\tJobOutput[{i}] is '{output.State}'.");
if (output.State == JobState.Processing)
{
Console.Write($" Progress: '{output.Progress}'.");
Console.Write($" Progress (%): '{output.Progress}'.");
}

Console.WriteLine();
Expand Down Expand Up @@ -500,9 +498,11 @@ private static async Task<string> GetDASHStreamingUrlAsync(

foreach (StreamingPath path in paths.StreamingPaths)
{
UriBuilder uriBuilder = new UriBuilder();
uriBuilder.Scheme = "https";
uriBuilder.Host = streamingEndpoint.HostName;
UriBuilder uriBuilder = new UriBuilder
{
Scheme = "https",
Host = streamingEndpoint.HostName
};

// Look for just the DASH path and generate a URL for the Azure Media Player to playback the content with the AES token to decrypt.
// Note that the JWT token is set to expire in 1 hour.
Expand Down Expand Up @@ -570,8 +570,7 @@ private static async Task DownloadOutputAssetAsync(

foreach (IListBlobItem blobItem in segment.Results)
{
CloudBlockBlob blob = blobItem as CloudBlockBlob;
if (blob != null)
if (blobItem is CloudBlockBlob blob)
{
string path = Path.Combine(directory, blob.Name);

Expand Down
14 changes: 9 additions & 5 deletions AMSV3Tutorials/EncryptWithDRM/EncryptWithDRM.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Azure.Storage.Blob" Version="11.1.7" />
<PackageReference Include="Microsoft.Azure.Storage.Blob" Version="11.2.0" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt " Version="5.3.0" />
<PackageReference Include="Microsoft.IdentityModel.Tokens" Version="5.3.0" />
<PackageReference Include="Microsoft.IdentityModel.Tokens" Version="6.7.1" />
<PackageReference Include="Microsoft.Azure.Management.Media" Version="2.0.5" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="3.1.5" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="3.1.5" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="3.1.5" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="3.1.6" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="3.1.6" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="3.1.6" />
<PackageReference Include="Microsoft.Rest.ClientRuntime.Azure.Authentication" Version="2.4.1" />
<PackageReference Include="System.Security.Claims" Version="4.3.0" />
</ItemGroup>
Expand All @@ -28,4 +28,8 @@
</None>
</ItemGroup>

<ItemGroup>
<PackageReference Update="System.IdentityModel.Tokens.Jwt" Version="6.7.1" />
</ItemGroup>

</Project>
25 changes: 10 additions & 15 deletions AMSV3Tutorials/EncryptWithDRM/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ class Program
{
private const string AdaptiveStreamingTransformName = "MyTransformWithAdaptiveStreamingPreset";

private static string Issuer = "myIssuer";
private static string Audience = "myAudience";
private static readonly string Issuer = "myIssuer";
private static readonly string Audience = "myAudience";

private static byte[] TokenSigningKey = new byte[40];
private static string ContentKeyPolicyName = "DRMContentKeyPolicy";
private static readonly string ContentKeyPolicyName = "DRMContentKeyPolicy";

public static async Task Main(string[] args)
{
Expand All @@ -44,8 +44,7 @@ public static async Task Main(string[] args)
{
Console.Error.WriteLine($"{exception.Message}");

ApiErrorException apiException = exception.GetBaseException() as ApiErrorException;
if (apiException != null)
if (exception.GetBaseException() is ApiErrorException apiException)
{
Console.Error.WriteLine(
$"ERROR: API call failed with error code '{apiException.Body.Error.Code}' and message '{apiException.Body.Error.Message}'.");
Expand Down Expand Up @@ -236,11 +235,9 @@ ContentKeyPolicyTokenRestriction restriction
{
// Get the signing key from the existing policy.
var policyProperties = await client.ContentKeyPolicies.GetPolicyPropertiesWithSecretsAsync(resourceGroupName, accountName, contentKeyPolicyName);
var restriction = policyProperties.Options[0].Restriction as ContentKeyPolicyTokenRestriction;
if (restriction != null)
if (policyProperties.Options[0].Restriction is ContentKeyPolicyTokenRestriction restriction)
{
var signingKey = restriction.PrimaryVerificationKey as ContentKeyPolicySymmetricTokenKey;
if (signingKey != null)
if (restriction.PrimaryVerificationKey is ContentKeyPolicySymmetricTokenKey signingKey)
{
TokenSigningKey = signingKey.KeyValue;
}
Expand Down Expand Up @@ -318,7 +315,7 @@ private static async Task<Asset> CreateOutputAssetAsync(IAzureMediaServicesClien
// Name collision! In order to get the sample to work, let's just go ahead and create a unique asset name
// Note that the returned Asset can have a different name than the one specified as an input parameter.
// You may want to update this part to throw an Exception instead, and handle name collisions differently.
string uniqueness = $"-{Guid.NewGuid().ToString("N")}";
string uniqueness = $"-{Guid.NewGuid():N}";
outputAssetName += uniqueness;

Console.WriteLine("Warning – found an existing Asset with name = " + assetName);
Expand Down Expand Up @@ -396,8 +393,7 @@ private static async Task<Job> WaitForJobToFinishAsync(IAzureMediaServicesClient
{
const int SleepIntervalMs = 20 * 1000;

Job job = null;

Job job;
do
{
job = await client.Jobs.GetAsync(resourceGroupName, accountName, transformName, jobName);
Expand All @@ -409,7 +405,7 @@ private static async Task<Job> WaitForJobToFinishAsync(IAzureMediaServicesClient
Console.Write($"\tJobOutput[{i}] is '{output.State}'.");
if (output.State == JobState.Processing)
{
Console.Write($" Progress: '{output.Progress}'.");
Console.Write($" Progress (%): '{output.Progress}'.");
}

Console.WriteLine();
Expand Down Expand Up @@ -726,8 +722,7 @@ private static async Task DownloadOutputAssetAsync(

foreach (IListBlobItem blobItem in segment.Results)
{
CloudBlockBlob blob = blobItem as CloudBlockBlob;
if (blob != null)
if (blobItem is CloudBlockBlob blob)
{
string path = Path.Combine(directory, blob.Name);

Expand Down
Loading

0 comments on commit 4ff2680

Please sign in to comment.