示例#1
0
        private static async Task <string> ExecuteGetRequest(string urlRestEndpoint)
        {
            string accessToken = await TokenManagerService.GetPowerBiAccessToken();

            HttpClient         client  = new HttpClient();
            HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, urlRestEndpoint);

            request.Headers.Add("Authorization", "Bearer " + accessToken);
            request.Headers.Add("Accept", "application/json;odata.metadata=minimal");

            HttpResponseMessage response = await client.SendAsync(request);

            if (response.StatusCode != HttpStatusCode.OK)
            {
                throw new ApplicationException("Error!!!!!");
            }

            return(await response.Content.ReadAsStringAsync());
        }
示例#2
0
        public static async Task <ReportsViewModel> GetReports(string reportId)
        {
            string jsonResult = await ExecuteGetRequest(restUrlReports);

            ReportCollection reports     = JsonConvert.DeserializeObject <ReportCollection>(jsonResult);
            string           accessToken = await TokenManagerService.GetPowerBiAccessToken();

            ReportsViewModel reportsViewModel = new ReportsViewModel {
                UserIsAuthenticated = true,
                Reports             = reports.value,
                CurrentReport       = null,
                AccessToken         = accessToken
            };

            if (!string.IsNullOrEmpty(reportId))
            {
                reportsViewModel.CurrentReport = reports.value.Find(report => report.id.Equals(reportId));
            }

            return(reportsViewModel);
        }