private async Task LoadReportAsync() { if (Uri.TryCreate(EmbedUrl, UriKind.Absolute, out Uri embedUri)) { string token = await GetUserTokenAsync(); if (!string.IsNullOrEmpty(token) && embedUri.Query.IndexOf("reportid", StringComparison.OrdinalIgnoreCase) != -1 && embedUri.Query.IndexOf("groupid", StringComparison.OrdinalIgnoreCase) != -1) { var tokenCredentials = new TokenCredentials(token, "Bearer"); using (var client = new PowerBIClient(new Uri(ApiUrl), tokenCredentials)) { var decoder = new WwwFormUrlDecoder(embedUri.Query.ToLower()); string groupId = decoder.GetFirstValueByName("groupid"); string reportId = decoder.GetFirstValueByName("reportid"); Report report = await client.Reports.GetReportAsync(groupId, reportId); if (report != null) { InvokeScriptAsync($"loadGroups(" + $"'{token}', " + $"{JsonConvert.SerializeObject(new Report[] { report })}, " + $"{JsonConvert.SerializeObject(report)}, " + (IsWindowsPhone ? $"'{DisplayInformation.CurrentOrientation.ToString()}'," : "'', ") + $"{ShowFilter.ToString().ToLower()}" + ")"); return; } } } ClearReport(); } else { throw new ArgumentException(nameof(EmbedUrl)); } }
private async Task LoadGroupAsync() { string token = await GetUserTokenAsync(); if (!string.IsNullOrEmpty(token)) { var tokenCredentials = new TokenCredentials(token, "Bearer"); using (var client = new PowerBIClient(new Uri(ApiUrl), tokenCredentials)) { IList <Report> reports = (await client.Reports.GetReportsAsync(GroupId))?.Value; Report selectionReport = null; if (reports.Count > 0) { Report findReport = reports.Where( i => i.EmbedUrl.Equals( EmbedUrl, StringComparison.OrdinalIgnoreCase)) .FirstOrDefault(); selectionReport = findReport ?? reports.First(); } InvokeScriptAsync($"loadGroups(" + $"'{token}', " + $"{JsonConvert.SerializeObject(reports)}, " + $"{JsonConvert.SerializeObject(selectionReport)}, " + (IsWindowsPhone ? $"'{DisplayInformation.CurrentOrientation.ToString()}'," : "'', ") + $"{ShowFilter.ToString().ToLower()}" + ")"); } } else { ClearReport(); } }