Exemplo n.º 1
0
    /// <summary>
    /// Attempts to upload a single file a Tableau Server, and then make it a published workbook
    /// </summary>
    /// <param name="localFilePath"></param>
    /// <returns></returns>
    private bool AttemptUploadSingleFile_Inner(
        string localFilePath,
        string projectId,
        CredentialManager.Credential dbCredentials)
    {
        string uploadSessionId;

        try
        {
            var fileUploader = new UploadFile(_onlineUrls, _onlineSession, localFilePath, _uploadChunkSizeBytes, _uploadChunkDelaySeconds);
            uploadSessionId = fileUploader.ExecuteRequest();
        }
        catch (Exception exFileUpload)
        {
            this.StatusLog.AddError("Unexpected error attempting to upload file " + localFilePath + ", " + exFileUpload.Message);
            throw exFileUpload;
        }

        this.StatusLog.AddStatus("File chunks upload successful. Next step, make it a published workbook", -10);
        try
        {
            string fileName   = Path.GetFileNameWithoutExtension(localFilePath);
            string uploadType = RemoveFileExtensionDot(Path.GetExtension(localFilePath).ToLower());
            var    workbook   = FinalizePublish(uploadSessionId, fileName, uploadType, projectId, dbCredentials);
            StatusLog.AddStatus("Upload content details: " + workbook.ToString(), -10);
            StatusLog.AddStatus("Success! Uploaded workbook " + Path.GetFileName(localFilePath));
        }
        catch (Exception exPublishFinalize)
        {
            this.StatusLog.AddError("Unexpected error finalizing publish of file " + localFilePath + ", " + exPublishFinalize.Message);
            LogManualAction_UploadWorkbook(localFilePath);
            throw exPublishFinalize;
        }
        return(true);     //Success
    }
Exemplo n.º 2
0
    /// <summary>
    /// Sanity testing on whether the file being uploaded is worth uploading
    /// </summary>
    /// <param name="localFilePath"></param>
    /// <returns></returns>
    bool IsValidUploadFile(string localFilePath)
    {
        //If the file is a custom settings file for the workbook, then ignore it
        if (DatasourcePublishSettings.IsSettingsFile(localFilePath))
        {
            return(false); //Nothing to do, it's just a settings file
        }

        //Ignore temp files, since we know we don't want to upload them
        var fileExtension = Path.GetExtension(localFilePath).ToLower();

        if ((fileExtension == ".tmp") || (fileExtension == ".temp"))
        {
            StatusLog.AddStatus("Ignoring temp file, " + localFilePath, -10);
            return(false);
        }

        //These are the only kinds of data sources we know about...
        if ((fileExtension != ".tds") && (fileExtension != ".tdsx"))
        {
            StatusLog.AddError("File is not a data source: " + localFilePath);
            return(false);
        }

        return(true);
    }
Exemplo n.º 3
0
    /// <summary>
    /// Attempts to upload a single file a Tableau Server, and then make it a published workbook
    /// </summary>
    /// <param name="localFilePath"></param>
    /// <returns></returns>
    private bool AttemptUploadSingleFile_Inner(
        string localFilePath,
        string projectId,
        CredentialManager.Credential dbCredentials,
        WorkbookPublishSettings publishSettings)
    {
        string uploadSessionId;

        try
        {
            var fileUploader = new UploadFile(_onlineUrls, _onlineSession, localFilePath, _uploadChunkSizeBytes, _uploadChunkDelaySeconds);
            uploadSessionId = fileUploader.ExecuteRequest();
        }
        catch (Exception exFileUpload)
        {
            this.StatusLog.AddError("Unexpected error attempting to upload file " + localFilePath + ", " + exFileUpload.Message);
            throw exFileUpload;
        }

        SiteWorkbook workbook;

        this.StatusLog.AddStatus("File chunks upload successful. Next step, make it a published workbook", -10);
        try
        {
            string fileName   = Path.GetFileNameWithoutExtension(localFilePath);
            string uploadType = RemoveFileExtensionDot(Path.GetExtension(localFilePath).ToLower());
            workbook = FinalizePublish(
                uploadSessionId,
                FileIOHelper.Undo_GenerateWindowsSafeFilename(fileName), //[2016-05-06] If the name has escapted characters, unescape them
                uploadType,
                projectId,
                dbCredentials,
                publishSettings);
            StatusLog.AddStatus("Upload content details: " + workbook.ToString(), -10);
            StatusLog.AddStatus("Success! Uploaded workbook " + Path.GetFileName(localFilePath));
        }
        catch (Exception exPublishFinalize)
        {
            this.StatusLog.AddError("Unexpected error finalizing publish of file " + localFilePath + ", " + exPublishFinalize.Message);
            LogManualAction_UploadWorkbook(localFilePath);
            throw exPublishFinalize;
        }

        //See if we want to reassign ownership of the workbook
        if (_attemptOwnershipAssignment)
        {
            try
            {
                AttemptOwnerReassignment(workbook, publishSettings, _siteUsers);
            }
            catch (Exception exOwnershipAssignment)
            {
                this.StatusLog.AddError("Unexpected error reassigning ownership of published workbook " + workbook.Name + ", " + exOwnershipAssignment.Message);
                LogManualAction_ReassignOwnership(workbook.Name);
                throw exOwnershipAssignment;
            }
        }

        return(true);     //Success
    }
 /// <summary>
 /// Create a project on server
 /// </summary>
 public void ExecuteRequest()
 {
     try
     {
         _UpdateUser(_userID, _siteRole);
         StatusLog.AddStatus("User updated. " + _userID);
     }
     catch (Exception exUser)
     {
         StatusLog.AddError("Error attempting to update user '" + _userID + "', " + exUser.Message);
     }
 }
Exemplo n.º 5
0
        /// <summary>
        /// Update a user on server
        /// </summary>

        public void ExecuteRequest()
        {
            try
            {
                _UpdateUser(_userId, _fullName, _email, _password);
                StatusLog.AddStatus("User updated. " + _userId);
            }
            catch (Exception exUser)
            {
                StatusLog.AddError("Error attempting to update user '" + _userId + "'," + exUser.Message);
            }
        }
Exemplo n.º 6
0
 /// <summary>
 /// Delete the tag from the workbook.
 /// </summary>
 public void ExecuteRequest()
 {
     try
     {
         //Attempt the delete
         _DeleteTagFromContent(_contentId, _tagText);
         StatusLog.AddStatus("Tag deleted from workbook " + _contentId + "/" + _tagText);
     }
     catch (Exception exProject)
     {
         StatusLog.AddError("Error attempting to delete content tag " + _contentId + "/" + _tagText + "', " + exProject.Message);
     }
 }
 /// <summary>
 /// Create a project on server
 /// </summary>
 public SiteProject ExecuteRequest()
 {
     try
     {
         var newProj = _CreateProject(_projectName, _projectDesciption);
         StatusLog.AddStatus("Project created. " + newProj);
         return(newProj);
     }
     catch (Exception exProject)
     {
         StatusLog.AddError("Error attempting to create project '" + _projectName + "', " + exProject.Message);
         return(null);
     }
 }
Exemplo n.º 8
0
 /// <summary>
 /// Create a user on server
 /// </summary>
 public string ExecuteRequest()
 {
     try
     {
         var newUser = _CreateUser(_name, _fullName, _siteRole, _authSetting);
         StatusLog.AddStatus("User created. " + newUser);
         return(newUser);
     }
     catch (Exception exProject)
     {
         StatusLog.AddError("Error attempting to create user '" + _name + "', " + exProject.Message);
         return(null);
     }
 }
Exemplo n.º 9
0
    /// <summary>
    /// Sanity testing on whether the file being uploaded is worth uploading
    /// </summary>
    /// <param name="localFilePath"></param>
    /// <returns></returns>
    bool IsValidUploadFile(string localFilePath)
    {
        //Ignore temp files, since we know we don't want to upload them
        var fileExtension = Path.GetExtension(localFilePath).ToLower();

        if ((fileExtension == ".tmp") || (fileExtension == ".temp"))
        {
            StatusLog.AddStatus("Ignoring temp file, " + localFilePath, -10);
            return(false);
        }

        //These are the only kinds of data sources we know about...
        if ((fileExtension != ".twb") && (fileExtension != ".twbx"))
        {
            StatusLog.AddError("File is not a data source: " + localFilePath);
            return(false);
        }

        return(true);
    }
Exemplo n.º 10
0
    /// <summary>
    /// Attempts to upload a single file a Tableau Server, and then make it a published data source
    /// </summary>
    /// <param name="localFilePath"></param>
    /// <param name="projectId"></param>
    /// <param name="dbCredentials">If not NULL, then these are the DB credentials we want to associate with the content we are uploading</param>
    /// <returns></returns>
    private bool AttemptUploadSingleFile(
        string localFilePath,
        string projectId,
        CredentialManager.Credential dbCredentials)
    {
        string uploadSessionId;

        try
        {
            var fileUploader = new UploadFile(_onlineUrls, _onlineSession, localFilePath, _uploadChunkSizeBytes, _uploadChunkDelaySeconds);
            uploadSessionId = fileUploader.ExecuteRequest();
        }
        catch (Exception exFileUpload)
        {
            this.StatusLog.AddError("Unexpected error attempting to upload file " + localFilePath + ", " + exFileUpload.Message);
            throw exFileUpload;
        }

        this.StatusLog.AddStatus("File chunks upload successful. Next step, make it a published datasource", -10);
        try
        {
            string fileName   = Path.GetFileNameWithoutExtension(localFilePath);
            string uploadType = RemoveFileExtensionDot(Path.GetExtension(localFilePath).ToLower());
            var    dataSource = FinalizePublish(
                uploadSessionId,
                FileIOHelper.Undo_GenerateWindowsSafeFilename(fileName), //[2016-05-06] If the name has escapted characters, unescape them
                uploadType,
                projectId,
                dbCredentials);
            StatusLog.AddStatus("Upload content details: " + dataSource.ToString(), -10);
            StatusLog.AddStatus("Success! Uploaded datasource " + Path.GetFileName(localFilePath));
        }
        catch (Exception exPublishFinalize)
        {
            this.StatusLog.AddError("Unexpected error finalizing publish of file " + localFilePath + ", " + exPublishFinalize.Message);
            throw exPublishFinalize;;
        }
        return(true);     //Success
    }
        /// <summary>
        /// Looks up the default project ID
        /// </summary>
        /// <returns></returns>
        public string GetProjectIdForUploads(string projectName)
        {
            //If the project name is empty - look for the default project
            if (string.IsNullOrEmpty(projectName))
            {
                goto find_default_project;
            }

            //Look for the matching project
            var project = _projectsList.FindProjectWithName(projectName);

            if (project != null)
            {
                return(project.Id);
            }

            //If the option is specified; attempt to create the project
            if (_uploadProjectBehavior.AttemptProjectCreate)
            {
                //Create the project name
                var createProject = new SendCreateProject(_onlineUrls, OnlineSession, projectName);
                try
                {
                    var newProject = createProject.ExecuteRequest();
                    _projectsList.AddProject(newProject);
                    return(newProject.Id);
                }
                catch (Exception exCreateProject)
                {
                    StatusLog.AddError("Failed attempting to create project '" + projectName + "', " + exCreateProject.Message);
                }
            }

            //If we are not allowed to fall back the default project then error
            if (!_uploadProjectBehavior.UseDefaultProjectIfNeeded)
            {
                throw new Exception("Not allowed to use default project");
            }

            StatusLog.AddStatus("Project name not found '" + projectName + "'. Reverting to default project", -10);

find_default_project:
            //If all else fails, fall back to using the default project
            var defaultProject = _projectsList.FindProjectWithName("default"); //Find the default project

            if (defaultProject != null)
            {
                return(defaultProject.Id);
            }

            defaultProject = _projectsList.FindProjectWithName("Default");
            if (defaultProject != null)
            {
                return(defaultProject.Id);
            }

            defaultProject = _projectsList.FindProjectWithName(""); //Try empty
            if (defaultProject != null)
            {
                return(defaultProject.Id);
            }

            //Default project not found. Choosing any project
            StatusLog.AddError("Default project not found. Reverting to any project");
            foreach (var thisProj in _projectsList.Projects)
            {
                return(thisProj.Id);
            }

            StatusLog.AddError("Upload could not find a project ID to use");
            throw new Exception("Aborting. Upload Datasources could not find a project ID to use");
        }