Exemplo n.º 1
0
        public static ReportsController.FetchReportResult FetchReport(string reportId)
        {
            // Create a dev token for fetch
            var devToken = PowerBIToken.CreateDevToken(WorkspaceCollection, WorkspaceId);

            using (var client = CreatePowerBiClient(devToken))
            {
                var reports = ReportsExtensions.GetReports(client.Reports, WorkspaceCollection, WorkspaceId);
                var report  = reports.Value.FirstOrDefault(r => r.Id == reportId);

                if (report != null)
                {
                    var embedToken = PowerBIToken.CreateReportEmbedToken(WorkspaceCollection, WorkspaceId, report.Id);

                    var result = new ReportsController.FetchReportResult
                    {
                        Report      = report,
                        AccessToken = embedToken.Generate(ConfigHelper.PowerbiSigningKey)
                    };

                    return(result);
                }

                return(new ReportsController.FetchReportResult()
                {
                    AccessToken = string.Empty,
                    Report = null
                });
            }
        }
Exemplo n.º 2
0
        public static SelectList FetchReports(string reportId, string exclude = null)
        {
            // Create a dev token for fetch
            var devToken = PowerBIToken.CreateDevToken(WorkspaceCollection, WorkspaceId);

            using (var client = CreatePowerBiClient(devToken))
            {
                var reportsResponse = ReportsExtensions.GetReports(client.Reports, WorkspaceCollection, WorkspaceId);

                if (!string.IsNullOrEmpty(exclude))
                {
                    reportsResponse.Value = reportsResponse.Value.Where(r => !r.Name.Equals(exclude)).ToList();
                }

                return(new SelectList(reportsResponse.Value.ToList(), "Id", "Name", reportId));
            }
        }