示例#1
0
        static Workspace CreateWorkspace(string workspaceCollectionName, string accessKey, string apiUrl)
        {
            // Create a provision token required to create a new workspace within your collection
            var provisionToken = PowerBIToken.CreateProvisionToken(workspaceCollectionName);

            using (var client = CreateClient(provisionToken, accessKey, apiUrl))
            {
                // Create a new workspace witin the specified collection
                return(client.Workspaces.PostWorkspace(workspaceCollectionName));
            }
        }
示例#2
0
        /// <summary>
        /// Creates a new Power BI Embedded workspace within the specified collection
        /// </summary>
        /// <param name="workspaceCollectionName">The Power BI workspace collection name</param>
        /// <returns></returns>
        static async Task <Workspace> CreateWorkspace(string workspaceCollectionName)
        {
            // Create a provision token required to create a new workspace within your collection
            var provisionToken = PowerBIToken.CreateProvisionToken(workspaceCollectionName);

            using (var client = await CreateClient(provisionToken))
            {
                // Create a new workspace witin the specified collection
                return(await client.Workspaces.PostWorkspaceAsync(workspaceCollectionName));
            }
        }
示例#3
0
        /// <summary>
        /// Gets a list of Power BI Embedded workspaces within the specified collection
        /// </summary>
        /// <param name="workspaceCollectionName">The Power BI workspace collection name</param>
        /// <returns></returns>
        static async Task <IEnumerable <Workspace> > GetWorkspaces(string workspaceCollectionName)
        {
            var provisionToken = PowerBIToken.CreateProvisionToken(workspaceCollectionName);

            using (var client = await CreateClient(provisionToken))
            {
                var response = await client.Workspaces.GetWorkspacesByCollectionNameAsync(workspaceCollectionName);

                return(response.Value);
            }
        }
示例#4
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"));
        }