/// <summary> /// Clones the specified tile /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='groupId'> /// The group id /// </param> /// <param name='dashboardKey'> /// The dashboard id /// </param> /// <param name='tileKey'> /// The tile id /// </param> /// <param name='requestParameters'> /// Clone tile parameters /// </param> /// <param name='cancellationToken'> /// The cancellation token. /// </param> public static async Task <Tile> CloneTileInGroupAsync(this IDashboards operations, string groupId, string dashboardKey, string tileKey, CloneTileRequest requestParameters, CancellationToken cancellationToken = default(CancellationToken)) { using (var _result = await operations.CloneTileInGroupWithHttpMessagesAsync(groupId, dashboardKey, tileKey, requestParameters, null, cancellationToken).ConfigureAwait(false)) { return(_result.Body); } }
/// <summary> /// Clones the specified tile /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='groupId'> /// The group id /// </param> /// <param name='dashboardKey'> /// The dashboard id /// </param> /// <param name='tileKey'> /// The tile id /// </param> /// <param name='requestParameters'> /// Clone tile parameters /// </param> public static Tile CloneTileInGroup(this IDashboards operations, string groupId, string dashboardKey, string tileKey, CloneTileRequest requestParameters) { return(operations.CloneTileInGroupAsync(groupId, dashboardKey, tileKey, requestParameters).GetAwaiter().GetResult()); }
/// <summary> /// Clones the specified tile from **"My Workspace"**. /// </summary> /// <remarks> /// <br/>If target report id and target dataset are not specified, the /// following can occur:<li>When a tile clone is performed within the /// same workspace, the report and dataset links will be cloned from the source /// tile.</li><li>When cloning a tile within a different workspace, /// report and dataset links will be rested, and the tile will be /// broken.</li><br/>**Note:** When a tile is cloned to another /// workspace and bound to another report and dataset, it is cloned as is with /// its underlying query containing the original report /// filters.<br/><br/>**Required scope**: Dashboard.ReadWrite.All /// <br/>To set the permissions scope, see [Register an /// app](https://docs.microsoft.com/power-bi/developer/register-app). /// </remarks> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='dashboardId'> /// The dashboard id /// </param> /// <param name='tileId'> /// The tile id /// </param> /// <param name='requestParameters'> /// Clone tile parameters /// </param> /// <param name='cancellationToken'> /// The cancellation token. /// </param> public static async Task <Tile> CloneTileAsync(this IDashboardsOperations operations, System.Guid dashboardId, System.Guid tileId, CloneTileRequest requestParameters, CancellationToken cancellationToken = default(CancellationToken)) { using (var _result = await operations.CloneTileWithHttpMessagesAsync(dashboardId, tileId, requestParameters, null, cancellationToken).ConfigureAwait(false)) { return(_result.Body); } }
/// <summary> /// Clones the specified tile from the specified workspace. /// </summary> /// <remarks> /// <br/>If target report id and target dataset are missing, the /// following can occur:<li>When a tile clone is performed within the /// same workspace, the report and dataset links will be cloned from the source /// tile.</li><li>If you are cloning a tile within a different /// workspace, report and dataset links will be rested. The tile will be /// broken.</li><br/>**Note:** When a tile is cloned to another /// workspace and bound to another report and dataset, it is cloned as is with /// its underlying query containing the original report /// filters.<br/><br/>**Required scope**: Dashboard.ReadWrite.All /// <br/>To set the permissions scope, see [Register an /// app](https://docs.microsoft.com/power-bi/developer/register-app). /// </remarks> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='groupId'> /// The workspace id /// </param> /// <param name='dashboardId'> /// The dashboard id /// </param> /// <param name='tileId'> /// The tile id /// </param> /// <param name='requestParameters'> /// Clone tile parameters /// </param> public static Tile CloneTileInGroup(this IDashboardsOperations operations, System.Guid groupId, System.Guid dashboardId, System.Guid tileId, CloneTileRequest requestParameters) { return(operations.CloneTileInGroupAsync(groupId, dashboardId, tileId, requestParameters).GetAwaiter().GetResult()); }
static void CloneAppWorkspace(string sourceAppWorkspaceName, string targetAppWorkpaceName) { PowerBIClient pbiClient = GetPowerBiClient(); string sourceAppWorkspaceId = ""; string targetAppWorkspaceId = ""; var workspaces = pbiClient.Groups.GetGroups().Value; foreach (var workspace in workspaces) { if (workspace.Name.Equals(sourceAppWorkspaceName)) { sourceAppWorkspaceId = workspace.Id; } if (workspace.Name.Equals(targetAppWorkpaceName)) { targetAppWorkspaceId = workspace.Id; } } if (sourceAppWorkspaceId == "") { throw new ApplicationException("Source Workspace does not exist"); } if (targetAppWorkspaceId == "") { // create app workspace if it doesn't exist Console.WriteLine("Creating app workspace named " + targetAppWorkpaceName); Console.WriteLine(); GroupCreationRequest request = new GroupCreationRequest(targetAppWorkpaceName); Group AppWorkspace = pbiClient.Groups.CreateGroup(request); targetAppWorkspaceId = AppWorkspace.Id; } var reports = pbiClient.Reports.GetReportsInGroup(sourceAppWorkspaceId).Value; string downloadPath = @"C:\Student\downloads\"; // create download folder if it doesn't exist if (!Directory.Exists(downloadPath)) { Directory.CreateDirectory(downloadPath); } foreach (var report in reports) { var reportStream = pbiClient.Reports.ExportReportInGroup(sourceAppWorkspaceId, report.Id); string filePath = downloadPath + report.Name + ".pbix"; Console.WriteLine("Downloading PBIX file for " + report.Name + "to " + filePath); FileStream stream1 = new FileStream(filePath, FileMode.Create, FileAccess.ReadWrite); reportStream.CopyToAsync(stream1).Wait(); reportStream.Close(); stream1.Close(); stream1.Dispose(); FileStream stream = new FileStream(filePath, FileMode.Open, FileAccess.Read); Console.WriteLine("Publishing " + filePath + " to " + targetAppWorkpaceName); var import = pbiClient.Imports.PostImportWithFileInGroup(targetAppWorkspaceId, stream, report.Name); Console.WriteLine("Deleing file " + filePath); stream.Close(); stream.Dispose(); File.Delete(filePath); Console.WriteLine(); } Console.WriteLine("Export/Import process completed"); var dashboards = pbiClient.Dashboards.GetDashboardsInGroup(sourceAppWorkspaceId).Value; foreach (var sourceDashboard in dashboards) { // create the target dashboard Console.WriteLine(); Console.WriteLine("Creating Dashboard named " + sourceDashboard.DisplayName); AddDashboardRequest addReq = new AddDashboardRequest(sourceDashboard.DisplayName); Dashboard targetDashboard = pbiClient.Dashboards.AddDashboardInGroup(targetAppWorkspaceId, addReq); // clone tiles IList <Tile> sourceTiles = pbiClient.Dashboards.GetTilesInGroup(sourceAppWorkspaceId, sourceDashboard.Id).Value; foreach (Tile sourceTile in sourceTiles) { Console.WriteLine("Adding dashboard tile with title of " + sourceTile.Title); var sourceDatasetID = sourceTile.DatasetId; var sourceDatasetName = pbiClient.Datasets.GetDatasetByIdInGroup(sourceAppWorkspaceId, sourceDatasetID).Name; var targetWorkspaceDatasets = pbiClient.Datasets.GetDatasetsInGroup(targetAppWorkspaceId).Value; string targetDatasetId = ""; foreach (var ds in targetWorkspaceDatasets) { if (ds.Name.Equals(sourceDatasetName)) { targetDatasetId = ds.Id; } } if (targetDatasetId.Equals("")) { throw new ApplicationException("OOOOOuch!"); } var sourceReportId = sourceTile.ReportId; var sourceReportName = pbiClient.Reports.GetReportInGroup(sourceAppWorkspaceId, sourceReportId).Name; var targetWorkspaceReports = pbiClient.Reports.GetReportsInGroup(targetAppWorkspaceId).Value; string targetReportId = ""; foreach (var r in targetWorkspaceReports) { if (r.Name.Equals(sourceReportName)) { targetReportId = r.Id; } } CloneTileRequest addReqTile = new CloneTileRequest(targetDashboard.Id, targetAppWorkspaceId, targetReportId, targetDatasetId); pbiClient.Dashboards.CloneTileInGroup(sourceAppWorkspaceId, sourceDashboard.Id, sourceTile.Id, addReqTile); } } Console.WriteLine(); Console.WriteLine("All done - wow that was a lot of work :)"); Console.WriteLine(); }