@@ -13,6 +13,7 @@ namespace AppOwnsData.Services
1313 using System . Collections . Generic ;
1414 using System . Linq ;
1515 using System . Runtime . InteropServices ;
16+ using System . Threading . Tasks ;
1617
1718 public class PbiEmbedService
1819 {
@@ -28,19 +29,20 @@ public PbiEmbedService(AadService aadService)
2829 /// Get Power BI client
2930 /// </summary>
3031 /// <returns>Power BI client object</returns>
31- public PowerBIClient GetPowerBIClient ( )
32+ public async Task < PowerBIClient > GetPowerBIClient ( )
3233 {
33- var tokenCredentials = new TokenCredentials ( aadService . GetAccessToken ( ) , "Bearer" ) ;
34+ var accessToken = await aadService . GetAccessToken ( ) ;
35+ var tokenCredentials = new TokenCredentials ( accessToken , "Bearer" ) ;
3436 return new PowerBIClient ( new Uri ( powerBiApiUrl ) , tokenCredentials ) ;
3537 }
3638
3739 /// <summary>
3840 /// Get embed params for a report
3941 /// </summary>
4042 /// <returns>Wrapper object containing Embed token, Embed URL, Report Id, and Report name for single report</returns>
41- public EmbedParams GetEmbedParams ( Guid workspaceId , Guid reportId , [ Optional ] Guid additionalDatasetId )
43+ public async Task < EmbedParams > GetEmbedParams ( Guid workspaceId , Guid reportId , [ Optional ] Guid additionalDatasetId )
4244 {
43- PowerBIClient pbiClient = this . GetPowerBIClient ( ) ;
45+ PowerBIClient pbiClient = await this . GetPowerBIClient ( ) ;
4446
4547 // Get report info
4648 var pbiReport = pbiClient . Reports . GetReportInGroup ( workspaceId , reportId ) ;
@@ -55,7 +57,7 @@ public EmbedParams GetEmbedParams(Guid workspaceId, Guid reportId, [Optional] Gu
5557 if ( isRDLReport )
5658 {
5759 // Get Embed token for RDL Report
58- embedToken = GetEmbedTokenForRDLReport ( workspaceId , reportId ) ;
60+ embedToken = await GetEmbedTokenForRDLReport ( workspaceId , reportId ) ;
5961 }
6062 else
6163 {
@@ -72,7 +74,7 @@ public EmbedParams GetEmbedParams(Guid workspaceId, Guid reportId, [Optional] Gu
7274 }
7375
7476 // Get Embed token multiple resources
75- embedToken = GetEmbedToken ( reportId , datasetIds , workspaceId ) ;
77+ embedToken = await GetEmbedToken ( reportId , datasetIds , workspaceId ) ;
7678 }
7779
7880 // Add report data for embedding
@@ -99,11 +101,11 @@ public EmbedParams GetEmbedParams(Guid workspaceId, Guid reportId, [Optional] Gu
99101 /// </summary>
100102 /// <returns>Wrapper object containing Embed token, Embed URL, Report Id, and Report name for multiple reports</returns>
101103 /// <remarks>This function is not supported for RDL Report</remakrs>
102- public EmbedParams GetEmbedParams ( Guid workspaceId , IList < Guid > reportIds , [ Optional ] IList < Guid > additionalDatasetIds )
104+ public async Task < EmbedParams > GetEmbedParams ( Guid workspaceId , IList < Guid > reportIds , [ Optional ] IList < Guid > additionalDatasetIds )
103105 {
104106 // Note: This method is an example and is not consumed in this sample app
105107
106- PowerBIClient pbiClient = this . GetPowerBIClient ( ) ;
108+ PowerBIClient pbiClient = await this . GetPowerBIClient ( ) ;
107109
108110 // Create mapping for reports and Embed URLs
109111 var embedReports = new List < EmbedReport > ( ) ;
@@ -130,7 +132,7 @@ public EmbedParams GetEmbedParams(Guid workspaceId, IList<Guid> reportIds, [Opti
130132 }
131133
132134 // Get Embed token multiple resources
133- var embedToken = GetEmbedToken ( reportIds , datasetIds , workspaceId ) ;
135+ var embedToken = await GetEmbedToken ( reportIds , datasetIds , workspaceId ) ;
134136
135137 // Capture embed params
136138 var embedParams = new EmbedParams
@@ -148,9 +150,9 @@ public EmbedParams GetEmbedParams(Guid workspaceId, IList<Guid> reportIds, [Opti
148150 /// </summary>
149151 /// <returns>Embed token</returns>
150152 /// <remarks>This function is not supported for RDL Report</remakrs>
151- public EmbedToken GetEmbedToken ( Guid reportId , IList < Guid > datasetIds , [ Optional ] Guid targetWorkspaceId )
153+ public async Task < EmbedToken > GetEmbedToken ( Guid reportId , IList < Guid > datasetIds , [ Optional ] Guid targetWorkspaceId )
152154 {
153- PowerBIClient pbiClient = this . GetPowerBIClient ( ) ;
155+ PowerBIClient pbiClient = await this . GetPowerBIClient ( ) ;
154156
155157 // Create a request for getting Embed token
156158 // This method works only with new Power BI V2 workspace experience
@@ -174,11 +176,11 @@ public EmbedToken GetEmbedToken(Guid reportId, IList<Guid> datasetIds, [Optional
174176 /// </summary>
175177 /// <returns>Embed token</returns>
176178 /// <remarks>This function is not supported for RDL Report</remakrs>
177- public EmbedToken GetEmbedToken ( IList < Guid > reportIds , IList < Guid > datasetIds , [ Optional ] Guid targetWorkspaceId )
179+ public async Task < EmbedToken > GetEmbedToken ( IList < Guid > reportIds , IList < Guid > datasetIds , [ Optional ] Guid targetWorkspaceId )
178180 {
179181 // Note: This method is an example and is not consumed in this sample app
180182
181- PowerBIClient pbiClient = this . GetPowerBIClient ( ) ;
183+ PowerBIClient pbiClient = await this . GetPowerBIClient ( ) ;
182184
183185 // Convert report Ids to required types
184186 var reports = reportIds . Select ( reportId => new GenerateTokenRequestV2Report ( reportId ) ) . ToList ( ) ;
@@ -208,11 +210,11 @@ public EmbedToken GetEmbedToken(IList<Guid> reportIds, IList<Guid> datasetIds, [
208210 /// </summary>
209211 /// <returns>Embed token</returns>
210212 /// <remarks>This function is not supported for RDL Report</remakrs>
211- public EmbedToken GetEmbedToken ( IList < Guid > reportIds , IList < Guid > datasetIds , [ Optional ] IList < Guid > targetWorkspaceIds )
213+ public async Task < EmbedToken > GetEmbedToken ( IList < Guid > reportIds , IList < Guid > datasetIds , [ Optional ] IList < Guid > targetWorkspaceIds )
212214 {
213215 // Note: This method is an example and is not consumed in this sample app
214216
215- PowerBIClient pbiClient = this . GetPowerBIClient ( ) ;
217+ PowerBIClient pbiClient = await this . GetPowerBIClient ( ) ;
216218
217219 // Convert report Ids to required types
218220 var reports = reportIds . Select ( reportId => new GenerateTokenRequestV2Report ( reportId ) ) . ToList ( ) ;
@@ -248,9 +250,9 @@ public EmbedToken GetEmbedToken(IList<Guid> reportIds, IList<Guid> datasetIds, [
248250 /// Get Embed token for RDL Report
249251 /// </summary>
250252 /// <returns>Embed token</returns>
251- public EmbedToken GetEmbedTokenForRDLReport ( Guid targetWorkspaceId , Guid reportId , string accessLevel = "view" )
253+ public async Task < EmbedToken > GetEmbedTokenForRDLReport ( Guid targetWorkspaceId , Guid reportId , string accessLevel = "view" )
252254 {
253- PowerBIClient pbiClient = this . GetPowerBIClient ( ) ;
255+ PowerBIClient pbiClient = await this . GetPowerBIClient ( ) ;
254256
255257 // Generate token request for RDL Report
256258 var generateTokenRequestParameters = new GenerateTokenRequest (
0 commit comments