Exemplo n.º 1
0
        public static async Task <DashboardsViewModel> GetDashboards(string dashboardId)
        {
            var client     = GetPowerBiClient();
            var dashboards = (await client.Dashboards.GetDashboardsInGroupAsync(appWorkspaceId)).Value;

            var viewModel = new DashboardsViewModel {
                Dashboards = dashboards.ToList()
            };

            if (!string.IsNullOrEmpty(dashboardId))
            {
                Dashboard dashboard = dashboards.Where(d => d.Id == dashboardId).First();
                var       generateTokenRequestParameters = new GenerateTokenRequest(accessLevel: "view");
                var       token = client.Dashboards.GenerateTokenInGroupAsync(appWorkspaceId, dashboard.Id, generateTokenRequestParameters).Result;

                var embedConfig = new EmbedConfiguration()
                {
                    EmbedToken = token,
                    EmbedUrl   = dashboard.EmbedUrl,
                    Id         = dashboard.Id
                };


                viewModel.CurrentDashboard = new DashboardViewModel {
                    Dashboard   = dashboard,
                    EmbedConfig = embedConfig
                };
            }

            return(viewModel);
        }
Exemplo n.º 2
0
        public static async Task <ReportsViewModel> GetReports(string reportId)
        {
            var client  = GetPowerBiClient();
            var reports = (await client.Reports.GetReportsInGroupAsync(appWorkspaceId)).Value;

            var viewModel = new ReportsViewModel {
                Reports = reports.ToList()
            };

            if (!string.IsNullOrEmpty(reportId))
            {
                Report report = reports.Where(r => r.Id == reportId).First();
                var    generateTokenRequestParameters = new GenerateTokenRequest(accessLevel: "view");
                var    token = client.Reports.GenerateTokenInGroupAsync(appWorkspaceId, report.Id, generateTokenRequestParameters).Result;

                var embedConfig = new EmbedConfiguration()
                {
                    EmbedToken = token,
                    EmbedUrl   = report.EmbedUrl,
                    Id         = report.Id
                };


                viewModel.CurrentReport = new ReportViewModel {
                    Report      = report,
                    EmbedConfig = embedConfig
                };
            }

            return(viewModel);
        }