Example #1
0
        public ActionResult LOBDashboard()
        {
            //if a user is already signed in but didn't go through the process of getting authorization code in auth config,
            //then GetAccessTokenAsync will succeed, but the returned access token can't be used to access the resource.
            //we have to ask the user to sign out and sign in again to get the authorization code first then access token.
            if (TokenCache.DefaultShared.Count > 0)
            {
                IEnumerable <TokenCacheItem> tokens = TokenCache.DefaultShared.ReadItems();
                ViewBag.accessToken = tokens.First().AccessToken;
                string responseContent = string.Empty;
                string dashboardsUri   = "https://api.powerbi.com/beta/myorg/dashboards";

                WebRequest request = WebRequest.Create(dashboardsUri) as HttpWebRequest;
                request.Method        = "GET";
                request.ContentLength = 0;
                request.Headers.Add("Authorization", String.Format("Bearer {0}", ViewBag.AccessToken));

                using (var response = request.GetResponse() as System.Net.HttpWebResponse)
                {
                    using (var reader = new System.IO.StreamReader(response.GetResponseStream()))
                    {
                        responseContent = reader.ReadToEnd();
                        PBIDashboards Dashboards = JsonConvert.DeserializeObject <PBIDashboards>(responseContent);
                        ViewBag.Dashboards = new SelectList(Dashboards.value.OrderBy(t => t.displayName), "embedUrl", "displayName");
                    }
                }
            }
            return(View());
        }
Example #2
0
        private PBIDashboard GetDashboardByDisplayName(string displayName)
        {
            string responseContent = string.Empty;

            //Configure datasets request
            System.Net.WebRequest request = System.Net.WebRequest.Create(String.Format("{0}dashboards", BaseUri)) as System.Net.HttpWebRequest;
            request.Method        = "GET";
            request.ContentLength = 0;
            request.Headers.Add("Authorization", String.Format("Bearer {0}", AuthResult.AccessToken));

            //Get datasets response from request.GetResponse()
            using (var response = request.GetResponse() as System.Net.HttpWebResponse)
            {
                //Get reader from response stream
                using (var reader = new System.IO.StreamReader(response.GetResponseStream()))
                {
                    responseContent = reader.ReadToEnd();
                    //Deserialize JSON string
                    PBIDashboards PBIDashboards = JsonConvert.DeserializeObject <PBIDashboards>(responseContent);

                    //Get each Dataset from
                    foreach (PBIDashboard db in PBIDashboards.value)
                    {
                        if (db.displayName == displayName)
                        {
                            return(db);
                        }
                    }
                }
            }

            // No Dashboard with displayName found
            return(null);
        }
Example #3
0
        public async Task <ActionResult> LOBDashboard()
        {
            ViewBag.accessToken = await GetTokenForApplication();

            string responseContent = string.Empty;
            string dashboardsUri   = "https://api.powerbi.com/beta/myorg/dashboards";

            WebRequest request = WebRequest.Create(dashboardsUri) as HttpWebRequest;

            request.Method        = "GET";
            request.ContentLength = 0;
            request.Headers.Add("Authorization", String.Format("Bearer {0}", ViewBag.AccessToken));

            using (var response = request.GetResponse() as System.Net.HttpWebResponse)
            {
                using (var reader = new System.IO.StreamReader(response.GetResponseStream()))
                {
                    responseContent = reader.ReadToEnd();
                    PBIDashboards Dashboards = JsonConvert.DeserializeObject <PBIDashboards>(responseContent);
                    ViewBag.Dashboards = new SelectList(Dashboards.value.OrderBy(t => t.displayName), "embedUrl", "displayName");
                }
            }
            return(View());
        }