예제 #1
0
    /// <summary>
    /// If we have Project Mapping information, generate a project based path for the download
    /// </summary>
    public static string EnsureProjectBasedPath(string basePath, IProjectsList projectList, IHasProjectId project, ILogger logger)
    {
        //If we have no project list to do lookups in then just return the base path
        if (projectList == null)
        {
            return(basePath);
        }

        //Look up the project name
        var projWithId = projectList.FindProjectWithId(project.ProjectId);

        if (projWithId == null)
        {
            logger.Error("Project not found with id " + project.ProjectId);
            return(basePath);
        }

        //Turn the project name into a directory name
        var safeDirectoryName = GenerateWindowsSafeFilename(projWithId.Name);

        var pathWithProject = Path.Combine(basePath, safeDirectoryName);

        //If needed, create the directory
        if (!Directory.Exists(pathWithProject))
        {
            Directory.CreateDirectory(pathWithProject);
        }

        return(pathWithProject);
    }
예제 #2
0
    /// <summary>
    /// If we have Project Mapping information, generate a project based path for the download
    /// </summary>
    /// <param name="basePath"></param>
    /// <param name="projectList"></param>
    /// <param name="projectId"></param>
    /// <returns></returns>
    public static string EnsureProjectBasedPath(string basePath, IProjectsList projectList, IHasProjectId project, TaskStatusLogs statusLog)
    {
        //If we have no project list to do lookups in then just return the base path
        if (projectList == null) return basePath;

        //Look up the project name
        var projWithId = projectList.FindProjectWithId(project.ProjectId);
        if(projWithId == null)
        {
            statusLog.AddError("Project not found with id " + project.ProjectId);
            return basePath;
        }

        //Turn the project name into a directory name
        var safeDirectoryName = GenerateWindowsSafeFilename(projWithId.Name);

        var pathWithProject = Path.Combine(basePath, safeDirectoryName);
        //If needed, create the directory
        if(!Directory.Exists(pathWithProject))
        {
            Directory.CreateDirectory(pathWithProject);
        }

        return pathWithProject;
    }
예제 #3
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="onlineUrls">Tableau Server Information</param>
 /// <param name="logInInfo">Tableau Sign In Information</param>
 /// <param name="workbooks">IEnumerable of SiteWorkbook objects</param>
 /// <param name="localSavePath">Local path where the workbooks should be saved</param>
 /// <param name="projectsList">IEnumerable of SiteProject objects</param>
 public DownloadWorkbooks(TableauServerUrls onlineUrls, TableauServerSignIn logInInfo, IEnumerable <SiteWorkbook> workbooks, string localSavePath, IProjectsList projectsList)
     : base(logInInfo)
 {
     _onlineUrls    = onlineUrls;
     _workbooks     = workbooks;
     _localSavePath = localSavePath;
     _downloadToProjectDirectories = projectsList;
 }
 /// <summary>
 /// Create the request for to download Data sources from the Tableau REST API
 /// </summary>
 /// <param name="onlineUrls">Tableau Server Information</param>
 /// <param name="logInInfo">Tableau Sign In Information</param>
 /// <param name="datasources">List of Tableau Data sources to save to disk</param>
 /// <param name="localSavePath">File system location where data sources should be saved</param>
 /// <param name="projectsList">List of projects for which we should pull data sources from</param>
 public DownloadDatasources(TableauServerUrls onlineUrls, TableauServerSignIn logInInfo, IEnumerable <SiteDatasource> datasources, string localSavePath, IProjectsList projectsList)
     : base(logInInfo)
 {
     _onlineUrls    = onlineUrls;
     _datasources   = datasources;
     _localSavePath = localSavePath;
     _downloadToProjectDirectories = projectsList;
 }
예제 #5
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="onlineUrls"></param>
 /// <param name="login"></param>
 /// <param name="workbooks"></param>
 /// <param name="localSavePath"></param>
 /// <param name="projectsList"></param>
 public DownloadWorkbooks(
     TableauServerUrls onlineUrls, 
     TableauServerSignIn login, 
     IEnumerable<SiteWorkbook> workbooks,
     string localSavePath,
     IProjectsList projectsList)
     : base(login)
 {
     _onlineUrls = onlineUrls;
     _workbooks = workbooks;
     _localSavePath = localSavePath;
     _downloadToProjectDirectories = projectsList;
 }
예제 #6
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="onlineUrls"></param>
 /// <param name="login"></param>
 /// <param name="Datasources"></param>
 /// <param name="localSavePath"></param>
 /// <param name="projectsList"></param>
 public DownloadDatasources(
     TableauServerUrls onlineUrls, 
     TableauServerSignIn login, 
     IEnumerable<SiteDatasource> Datasources,
     string localSavePath,
     IProjectsList projectsList)
     : base(login)
 {
     _onlineUrls = onlineUrls;
     _datasources = Datasources;
     _localSavePath = localSavePath;
     _downloadToProjectDirectories = projectsList;
 }
예제 #7
0
 public DownloadDatasources(
     TableauServerUrls onlineUrls,
     TableauServerSignIn login,
     IEnumerable <SiteDatasource> datasources,
     string localSavePath,
     IProjectsList projectsList,
     bool generateInfoFile,
     KeyedLookup <SiteUser> siteUserLookup,
     IHttpClientFactory httpClientFactory)
     : base(onlineUrls, login, httpClientFactory)
 {
     Datasources   = datasources;
     LocalSavePath = localSavePath;
     DownloadToProjectDirectories = projectsList;
     GenerateInfoFile             = generateInfoFile;
     SiteUserLookup = siteUserLookup;
 }
예제 #8
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="onlineUrls"></param>
 /// <param name="login"></param>
 /// <param name="workbooks"></param>
 /// <param name="localSavePath"></param>
 /// <param name="projectsList"></param>
 /// <param name="generateInfoFile">TRUE = Generate companion file for each download that contains metadata (e.g. whether "show tabs" is selected, the owner, etc)</param>
 /// <param name="siteUsersLookup">If not NULL, use to look up the owners name, so we can write it into the InfoFile for the downloaded content</param>
 public DownloadWorkbooks(
     TableauServerUrls onlineUrls, 
     TableauServerSignIn login, 
     IEnumerable<SiteWorkbook> workbooks,
     string localSavePath,
     IProjectsList projectsList,
     bool generateInfoFile,
     KeyedLookup<SiteUser> siteUserLookup)
     : base(login)
 {
     _onlineUrls = onlineUrls;
     _workbooks = workbooks;
     _localSavePath = localSavePath;
     _downloadToProjectDirectories = projectsList;
     _generateInfoFile = generateInfoFile;
     _siteUserLookup = siteUserLookup;
 }
예제 #9
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="onlineUrls"></param>
 /// <param name="login"></param>
 /// <param name="Datasources"></param>
 /// <param name="localSavePath"></param>
 /// <param name="projectsList"></param>
 /// <param name="generateInfoFile">TRUE = Generate companion file for each download that contains metadata (e.g. whether "show tabs" is selected, the owner, etc)</param>
 /// <param name="siteUsersLookup">If not NULL, use to look up the owners name, so we can write it into the InfoFile for the downloaded content</param>
 public DownloadDatasources(
     TableauServerUrls onlineUrls,
     TableauServerSignIn login,
     IEnumerable <SiteDatasource> Datasources,
     string localSavePath,
     IProjectsList projectsList,
     bool generateInfoFile,
     KeyedLookup <SiteUser> siteUserLookup)
     : base(login)
 {
     _onlineUrls    = onlineUrls;
     _datasources   = Datasources;
     _localSavePath = localSavePath;
     _downloadToProjectDirectories = projectsList;
     _generateInfoFile             = generateInfoFile;
     _siteUserLookup = siteUserLookup;
 }
예제 #10
0
    /// <summary>
    /// If the user has specified a single project filter, then get it from the projects list
    /// </summary>
    /// <param name="projectsList"></param>
    /// <returns></returns>
    private SiteProject helper_DetermineIfSingleProjectFilter(IProjectsList projectsList)
    {
        string exportSingleProject_name = _taskOptions.GetOptionValue(TaskMasterOptions.OptionParameter_ExportSingleProject);

        //If there's no exclusive project name in the config, then the fitler is null
        if (string.IsNullOrWhiteSpace(exportSingleProject_name))
        {
            return(null);
        }

        var project = projectsList.FindProjectWithName(exportSingleProject_name);

        if (project == null)
        {
            throw new Exception("Site contains no project with name " + exportSingleProject_name);
        }
        return(project);
    }
예제 #11
0
    /// <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);
        }
    }
예제 #12
0
    /// <summary>
    /// 
    /// </summary>
    /// <param name="onlineLogin"></param>
    /// <param name="exportToPath"></param>
    /// <param name="projectsList"></param>
    /// <param name="singleProjectIdFilter"></param>
    /// <param name="exportOnlyWithThisTag"></param>
    /// <param name="deleteTagAfterExport"></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_DownloadDatasources(
        TableauServerSignIn onlineLogin, 
        string exportToPath, 
        IProjectsList projectsList,
        SiteProject singleProjectIdFilter = null,
        string exportOnlyWithThisTag      = null,
        bool deleteTagAfterExport         = false,
        bool generateInfoFile             = false,
        IEnumerable<SiteUser>   siteUsers = null
        )
    {
        _statusLog.AddStatusHeader("Download datasources");
        ICollection<SiteDatasource> datasourcesList = null;
        try
        {
            //Get the list of datasources
            var datasourcesManager = new DownloadDatasourcesList(_onlineUrls, onlineLogin);
            datasourcesManager.ExecuteRequest();
            datasourcesList = datasourcesManager.Datasources;
        }
        catch(Exception exGetContentList)
        {
            _statusLog.AddError("Error querying for list of datasources, " + exGetContentList.Message.ToString());
        }

        if(datasourcesList == null)
        {
            _statusLog.AddError("Aborting datasources 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 = datasourcesList;
        _statusLog.AddStatus("Download datasources count before filters: " + filteredList.Count.ToString());

        //See if we have a PROJECTS filter to apply to the set of content to download
        filteredList = FilterProjectMembership<SiteDatasource>.KeepOnlyProjectMembers(
            filteredList,
            singleProjectIdFilter,
            true);
        _statusLog.AddStatus("Download datasources 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<SiteDatasource>.KeepOnlyTagged(
            filteredList,
            exportOnlyWithThisTag,
            true);
        _statusLog.AddStatus("Download datasources count after tags filter: " + filteredList.Count.ToString());

        ICollection<SiteDatasource> successfullExportSet = null;
        var datasourcePath = Path.Combine(exportToPath, "datasources");
        FileIOHelper.CreatePathIfNeeded(datasourcePath);

        //-----------------------------------------------------------
        //Download the data sources
        //-----------------------------------------------------------
        //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> contentOwnerLookup = null;
        if ((generateInfoFile) && (siteUsers != null))
        {
            contentOwnerLookup = new KeyedLookup<SiteUser>(siteUsers);
        }
        try
        {
            var datasourceDownloads = new DownloadDatasources(
                _onlineUrls,
                onlineLogin,
                filteredList,
                datasourcePath,
                projectsList,
                generateInfoFile,
                contentOwnerLookup);
            successfullExportSet = datasourceDownloads.ExecuteRequest();
        }
        catch (Exception exDatasourceDownload)
        {
            _statusLog.AddError("Error during datasource download, " + exDatasourceDownload.ToString());
        }

        //--------------------------------------------------------------------------------
        //Do we want to remove tags from successfully downloaded content?
        //--------------------------------------------------------------------------------
        if ((successfullExportSet != null) && (deleteTagAfterExport) && (!string.IsNullOrWhiteSpace(exportOnlyWithThisTag)))
        {
            Execute_DeleteTagFromDatasources(onlineLogin, successfullExportSet, exportOnlyWithThisTag);
        }
    }
예제 #13
0
    /// <summary>
    /// If the user has specified a single project filter, then get it from the projects list
    /// </summary>
    /// <param name="projectsList"></param>
    /// <returns></returns>
    private SiteProject helper_DetermineIfSingleProjectFilter(IProjectsList projectsList)
    {
        string exportSingleProject_name = _taskOptions.GetOptionValue(TaskMasterOptions.OptionParameter_ExportSingleProject);
        //If there's no exclusive project name in the config, then the fitler is null
        if (string.IsNullOrWhiteSpace(exportSingleProject_name))
        {
            return null;
        }

        var project = projectsList.FindProjectWithName(exportSingleProject_name);
        if (project == null)
        {
            throw new Exception("Site contains no project with name " + exportSingleProject_name);
        }
        return project;
    }
예제 #14
0
    /// <summary>
    /// Perform the work
    /// </summary>
    private void ExecuteTask_InternalAllTasks()
    {
        string exportToPath = _exportToLocalPath;
        var    onlineUrls   = _onlineUrls;
        var    taskOptions  = _taskOptions;

        //========================================================================================
        //Log into Tableau Online
        //========================================================================================
        var serverLogin = new TableauServerSignIn(onlineUrls, _userName, _password, _statusLog);

        try
        {
            serverLogin.ExecuteRequest();
        }
        catch (Exception exLogin)
        {
            _statusLog.AddError("Failed loging, " + exLogin.ToString());

            _isDone = true;
            return;
        }

        //========================================================================================
        //If there is a custom command we want to execute, do it
        //========================================================================================
        var customCommand1 = taskOptions.GetOptionValue(TaskMasterOptions.OptionParameter_ArbitraryCommand1);

        if (!string.IsNullOrWhiteSpace(customCommand1))
        {
            AttemptExecutionOfCustomHttpGet(serverLogin, customCommand1);
        }
        var customCommand2 = taskOptions.GetOptionValue(TaskMasterOptions.OptionParameter_ArbitraryCommand2);

        if (!string.IsNullOrWhiteSpace(customCommand2))
        {
            AttemptExecutionOfCustomHttpGet(serverLogin, customCommand2);
        }

        //========================================================================================
        //If there is a project we want to create, then do it
        //========================================================================================
        var createProjectName = taskOptions.GetOptionValue(TaskMasterOptions.OptionParameter_CreateProjectWithName);

        if (!string.IsNullOrWhiteSpace(createProjectName))
        {
            Execute_CreateProjectWithName(serverLogin, createProjectName);
        }

        //========================================================================================
        //Attempt to get the list of users
        //========================================================================================
        if (taskOptions.IsOptionSet(TaskMasterOptions.Option_GetSiteUsers))
        {
            _downloadedList_Users = Execute_DownloadSiteUsers(serverLogin);
        }

        //========================================================================================
        //Attempt to get the site information
        //========================================================================================
        SiteinfoSite site = null;

        if (taskOptions.IsOptionSet(TaskMasterOptions.Option_GetSiteInfo))
        {
            site = Execute_DownloadSiteInfo(serverLogin);
        }

        //If this gets set then we will pass the information for project/name mapping to the workbook and datasource downloaders
        IProjectsList projectNameIdMapping = null;
        SiteProject   exportSingleProject  = null; //If non NULL, then look up the project

        //===================================================================================
        //Projects List
        //===================================================================================
        if ((taskOptions.IsOptionSet(TaskMasterOptions.Option_GetProjectsList)) ||
            (taskOptions.IsOptionSet(TaskMasterOptions.Option_DownloadIntoProjects)) ||
            (taskOptions.IsOptionSet(TaskMasterOptions.OptionParameter_ExportSingleProject))
            )
        {
            var projectsList = Execute_DownloadProjectsList(serverLogin);

            if (taskOptions.IsOptionSet(TaskMasterOptions.Option_DownloadIntoProjects))
            {
                projectNameIdMapping = projectsList;
            }

            //Determine if the there is a project filter
            exportSingleProject = helper_DetermineIfSingleProjectFilter(projectsList);
        }


        //===================================================================================
        //List of groups?
        //===================================================================================
        if (taskOptions.IsOptionSet(TaskMasterOptions.Option_GetGroupsList))
        {
            Execute_DownloadGroupsList(serverLogin);
        }

        //===================================================================================
        //List of datasources? (does not download actual data sources, just the list)
        //===================================================================================
        if (taskOptions.IsOptionSet(TaskMasterOptions.Option_GetDatasourcesList))
        {
            Execute_DownloadDatasourcesList(serverLogin);
        }

        //===================================================================================
        //Datasources download...
        //===================================================================================
        if (taskOptions.IsOptionSet(TaskMasterOptions.Option_DownloadDatasources))
        {
            Execute_DownloadDatasources(
                serverLogin
                , exportToPath
                , projectNameIdMapping
                , exportSingleProject
                , taskOptions.GetOptionValue(TaskMasterOptions.OptionParameter_ExportOnlyTaggedWith)
                , taskOptions.IsOptionSet(TaskMasterOptions.OptionParameter_RemoveTagFromExportedContent)
                );
        }


        //===================================================================================
        //Workbooks download...
        //===================================================================================
        if (taskOptions.IsOptionSet(TaskMasterOptions.Option_DownloadWorkbooks))
        {
            Execute_DownloadWorkbooks(
                serverLogin
                , exportToPath
                , projectNameIdMapping
                , exportSingleProject
                , taskOptions.GetOptionValue(TaskMasterOptions.OptionParameter_ExportOnlyTaggedWith)
                , taskOptions.IsOptionSet(TaskMasterOptions.OptionParameter_RemoveTagFromExportedContent)
                );
        }

        //===================================================================================
        //List of workbooks? (does not download actual workbooks, just the list)
        //===================================================================================
        if (taskOptions.IsOptionSet(TaskMasterOptions.Option_GetWorkbooksList))
        {
            Execute_DownloadWorkbooksList(serverLogin);

            //Do we want to download the connection information for each workbook?
            if (taskOptions.IsOptionSet(TaskMasterOptions.Option_GetWorkbooksConnections))
            {
                Execute_DownloadWorkbooksConnections(
                    serverLogin
                    , this.WorkbooksList);
            }
        }

        //===================================================================================
        //Are there database credentials we need to associate with content being uploaded...
        //===================================================================================
        var pathDBCredentials = taskOptions.GetOptionValue(TaskMasterOptions.Option_DBCredentialsPath);
        CredentialManager uploadCredentialManager = null;

        if (!string.IsNullOrWhiteSpace(pathDBCredentials))
        {
            uploadCredentialManager = Execute_LoadDBCredentialsFile(pathDBCredentials);
        }

        //===================================================================================
        //Datasources upload...
        //===================================================================================
        if (taskOptions.IsOptionSet(TaskMasterOptions.Option_UploadDatasources))
        {
            Execute_UploadDatasources(
                serverLogin,
                taskOptions.GetOptionValue(TaskMasterOptions.OptionParameter_PathUploadFrom),
                uploadCredentialManager);
        }

        //===================================================================================
        //Workbooks upload...
        //===================================================================================
        if (taskOptions.IsOptionSet(TaskMasterOptions.Option_UploadWorkbooks))
        {
            Execute_UploadWorkbooks(
                serverLogin,
                taskOptions.GetOptionValue(TaskMasterOptions.OptionParameter_PathUploadFrom),
                taskOptions.IsOptionSet(TaskMasterOptions.Option_RemapWorkbookReferencesOnUpload),
                uploadCredentialManager);
        }

        //===================================================================================
        //Save the site inventory file
        //===================================================================================
        var inventoryFile = taskOptions.GetOptionValue(TaskMasterOptions.OptionParameter_SaveInventoryFile);

        if (!string.IsNullOrWhiteSpace(inventoryFile))
        {
            Execute_GenerateSiteInventoryFile(inventoryFile);

            //Do we want to generate a TWB file that uses the inventory file
            if (taskOptions.IsOptionSet(TaskMasterOptions.Option_GenerateInventoryTwb))
            {
                Execute_GenerateSiteInventoryFile_Twb(inventoryFile);
            }
        }

        //===================================================================================
        //Save the manual steps file
        //===================================================================================
        var manualStepsFile = taskOptions.GetOptionValue(TaskMasterOptions.OptionParameter_SaveManualSteps);

        if (!string.IsNullOrWhiteSpace(manualStepsFile))
        {
            Execute_GenerateManualStepsFile(manualStepsFile);
        }

        //===================================================================================
        //Save the logs file
        //===================================================================================
        var logFile = taskOptions.GetOptionValue(TaskMasterOptions.OptionParameter_SaveLogFile);

        if (!string.IsNullOrWhiteSpace(logFile))
        {
            Execute_SaveLogFile(logFile);
        }

        //===================================================================================
        //Save the errors file
        //===================================================================================
        var errorsFile = taskOptions.GetOptionValue(TaskMasterOptions.OptionParameter_SaveErrorsFile);

        if (!string.IsNullOrWhiteSpace(errorsFile))
        {
            Execute_SaveErrorsFile(errorsFile);
        }
    }
예제 #15
0
    /// <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);
        }
    }
예제 #16
0
    /// <summary>
    /// Download the data sources
    /// </summary>
    /// <param name="onlineLogin"></param>
    private void Execute_DownloadDatasources(
        TableauServerSignIn onlineLogin,
        string exportToPath,
        IProjectsList projectsList,
        SiteProject singleProjectIdFilter = null,
        string exportOnlyWithThisTag      = null,
        bool deleteTagAfterExport         = false)
    {
        _statusLog.AddStatusHeader("Download datasources");
        ICollection <SiteDatasource> datasourcesList = null;

        try
        {
            //Get the list of datasources
            var datasourcesManager = new DownloadDatasourcesList(_onlineUrls, onlineLogin);
            datasourcesManager.ExecuteRequest();
            datasourcesList = datasourcesManager.Datasources;
        }
        catch (Exception exGetContentList)
        {
            _statusLog.AddError("Error querying for list of datasources, " + exGetContentList.Message.ToString());
        }

        if (datasourcesList == null)
        {
            _statusLog.AddError("Aborting datasources 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 = datasourcesList;

        _statusLog.AddStatus("Download datasources count before filters: " + filteredList.Count.ToString());

        //See if we have a PROJECTS filter to apply to the set of content to download
        filteredList = FilterProjectMembership <SiteDatasource> .KeepOnlyProjectMembers(
            filteredList,
            singleProjectIdFilter,
            true);

        _statusLog.AddStatus("Download datasources 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 <SiteDatasource> .KeepOnlyTagged(
            filteredList,
            exportOnlyWithThisTag,
            true);

        _statusLog.AddStatus("Download datasources count after tags filter: " + filteredList.Count.ToString());

        ICollection <SiteDatasource> successfullExportSet = null;
        var datasourcePath = Path.Combine(exportToPath, "datasources");

        FileIOHelper.CreatePathIfNeeded(datasourcePath);

        //-----------------------------------------------------------
        //Download the data sources
        //-----------------------------------------------------------
        try
        {
            var datasourceDownloads = new DownloadDatasources(
                _onlineUrls,
                onlineLogin,
                filteredList,
                datasourcePath,
                projectsList);
            successfullExportSet = datasourceDownloads.ExecuteRequest();
        }
        catch (Exception exDatasourceDownload)
        {
            _statusLog.AddError("Error during datasource download, " + exDatasourceDownload.ToString());
        }

        //--------------------------------------------------------------------------------
        //Do we want to remove tags from successfully downloaded content?
        //--------------------------------------------------------------------------------
        if ((successfullExportSet != null) && (deleteTagAfterExport) && (!string.IsNullOrWhiteSpace(exportOnlyWithThisTag)))
        {
            Execute_DeleteTagFromDatasources(onlineLogin, successfullExportSet, exportOnlyWithThisTag);
        }
    }