Пример #1
0
        private async Task <Report> GetReportByGroupAndName(string GroupID, string Name)
        {
            try
            {
                if (string.IsNullOrEmpty(GroupID) || string.IsNullOrEmpty(Name))
                {
                    return(null);
                }
                var tokenCredentials = await PowerBIService.GetAccessTokenSecretAsync();

                // Create a Power BI Client object. it's used to call Power BI APIs.
                using (var client = new PowerBIClient(new Uri(Constants.ApiUrl), tokenCredentials))
                {
                    Microsoft.PowerBI.Api.Models.Reports ReportsInGroup = client.Reports.GetReportsInGroup(Guid.Parse(GroupID));

                    if (ReportsInGroup != null)
                    {
                        Report found = ReportsInGroup.Value.Where(a => a.Name.Equals(Name)).FirstOrDefault();
                        return(ReportsInGroup.Value.Where(a => a.Name.Equals(Name)).FirstOrDefault());
                    }
                }
            }
            catch (Microsoft.IdentityModel.Clients.ActiveDirectory.AdalServiceException)
            {
            }
            catch (Exception ex)
            {
            }

            return(null);
        }
        private async void GenerateEmbedToken()
        {
            try
            {
                tokenCredentials = await PowerBIService.GetAccessTokenSecretAsync();

                using (var client = new PowerBIClient(new Uri(Constants.ApiUrl), tokenCredentials))
                {
                    var TokenCached = App.EmbedTokenB.GetByGroupIDAndReportID(EmbedConfig.GroupID, EmbedConfig.Id);

                    if (TokenCached == null)
                    {
                        //IList<Guid> ds = new List<Guid>();
                        //ds.Add(Guid.Parse(EmbedConfig.GroupID));
                        EmbedToken tokenResponse = client.Reports.GenerateToken(Guid.Parse(EmbedConfig.GroupID), Guid.Parse(EmbedConfig.Id), new GenerateTokenRequest(accessLevel: "view"));

                        EmbedConfig.EmbedToken = tokenResponse;

                        App.EmbedTokenB.Create(new Data.Models.EmbedTokenDTO()
                        {
                            Expiration = tokenResponse.Expiration, Token = tokenResponse.Token, GroupID = EmbedConfig.GroupID, Id = EmbedConfig.Id, TokenId = tokenResponse.TokenId.ToString()
                        });


                        ConfigureReportViewer();
                    }
                    else
                    {
                        EmbedConfig.EmbedToken = new EmbedToken(TokenCached.Token, Guid.Parse(TokenCached.TokenId), TokenCached.Expiration.Value);

                        ConfigureReportViewer();
                    }
                }
            }
            catch (HttpOperationException ex)
            {
                var content = ex.Response.Content;
                Alerts.ShowAlert(string.Empty, "Error al mostrar el reporte.");
            }
        }