private BeholdEmailer CreateBeholdEmailerFromConfig(string site) { var tabrep = new TableauRepository( Configurator.GetConfig("tableau_server"), Configurator.GetConfig("repository_pw"), "readonly" ) { logger = this.Logger }; var tabcmd = new Tabcmd( Configurator.GetConfig("tabcmd_program_location"), Configurator.GetConfig("tableau_server"), Configurator.GetConfig("server_admin_username"), Configurator.GetConfig("server_admin_password"), site, Configurator.GetConfig("tabcmd_config_location"), tabrep, this.Logger ); BeholdEmailer tabemailer = new BeholdEmailer(tabcmd, this.CreateSmtpClientFromConfig()); tabemailer.Logger = this.Logger; tabemailer.HtmlEmailTemplateFilename = Configurator.GetConfig("html_email_template_filename"); tabemailer.TextEmailTemplateFilename = Configurator.GetConfig("text_email_template_filename"); return(tabemailer); }
// In this situation you create the tabcmd and smtpClient objects separately public BeholdEmailer(Tabcmd tabcmd, SmtpClient smtpClient) { this.Tabcmd = tabcmd; this.TableauServerUrl = this.Tabcmd.TableauServerUrl; this.SmtpServer = smtpClient; this.HtmlEmailTemplateFilename = ""; this.TextEmailTemplateFilename = ""; this.Logger = null; this.ExportArchiveFolderPath = null; if (Configurator.GetConfigBool("save_emailed_copies_flag")) { SaveEmailsToArchive = Configurator.GetConfigBool("save_emailed_copies_flag"); } if (!String.IsNullOrEmpty(Configurator.GetConfig("export_archive_folder"))) { this.ExportArchiveFolderPath = Configurator.GetConfig("export_archive_folder"); } // Cancel action if no archive folder exists else { MessageBox.Show("Please configure the local save folder", "No Local Configuration", MessageBoxButtons.OK, MessageBoxIcon.Error); throw new ConfigurationException("Please configure the local save folder"); } }
// Original constructor created the tabcmd object public BeholdEmailer(string tabcmdDirectory, string tabcmdConfigLocation, string repositoryPassword, string tableauServerUrl, string tableauServerAdminUsername, string tableauServerAdminPassword, string smtpServerName, string smtpServerUsername, string smtpServerPassword) { this.TableauServerUrl = tableauServerUrl; this.RepositoryPassword = repositoryPassword; this.SmtpServer = new SmtpClient(smtpServerName); this.HtmlEmailTemplateFilename = ""; this.TextEmailTemplateFilename = ""; // Add credentials stuff here this.Tabcmd = new Tabcmd(tabcmdDirectory, tableauServerUrl, tableauServerAdminUsername, tableauServerAdminPassword, "default", repositoryPassword, tabcmdConfigLocation); this.Logger = null; if (Configurator.GetConfigBool("save_emailed_copies_flag")) { SaveEmailsToArchive = Configurator.GetConfigBool("save_emailed_copies_flag"); } if (!String.IsNullOrEmpty(Configurator.GetConfig("export_archive_folder"))) { this.ExportArchiveFolderPath = Configurator.GetConfig("export_archive_folder"); } // Cancel action if no archive folder exists else { MessageBox.Show("Please configure the local save folder", "No Local Configuration", MessageBoxButtons.OK, MessageBoxIcon.Error); throw new ConfigurationException("Please configure the local save folder"); } }
public BeholdEmailer(Tabcmd Tabcmd, SmtpClient smtp_client) { this.tabcmd = Tabcmd; this.tableau_server_url = this.tabcmd.tableau_server_url; this.smtp_server = smtp_client; this.html_email_template_filename = ""; this.text_email_template_filename = ""; this.logger = null; this.export_archive_folder = null; }
private string GenerateSingleExport(string exportSite, string exportUsername, string exportViewLocation, string exportAttachmentType, string exportFilename, Dictionary <string, string> viewFilterDictionary) { // Generate Single File try { TableauRepository tabrep = new TableauRepository( Configurator.GetConfig("tableau_server"), Configurator.GetConfig("repository_pw"), "readonly" ); tabrep.logger = this.Logger; Tabcmd tabcmd = new Tabcmd( Configurator.GetConfig("tabcmd_program_location"), Configurator.GetConfig("tableau_server"), Configurator.GetConfig("server_admin_username"), Configurator.GetConfig("server_admin_password"), exportSite, Configurator.GetConfig("tabcmd_config_location"), tabrep, this.Logger ); // Emailer here is used because the Watermarking is built in there. Would it make more sense to move it to Tabcmd eventually, or its own class? BeholdEmailer tabemailer = new BeholdEmailer(tabcmd, Configurator.GetConfig("smtp_server")); Watermarker wm = new Watermarker(); string[] pageLocations = { "top_left", "top_center", "top_right", "bottom_left", "bottom_center", "bottom_right" }; foreach (string pageLocation in pageLocations) { string settingsPageLocation = pageLocation.Split('_')[0] + pageLocation.Split('_')[1].First() + pageLocation.Split('_')[1].Substring(1); wm.SetPageLocationWatermarkFromConfig(pageLocation, Configurator.GetConfigSerializableStringDict(settingsPageLocation)); } string filename = tabemailer.GenerateExportAndWatermark(exportUsername, exportViewLocation, exportAttachmentType, viewFilterDictionary, wm); string[] fileEnding = filename.Split('.'); string finalFilename = String.Format("{0}{1}.{2}", Configurator.GetConfig("export_archive_folder"), exportFilename, fileEnding[fileEnding.Length - 1]); this.Logger.Log(String.Format("Finalizing file and putting it here: {0}", finalFilename)); File.Copy(filename, finalFilename, true); this.Logger.Log(String.Format("Removing original file {0}", filename)); File.Delete(filename); return("Finished single export file creation. Saved to: " + finalFilename); } catch (ConfigurationException ce) { //progress.finish_progress_bar(33); // progress.update_status("Export failed for some reason, most likely bad settings.\nCheck logs for more info"); this.Logger.Log(ce.Message); return("Single export failed. Please see logs for more information."); } }
public BeholdEmailer(string tabcmd_dir, string tabcmd_config_location, string repository_pw, string tableau_server_url, string tableau_server_admin_user, string tableau_server_admin_pw, string smtp_server, string smtp_username, string smtp_password) { this.tableau_server_url = tableau_server_url; this.repository_pw = repository_pw; this.smtp_server = new SmtpClient(smtp_server); this.html_email_template_filename = ""; this.text_email_template_filename = ""; // Add credentials stuff here this.tabcmd = new Tabcmd(tabcmd_dir, tableau_server_url, tableau_server_admin_user, tableau_server_admin_pw, "default", repository_pw, tabcmd_config_location); this.logger = null; this.export_archive_folder = null; }
/* * Test Page Methods */ private void create_test_export(object sender, EventArgs e) { // Needs validation here TextBox[] elements_to_validate = { testFileSaveLocation, testFilename, testSite, testUsernameForImpersonation, testViewLocation }; bool validation = this.validate_set_of_elements(elements_to_validate); if (validation == false) { return; } Progress progress = new Progress(0, "Creating test file"); progress.Show(this); progress.Update(); try { TableauRepository tabrep = new TableauRepository(tableau_server_url.Text, repositoryPW.Text, "readonly"); tabrep.logger = this.logger; Tabcmd tabcmd = new Tabcmd(tabcmdProgramLocation.Text, tableau_server_url.Text, server_admin_username.Text, server_password.Text, testSite.Text, tabcmdConfigLocation.Text, tabrep, this.logger); // Emailer here is used because the Watermarking is built in there. Would it make more sense to move it to Tabcmd eventually, or its own class? BeholdEmailer tabemailer = new BeholdEmailer(tabcmd, emailServer.Text); Watermarker wm = new Watermarker(); string[] page_locations = { "top_left", "top_center", "top_right", "bottom_left", "bottom_center", "bottom_right" }; foreach (string page_location in page_locations) { string settingsPageLocation = page_location.Split('_')[0] + page_location.Split('_')[1].First() + page_location.Split('_')[1].Substring(1); wm.setPageLocationWatermarkFromConfig(page_location, Configurator.GetConfigSerializableStringDict(settingsPageLocation)); } string filename = tabemailer.generate_export_and_watermark(testUsernameForImpersonation.Text, testViewLocation.Text, "fullpdf", new Dictionary <string, string>(), wm); string[] file_ending = filename.Split('.'); string final_filename = String.Format("{0}{1}.{2}", testFileSaveLocation.Text, testFilename.Text, file_ending[file_ending.Length - 1]); this.logger.Log(String.Format("Finalizing file and putting it here: {0}", final_filename)); File.Copy(filename, final_filename, true); this.logger.Log(String.Format("Removing original file {0}", filename)); File.Delete(filename); progress.finish_progress_bar(100); progress.update_status("Export created successfully!"); } catch (ConfigurationException ce) { progress.finish_progress_bar(33); progress.update_status("Export failed for some reason, most likely bad settings.\nCheck logs for more info"); this.logger.Log(ce.Message); } }
private BeholdEmailer create_behold_emailer_from_config(string site) { TableauRepository tabrep = new TableauRepository(tableau_server_url.Text, repositoryPW.Text, "readonly"); tabrep.logger = this.logger; Tabcmd tabcmd = new Tabcmd(tabcmdProgramLocation.Text, tableau_server_url.Text, server_admin_username.Text, server_password.Text, site, tabcmdConfigLocation.Text, tabrep, this.logger); BeholdEmailer tabemailer = new BeholdEmailer(tabcmd, this.create_smtp_client_from_config()); tabemailer.logger = this.logger; tabemailer.html_email_template_filename = htmlEmailFilename.Text; tabemailer.text_email_template_filename = textEmailFilename.Text; return(tabemailer); }