static void Main(string[] args) { var workFront_BASE_URL = ConfigurationManager.AppSettings["WorkFront_BASE_URL"]; var workFront_URL = ConfigurationManager.AppSettings["WorkFront_URL"]; var workFront_Username = ConfigurationManager.AppSettings["WorkFront_Username"]; var workFront_Password = ConfigurationManager.AppSettings["WorkFront_Password"]; var workFront_Team_ID = ConfigurationManager.AppSettings["WorkFront_Team_ID"]; var workFrontUpdatesFile = ConfigurationManager.AppSettings["WorkFront_Update_File"]; var slack_webhook_URL = ConfigurationManager.AppSettings["Slack_Webhook_URL"]; var slack_channel = ConfigurationManager.AppSettings["Slack_Channel"]; var slack_username = ConfigurationManager.AppSettings["Slack_Username"]; var slack_user_icon_URL = ConfigurationManager.AppSettings["Slack_User_Icon_URL"]; var csvUpdateList = new List <UpdateForCSV>(); var updatesEncounteredInThisSession = new List <UpdateForCSV>(); if (File.Exists(workFrontUpdatesFile)) { using (TextReader reader = File.OpenText(workFrontUpdatesFile)) { var csv = new CsvReader(reader); csvUpdateList = csv.GetRecords <UpdateForCSV>().ToList(); } } Console.WriteLine("workfront username: "******"update already send to slack previously."); } } } } var updatesToRemoveFromFile = new List <UpdateForCSV>(); for (int i = 0; i < csvUpdateList.Count(); i++) { // loop through the csv file updates, and see if there are records in the file which we did not // encounter in this run of the program. If that is the case, we can prune them from the file // to prevent the file from getting too large. var fileUpdate = csvUpdateList[i]; var searchResult = updatesEncounteredInThisSession.Where(u => u.updateObjCode.Equals(fileUpdate.updateObjCode) && u.updateObjID.Equals(fileUpdate.updateObjID)).FirstOrDefault(); if (searchResult == null) { // we didn't see this update in this run, so we should prune it from the file updatesToRemoveFromFile.Add(fileUpdate); } } foreach (var fileUpdate in updatesToRemoveFromFile) { csvUpdateList.Remove(fileUpdate); } using (TextWriter writer = File.CreateText(workFrontUpdatesFile)) { var csv = new CsvWriter(writer); csv.WriteRecords(csvUpdateList); } workFrontClient.logout(); }