public EmbeddedViewModelService(IServiceProvider serviceProvider) : base(serviceProvider) { m_tokenCredentials = null; m_embedConfig = new EmbedConfig(); m_tileEmbedConfig = new TileEmbedConfig(); }
public EmbedService(int portalId, int tabModuleId) { tokenCredentials = null; embedConfig = new EmbedConfig(); tileEmbedConfig = new TileEmbedConfig(); powerBISettings = PowerBISettings.GetPortalPowerBISettings(portalId, tabModuleId); }
public EmbedService(IOptions <EmbedSettings> embedSettings) { _settings = embedSettings.Value; _tokenCredentials = null; EmbedConfig = new EmbedConfig(); TileEmbedConfig = new TileEmbedConfig(); }
public async Task <ActionResult> EmbedTile() { string tileId = Request.Form["SelectedTile"].ToString(); string dashboardId = Request.Form["SelectedDashboard"].ToString(); using (var client = await CreatePowerBIClientForISV()) { var tile = await client.Dashboards.GetTileInGroupAsync(GroupId, dashboardId, tileId); // Generate Embed Token for a tile. var generateTokenRequestParameters = new GenerateTokenRequest(accessLevel: "view"); var tokenResponse = await client.Tiles.GenerateTokenInGroupAsync(GroupId, dashboardId, tileId, generateTokenRequestParameters); // Generate Embed Configuration. var embedConfig = new TileEmbedConfig() { EmbedToken = tokenResponse, EmbedUrl = tile.EmbedUrl, Id = tileId, dashboardId = dashboardId }; return(View(embedConfig)); } }
public EmbedService(AzureAdOptions azureAdOptions) { m_tokenCredentials = null; m_embedConfig = new EmbedConfig(); m_tileEmbedConfig = new TileEmbedConfig(); ApplicationSecret = azureAdOptions.ClientSecret; }
public EmbedService() { m_tokenCredentials = null; m_embedConfig = new EmbedConfig(); m_tileEmbedConfig = new TileEmbedConfig(); m_ReportList = new List <ReportDefinition>(); }
public async Task <TileEmbedConfig> GetTileEmbedConfigAsync(int userId, string tileId, string dashboardId) { var model = (TileEmbedConfig)CachingProvider.Instance().GetItem($"PBI_{Settings.PortalId}_{Settings.SettingsId}_{userId}_{Thread.CurrentThread.CurrentUICulture.Name}_Dashboard_{dashboardId}_Tile_{tileId}"); if (model != null) { return(model); } model = new TileEmbedConfig(); // Get token credentials for user var getCredentialsResult = await GetTokenCredentials(); if (!getCredentialsResult) { // The error message set in GetTokenCredentials model.ErrorMessage = "Authentication failed."; return(model); } // Create a Power BI Client object. It will be used to call Power BI APIs. using (var client = new PowerBIClient(new Uri(Settings.ApiUrl), tokenCredentials)) { // Get a list of dashboards. var dashboards = await client.Dashboards.GetDashboardsInGroupAsync(Guid.Parse(Settings.WorkspaceId)).ConfigureAwait(false); // Get the first report in the workspace. var dashboard = dashboards.Value.FirstOrDefault(r => r.Id.ToString().Equals(dashboardId, StringComparison.InvariantCultureIgnoreCase)); if (dashboard == null) { tileEmbedConfig.ErrorMessage = "Workspace has no dashboards."; return(model); } var tiles = await client.Dashboards.GetTilesInGroupAsync(Guid.Parse(Settings.WorkspaceId), Guid.Parse(dashboardId)).ConfigureAwait(false); // Get the first tile in the workspace. var tile = tiles.Value.FirstOrDefault(x => x.Id.ToString() == tileId); // Generate Embed Token for a tile. var generateTokenRequestParameters = new GenerateTokenRequest(accessLevel: "view"); var tokenResponse = await client.Tiles.GenerateTokenInGroupAsync(Guid.Parse(Settings.WorkspaceId), dashboard.Id, tile.Id, generateTokenRequestParameters).ConfigureAwait(false); if (tokenResponse == null) { tileEmbedConfig.ErrorMessage = "Failed to generate embed token."; return(model); } // Generate Embed Configuration. tileEmbedConfig = new TileEmbedConfig() { EmbedToken = tokenResponse, EmbedUrl = tile.EmbedUrl, Id = tile.Id.ToString(), dashboardId = dashboard.Id.ToString(), ContentType = "tile" }; CachingProvider.Instance().Insert($"PBI_{Settings.PortalId}_{Settings.SettingsId}_{userId}_{Thread.CurrentThread.CurrentUICulture.Name}_Dashboard_{dashboardId}_Tile_{tileId}", model, null, DateTime.Now.AddSeconds(60), TimeSpan.Zero); } return(model); }
public async Task <ActionResult> EmbedTile(string tileId, string dashboardId) { TokenCredentials tokenCredentials = await CreateCredentials(); if (tokenCredentials == null) { var error = "Authentication Failed"; return(Json(error, JsonRequestBehavior.AllowGet)); } // Create a Power BI Client object. It will be used to call Power BI APIs. using (var client = new PowerBIClient(new Uri(powerbiSettings.ApiUrl), tokenCredentials)) { // Get a list of dashboards. var dashboards = await client.Dashboards.GetDashboardsInGroupAsync(powerbiSettings.WorkspaceId); // Get the first report in the workspace. var dashboard = dashboards.Value.Where(x => x.Id == dashboardId).FirstOrDefault(); if (dashboard == null) { return(Json(new TileEmbedConfig() { ErrorMessage = "Workspace has no dashboards." }, JsonRequestBehavior.AllowGet)); } var tiles = await client.Dashboards.GetTilesInGroupAsync(powerbiSettings.WorkspaceId, dashboard.Id); // Get the first tile in the workspace. var tile = tiles.Value.Where(x => x.Id == tileId).FirstOrDefault(); // Generate Embed Token for a tile. var generateTokenRequestParameters = new GenerateTokenRequest(accessLevel: "view"); var tokenResponse = await client.Tiles.GenerateTokenInGroupAsync(powerbiSettings.WorkspaceId, dashboard.Id, tile.Id, generateTokenRequestParameters); if (tokenResponse == null) { return(Json(new TileEmbedConfig() { ErrorMessage = "Failed to generate embed token." }, JsonRequestBehavior.AllowGet)); } // Generate Embed Configuration. var embedConfig = new TileEmbedConfig() { EmbedToken = tokenResponse, EmbedUrl = tile.EmbedUrl, Id = tile.Id, dashboardId = dashboard.Id }; return(Json(embedConfig, JsonRequestBehavior.AllowGet)); } }
public EmbedService(int portalId, int tabModuleId, int settingsId) { tokenCredentials = null; embedConfig = new EmbedConfig(); tileEmbedConfig = new TileEmbedConfig(); if (settingsId == 0) { powerBISettings = PowerBISettings.GetPortalPowerBISettings(portalId, tabModuleId); } else { powerBISettings = SharedSettingsRepository.Instance.GetSettingsById(settingsId, portalId); } }
public EmbedService(int portalId, int tabModuleId, string settingsGroupId) { tokenCredentials = null; embedConfig = new EmbedConfig(); tileEmbedConfig = new TileEmbedConfig(); if (string.IsNullOrEmpty(settingsGroupId)) { powerBISettings = PowerBISettings.GetPortalPowerBISettings(portalId, tabModuleId); } else { powerBISettings = SharedSettingsRepository.Instance.GetSettingsByGroupId(settingsGroupId, portalId); } }
/// <summary> /// Get embed params for a tile /// </summary> /// <returns>Wrapper object containing Embed token, Embed URL for single tile</returns> public static async Task <TileEmbedConfig> EmbedTile(Guid workspaceId) { // Create a Power BI Client object. It will be used to call Power BI APIs. using (var client = await GetPowerBiClient()) { // Get a list of dashboards. var dashboards = await client.Dashboards.GetDashboardsInGroupAsync(workspaceId); // Get the first report in the workspace. var dashboard = dashboards.Value.FirstOrDefault(); if (dashboard == null) { throw new NullReferenceException("Workspace has no dashboards"); } var tiles = await client.Dashboards.GetTilesInGroupAsync(workspaceId, dashboard.Id); // Get the first tile in the workspace. var tile = tiles.Value.FirstOrDefault(); // Generate Embed Token for a tile. var generateTokenRequestParameters = new GenerateTokenRequest(accessLevel: "view"); var tokenResponse = await client.Tiles.GenerateTokenInGroupAsync(workspaceId, dashboard.Id, tile.Id, generateTokenRequestParameters); if (tokenResponse == null) { throw new NullReferenceException("Failed to generate embed token"); } // Generate Embed Configuration. var tileEmbedConfig = new TileEmbedConfig() { EmbedToken = tokenResponse, EmbedUrl = tile.EmbedUrl, TileId = tile.Id, DashboardId = dashboard.Id }; return(tileEmbedConfig); } }
public FinanceFYView() { m_tokenCredentials = null; m_embedConfig = new EmbedConfig(); m_tileEmbedConfig = new TileEmbedConfig(); }
public NetworkComparison() { m_tokenCredentials = null; m_embedConfig = new EmbedConfig(); m_tileEmbedConfig = new TileEmbedConfig(); }
public OPInsight() { m_tokenCredentials = null; m_embedConfig = new EmbedConfig(); m_tileEmbedConfig = new TileEmbedConfig(); }
public MobileQuickStatLFLReportService() { m_tokenCredentials = null; m_embedConfig = new EmbedConfig(); m_tileEmbedConfig = new TileEmbedConfig(); }
public async Task <ActionResult> EmbedTile() { var error = GetWebConfigErrors(); if (error != null) { return(View(new TileEmbedConfig() { ErrorMessage = error })); } // Create a user password cradentials. var credential = new UserPasswordCredential(Username, Password); // Authenticate using created credentials var authenticationContext = new AuthenticationContext(AuthorityUrl); var authenticationResult = await authenticationContext.AcquireTokenAsync(ResourceUrl, ClientId, credential); if (authenticationResult == null) { return(View(new TileEmbedConfig() { ErrorMessage = "Authentication Failed." })); } 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 = await client.Dashboards.GetDashboardsInGroupAsync(GroupId); // Get the first report in the group. var dashboard = dashboards.Value.FirstOrDefault(); if (dashboard == null) { return(View(new TileEmbedConfig() { ErrorMessage = "Group has no dashboards." })); } var tiles = await client.Dashboards.GetTilesInGroupAsync(GroupId, dashboard.Id); // Get the first tile in the group. var tile = tiles.Value.FirstOrDefault(); // Generate Embed Configuration. var embedConfig = new TileEmbedConfig() { EmbedToken = authenticationResult.AccessToken, EmbedUrl = tile.EmbedUrl, Id = tile.Id, dashboardId = dashboard.Id }; return(View(embedConfig)); } }
public OPsalesByPromotions() { m_tokenCredentials = null; m_embedConfig = new EmbedConfig(); m_tileEmbedConfig = new TileEmbedConfig(); }
public async Task <bool> EmbedTile() { // Get token credentials for user var getCredentialsResult = await GetTokenCredentials(); if (!getCredentialsResult) { // The error message set in GetTokenCredentials m_tileEmbedConfig.ErrorMessage = m_embedConfig.ErrorMessage; return(false); } try { // Create a Power BI Client object. It will be used to call Power BI APIs. using (var client = new PowerBIClient(new Uri(ApiUrl), m_tokenCredentials)) { // Get a list of dashboards. var dashboards = await client.Dashboards.GetDashboardsInGroupAsync(WorkspaceId); // Get the first report in the workspace. var dashboard = dashboards.Value.FirstOrDefault(); if (dashboard == null) { m_tileEmbedConfig.ErrorMessage = "Workspace has no dashboards."; return(false); } var tiles = await client.Dashboards.GetTilesInGroupAsync(WorkspaceId, dashboard.Id); // Get the first tile in the workspace. var tile = tiles.Value.FirstOrDefault(); // Generate Embed Token for a tile. var generateTokenRequestParameters = new GenerateTokenRequest(accessLevel: "view"); var tokenResponse = await client.Tiles.GenerateTokenInGroupAsync(WorkspaceId, dashboard.Id, tile.Id, generateTokenRequestParameters); if (tokenResponse == null) { m_tileEmbedConfig.ErrorMessage = "Failed to generate embed token."; return(false); } // Generate Embed Configuration. m_tileEmbedConfig = new TileEmbedConfig() { EmbedToken = tokenResponse, EmbedUrl = tile.EmbedUrl, Id = tile.Id, dashboardId = dashboard.Id }; return(true); } } catch (HttpOperationException exc) { m_embedConfig.ErrorMessage = string.Format("Status: {0} ({1})\r\nResponse: {2}\r\nRequestId: {3}", exc.Response.StatusCode, (int)exc.Response.StatusCode, exc.Response.Content, exc.Response.Headers["RequestId"].FirstOrDefault()); return(false); } }
public SCSummary() { m_tokenCredentials = null; m_embedConfig = new EmbedConfig(); m_tileEmbedConfig = new TileEmbedConfig(); }
public async Task <ActionResult> EmbedTile() { var error = GetWebConfigErrors(); if (error != null) { return(View(new TileEmbedConfig() { ErrorMessage = error })); } // Authenticate using created credentials var authenticationContext = new AuthenticationContext(AuthorityUrl); /* * // Create a user password cradentials. * var credential = new UserPasswordCredential(Username, Password); * var authenticationResult = await authenticationContext.AcquireTokenAsync(ResourceUrl, ApplicationId, credential); */ //Prompt for authentication var authenticationResult = await authenticationContext.AcquireTokenAsync(ResourceUrl, ApplicationId, new Uri(RedirectUrl), new PlatformParameters(PromptBehavior.Always)); if (authenticationResult == null) { return(View(new TileEmbedConfig() { ErrorMessage = "Authentication Failed." })); } 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 = await client.Dashboards.GetDashboardsInGroupAsync(WorkspaceId); // Get the first report in the workspace. var dashboard = dashboards.Value.FirstOrDefault(); if (dashboard == null) { return(View(new TileEmbedConfig() { ErrorMessage = "Workspace has no dashboards." })); } var tiles = await client.Dashboards.GetTilesInGroupAsync(WorkspaceId, dashboard.Id); // Get the first tile in the workspace. var tile = tiles.Value.FirstOrDefault(); // Generate Embed Token for a tile. var generateTokenRequestParameters = new GenerateTokenRequest(accessLevel: "view"); var tokenResponse = await client.Tiles.GenerateTokenInGroupAsync(WorkspaceId, dashboard.Id, tile.Id, generateTokenRequestParameters); if (tokenResponse == null) { return(View(new TileEmbedConfig() { ErrorMessage = "Failed to generate embed token." })); } // Generate Embed Configuration. var embedConfig = new TileEmbedConfig() { EmbedToken = tokenResponse, EmbedUrl = tile.EmbedUrl, Id = tile.Id, dashboardId = dashboard.Id }; return(View(embedConfig)); } }
public async Task <ActionResult> EmbedTile() { var error = GetWebConfigErrors(); if (error != null) { return(View(new TileEmbedConfig() { ErrorMessage = error })); } //// Create a user password cradentials. //var credential = new UserPasswordCredential(Username, Password); //// Authenticate using created credentials //var authenticationContext = new AuthenticationContext(AuthorityUrl); //var authenticationResult = await authenticationContext.AcquireTokenAsync(ResourceUrl, ClientId, credential); //if (authenticationResult == null) //{ // return View(new TileEmbedConfig() // { // ErrorMessage = "Authentication Failed." // }); //} //var tokenCredentials = new TokenCredentials(authenticationResult.AccessToken, "Bearer"); OAuthResult oAuthResult; using (var client = new HttpClient()) { client.DefaultRequestHeaders.Add("Cache-Control", "no-cache"); var _result = await client.PostAsync( new Uri(TokenUrl), new FormUrlEncodedContent( new[] { new KeyValuePair <string, string>("resource", ResourceUrl), new KeyValuePair <string, string>("client_id", ClientId), new KeyValuePair <string, string>("grant_type", "password"), new KeyValuePair <string, string>("username", Username), new KeyValuePair <string, string>("password", Password), new KeyValuePair <string, string>("scope", "openid"), })); if (_result.IsSuccessStatusCode) { oAuthResult = JsonConvert.DeserializeObject <OAuthResult>(await _result.Content.ReadAsStringAsync()); } else { return(View(new TileEmbedConfig() { ErrorMessage = "Authentication Failed." })); } } var tokenCredentials = new TokenCredentials(oAuthResult.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 = await client.Dashboards.GetDashboardsInGroupAsync(GroupId); // Get the first report in the group. var dashboard = dashboards.Value.FirstOrDefault(); if (dashboard == null) { return(View(new TileEmbedConfig() { ErrorMessage = "Group has no dashboards." })); } var tiles = await client.Dashboards.GetTilesInGroupAsync(GroupId, dashboard.Id); // Get the first tile in the group. var tile = tiles.Value.FirstOrDefault(); // Generate Embed Token for a tile. var generateTokenRequestParameters = new GenerateTokenRequest(accessLevel: "view"); var tokenResponse = await client.Tiles.GenerateTokenInGroupAsync(GroupId, dashboard.Id, tile.Id, generateTokenRequestParameters); if (tokenResponse == null) { return(View(new TileEmbedConfig() { ErrorMessage = "Failed to generate embed token." })); } // Generate Embed Configuration. var embedConfig = new TileEmbedConfig() { EmbedToken = tokenResponse, EmbedUrl = tile.EmbedUrl, Id = tile.Id, dashboardId = dashboard.Id }; return(View(embedConfig)); } }
public OPdailyCropStoreView() { m_tokenCredentials = null; m_embedConfig = new EmbedConfig(); m_tileEmbedConfig = new TileEmbedConfig(); }
public EmbedService() { m_tokenCredentials = null; m_embedConfig = new EmbedConfig(); m_tileEmbedConfig = new TileEmbedConfig(); }
public MobileSCSummaryService() { m_tokenCredentials = null; m_embedConfig = new EmbedConfig(); m_tileEmbedConfig = new TileEmbedConfig(); }
public OPSalesProdHierarchy() { m_tokenCredentials = null; m_embedConfig = new EmbedConfig(); m_tileEmbedConfig = new TileEmbedConfig(); }
public OPDailyLabourAnalysis() { m_tokenCredentials = null; m_embedConfig = new EmbedConfig(); m_tileEmbedConfig = new TileEmbedConfig(); }
public async Task <ActionResult> EmbedTile() { var error = GetWebConfigErrors(); if (error != null) { return(View(new TileEmbedConfig() { ErrorMessage = error })); } // Create user credentials dictionary. var content = new Dictionary <string, string>(); content["grant_type"] = "password"; content["resource"] = ResourceUrl; content["username"] = Username; content["password"] = Password; content["client_id"] = ClientId; var httpClient = new HttpClient { Timeout = new TimeSpan(0, 5, 0), BaseAddress = new Uri(AuthorityUrl) }; httpClient.DefaultRequestHeaders.TryAddWithoutValidation("Content-Type: application/x-www-form-urlencoded", "application/json"); if (content == null) { content = new Dictionary <string, string>(); } var encodedContent = new FormUrlEncodedContent(content); //Authenticate using credentials var authResponse = await httpClient.PostAsync(httpClient.BaseAddress, encodedContent); if (authResponse == null) { return(View(new TileEmbedConfig() { ErrorMessage = "Authentication Failed." })); } var authObj = JsonConvert.DeserializeObject <AuthObject>(authResponse.Content.ReadAsStringAsync().Result); var tokenCredentials = new TokenCredentials(authObj.access_token, "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 = await client.Dashboards.GetDashboardsInGroupAsync(GroupId); // Get the first report in the group. var dashboard = dashboards.Value.FirstOrDefault(); if (dashboard == null) { return(View(new TileEmbedConfig() { ErrorMessage = "Group has no dashboards." })); } var tiles = await client.Dashboards.GetTilesInGroupAsync(GroupId, dashboard.Id); // Get the first tile in the group. var tile = tiles.Value.FirstOrDefault(); // Generate Embed Token for a tile. var generateTokenRequestParameters = new GenerateTokenRequest(accessLevel: "view"); var tokenResponse = await client.Tiles.GenerateTokenInGroupAsync(GroupId, dashboard.Id, tile.Id, generateTokenRequestParameters); if (tokenResponse == null) { return(View(new TileEmbedConfig() { ErrorMessage = "Failed to generate embed token." })); } // Generate Embed Configuration. var embedConfig = new TileEmbedConfig() { EmbedToken = tokenResponse, EmbedUrl = tile.EmbedUrl, Id = tile.Id, dashboardId = dashboard.Id }; return(View(embedConfig)); } }
public SCMonRunRate() { m_tokenCredentials = null; m_embedConfig = new EmbedConfig(); m_tileEmbedConfig = new TileEmbedConfig(); }
public HOFSSFW() { m_tokenCredentials = null; m_embedConfig = new EmbedConfig(); m_tileEmbedConfig = new TileEmbedConfig(); }
public OPActualProjectLabour() { m_tokenCredentials = null; m_embedConfig = new EmbedConfig(); m_tileEmbedConfig = new TileEmbedConfig(); }