internal void ReportFailures(string startupPath, string emailTo, string emailFrom) { if (RunSheetFailures.Count > 0) { StringBuilder sb = new StringBuilder(); sb.AppendLine("<h2>ABS Butler Report</h2>"); sb.Append("<BR><BR>"); sb.Append("<BR><BR>"); sb.Append("By: "); sb.Append(Environment.UserName); sb.Append(", on machine: "); sb.Append(Environment.MachineName); sb.Append(" from: "); sb.Append(startupPath); sb.Append("<BR><BR>"); sb.Append("<Table border=1>"); sb.Append("<tr><td width=100><b>Status</b></td><td width=100><b>File Name</b></td><td width=100><b></b></td>Download URL<td width=300><b>ABS Page</b></td></tr>"); foreach (string line in RunSheetFailures) { sb.AppendLine(line); } sb.Append("</Table>"); EmailSMTP.SendEmail(emailTo, "", "", "ABS Butler Report", sb.ToString(), null, jsonConfigObj.FromEmail, jsonConfigObj.SMTPPassword, jsonConfigObj.SMTPDomain, jsonConfigObj.SMTPHost, jsonConfigObj.SMTPPort, jsonConfigObj.SMTPTLSEnabled); } }
private bool SaveRunSheet() { try { string runSheetTSVFile = Path.Combine(Application.StartupPath.Replace("\\bin\\Debug", ""), DownloadHelper.ABSFILETORUNCSV); var sb = new StringBuilder(); var headers = dgv.Columns.Cast <DataGridViewColumn>(); sb.AppendLine(string.Join("\t", headers.Select(column => column.HeaderText).ToArray())); foreach (DataGridViewRow row in dgv.Rows) { if (string.IsNullOrEmpty(row.Cells[0].ToString())) { continue; } var cells = row.Cells.Cast <DataGridViewCell>(); sb.AppendLine(string.Join("\t", cells.Select(cell => cell.Value).ToArray())); } File.WriteAllText(runSheetTSVFile, sb.ToString()); } catch (Exception ex) { if (AutoRunFromCommandLineParameter) { EmailSMTP.SendEmail(jsonConfigObj.EmailAlerts, "", "", "ABSButler Error", "WARNING: You need to make sure the " + DownloadHelper.ABSFILETORUNCSV + " file has Read Write permissions. Exception: " + ex.Message + "<BR><BR>StackTrace:<BR>" + ex.StackTrace, null, jsonConfigObj.FromEmail, jsonConfigObj.SMTPPassword, jsonConfigObj.SMTPDomain, jsonConfigObj.SMTPHost, jsonConfigObj.SMTPPort, jsonConfigObj.SMTPTLSEnabled); } else { MessageBox.Show("WARNING: You need to make sure the " + DownloadHelper.ABSFILETORUNCSV + " file has Read Write permissions otherwise you will download all files from the ABS everyday! Exception: " + ex.Message); } return(false); } return(true); }
private void LoadRunSheet() { string runSheetFile = Path.Combine(Application.StartupPath.Replace("\\bin\\Debug", ""), "RunSheet.tsv"); if (!File.Exists(runSheetFile)) { if (AutoRunFromCommandLineParameter) { EmailSMTP.SendEmail(jsonConfigObj.EmailAlerts, "", "", "ABSButler Error", "WARNING: The " + DownloadHelper.ABSFILETORUNCSV + " file does not exist in the Applications Startup Folder: " + Application.StartupPath + Environment.NewLine + Environment.NewLine + "ABSButler will now quit.", null, jsonConfigObj.FromEmail, jsonConfigObj.SMTPPassword, jsonConfigObj.SMTPDomain, jsonConfigObj.SMTPHost, jsonConfigObj.SMTPPort, jsonConfigObj.SMTPTLSEnabled); } else { MessageBox.Show("The RunSheet.tsv file does not exist in the Applications Startup Folder: " + Application.StartupPath + Environment.NewLine + Environment.NewLine + "ABSButler will now quit.", "Cannot find run sheet file...", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } Environment.Exit(3); } List <string[]> rows = FileHelper.ReadFileTextWithEncoding(runSheetFile).Split(new string[] { Environment.NewLine }, StringSplitOptions.None).Select(x => x.Split('\t')).ToList(); dataTable.Columns.Add("Directory to Download"); dataTable.Columns.Add("Links Include Words"); dataTable.Columns.Add("Time Series Page"); dataTable.Columns.Add("Last Working URL"); try { //Skip the header record in the RunSheet.tsv file and load the remaining records into a DataTable rows.Skip(1).ToList().ForEach(x => { dataTable.Rows.Add(x); }); } catch (Exception ex) { if (AutoRunFromCommandLineParameter) { EmailSMTP.SendEmail(jsonConfigObj.EmailAlerts, "", "", "ABSButler Error", "WARNING: The " + DownloadHelper.ABSFILETORUNCSV + " file failed to load, Exception: " + ex.Message + "<BR><BR>StackTrace:<BR>" + ex.StackTrace, null, jsonConfigObj.FromEmail, jsonConfigObj.SMTPPassword, jsonConfigObj.SMTPDomain, jsonConfigObj.SMTPHost, jsonConfigObj.SMTPPort, jsonConfigObj.SMTPTLSEnabled); } else { MessageBox.Show("The RunSheet.tsv file failed to load, Exception: " + ex.Message + Environment.NewLine + Environment.NewLine + "ABSButler will now quit.", "Failed to load config file...", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } Environment.Exit(4); } if (string.IsNullOrEmpty(dataTable.Rows[dataTable.Rows.Count - 1][0].ToString())) { dataTable.Rows.RemoveAt(dataTable.Rows.Count - 1); } dgv.DataSource = dataTable; dgv.Columns[0].Width = 790; dgv.Columns[1].Width = 125; dgv.Columns[2].Width = 124; dgv.Columns[3].Width = 543; progressBar1.Maximum = dataTable.Rows.Count; }
private void LoadConfiguration() { string configJSONFile = Path.Combine(Application.StartupPath.Replace("\\bin\\Debug", ""), "Configuration.json"); if (!File.Exists(configJSONFile)) { MessageBox.Show("The Configuration.json file does not exist in the Applications Startup Folder: " + Application.StartupPath + Environment.NewLine + Environment.NewLine + "ABSButler will now quit.", "Cannot find config file...", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); Environment.Exit(1); } try { for (int i = 0; i < 25; i++) { cboMaxMonths.Items.Add(i.ToString()); } string jsonConfigFileContents = FileHelper.ReadFileTextWithEncoding(configJSONFile); jsonConfigObj = fastJSON.JSON.ToObject <JSONConfig>(jsonConfigFileContents); txtEmailAlerts.Text = jsonConfigObj.EmailAlerts; txtEmailFrom.Text = jsonConfigObj.FromEmail; txtSMTPHost.Text = jsonConfigObj.SMTPHost; txtSMTPDomain.Text = jsonConfigObj.SMTPDomain; txtEmailFromPassword.Text = jsonConfigObj.SMTPPassword; txtSMTPPort.Text = jsonConfigObj.SMTPPort.ToString(); chkTLS.Checked = Convert.ToBoolean(jsonConfigObj.SMTPTLSEnabled); cboMaxMonths.SelectedIndex = Convert.ToInt32(jsonConfigObj.MaxMonthsToLookBack); } catch (Exception ex) { if (AutoRunFromCommandLineParameter) { EmailSMTP.SendEmail(jsonConfigObj.EmailAlerts, "", "", "ABSButler Error", "WARNING: The Configuration.json file failed to load, Exception: " + ex.Message + "<BR><BR>StackTrace:<BR>" + ex.StackTrace, null, jsonConfigObj.FromEmail, jsonConfigObj.SMTPPassword, jsonConfigObj.SMTPDomain, jsonConfigObj.SMTPHost, jsonConfigObj.SMTPPort, jsonConfigObj.SMTPTLSEnabled); } else { MessageBox.Show("The Configuration.json file failed to load, Exception: " + ex.Message + Environment.NewLine + Environment.NewLine + "ABSButler will now quit.", "Failed to load config file...", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } Environment.Exit(2); } }
private void Form1_Load(object sender, EventArgs e) { try { //Note no need to test these private methods, espcially if they populate 4 obvious fields on App Start Up LoadConfiguration(); LoadRunSheet(); if (AutoRunFromCommandLineParameter) { btnGo_Click(null, null); Environment.Exit(0); } System.Reflection.Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly(); FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(assembly.Location); string version = fvi.FileVersion; this.Text = "ABS Butler v" + version; } catch (Exception ex) { EmailSMTP.SendEmail(jsonConfigObj.EmailAlerts, "", "", "Exception in ABSButler!! Form1_Load", "Message: " + ex.Message + "<BR><BR>StackTrace:<BR>" + ex.StackTrace, null, jsonConfigObj.FromEmail, jsonConfigObj.SMTPPassword, jsonConfigObj.SMTPDomain, jsonConfigObj.SMTPHost, jsonConfigObj.SMTPPort, jsonConfigObj.SMTPTLSEnabled); } }
private void btnSendTest_Click(object sender, EventArgs e) { EmailSMTP.SendEmail(txtEmailAlerts.Text, "", "", "ABSButler Report", "TEST", null, jsonConfigObj.FromEmail, jsonConfigObj.SMTPPassword, jsonConfigObj.SMTPDomain, jsonConfigObj.SMTPHost, jsonConfigObj.SMTPPort, jsonConfigObj.SMTPTLSEnabled); }