Beispiel #1
0
        public async Task <IActionResult> PowerBI(PowerBIModel data)
        {
            List <ValidationResult> errors = new List <ValidationResult>();

            try
            {
                ValidatePowerBIConfiguration(errors, data);

                if (!errors.Any())
                {
                    IConfidentialClientApplication clientApp = ConfidentialClientApplicationBuilder
                                                               .Create(data.ClientId)
                                                               .WithClientSecret(data.AppSecret)
                                                               .WithAuthority($"{data.Authority}{data.TenantId}")
                                                               .Build();
                    List <string> scopes = new List <string>
                    {
                        data.Scope,
                    };

                    Microsoft.Identity.Client.AuthenticationResult authenticationResult = await clientApp.AcquireTokenForClient(scopes).ExecuteAsync();

                    if (authenticationResult is null)
                    {
                        errors.Add(new ValidationResult("Unable to authenticate the Power BI client"));
                    }
                    if (!errors.Any())
                    {
                        TokenCredentials tokenCredentials = new TokenCredentials(authenticationResult.AccessToken, "Bearer");

                        // 3. Get embedded report info
                        var client = new PowerBIClient(new Uri(data.APIBaseURL), tokenCredentials);

                        Reports reports = client.Reports.GetReports(Guid.Parse(data.WorkSpaceId));

                        ViewBag.Reports = reports;
                    }
                }
            }
            catch (HttpOperationException ex)
            {
                errors.Add(new ValidationResult(ex.Message));
            }
            catch (Exception e)
            {
                errors.Add(new ValidationResult(e.Message));
            }

            errors.ForEach(_ =>
            {
                ModelState.AddModelError(string.Empty, _.ErrorMessage);
            });

            return(View(data));
        }
        public async Task <PowerBIModel> GetEmbedData([FromServices] AzureModel azureSettings)
        {
            var accessToken = await _embeddedService.GetPowerBiAccessToken(azureSettings);

            var tokenCredentials   = new TokenCredentials(accessToken, "Bearer");
            var requestAccessLevel = new GenerateTokenRequest(accessLevel: "view");

            using var client = new PowerBIClient(new Uri(azureSettings.ApiUrl), tokenCredentials);

            var report = await client.Reports.GetReportInGroupAsync(azureSettings.GroupId, azureSettings.ReportId);

            var tokenResponse = await client.Reports.GenerateTokenAsync(azureSettings.GroupId, azureSettings.ReportId, requestAccessLevel);

            var result = new PowerBIModel(tokenResponse, report.EmbedUrl);

            return(result);
        }
Beispiel #3
0
 public virtual void SavePowerBIConnection(PowerBIModel powerBi)
 {
     PowerBI = powerBi;
 }
Beispiel #4
0
        private void ValidatePowerBIConfiguration(ICollection <ValidationResult> errors, PowerBIModel data)
        {
            if (string.IsNullOrWhiteSpace(data.ClientId))
            {
                errors.Add(new ValidationResult("ClientId_Empty"));
            }
            else if (!Guid.TryParse(data.ClientId, out _))
            {
                errors.Add(new ValidationResult("ClientId_Not_Valid"));
            }

            if (string.IsNullOrWhiteSpace(data.WorkSpaceId))
            {
                errors.Add(new ValidationResult("WorkspaceId_Empty"));
            }
            else if (!Guid.TryParse(data.WorkSpaceId, out _))
            {
                errors.Add(new ValidationResult("WorkspaceId_Not_Valid"));
            }

            if (string.IsNullOrWhiteSpace(data.TenantId))
            {
                errors.Add(new ValidationResult("TenantId_Empty"));
            }
            else if (!Guid.TryParse(data.TenantId, out _))
            {
                errors.Add(new ValidationResult("TenantId_Not_Valid"));
            }

            if (string.IsNullOrWhiteSpace(data.AppSecret))
            {
                errors.Add(new ValidationResult("App_Secret_Empty"));
            }
        }
Beispiel #5
0
 public async Task <bool> AddTableRows(PowerBITableRows rows)
 {
     return(await PowerBIModel.AddTableRows(rows.datasetId, rows.tableName, rows.rows));
 }
Beispiel #6
0
 public async Task <bool> ClearTable(PowerBITableRef tableRef)
 {
     return(await PowerBIModel.ClearTable(tableRef.datasetId, tableRef.tableName));
 }
Beispiel #7
0
 public async Task <bool> DeleteDataset(Guid id)
 {
     //DELETE IS UNSUPPORTED
     return(await PowerBIModel.DeleteDataset(id));
 }
Beispiel #8
0
 public async Task <Guid> CreateDataset(PowerBIDataset dataset)
 {
     return(await PowerBIModel.CreateDataset(dataset));
 }
Beispiel #9
0
 public async Task <PowerBIDataset> GetDataset(Guid id)
 {
     return(await PowerBIModel.GetDataset(id));
 }
Beispiel #10
0
 public async Task <List <PowerBIDataset> > GetDatasets()
 {
     return(await PowerBIModel.GetDatasets());
 }