Re-Maps all of the references to published datasources inside a Workbook to point to a different server/site. This transformation is needed to successfully copy a Workbook from one site/server to another site/server.
예제 #1
0
    /// <summary>
    ///
    /// </summary>
    /// <returns>Path to the ZIPed fixed up TWBX</returns>
    public string Execute()
    {
        //1. Create temp directory to decompress file to
        //      - Create subdirectories for 'unzipped', 're-zipped'
        //Create the directories we nee
        CreateDirectoryIfNeeded(_pathToWorkIn);
        CreateDirectoryIfNeeded(this.UnzipDirectory);
        CreateDirectoryIfNeeded(this.OutputDirectory);

        //2. Unzip file
        ZipFile.ExtractToDirectory(_pathToTwbx, this.UnzipDirectory);

        //3. Look for *.twb file in uncompressed directory (does not need to have maching name)
        string twbFile = GetPathToUnzippedTwb();
        //4. Remap server-path to point to correct server/site (replaces existing file)
        var twbMapper = new TwbDataSourceEditor(twbFile, twbFile, _serverInfo, _statusLog);

        twbMapper.Execute();

        //5. Recreate the TWBX File
        string filenameTwbx = Path.GetFileName(_pathToTwbx);
        string outputPath   = Path.Combine(this.OutputDirectory, filenameTwbx);

        ZipFile.CreateFromDirectory(this.UnzipDirectory, outputPath);

        //Return the path to the remapped/re-zipped *.twbx file
        return(outputPath);
    }
예제 #2
0
    /// <summary>
    /// Makes a copy of the file; remaps the Workbook references to the server, uploads the remapped file
    /// </summary>
    /// <param name="thisFilePath"></param>
    /// <param name="projectIdForUploads"></param>
    private bool AttemptUploadSingleFile_ReferencesRemapped(
        string thisFilePath,
        string projectIdForUploads,
        CredentialManager.Credential dbCredentials,
        WorkbookPublishSettings publishSettings)
    {
        bool success = false;

        string filename        = Path.GetFileName(thisFilePath);
        string pathToRemapFile = Path.Combine(_localPathTempWorkspace, filename);

        File.Copy(thisFilePath, pathToRemapFile, true); //Copy the file

        string fileType = Path.GetExtension(filename).ToLower();

        if (fileType == ".twb")
        {
            //Remap the references in the file
            var twbRemapper = new TwbDataSourceEditor(pathToRemapFile, pathToRemapFile, _onlineUrls, this.StatusLog);
            twbRemapper.Execute();
            success = AttemptUploadSingleFile_Inner(pathToRemapFile, projectIdForUploads, dbCredentials, publishSettings);
        }
        else if (fileType == ".twbx")
        {
            //Make sure we have a directory to unzip to
            var pathUnzip = Path.Combine(_localPathTempWorkspace, "unzipped");
            if (Directory.Exists(pathUnzip))
            {
                Directory.Delete(pathUnzip, true);
            }
            Directory.CreateDirectory(pathUnzip);

            var    twbxRemapper           = new TwbxDataSourceEditor(pathToRemapFile, pathUnzip, _onlineUrls, this.StatusLog);
            string pathTwbxRemappedOutput = twbxRemapper.Execute();
            //Upload the remapped file
            success = AttemptUploadSingleFile_Inner(pathTwbxRemappedOutput, projectIdForUploads, dbCredentials, publishSettings);

            //Clean-up and delete the whole unzipped directory
            Directory.Delete(pathUnzip, true);
        }
        else
        {
            //We should never hit this... bad content
            this.StatusLog.AddError("Error Workbook upload - Expected Workbook filetype! " + filename);
        }

        //Delete the remap file
        File.Delete(pathToRemapFile);
        return(success);
    }
예제 #3
0
    /// <summary>
    /// Makes a copy of the file; remaps the Workbook references to the server, uploads the remapped file
    /// </summary>
    /// <param name="thisFilePath"></param>
    /// <param name="projectIdForUploads"></param>
    private bool AttemptUploadSingleFile_ReferencesRemapped(
        string thisFilePath, 
        string projectIdForUploads,
        CredentialManager.Credential dbCredentials,
        WorkbookPublishSettings publishSettings)
    {
        bool success = false;

        string filename = Path.GetFileName(thisFilePath);
        string pathToRemapFile = Path.Combine(_localPathTempWorkspace, filename);
        File.Copy(thisFilePath, pathToRemapFile, true); //Copy the file

        string fileType = Path.GetExtension(filename).ToLower();
        if(fileType == ".twb")
        {
            //Remap the references in the file
            var twbRemapper = new TwbDataSourceEditor(pathToRemapFile, pathToRemapFile, _onlineUrls, this.StatusLog);
            twbRemapper.Execute();
            success = AttemptUploadSingleFile_Inner(pathToRemapFile, projectIdForUploads, dbCredentials, publishSettings);
        }
        else if(fileType == ".twbx")
        {
            //Make sure we have a directory to unzip to
            var pathUnzip = Path.Combine(_localPathTempWorkspace, "unzipped");
            if(Directory.Exists(pathUnzip))
            {
                Directory.Delete(pathUnzip, true);
            }
            Directory.CreateDirectory(pathUnzip);

            var twbxRemapper = new TwbxDataSourceEditor(pathToRemapFile, pathUnzip, _onlineUrls, this.StatusLog);
            string pathTwbxRemappedOutput = twbxRemapper.Execute();
            //Upload the remapped file
            success = AttemptUploadSingleFile_Inner(pathTwbxRemappedOutput, projectIdForUploads, dbCredentials, publishSettings);

            //Clean-up and delete the whole unzipped directory
            Directory.Delete(pathUnzip, true);
        }
        else
        {
            //We should never hit this... bad content
            this.StatusLog.AddError("Error Workbook upload - Expected Workbook filetype! " + filename);
        }

        //Delete the remap file
        File.Delete(pathToRemapFile);
        return success;
    }
    /// <summary>
    /// 
    /// </summary>
    /// <returns>Path to the ZIPed fixed up TWBX</returns>
    public string Execute()
    {
        //1. Create temp directory to decompress file to
        //      - Create subdirectories for 'unzipped', 're-zipped'
        //Create the directories we nee
        CreateDirectoryIfNeeded(_pathToWorkIn);
        CreateDirectoryIfNeeded(this.UnzipDirectory);
        CreateDirectoryIfNeeded(this.OutputDirectory);

        //2. Unzip file
        ZipFile.ExtractToDirectory(_pathToTwbx, this.UnzipDirectory);

        //3. Look for *.twb file in uncompressed directory (does not need to have maching name)
        string twbFile = GetPathToUnzippedTwb();
        //4. Remap server-path to point to correct server/site (replaces existing file)
        var twbMapper = new TwbDataSourceEditor(twbFile, twbFile, _serverInfo, _statusLog);
        twbMapper.Execute();

        //5. Recreate the TWBX File
        string filenameTwbx = Path.GetFileName(_pathToTwbx);
        string outputPath = Path.Combine(this.OutputDirectory, filenameTwbx);
        ZipFile.CreateFromDirectory(this.UnzipDirectory, outputPath);

        //Return the path to the remapped/re-zipped *.twbx file
        return outputPath;
    }