FromContentUrl() public static method

Parse out the server-user and site name from the content URL
public static FromContentUrl ( string userContentUrl, int pageSize ) : TableauServerUrls,
userContentUrl string e.g. https://online.tableausoftware.com/t/tableausupport/workbooks
pageSize int
return TableauServerUrls,
示例#1
0
            public void WhenGivenUrlReturnTableauServerUrlsInstance()
            {
                var testObject =
                    TableauServerUrls.FromContentUrl("http://traffk-dev-tab.eastus.cloudapp.azure.com/#/projects", 1);

                Assert.IsNotNull(testObject);
            }
示例#2
0
    /// <summary>
    /// Sets up parameters needed by Site Import
    /// </summary>
    /// <param name="dirImportFromDirectory"></param>
    /// <param name="urlToServerSite"></param>
    /// <param name="useAccessToken"></param>
    /// <param name="userName"></param>
    /// <param name="password"></param>
    /// <param name="isSystemAdmin"></param>
    /// <param name="remapDataserverReferences"></param>
    /// <param name="pathDbCredentials"></param>
    /// <param name="assignContentOwnership">TRUE: Look for metadata files for uploaded content and attempt to reassign its ownership</param>
    /// <param name="options"></param>
    /// <returns></returns>
    private static TaskMaster helper_CreateTaskMaster_SiteImport(
        string dirImportFromDirectory,
        string urlToServerSite,
        bool useAccessToken,
        string userName,
        string password,
        bool isSiteAdmin,
        bool remapDataserverReferences,
        string pathDbCredentials,
        bool assignContentOwnership,
        TaskMasterOptions options)
    {
        //If we were passed in no existing options, then add them
        if (options == null)
        {
            options = new TaskMasterOptions();
        }

        //The local file system path we want to upload from
        options.AddOption(TaskMasterOptions.OptionParameter_PathUploadFrom, dirImportFromDirectory);

        //Things we want to upload
        options.AddOption(TaskMasterOptions.Option_UploadDatasources);
        options.AddOption(TaskMasterOptions.Option_UploadWorkbooks);

        //Some features are only accessible to System Admins
        if (isSiteAdmin)
        {
            options.AddOption(TaskMasterOptions.Option_UploadCreateNeededProjects);
        }

        if (assignContentOwnership)
        {
            options.AddOption(TaskMasterOptions.Option_AssignContentOwnershipAfterPublish);
        }

        //Do we need to remap workbook references to point to the Server/Site we are uploading to
        if (remapDataserverReferences)
        {
            options.AddOption(TaskMasterOptions.Option_RemapWorkbookReferencesOnUpload);
        }

        if (!string.IsNullOrWhiteSpace(pathDbCredentials))
        {
            options.AddOption(TaskMasterOptions.Option_DBCredentialsPath, pathDbCredentials);
        }

        //Generate the URLs mapping class
        var onlineUrls = TableauServerUrls.FromContentUrl(urlToServerSite, TaskMasterOptions.RestApiReponsePageSizeDefault);

        //Create the task master object
        return(new TaskMaster(
                   JobName_SiteImport,
                   onlineUrls,
                   useAccessToken,
                   userName,
                   password,
                   options));
    }
示例#3
0
    /// <summary>
    /// Sets up parameters needed by site inventory
    /// </summary>
    /// <param name="pathToWriteInventoryFile"></param>
    /// <param name="urlToServerSite"></param>
    /// <param name="useAccessToken"></param>
    /// <param name="userName"></param>
    /// <param name="password"></param>
    /// <param name="isAdmin"></param>
    /// <param name="options"></param>
    /// <returns></returns>
    private static TaskMaster helper_CreateTaskMaster_SiteInventory(
        string pathToWriteInventoryFile,
        string urlToServerSite,
        bool useAccessToken,
        string userName,
        string password,
        bool isAdmin,
        bool generateTwbFile,
        TaskMasterOptions options)
    {
        //If we were passed in no existing options, then add them
        if (options == null)
        {
            options = new TaskMasterOptions();
        }

        //Where we want to write the results file to
        options.AddOption(TaskMasterOptions.OptionParameter_SaveInventoryFile, pathToWriteInventoryFile);

        //Things we want to download to
        options.AddOption(TaskMasterOptions.Option_GetProjectsList);
        options.AddOption(TaskMasterOptions.Option_GetDatasourcesList);
        options.AddOption(TaskMasterOptions.Option_GetWorkbooksList);
        options.AddOption(TaskMasterOptions.Option_GetWorkbooksConnections);
        options.AddOption(TaskMasterOptions.Option_GetSubscriptionsList);
        options.AddOption(TaskMasterOptions.Option_GetViewsList);

        //Some features are only accessible to System/Site Admins
        if (isAdmin)
        {
            options.AddOption(TaskMasterOptions.Option_GetSiteUsers);
            options.AddOption(TaskMasterOptions.Option_GetSiteInfo);
            options.AddOption(TaskMasterOptions.Option_GetGroupsList);
            options.AddOption(TaskMasterOptions.Option_GetSchedulesList);
            options.AddOption(TaskMasterOptions.Option_GetExtractTasksList);
        }

        //Do we want to create a Tableau Workbook that uses the inventory CSV file?
        if (generateTwbFile)
        {
            options.AddOption(TaskMasterOptions.Option_GenerateInventoryTwb);
        }


        //Generate the URLs mapping class
        var onlineUrls = TableauServerUrls.FromContentUrl(urlToServerSite, TaskMasterOptions.RestApiReponsePageSizeDefault);

        //Create the task master object
        return(new TaskMaster(
                   JobName_SiteInventory,
                   onlineUrls,
                   useAccessToken,
                   userName,
                   password,
                   options));
    }
    /// <summary>
    /// Synchronous call to test and make sure sign in works
    /// </summary>
    /// <param name="url"></param>
    /// <param name="userId"></param>
    /// <param name="userPassword"></param>
    /// <param name="statusLog"></param>
    public static void VerifySignInPossible(string url, string userId, string userPassword, TaskStatusLogs statusLog)
    {
        var  urlManager = TableauServerUrls.FromContentUrl(url, TaskMasterOptions.RestApiReponsePageSizeDefault);
        var  signIn     = new TableauServerSignIn(urlManager, userId, userPassword, statusLog);
        bool success    = signIn.Execute();

        if (!success)
        {
            throw new Exception("Failed sign in");
        }
    }
        /// <summary>
        /// Synchronous call to test and make sure sign in works
        /// </summary>
        /// <param name="url">Tableau site url</param>
        /// <param name="username">Tableau username</param>
        /// <param name="userPassword">Tableau user's password</param>
        /// <param name="statusLog">Status log</param>
        public static void VerifySignInPossible(string url, string username, string userPassword, TaskStatusLogs statusLog)
        {
            var urlManager = TableauServerUrls.FromContentUrl(url, 1000);
            var signIn     = new TableauServerSignIn(urlManager, username, userPassword, statusLog);
            var success    = signIn.ExecuteRequest();

            if (!success)
            {
                throw new Exception("Failed sign in");
            }
        }
示例#6
0
    /// <summary>
    /// Sets up parameters needed by site inventory
    /// </summary>
    /// <param name="pathToWriteInventoryFile"></param>
    /// <param name="urlToServerSite"></param>
    /// <param name="userName"></param>
    /// <param name="password"></param>
    /// <param name="isSystemAdmin"></param>
    /// <param name="options"></param>
    /// <returns></returns>
    private static TaskMaster helper_CreateTaskMaster_SiteInventory(
        string pathToWriteInventoryFile,
        string urlToServerSite,
        string userName,
        string password,
        bool isSystemAdmin,
        bool generateTwbFile,
        TaskMasterOptions options)
    {
        //If we were passed in no existing options, then add them
        if (options == null)
        {
            options = new TaskMasterOptions();
        }

        //Where we want to write the results file to
        options.AddOption(TaskMasterOptions.OptionParameter_SaveInventoryFile, pathToWriteInventoryFile);

        //Things we want to download to
        options.AddOption(TaskMasterOptions.Option_GetProjectsList);
        options.AddOption(TaskMasterOptions.Option_GetDatasourcesList);
        options.AddOption(TaskMasterOptions.Option_GetWorkbooksList);
        options.AddOption(TaskMasterOptions.Option_GetWorkbooksConnections);

        //Some features are only accessible to System Admins
        //NOTE: When the APIs support site-admin getting this information, they will be moved into the more general block above
        if (isSystemAdmin)
        {
            options.AddOption(TaskMasterOptions.Option_GetSiteUsers);
            options.AddOption(TaskMasterOptions.Option_GetSiteInfo);
            options.AddOption(TaskMasterOptions.Option_GetGroupsList);
        }

        //Do we want to create a Tableau Workbook that uses the inventory CSV file?
        if (generateTwbFile)
        {
            options.AddOption(TaskMasterOptions.Option_GenerateInventoryTwb);
        }


        //Generate the URLs mapping class
        var onlineUrls = TableauServerUrls.FromContentUrl(urlToServerSite, TaskMasterOptions.RestApiReponsePageSizeDefault);

        //Create the task master object
        return(new TaskMaster(
                   JobName_SiteInventory,
                   onlineUrls,
                   userName,
                   password,
                   options));
    }
示例#7
0
    /// <summary>
    /// Queries a site for all its users, and for recent content.
    /// Genterates and sends email to all the users
    /// </summary>
    /// <param name="showLogsHere"></param>
    /// <param name="statusLogs"></param>
    public void Execute()
    {
        WorkingListSiteUsers workingList_allKnownUsers = null;
        //==================================================================================
        //Get the data we need to run
        //==================================================================================
        //Generate the URLs we will need
        var siteUrlManager = TableauServerUrls.FromContentUrl(_config.SiteUrl, TaskMasterOptions.RestApiReponsePageSizeDefault);

        //=================================================================================
        //Sign in to the site
        //=================================================================================
        var siteSignIn = new TableauServerSignIn(
            siteUrlManager,
            _config.SiteClientId,
            _config.Secret,
            _statusLogs,
            _config.SiteSignInMode);

        var signInSuccess = siteSignIn.Execute();

        ShowLogs();

        //=================================================================================
        //Get the basic site info
        //=================================================================================
        var downloadSiteInfo = new DownloadSiteInfo(siteSignIn);

        downloadSiteInfo.ExecuteRequest();
        var siteInfo = downloadSiteInfo.Site;

        ShowLogs();
        //=================================================================================
        //Provision the users
        //=================================================================================
        workingList_allKnownUsers = Execute_ProvisionUsers(siteSignIn);
        ShowLogs();

        //=================================================================================
        //Provision the groups
        //=================================================================================
        Execute_ProvisionGroups(siteSignIn, workingList_allKnownUsers);

        //=================================================================================
        //Content ownership changes
        //=================================================================================
        Execute_ProvisionContentOwnershipChanges(siteSignIn, workingList_allKnownUsers);
    }
示例#8
0
    /// <summary>
    /// Queries a site for all its users, and for recent content.
    /// Genterates and sends email to all the users
    /// </summary>
    /// <param name="showLogsHere"></param>
    /// <param name="statusLogs"></param>
    public void Execute()
    {
        //==================================================================================
        //Get the data we need to run
        //==================================================================================
        //Generate the URLs we will need
        var siteUrlManager = TableauServerUrls.FromContentUrl(_configTableauSecrets.SiteUrl, TaskMasterOptions.RestApiReponsePageSizeDefault);

        //=================================================================================
        //Sign in to the site
        //=================================================================================
        var siteSignIn = new TableauServerSignIn(
            siteUrlManager,
            _configTableauSecrets.SiteClientId,
            _configTableauSecrets.Secret,
            _statusLogs,
            _configTableauSecrets.SiteSignInMode);

        var signInSuccess = siteSignIn.Execute();

        ShowLogs();

        //=================================================================================
        //Get the basic site info
        //=================================================================================
        var downloadSiteInfo = new DownloadSiteInfo(siteSignIn);

        downloadSiteInfo.ExecuteRequest();
        var siteInfo = downloadSiteInfo.Site;

        //===================================================================================
        //Get Groups that map to Tableau Site User Roles from Tableau
        //===================================================================================
        _statusLogs.AddStatus("Tableau: Getting user roles groups");
        GenerateUsersRolesList_FromTableauSite(siteSignIn);

        //===================================================================================
        //Get Groups that map to Tableau Site Groups from Tableau
        //===================================================================================
        _statusLogs.AddStatus("Tableau: Getting user roles groups");
        GenerateGroupsMembersList_FromTableauSite(siteSignIn);
    }
示例#9
0
        /// <summary>
        /// Get an inventory of content on the specified server
        /// </summary>
        private TaskMaster CreateAsyncInventoryTask(bool showPasswordInUi)
        {
            string siteUrl        = txtUrlInventoryFrom.Text;
            bool   useAccessToken = (comboBoxAuthMethodInventoryFrom.SelectedIndex == 1);
            string signInUser     = txtIdInventoryFromUserId.Text;
            string signInPassword = txtPasswordInventoryFrom.Text;
            bool   isSystemAdmin  = chkInventoryUserIsAdmin.Checked;
            var    nowTime        = DateTime.Now;

            //----------------------------------------------------------------------
            //Sanity test the sign in.  If this fails, then there is no point in
            //moving forward
            //----------------------------------------------------------------------
            bool signInTest = ValidateSignInPossible(siteUrl, useAccessToken, signInUser, signInPassword);

            if (!signInTest)
            {
                return(null);
            }

            var onlineUrls = TableauServerUrls.FromContentUrl(siteUrl, TaskMasterOptions.RestApiReponsePageSizeDefault);

            //Local path
            string localPathForSiteOutput = GeneratePathFromSiteUrl(onlineUrls);

            //Output file
            string localPathForOutputFile =
                Path.Combine(localPathForSiteOutput,
                             FileIOHelper.FilenameWithDateTimeUnique("siteInventory.csv", nowTime));

            //Log file
            string localPathForLogFile =
                Path.Combine(localPathForSiteOutput,
                             FileIOHelper.FilenameWithDateTimeUnique("siteInventory_log.txt", nowTime));

            //Errors file
            string localPathForErrorsFile =
                Path.Combine(localPathForSiteOutput,
                             FileIOHelper.FilenameWithDateTimeUnique("siteInventory_errors.txt", nowTime));

            //-----------------------------------------------------------------
            //Generate a command line
            //-----------------------------------------------------------------
            string            commandLineAsText;
            CommandLineParser commandLineParsed;

            CommandLineParser.GenerateCommandLine_SiteInventory(
                showPasswordInUi,
                localPathForOutputFile,
                siteUrl,
                useAccessToken,
                signInUser,
                signInPassword,
                isSystemAdmin,
                localPathForLogFile,
                localPathForErrorsFile,
                chkGenerateInventoryTwb.Checked,
                chkVerboseLog.Checked,
                out commandLineAsText,
                out commandLineParsed);

            //Show the user the command line, so that they can copy/paste and run it
            txtInventoryExampleCommandLine.Text = PathHelper.GetApplicaitonPath() + " " + commandLineAsText;


            //=====================================================================
            //Create the task
            //=====================================================================
            return(TaskMaster.FromCommandLine(commandLineParsed));
        }
示例#10
0
        /// <summary>
        /// Creates the task we use to export a Tableau Server sites content to the local file system
        /// </summary>
        /// <returns></returns>
        private TaskMaster CreateAsyncImportTask(bool showPasswordInUi)
        {
            string siteUrl               = txtUrlImportTo.Text;
            bool   useAccessToken        = (comboBoxAuthMethodImportTo.SelectedIndex == 1);
            string signInUser            = txtIdImportTo.Text;
            string signInPassword        = txtPasswordImportTo.Text;
            bool   isSiteAdmin           = chkImportIsSiteAdmin.Checked;
            string localPathImportFrom   = txtSiteImportContentPath.Text;
            bool   remapContentOwnership = chkImportRemapContentOwnership.Checked;

            //Check that this contains Workbooks or Data Sources; otherwise it's not a valid path with content
            if (!TaskMaster.IsValidImportFromDirectory(localPathImportFrom))
            {
                throw new Exception("The import directory specified does not contain datasources/workbooks sub directories. Import aborted.");
            }

            //If there is a DB credentials file path make sure it actually points to a file
            string pathDBCredentials = GetDBCredentialsImportPath();

            if (!string.IsNullOrWhiteSpace(pathDBCredentials))
            {
                if (!File.Exists(pathDBCredentials))
                {
                    throw new Exception("The path to the db credentials file does not exist, " + pathDBCredentials);
                }
            }

            //----------------------------------------------------------------------
            //Sanity test the sign in.  If this fails, then there is no point in
            //moving forward
            //----------------------------------------------------------------------
            bool signInTest = ValidateSignInPossible(siteUrl, useAccessToken, signInUser, signInPassword);

            if (!signInTest)
            {
                return(null);
            }

            var onlineUrls = TableauServerUrls.FromContentUrl(siteUrl, TaskMasterOptions.RestApiReponsePageSizeDefault);

            //Local path
            string localPathForSiteOutput = GeneratePathFromSiteUrl(onlineUrls);

            //Output file
            var    nowTime = DateTime.Now;
            string localPathForOutputFile =
                Path.Combine(localPathForSiteOutput,
                             FileIOHelper.FilenameWithDateTimeUnique("siteImport.csv", nowTime));

            //Log file
            string localPathForLogFile =
                Path.Combine(localPathForSiteOutput,
                             FileIOHelper.FilenameWithDateTimeUnique("siteImport_log.txt", nowTime));

            //Errors file
            string localPathForErrorsFile =
                Path.Combine(localPathForSiteOutput,
                             FileIOHelper.FilenameWithDateTimeUnique("siteImport_errors.txt", nowTime));

            //Manual steps file
            string localPathForManualStepsFile =
                Path.Combine(localPathForSiteOutput,
                             FileIOHelper.FilenameWithDateTimeUnique("siteImport_manualSteps.csv", nowTime));


            //-----------------------------------------------------------------
            //Generate a command line
            //-----------------------------------------------------------------
            string            commandLineAsText;
            CommandLineParser commandLineParsed;

            CommandLineParser.GenerateCommandLine_SiteImport(
                showPasswordInUi,
                localPathImportFrom,
                siteUrl,
                useAccessToken,
                signInUser,
                signInPassword,
                isSiteAdmin,
                chkRemapWorkbookDataserverReferences.Checked,
                pathDBCredentials,
                localPathForLogFile,
                localPathForErrorsFile,
                localPathForManualStepsFile,
                remapContentOwnership,
                chkVerboseLog.Checked,
                out commandLineAsText,
                out commandLineParsed);

            //Show the user the command line, so that they can copy/paste and run it
            txtSiteImportCommandLineExample.Text = PathHelper.GetApplicaitonPath() + " " + commandLineAsText;

            //=====================================================================
            //Create the task
            //=====================================================================
            return(TaskMaster.FromCommandLine(commandLineParsed));
        }
示例#11
0
        /// <summary>
        /// Creates the task we use to export a Tableau Server sites content to the local file system
        /// </summary>
        /// <returns></returns>
        private TaskMaster CreateAsyncExportTask(bool showPasswordInUi)
        {
            string siteUrl                 = txtUrlExportFrom.Text;
            bool   useAccessToken          = (comboBoxAuthMethodExportFrom.SelectedIndex == 1);
            string signInUser              = txtIdExportFrom.Text;
            string signInPassword          = txtPasswordExportFrom.Text;
            bool   isSiteAdmin             = chkExportUserIsAdmin.Checked;
            string exportOnlySingleProject = txtExportSingleProject.Text.Trim();
            string exportOnlyWithTag       = txtExportOnlyTagged.Text.Trim();


            //----------------------------------------------------------------------
            //Sanity test the sign in.  If this fails, then there is no point in
            //moving forward
            //----------------------------------------------------------------------
            bool signInTest = ValidateSignInPossible(siteUrl, useAccessToken, signInUser, signInPassword);

            if (!signInTest)
            {
                return(null);
            }

            var onlineUrls = TableauServerUrls.FromContentUrl(siteUrl, TaskMasterOptions.RestApiReponsePageSizeDefault);

            var nowTime = DateTime.Now;
            //Local path
            string localPathForSiteOutput = GeneratePathFromSiteUrl(onlineUrls);

            localPathForSiteOutput = FileIOHelper.PathDateTimeSubdirectory(localPathForSiteOutput, true, "siteExport", nowTime);

            //Log file
            string localPathForLogFile =
                Path.Combine(localPathForSiteOutput, "siteExport_log.txt");

            //Errors file
            string localPathForErrorsFile =
                Path.Combine(localPathForSiteOutput, "siteExport_errors.txt");

            //-----------------------------------------------------------------
            //Generate a command line
            //-----------------------------------------------------------------
            string            commandLineAsText;
            CommandLineParser commandLineParsed;

            CommandLineParser.GenerateCommandLine_SiteExport(
                showPasswordInUi,
                localPathForSiteOutput,
                siteUrl,
                useAccessToken,
                signInUser,
                signInPassword,
                isSiteAdmin,
                exportOnlySingleProject,
                exportOnlyWithTag,
                chkExportRemoveExportTag.Checked,
                localPathForLogFile,
                localPathForErrorsFile,
                chkExportContentsWithKeepAlive.Checked,
                chkVerboseLog.Checked,
                chkGenerateDownloadMetadataFiles.Checked,
                out commandLineAsText,
                out commandLineParsed);

            //Show the user the command line, so that they can copy/paste and run it
            textSiteExportCommandLine.Text = PathHelper.GetApplicaitonPath() + " " + commandLineAsText;

            //=====================================================================
            //Create the task
            //=====================================================================
            return(TaskMaster.FromCommandLine(commandLineParsed));
        }
示例#12
0
    /// <summary>
    /// Sets up parameters needed by Site Export
    /// </summary>
    /// <param name="dirExportDirectory"></param>
    /// <param name="urlToServerSite"></param>
    /// <param name="userName"></param>
    /// <param name="password"></param>
    /// <param name="isSystemAdmin"></param>
    /// <param name="options"></param>
    /// <returns></returns>
    private static TaskMaster helper_CreateTaskMaster_SiteExport(
        string dirExportDirectory,
        string urlToServerSite,
        string userName,
        string password,
        bool isSiteAdmin,
        string exportSingleProject,
        string exportOnlyTaggedWith,
        bool removeTagAfterExport,
        bool generateInfoFilesForDownloadedContent,
        TaskMasterOptions options)
    {
        //If we were passed in no existing options, then add them
        if (options == null)
        {
            options = new TaskMasterOptions();
        }

        //Path to download to
        options.AddOption(TaskMasterOptions.OptionParameter_PathDownloadTo, dirExportDirectory);

        //Things we want to download to
        options.AddOption(TaskMasterOptions.Option_DownloadIntoProjects);
        options.AddOption(TaskMasterOptions.Option_DownloadDatasources);
        options.AddOption(TaskMasterOptions.Option_DownloadWorkbooks);

        //Export only a single project
        if (!string.IsNullOrWhiteSpace(exportSingleProject))
        {
            options.AddOption(TaskMasterOptions.OptionParameter_ExportSingleProject, exportSingleProject);
        }

        //Export only if tagged
        if (!string.IsNullOrWhiteSpace(exportOnlyTaggedWith))
        {
            options.AddOption(TaskMasterOptions.OptionParameter_ExportOnlyTaggedWith, exportOnlyTaggedWith);

            //Does the tag need to get get removed from content we export?
            if (removeTagAfterExport)
            {
                options.AddOption(TaskMasterOptions.OptionParameter_RemoveTagFromExportedContent);
            }
        }

        //Do we want add to save additional metadata with each downloaded workbook/datasource?
        if (generateInfoFilesForDownloadedContent)
        {
            options.AddOption(TaskMasterOptions.OptionParameter_GenerateInfoFilesForDownloadedContent);
        }

        //Some features are only accessible to Site Admins
        if (isSiteAdmin)
        {
            options.AddOption(TaskMasterOptions.Option_GetSiteUsers);
            options.AddOption(TaskMasterOptions.Option_GetSiteInfo);
        }

        //Generate the URLs mapping class
        var onlineUrls = TableauServerUrls.FromContentUrl(urlToServerSite, TaskMasterOptions.RestApiReponsePageSizeDefault);

        //Create the task master object
        return(new TaskMaster(
                   JobName_SiteExport,
                   onlineUrls,
                   userName,
                   password,
                   options));
    }