protected void Page_Load(object sender, EventArgs e)
 {
     //Check if we are authenticated, if we are, pull the token from the session, if not follow the sign in process
     if (Session[authResultString] != null)
     {
         //Get the authentication result from the session
         authResult = (AuthenticationResult)Session[authResultString];
         embedConf  = EmbedReport();
     }
     else
     {
         signIn();
     }
 }
Beispiel #2
0
 protected void Page_Load(object sender, EventArgs e)
 {
     //Test for AuthenticationResult
     if (Session[authResultString] != null)
     {
         //Get the authentication result from the session
         authResult = (AuthenticationResult)Session[authResultString];
         embedConf  = EmbedDashboard();
     }
     else
     {
         signIn();
     }
 }
        public static EmbedConfig EmbedDashboard()
        {
            // Create a user password cradentials.
            var credential = new UserPasswordCredential(Username, Password);

            // Authenticate using created credentials
            var authenticationContext = new AuthenticationContext(AuthorityUrl);
            var authenticationResult  = authenticationContext.AcquireTokenAsync(ResourceUrl, ApplicationId, credential).Result;

            var tokenCredentials = new TokenCredentials(authenticationResult.AccessToken, "Bearer");

            // Create a Power BI Client object. It will be used to call Power BI APIs.
            using (var client = new PowerBIClient(new Uri(ApiUrl), tokenCredentials))
            {
                // Get a list of dashboards.
                var dashboards = client.Dashboards.GetDashboardsInGroup(WorkspaceId);

                // Get the first report in the workspace.
                var dashboard = dashboards.Value.FirstOrDefault();

                //This is where we determine if your DashboardID set above is blank, if blank use the queried dashboard. If not just use your setting
                var dashboardid = "";
                if (DashboardId == "")
                {
                    dashboardid = dashboard.Id;
                }
                else
                {
                    dashboardid = DashboardId;
                }

                // Generate Embed Token, a very import part of this is you can change the access level which will let end users edit!
                var generateTokenRequestParameters = new GenerateTokenRequest(accessLevel: "view");
                var tokenResponse = client.Dashboards.GenerateTokenInGroupAsync(WorkspaceId, dashboardid, generateTokenRequestParameters).Result;

                // Generate Embed Configuration.
                var embedConfig = new EmbedConfig()
                {
                    EmbedToken = tokenResponse,
                    EmbedUrl   = dashboard.EmbedUrl,
                    Id         = dashboardid
                };

                return(embedConfig);
            }
        }
        public static EmbedConfig EmbedReport()
        {
            var tokenCredentials = new TokenCredentials(authResult.AccessToken, "Bearer");

            // Create a Power BI Client object. It will be used to call Power BI APIs.
            using (var client = new PowerBIClient(new Uri(ApiUrl), tokenCredentials))
            {
                // Get a list of reports.
                var reports = client.Reports.GetReportsInGroup(WorkspaceId);

                // Get the first report in the workspace.
                var report = reports.Value.FirstOrDefault();

                //This is where we determine if your DashboardID set above is blank, if blank use the queried dashboard. If not just use your setting
                var reportid = "";
                if (ReportId == "")
                {
                    reportid = report.Id;
                }
                else
                {
                    reportid = ReportId;
                }

                // Generate Embed Token, a very import part of this is you can change the access level which will let end users edit!
                var generateTokenRequestParameters = new GenerateTokenRequest(accessLevel: "view");
                var tokenResponse = client.Reports.GenerateTokenInGroupAsync(WorkspaceId, reportid, generateTokenRequestParameters).Result;

                // Generate Embed Configuration.
                var embedConfig = new EmbedConfig()
                {
                    EmbedToken = tokenResponse,
                    EmbedUrl   = report.EmbedUrl,
                    Id         = reportid
                };

                return(embedConfig);
            }
        }
 protected void Page_Load(object sender, EventArgs e)
 {
     embedConf = EmbedDashboard();
 }
Beispiel #6
0
 protected void Page_Load(object sender, EventArgs e)
 {
     embedConf = EmbedReport();
 }