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); } }
public DownloadHelper() { this.jsonConfigObj = jsonConfigObj; }