public WorkbookPublisher( ITableauServerConnectionInfo tableauConnectionInfo, IPostgresUserInfo postgresUserInfo, PublishingOptions publishingOptions, IRestApiRequestor restApiRequestor) { this.tableauConnectionInfo = tableauConnectionInfo; this.postgresUserInfo = postgresUserInfo; this.publishingOptions = publishingOptions; this.restApiRequestor = restApiRequestor; }
protected PublishedWorkbookResult PublishWorkbook(IRestApiRequestor requestor, string pluginName, string workbookPath) { var workbookFilename = Path.GetFileName(workbookPath); Log.InfoFormat("Publishing workbook '{0}' to {1}..", workbookFilename, tableauConnectionInfo.Uri); var publishWorkbookRequest = new PublishWorkbookRequest(workbookPath) { PluginName = pluginName, SiteId = siteId, SiteName = tableauConnectionInfo.Site, ProjectId = projectId, ProjectName = publishingOptions.ProjectName, // Tag the workbook with the name of the plugin that generated it. Tags = new HashSet <string>(publishingOptions.Tags) { pluginName }, OverwriteExistingWorkbook = publishingOptions.OverwriteExistingWorkbooks, ShowSheetsAsTabs = true, PublishingTimeoutSeconds = tableauConnectionInfo.PublishingTimeoutSeconds }; postgresConnectionInfo.MatchSome(user => { publishWorkbookRequest.DatasourceUserName = user.Username; publishWorkbookRequest.DatasourcePassword = user.Password; }); PublishedWorkbookResult result = requestor.PublishWorkbookWithEmbeddedCredentials(publishWorkbookRequest); int attemptsMade = 1; while (!result.IsSuccessful && attemptsMade < WorkbookPublishingMaxAttempts) { Log.WarnFormat("Workbook publishing attempt #{0} failed. Retrying in {1} {2}..", attemptsMade, WorkbookPublishingRetryDelaySec, "second".Pluralize(WorkbookPublishingRetryDelaySec)); Thread.Sleep(1000 * WorkbookPublishingRetryDelaySec); result = requestor.PublishWorkbookWithEmbeddedCredentials(publishWorkbookRequest); attemptsMade++; } if (!result.IsSuccessful) { Log.ErrorFormat("Publishing of workbook '{0}' failed: {1} [{2} {3} made]", workbookFilename, result.ErrorMessage, attemptsMade, "attempt".Pluralize(attemptsMade)); } return(result); }
protected void InitializeProject(IRestApiRequestor requestor) { // Get all of the information we'll need to compose our publishing requests, and cache it for future publishing attempts. if (String.IsNullOrWhiteSpace(siteId)) { siteId = requestor.GetSiteId(); } if (String.IsNullOrWhiteSpace(projectId)) { projectId = requestor.GetOrCreateProject(publishingOptions.ProjectName, publishingOptions.ProjectDescription); } if (String.IsNullOrWhiteSpace(groupId)) { groupId = requestor.GetGroupId(DefaultProjectPermissionsGroup); } if (!hasSetProjectPermissions) { requestor.AddDefaultProjectPermissions(projectId, groupId, DefaultProjectPermissions); hasSetProjectPermissions = true; } }