protected ICollection <SiteWorkbook> DownloadWorkbookFiles(IEnumerable <SiteWorkbook> workbooksToDownload, string localSavePath, bool generateInfoFile) { var downloadWorkbooksRequest = new DownloadWorkbooks(Urls, Login, workbooksToDownload, localSavePath, HttpClientFactory, generateInfoFile); var downloadedWorkbooks = downloadWorkbooksRequest.ExecuteRequest(); return(downloadedWorkbooks); }
/// <summary> /// Download the workbooks /// </summary> /// <param name="onlineLogin">logged in session</param> /// <param name="exportToPath">local path to export to</param> /// <param name="projectsList">project id/name mapping</param> /// <param name="singleProjectIdFilter">if specified, export only from a single project</param> /// <param name="exportOnlyWithThisTag">if specified, export only content with this tag</param> /// <param name="deleteTagAfterExport">TRUE: Remove the server-side tag from exported content (only valid if we have an export tag)</param> /// <param name="generateInfoFile">TRUE: Each downloaded workbook will get an information file generated that has additional metadata about it</param> /// <param name="siteUsers"> If not NULL, then this will get used to look the user name for each downloaded workbook, and safe it into the info file</param> private void Execute_DownloadWorkbooks( TableauServerSignIn onlineLogin, string exportToPath, IProjectsList projectsList, SiteProject singleProjectIdFilter = null, string exportOnlyWithThisTag = null, bool deleteTagAfterExport = false, bool generateInfoFile = false, IEnumerable<SiteUser> siteUsers = null ) { var onlineUrls = _onlineUrls; _statusLog.AddStatusHeader("Download workbooks"); //Get the UserID we need to use for the workbooks query. var explicitUserId = onlineLogin.UserId; //See if we have a default user id //=================================================================================== //Workbooks... //=================================================================================== ICollection<SiteWorkbook> workbooksList = null; try { var workbooks = new DownloadWorkbooksList(onlineUrls, onlineLogin, explicitUserId); //Query for the list of workbook workbooks.ExecuteRequest(); workbooksList = workbooks.Workbooks; } catch (Exception exWorkbooksList) { _statusLog.AddError("Error querying for list of workbooks, " + exWorkbooksList.Message.ToString()); return; } //No list of workbooks? Exit. if(workbooksList == null) { _statusLog.AddStatus("Aborting workbooks download"); return; } //==================================================================================================== //Apply filters to the list of content to see if we need to reduce the set of content to be downloaded //==================================================================================================== var filteredList = workbooksList; _statusLog.AddStatus("Download workbooks count before filters: " + filteredList.Count.ToString()); //See if we have a PROJECTS filter to apply to the set of content to be downloaded filteredList = FilterProjectMembership<SiteWorkbook>.KeepOnlyProjectMembers( filteredList, singleProjectIdFilter, true); _statusLog.AddStatus("Download workbooks count after projects filter: " + filteredList.Count.ToString()); //See if we have a TAGS filter to apply to the set of content to be downloaded filteredList = FilterTagSet<SiteWorkbook>.KeepOnlyTagged( filteredList, exportOnlyWithThisTag, true); _statusLog.AddStatus("Download workbooks count after tags filter: " + filteredList.Count.ToString()); //----------------------------------------------------------- //Download the workbooks //----------------------------------------------------------- var workbookPath = Path.Combine(exportToPath, "workbooks"); ICollection<SiteWorkbook> successfullExportSet = null; FileIOHelper.CreatePathIfNeeded(workbookPath); //If we are going to write out metadata for each download, then create the object that lets us look up the owner of each workbook KeyedLookup<SiteUser> workbookOwnerLookup = null; if ((generateInfoFile) && (siteUsers != null)) { workbookOwnerLookup = new KeyedLookup<SiteUser>(siteUsers); } //Do the downloads...... try { //Create the workbooks downloader var workbookDownloads = new DownloadWorkbooks( onlineUrls, onlineLogin, filteredList, workbookPath, projectsList, generateInfoFile, workbookOwnerLookup); successfullExportSet = workbookDownloads.ExecuteRequest(); } catch (Exception exWorkbooksDownload) { _statusLog.AddError("Error during workbooks download, " + exWorkbooksDownload.ToString()); } //-------------------------------------------------------------------------------- //Do we want to remove tags from successfully downloaded content? //-------------------------------------------------------------------------------- if ((successfullExportSet != null) && (deleteTagAfterExport) && (!string.IsNullOrWhiteSpace(exportOnlyWithThisTag))) { Execute_DeleteTagFromWorkbooks(onlineLogin, successfullExportSet, exportOnlyWithThisTag); } }
/// <summary> /// Download the workbooks /// </summary> /// <param name="onlineLogin">logged in session</param> /// <param name="exportToPath">local path to export to</param> /// <param name="projectsList">project id/name mapping</param> /// <param name="singleProjectIdFilter">if specified, export only from a single project</param> /// <param name="exportOnlyWithThisTag">if specified, export only content with this tag</param> /// <param name="deleteTagAfterExport">TRUE: Remove the server-side tag from exported content (only valid if we have an export tag)</param> private void Execute_DownloadWorkbooks( TableauServerSignIn onlineLogin, string exportToPath, IProjectsList projectsList, SiteProject singleProjectIdFilter = null, string exportOnlyWithThisTag = null, bool deleteTagAfterExport = false) { var onlineUrls = _onlineUrls; _statusLog.AddStatusHeader("Download workbooks"); //Get the UserID we need to use for the workbooks query. var explicitUserId = onlineLogin.UserId; //See if we have a default user id //=================================================================================== //Workbooks... //=================================================================================== ICollection <SiteWorkbook> workbooksList = null; try { var workbooks = new DownloadWorkbooksList(onlineUrls, onlineLogin, explicitUserId); //Query for the list of workbook workbooks.ExecuteRequest(); workbooksList = workbooks.Workbooks; } catch (Exception exWorkbooksList) { _statusLog.AddError("Error querying for list of workbooks, " + exWorkbooksList.Message.ToString()); return; } //No list of workbooks? Exit. if (workbooksList == null) { _statusLog.AddStatus("Aborting workbooks download"); return; } //==================================================================================================== //Apply filters to the list of content to see if we need to reduce the set of content to be downloaded //==================================================================================================== var filteredList = workbooksList; _statusLog.AddStatus("Download workbooks count before filters: " + filteredList.Count.ToString()); //See if we have a PROJECTS filter to apply to the set of content to be downloaded filteredList = FilterProjectMembership <SiteWorkbook> .KeepOnlyProjectMembers( filteredList, singleProjectIdFilter, true); _statusLog.AddStatus("Download workbooks count after projects filter: " + filteredList.Count.ToString()); //See if we have a TAGS filter to apply to the set of content to be downloaded filteredList = FilterTagSet <SiteWorkbook> .KeepOnlyTagged( filteredList, exportOnlyWithThisTag, true); _statusLog.AddStatus("Download workbooks count after tags filter: " + filteredList.Count.ToString()); //----------------------------------------------------------- //Download the workbooks //----------------------------------------------------------- var workbookPath = Path.Combine(exportToPath, "workbooks"); ICollection <SiteWorkbook> successfullExportSet = null; FileIOHelper.CreatePathIfNeeded(workbookPath); try { var workbookDownloads = new DownloadWorkbooks(onlineUrls, onlineLogin, filteredList, workbookPath, projectsList); successfullExportSet = workbookDownloads.ExecuteRequest(); } catch (Exception exWorkbooksDownload) { _statusLog.AddError("Error during workbooks download, " + exWorkbooksDownload.ToString()); } //-------------------------------------------------------------------------------- //Do we want to remove tags from successfully downloaded content? //-------------------------------------------------------------------------------- if ((successfullExportSet != null) && (deleteTagAfterExport) && (!string.IsNullOrWhiteSpace(exportOnlyWithThisTag))) { Execute_DeleteTagFromWorkbooks(onlineLogin, successfullExportSet, exportOnlyWithThisTag); } }