IsValidImportFromDirectory() public static method

Returns TRUE if the specified directory looks to be a valid directory we can import site content from
public static IsValidImportFromDirectory ( string path ) : bool
path string
return bool
Ejemplo n.º 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));
        }