public bool send_email(string site, string[] email_to, string[] email_cc, string[] email_bcc, string email_subject, string username_for_impersonation, string view_location, Dictionary <String, String> view_filter_dictionary) { try { BeholdEmailer tabemailer = this.create_behold_emailer_from_config(site); Watermarker wm = this.create_watermarker_from_config(); try { bool result; result = tabemailer.generate_email_from_view(emailSender.Text, email_to, email_cc, email_bcc, email_subject, "Please see attached Tableau PDF", username_for_impersonation, view_location, "fullpdf", view_filter_dictionary, wm); return(result); } catch (ConfigurationException ce) { this.logger.Log(ce.Message); return(false); } } // From Repository Failing catch (ConfigurationException ce) { this.logger.Log(ce.Message); return(false); } }
public bool SendEmail(string site, string[] emailTo, string[] emailCc, string[] emailBcc, string emailSubject, string usernameForImpersonation, string viewLocation, Dictionary <String, String> viewFiltersMap, string attachmentContentType) { try { BeholdEmailer tabemailer = this.CreateBeholdEmailerFromConfig(site); Watermarker wm = this.CreateWatermarkerFromConfig(); try { bool result; this.Logger.Log("Fixin' to send the e-mail"); result = tabemailer.GenerateEmailFromView(Configurator.GetConfig("email_sender"), emailTo, emailCc, emailBcc, emailSubject, "Please see attached Tableau file", usernameForImpersonation, viewLocation, attachmentContentType.ToLower(), viewFiltersMap, wm); return(result); } catch (ConfigurationException ce) { this.Logger.Log(ce.Message); return(false); } } // From Repository Failing catch (ConfigurationException ce) { this.Logger.Log(ce.Message); return(false); } }
public bool send_email() { try { BeholdEmailer tabemailer = this.create_behold_emailer_from_config(); Watermarker wm = this.create_watermarker_from_config(); try { bool result; result = tabemailer.generate_email_from_view(emailSender.Text, new string[1] { testEmailRecipient.Text }, new string[0] { }, new string[0] { }, testEmailSubject.Text, "Please see attached Tableau PDF", testUsernameForImpersonation.Text, testViewLocation.Text, "fullpdf", new Dictionary <String, String>(), wm); return(result); } catch (ConfigurationException ce) { this.logger.Log(ce.Message); return(false); } } // From Repository Failing catch (ConfigurationException ce) { this.logger.Log(ce.Message); return(false); } }
public bool SendEmail() { try { BeholdEmailer tabemailer = this.CreateBeholdEmailerFromConfig(); Watermarker wm = this.CreateWatermarkerFromConfig(); try { bool result; result = tabemailer.GenerateEmailFromView(Configurator.GetConfig("email_sender"), new string[1] { testEmailRecipient.Text }, new string[0] { }, new string[0] { }, testEmailSubject.Text, "Please see attached Tableau file", singleUsernameForImpersonation.Text, singleViewLocation.Text, "fullpdf", new Dictionary <String, String>(), wm); return(result); } catch (ConfigurationException ce) { this.Logger.Log(ce.Message); return(false); } } // From Repository Failing catch (ConfigurationException ce) { this.Logger.Log(ce.Message); return(false); } }
private Watermarker create_watermarker_from_config() { 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)); } return(wm); }
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."); } }
/* * 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); } }
public bool SendEmail(string scheduleName) { try { BeholdEmailer tabemailer = this.CreateBeholdEmailerFromConfig(); Watermarker wm = this.CreateWatermarkerFromConfig(); try { bool result; if (scheduleName != "") { tabemailer.ExportArchiveFolderPath = Configurator.GetConfig("export_archive_folder"); result = tabemailer.GenerateEmailsFromNamedScheduleInRepository(scheduleName, Configurator.GetConfig("email_sender"), wm); } else { result = tabemailer.GenerateEmailFromView(Configurator.GetConfig("email_sender"), new string[1] { testEmailRecipient.Text }, new string[0] { }, new string[0] { }, testEmailSubject.Text, "Please see attached file", singleUsernameForImpersonation.Text, singleViewLocation.Text, ExportTypeIndexMap[Int32.Parse(Configurator.GetConfig("single_export_type_index"))], new Dictionary <String, String>(), wm); } return(result); } catch (ConfigurationException ce) { this.Logger.Log(ce.Message); return(false); } } // From Repository Failing catch (ConfigurationException ce) { this.Logger.Log(ce.Message); return(false); } }
public bool generate_emails_from_named_schedule_in_repository(string schedule_name, string from_user, Watermarker watermarker) { NpgsqlDataReader dr = this.tabcmd.repository.query_subscriptions_for_users(schedule_name, true); bool all_suceeded = true; var dataTable = new DataTable(); dataTable.Load(dr); dr.Close(); foreach (DataRow row in dataTable.Rows) { string email_subject = row[1].ToString(); string user = row[2].ToString(); string site = row[3].ToString(); string view_location = row[4].ToString(); string user_email = row[6].ToString(); this.tabcmd.site = site; this.log(String.Format("Generating e-mail of view {0} on site {1} for {2} at {3}", view_location, site, user, user_email)); bool result = this.generate_email_from_view(from_user, new string[1] { user_email }, new string[0] { }, new string[0] { }, email_subject, "", user, view_location, "fullpdf", new Dictionary <string, string>(), watermarker); if (all_suceeded == true && result == false) { all_suceeded = false; } if (result == true) { this.log("Email generated succesfully"); } else { this.log("Error creating email"); } } return(all_suceeded); }
public bool generate_email_from_view(string email_from_user, string[] email_to, string[] email_cc, string[] email_bcc, string email_subject, string email_template_name, string view_user, string view_location, string email_content_type, Dictionary <string, string> view_filter_dictionary, Watermarker watermark) { this.log(String.Format("Creating PDF export from tabcmd for {0} for user {1}", view_location, view_user)); try { string filename_to_attach = this.generate_export_and_watermark(view_user, view_location, email_content_type, view_filter_dictionary, watermark); this.log(String.Format("PDF created and saved successfully as {0}", filename_to_attach)); // Copy the file with a new name so that it can be archived string[] file_ending = filename_to_attach.Split('.'); string timestamp_string = DateTime.UtcNow.ToString("s"); timestamp_string = timestamp_string.Replace(":", "_"); timestamp_string = timestamp_string.Replace("-", "_"); string final_filename = String.Format("{0} - {1} - {2}.{3}", email_subject, view_user, timestamp_string, file_ending[file_ending.Length - 1]); if (this.export_archive_folder != null) { final_filename = this.export_archive_folder + final_filename; this.log(String.Format("Achiving export to {0}", final_filename)); } File.Copy(filename_to_attach, final_filename, true); this.log(String.Format("Sending e-mail of exported and watermarked PDF to {0}", email_to[0])); this.email_file_from_template(email_from_user, email_to, email_cc, email_bcc, email_subject, email_template_name, final_filename); this.log(String.Format("Removing original file {0}", filename_to_attach)); File.Delete(filename_to_attach); // Cleanup if no archive if (this.export_archive_folder == "") { this.log(String.Format("Removing e-mailed file {0}", final_filename)); File.Delete(final_filename); } this.log("Email sent successfully"); return(true); } catch (ConfigurationException ce) { this.log(ce.Message); return(false); } }
public string generate_export_and_watermark(string view_user, string view_location, string content_type, Dictionary <string, string> view_filter_dictionary, Watermarker watermark) { string filename_to_attach = this.tabcmd.create_export(content_type, view_location, view_filter_dictionary, view_user, "exported_workbook"); this.log(String.Format("PDF created and saved successfully as {0}", filename_to_attach)); // Watermark the PDF (working copy) if (watermark != null) { this.log("Adding watermark / header / footer to exported PDF"); watermark.add_watermark_to_pdf(filename_to_attach); this.log("Watermarking performed successfully"); } return(filename_to_attach); }
public bool generate_email_from_view(string email_from_user, string[] email_to, string[] email_cc, string[] email_bcc, string email_subject, string email_template_name, string view_user, string view_location, string email_content_type, Dictionary <string, string> view_filter_dictionary, Watermarker watermark) { this.log(String.Format("Creating PDF export from tabcmd for {0} for user {1}", view_location, view_user)); try { string filename_to_attach = this.generate_export_and_watermark(view_user, view_location, email_content_type, view_filter_dictionary, watermark); // If running selected schedules gives error when you put the app in C:\, uncomment the following line: // filename_to_attach = @"C:\Behold Emailer\exported_workbook.pdf"; // This is a hard-coded(bad) fix. this.log(String.Format("PDF created and saved successfully as {0}", filename_to_attach)); // Copy the file with a new name so that it can be archived string[] file_ending = filename_to_attach.Split('.'); string timestamp_string = DateTime.UtcNow.ToString("s"); timestamp_string = timestamp_string.Replace(":", "_"); timestamp_string = timestamp_string.Replace("-", "_"); //The line below makes filename valid when your username has a domain String view_user_temp = view_user.Replace(@"\", "_"); view_user_temp = view_user_temp.Replace(".", "_"); string final_filename = String.Format("{0} - {1} - {2}.{3}", email_subject, view_user_temp, timestamp_string, file_ending[file_ending.Length - 1]); if (this.export_archive_folder != null) { final_filename = this.export_archive_folder + final_filename; this.log(String.Format("Achiving export to {0}", final_filename)); } File.Copy(filename_to_attach, final_filename, true); this.log(String.Format("Sending e-mail of exported and watermarked PDF to {0}", email_to[0])); this.email_file_from_template(email_from_user, email_to, email_cc, email_bcc, email_subject, email_template_name, final_filename, view_location, view_user); this.log(String.Format("Removing original file {0}", filename_to_attach)); File.Delete(filename_to_attach); // Cleanup if no archive if (this.export_archive_folder == "") { this.log(String.Format("Removing e-mailed file {0}", final_filename)); File.Delete(final_filename); } this.log("Email sent successfully"); return(true); } catch (ConfigurationException ce) { this.log(ce.Message); return(false); } }
// This is the wrapper method for pulling all of the e-mails on the next schedule and generating them public bool GenerateEmailsFromNamedScheduleInRepository(string scheduleName, string fromAddress, Watermarker watermarker) { // Pull all of the scheduled e-mails NpgsqlDataReader dr = this.Tabcmd.Repository.QuerySubscriptionsForUsers(scheduleName, true); bool suceededFlag = true; var dataTable = new DataTable(); dataTable.Load(dr); dr.Close(); // For each of the scheduled e-mails, build and e-mail foreach (DataRow row in dataTable.Rows) { string emailSubject = row[1].ToString(); string user = row[2].ToString(); string site = row[3].ToString(); string viewLocation = row[4].ToString(); string userEmail = row[6].ToString(); this.Tabcmd.Site = site; this.Log(String.Format("Generating e-mail of view {0} on site {1} for {2} at {3}", viewLocation, site, user, userEmail)); // Call to the method that generates the e-mails bool result = this.GenerateEmailFromView(fromAddress, new string[1] { userEmail }, new string[0] { }, new string[0] { }, emailSubject, "", user, viewLocation, "fullpdf", new Dictionary <string, string>(), watermarker); if (suceededFlag == true && result == false) { suceededFlag = false; } if (result == true) { this.Log("Email generated succesfully"); } else { this.Log("Error creating email"); } } return(suceededFlag); }
// This is the main wrapper method for pulling the PDF, watermarking it, then e-mailing it out public bool GenerateEmailFromView(string fromAddress, string[] toAddresses, string[] ccAddresses, string[] bccAddresses, string emailSubject, string emailTemplateFilename, string viewUsername, string viewLocation, string attachmentContentFileType, Dictionary <string, string> viewFilterMap, Watermarker watermarker) { this.Log("Sending from " + fromAddress); this.Log(String.Format("Creating {2} export from tabcmd for {0} for user {1}", viewLocation, viewUsername, attachmentContentFileType)); try { string filenameToAttach = this.GenerateExportAndWatermark(viewUsername, viewLocation, attachmentContentFileType, viewFilterMap, watermarker); this.Log(String.Format("{1} created and saved successfully as {0}", filenameToAttach, attachmentContentFileType)); // Copy the file with a new name so that it can be archived string[] fileEnding = filenameToAttach.Split('.'); string timestamp = DateTime.UtcNow.ToString("s"); timestamp = timestamp.Replace(":", "_"); timestamp = timestamp.Replace("-", "_"); string finalFilename = String.Format("{0} - {1} - {2}.{3}", emailSubject, viewUsername, timestamp, fileEnding[fileEnding.Length - 1]); finalFilename = this.ExportArchiveFolderPath + finalFilename; this.Log(String.Format("Achiving export to {0}", finalFilename)); File.Copy(filenameToAttach, finalFilename, true); this.Log(String.Format("Sending e-mail of exported (and watermarked) file to {0}", toAddresses[0])); this.EmailFileFromTemplate(fromAddress, toAddresses, ccAddresses, bccAddresses, emailSubject, emailTemplateFilename, finalFilename); this.Log(String.Format("Removing original file {0}", filenameToAttach)); File.Delete(filenameToAttach); // Cleanup if no archive if (!SaveEmailsToArchive) { this.Log(String.Format("Removing e-mailed file {0}", finalFilename)); File.Delete(finalFilename); } this.Log("Email sent successfully"); return(true); } catch (ConfigurationException ce) { this.Log(ce.Message); return(false); } }
// Wrapper combination function to create the export public string GenerateExportAndWatermark(string viewUser, string viewLocation, string contentType, Dictionary <string, string> viewFilterDictionary, Watermarker watermarker) { string filenameToAttach = this.Tabcmd.CreateExportFile(contentType, viewLocation, viewFilterDictionary, viewUser, "exported_workbook"); this.Log(String.Format("{1} created and saved successfully as {0}", filenameToAttach, contentType)); // Watermark the PDF (working copy) if PDF if (contentType == "fullpdf" || contentType == "pdf") { if (watermarker != null) { this.Log("Adding watermark / header / footer to exported PDF"); watermarker.AddWatermarkToPdf(filenameToAttach); this.Log("Watermarking performed successfully"); } } return(filenameToAttach); }