static async Task MainAsync(List <Target> data, SystemConfiguration configuration) { scrapeWeb = new ScrapeService(); scrapeWeb.LogEvent += ScrapeWeb_LogEvent; var outcomes = await scrapeWeb.ExecuteAsync(data); var filtered = outcomes.Where(x => x.KeywordsFound == true).GroupBy(y => y.Title); foreach (var value in filtered) { Log(ConsoleColor.DarkGreen, $"{value.Key} - {value.Count()}"); } if (configuration.GenerateCsv) { //generating the CSV CsvService csv = new CsvService(); using (MemoryStream ms = csv.Generate(outcomes)) { using (FileStream file = new FileStream(Path.Combine(@"Data/Output", DateTime.Now.ToString("yyyyMMdd"), "output.csv"), FileMode.Create, System.IO.FileAccess.Write)) { ms.CopyTo(file); } } } if (configuration.SendEmail) { //adding the CSV to the email if (configuration.GenerateCsv) { configuration.EmailMessage.Attachments.Add( new EmailAttachment(Convert.ToBase64String(File.ReadAllBytes(Path.Combine(@"Data/Output", DateTime.Now.ToString("yyyyMMdd"), "output.csv"))), "output.csv") ); } EmailService service = new EmailService(configuration); await service.SendAsync(outcomes); } }