public RenewalGenerationResults GenerateRenewalLetters(string InputFile, string OutPutFolder) { try { if (!File.Exists(InputFile)) { throw new FileNotFoundException("File Not Found", InputFile); } if (!Directory.Exists(OutPutFolder)) { throw new DirectoryNotFoundException("Folder Not Found"); } int lettersNotGeneratedCount = 0; DAL.DataRepo dataRepo = new DAL.DataRepo(OutPutFolder); List <DAL.CustomerItem> customerList = dataRepo.GetCustomersFromInputFile(InputFile); for (int i = 0; i < customerList.Count; i++) { DAL.CustomerItem customerItem = customerList[i]; if (customerItem.IsValid) { customerItem.CalculateMonthlyPayments(); string letterBody = generateLetterBody(customerItem); DAL.CreateResults sResults = dataRepo.CreateReminderLetter(letterBody, customerItem.ID, customerItem.FirstName + customerItem.SurName); if (!sResults.Success) { //sResults.Message //This file has not been created so Log this. Perhaps a monitor would be set to alert Support in this eventuality. log.Error(sResults.Message); lettersNotGeneratedCount++; } } else { //Log that the input row is invalid. log.Error(string.Format("Row {0} of file [{1}] has invalid items.", i.ToString(), InputFile)); } } return(new RenewalGenerationResults(customerList.Count - lettersNotGeneratedCount, lettersNotGeneratedCount)); } catch (Exception ex) { throw ex; } }