@@ -6,7 +6,7 @@ author: IngridAtMicrosoft
6
6
manager : femila
7
7
ms.service : media-services
8
8
ms.topic : tutorial
9
- ms.date : 05/18 /2021
9
+ ms.date : 09/13 /2021
10
10
ms.author : inhenkel
11
11
---
12
12
@@ -112,34 +112,35 @@ func new --name OnAir --template "HTTP trigger" --authlevel "anonymous"
112
112
113
113
## Configure the functions project
114
114
115
- ### Add items to the .csproj file
115
+ ### Install Media Services and other extensions
116
116
117
- In the autogenerated “.csproj” file, add the following lines to the first ` <ItemGroup> ` :
117
+ Run the dotnet add package command in the Terminal window to install the extension packages that you need in your project. The following command installs the Media Services and Azure Identity packages.
118
118
119
- ``` xml
120
- < PackageReference Include = " Microsoft.Azure.Management.Fluent " Version = " 1.37.0 " />
121
- < PackageReference Include = " Microsoft.Azure.Management.Media " Version = " 3.0.4 " />
119
+ ``` bash
120
+ dotnet add package Microsoft.Azure.Management.Media
121
+ dotnet add package Azure.Identity
122
122
```
123
123
124
124
### Edit the OnAir.cs code
125
125
126
126
Change the ` OnAir.cs ` file. Change ` subscriptionId ` , ` resourceGroup ` , and ` mediaServicesAccountName ` variables to the ones you decided upon earlier.
127
127
128
- ``` aspx-csharp
129
- using System.Threading.Tasks;
128
+ ``` csharp
129
+ using Azure .Core ;
130
+ using Azure .Identity ;
131
+ using Microsoft .AspNetCore .Http ;
130
132
using Microsoft .AspNetCore .Mvc ;
133
+ using Microsoft .Azure .Management .Media ;
134
+ using Microsoft .Azure .Management .Media .Models ;
131
135
using Microsoft .Azure .WebJobs ;
132
136
using Microsoft .Azure .WebJobs .Extensions .Http ;
133
- using Microsoft.AspNetCore.Http;
134
137
using Microsoft .Extensions .Logging ;
135
- using Microsoft.Azure.Management.Media;
136
- using Microsoft.Azure.Management.ResourceManager.Fluent.Authentication;
137
- using Microsoft.Azure.Management.ResourceManager.Fluent;
138
- using Microsoft.Azure.Management.Media.Models;
138
+ using Microsoft .Rest ;
139
+ using System .Threading .Tasks ;
139
140
140
141
namespace MediaServicesLiveMonitor
141
142
{
142
- public static class LatestAsset
143
+ public static class OnAir
143
144
{
144
145
[FunctionName (" OnAir" )]
145
146
public static async Task <IActionResult > Run (
@@ -154,14 +155,18 @@ namespace MediaServicesLiveMonitor
154
155
{
155
156
return new BadRequestObjectResult (" Missing 'name' URL parameter" );
156
157
}
157
-
158
- var credentials = SdkContext.AzureCredentialsFactory.FromSystemAssignedManagedServiceIdentity(
159
- MSIResourceType.AppService,
160
- AzureEnvironment.AzureGlobalCloud);
161
158
162
- var subscriptionId = "00000000-0000-0000-000000000000"; // Update
163
- var resourceGroup = "<your-resource-group-name>"; // Update
164
- var mediaServicesAccountName = "<your-media-services-account-name>"; // Update
159
+ var credential = new ManagedIdentityCredential ();
160
+ var accessTokenRequest = await credential .GetTokenAsync (
161
+ new TokenRequestContext (
162
+ scopes : new string [] { " https://management.core.windows.net" + " /.default" }
163
+ )
164
+ );
165
+ ServiceClientCredentials credentials = new TokenCredentials (accessTokenRequest .Token , " Bearer" );
166
+
167
+ var subscriptionId = " 00000000-0000-0000-000000000000" ; // Update
168
+ var resourceGroup = " <your-resource-group-name>" ; // Update
169
+ var mediaServicesAccountName = " <your-media-services-account-name>" ; // Update
165
170
166
171
var mediaServices = new AzureMediaServicesClient (credentials )
167
172
{
@@ -174,7 +179,7 @@ namespace MediaServicesLiveMonitor
174
179
{
175
180
return new NotFoundResult ();
176
181
}
177
-
182
+
178
183
return new OkObjectResult (liveEvent .ResourceState == LiveEventResourceState .Running ? " On air" : " Off air" );
179
184
}
180
185
}
0 commit comments