/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void button1_Click(object sender, EventArgs e) { // track enter and exit this.breakOutExited = false; if (lblExcelFileStatus.BackColor != Color.DarkGreen || lblConfirmedWorksheet.BackColor != Color.DarkGreen || lblAdvancedOptions.BackColor != Color.DarkGreen) { MessageBox.Show("Donna, you forgot a step make sure everything is green!", "Hey Donna... :-)"); return; } KeyInput input = new KeyInput(); ApplicationSettings settings = new ApplicationSettings(); // set csv output string csvOutput = settings.FILE_EXPORT_PATH; // remove files CleanUp(settings.WEB_EXPORT_PATH); try { // on new run, remove output file if (File.Exists(csvOutput)) { File.Copy(csvOutput, csvOutput.Replace(".csv", "_" + DateTime.Now.ToFileTime() + ".csv")); File.Delete(csvOutput); } } catch (Exception) { MessageBox.Show("Donna, did you close the Output.csv file? Close it, then press OK.", "Hey Donna... :-)"); File.Copy(csvOutput, csvOutput.Replace(".csv", "_" + DateTime.Now.ToFileTime() + ".csv")); File.Delete(csvOutput); } // check what was chosen Advanced.TREE_TYPE treeChosen = (this.radioEmailInactive.Checked) ? Advanced.TREE_TYPE.EMAIL_INACTIVE : Advanced.TREE_TYPE.EMAIL_ACTIVE; // based on the chosen value, load the new configuration Advanced advanced = new Advanced(treeChosen); // exit if the file goes away if (!File.Exists(this.excelFileLocation)) { return; } List <string[]> idNumbers = uwExcel.createFromExcel(this.excelFileLocation, "A", "B", txtWorksheetName.Text); // excel row number from original int rowIndexNo = 1; int startFromIndex = 0; int endIndexRow = 0; // startFrom if (settings.START_AT_ROW > 0) { startFromIndex = settings.START_AT_ROW; } // startFrom if (settings.END_AT_ROW > 0) { endIndexRow = settings.END_AT_ROW; } foreach (string[] person in idNumbers) { if (startFromIndex > 0) { if (rowIndexNo - 1 <= startFromIndex) { rowIndexNo++; continue; } } // skip if missing id number if (String.IsNullOrEmpty(person[0])) { rowIndexNo++; continue; } Process chrome = Process.Start(settings.DEFAULT_BROWSER_EXE, advanced.GetNewEndpoint(person[0], treeChosen)); Thread.Sleep(settings.DEFAULT_SLEEP_INTERVAL); foreach (var browserInstruction in input.InstructionsBrowser) { SendKeys.SendWait(browserInstruction); if (browserInstruction != "^{w}") { Thread.Sleep(settings.DEFAULT_SLEEP_INTERVAL); } } // remove files CleanUp(settings.WEB_EXPORT_PATH); var html = Clipboard.GetText(); Dictionary <string, EmailRecord> emailList = loadHtmlGetElementsBySelector(html, advanced); // if no emails returned skip if (emailList.Count == 0) { rowIndexNo++; continue; } // check index rowIndexNo++; // This text is always added, making the file longer over time // if it is not deleted. using (StreamWriter sw = File.AppendText(csvOutput)) { foreach (string key in emailList.Keys) { EmailRecord tempRecord = emailList[key]; if (tempRecord.status != Advanced.GetTreeTypeStatus(treeChosen)) { continue; } sw.WriteLine("{0},{1},{2},{3}", person[0], tempRecord.emailAddress, tempRecord.status, rowIndexNo); } } if (this.breakOutExited) { // break out break; } if (endIndexRow > 0) { if (rowIndexNo - 1 >= endIndexRow) { rowIndexNo++; // break out as it is the end. break; } } } }