FilenameWithDateTimeUnique() public static method

Gives us a high probability unqique file name
public static FilenameWithDateTimeUnique ( string baseName, Nullable when = null ) : string
baseName string
when Nullable
return string
Beispiel #1
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));
        }
Beispiel #2
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));
        }
Beispiel #3
0
        /// <summary>
        /// Called to generate a provisioning manifest file from a Tableau site
        /// This is useful for creating a "backup" of the sites existing users/groups
        /// provisioning
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnCreateBackupManifestFile_Click(object sender, EventArgs e)
        {
            var statusLogs = new TaskStatusLogs();

            statusLogs.AddStatus("Starting...");
            UpdateStatusText(statusLogs, true);
            bool ignoreAllUsersGroup = chkIgoreAllUsersGroup.Checked;


            string pathSecrets = txtPathToSecrets.Text;

            if (!File.Exists(pathSecrets))
            {
                MessageBox.Show("Secrets file does not exist at specified path (" + pathSecrets + ")");
                return;
            }


            string pathOutputManifestFile = txtPathToGenerateManifestFile.Text;

            //If they gave us a directory, not a file-name, then add filename to it
            if (Directory.Exists(pathOutputManifestFile))
            {
                pathOutputManifestFile = Path.Combine(
                    pathOutputManifestFile,
                    FileIOHelper.FilenameWithDateTimeUnique("SiteProvisionManifest.xml"));
                //Show it in the UI
                txtPathToGenerateManifestFile.Text = pathOutputManifestFile;
            }


            var pathOutput = Path.GetDirectoryName(pathOutputManifestFile);

            FileIOHelper.CreatePathIfNeeded(pathOutput);


            //Show the user a command line that they can use to run this same work
            GenerateProvisioningCommandLine(
                CommandLineParser.Command_GenerateManifestFromOnlineSite,
                pathSecrets,
                pathOutputManifestFile,
                pathOutput,
                ignoreAllUsersGroup);

            //Run the work
            try
            {
                GenerateManifestFromOnlineSite(
                    statusLogs,
                    pathSecrets,
                    pathOutputManifestFile,
                    ignoreAllUsersGroup);
            }
            catch (Exception exError)
            {
                MessageBox.Show("Error: " + exError.Message);
            }

            UpdateStatusText(statusLogs, true);

            //Open the file explorer to the output directory
            if (Directory.Exists(pathOutput))
            {
                System.Diagnostics.Process.Start(pathOutput);
            }
        }