Пример #1
0
 private IList <Report> GetWorkspaceReports(string workspaceId)
 {
     using (var client = new PowerBIReportClient(this.workspaceCollection, workspaceId))
     {
         try
         {
             return(client.Reports.GetReports(this.workspaceCollection, workspaceId).Value);
         }
         catch
         {
             return(new List <Report>());
         }
     }
 }
Пример #2
0
        public async Task <ActionResult> Report(string workspaceId, string reportId)
        {
            using (var client = new PowerBIReportClient(this.workspaceCollection, workspaceId))
            {
                var reportsResponse = await client.Reports.GetReportsAsync(this.workspaceCollection, workspaceId);

                var report     = reportsResponse.Value.FirstOrDefault(r => r.Id == reportId);
                var embedToken = PowerBIToken.CreateReportEmbedToken(this.workspaceCollection, workspaceId, report.Id);

                var viewModel = new ReportViewModel
                {
                    Report      = report,
                    AccessToken = embedToken.Generate(PowerBIReportClient.SigningKey)
                };

                return(View(viewModel));
            }
        }
Пример #3
0
        public async Task <ActionResult> Upload(ReportUploadModel report)
        {
            string workspaceId = report.ReportCategory;

            // See if we have a new workspace name
            if (!String.IsNullOrWhiteSpace(report.NewReportCategory))
            {
                using (var client = new PowerBIReportClient(PowerBIToken.CreateProvisionToken(this.workspaceCollection), this.workspaceCollection, String.Empty))
                {
                    var newWorkspaceResult = await client.Workspaces.PostWorkspaceAsync(this.workspaceCollection);

                    this.workspaces.Workspaces.Add(new ReportWorkspace
                    {
                        DisplayName = report.NewReportCategory,
                        WorkspaceId = newWorkspaceResult.WorkspaceId,
                        Reports     = new List <Report>(),
                    });
                    workspaceId = newWorkspaceResult.WorkspaceId;
                    // Update web.config
                    var webConfig = WebConfigurationManager.OpenWebConfiguration("~");
                    webConfig.AppSettings.Settings["WorkspaceMappings"].Value = String.Join(";", this.workspaces.Workspaces
                                                                                            .Select(workspace => String.Format("{0}|{1}", workspace.WorkspaceId, workspace.DisplayName)));
                    webConfig.Save();
                }
            }
            using (var client = new PowerBIReportClient(this.workspaceCollection, workspaceId))
            {
                var import = await client.Imports.PostImportWithFileAsync(this.workspaceCollection,
                                                                          workspaceId,
                                                                          report.PbixReport.InputStream,
                                                                          report.ReportName);

                import = await client.WaitForImportToComplete(import);

                if (import.ImportState == PowerBIReportClient.StateSucceeded)
                {
                    return(RedirectToAction("Report", new { workspaceId = workspaceId, reportId = import.Reports.First().Id }));
                }
            }
            return(RedirectToAction("Index"));
        }