private void InitializeDatabase() { string skills = "C#, Python, C++, Ruby, JavaScript, C, PHP, Go, Scala, Perl, Objective C"; using (System.Data.Entity.DbContext skillsDbContext = new DL.DataStore((new ConfigurationReader()).GetConnectionString("DefaultConnection"))) { BL.SkillsBL skillsManager = new BL.SkillsBL(new DL.SkillsRepository(skillsDbContext)); if (skillsManager.FindAll().Count() == 0) { skills.Split(',').ToList().ForEach(s => skillsManager.Add(new BusinessObjects.Skill() { SkillName = s.Trim() })); } } }
static void Main(string[] args) { Console.WriteLine("Starting the service"); List<Task> allTasks = new List<Task>(); DateTime reportDate = DateTime.Today.AddDays(-1); string reportFileFullName = string.Format(@"{0}\{1}.txt", ConfigReader.ReadFromApplicationConfiguration("ReportBaseLocation"), reportDate.ToString("yyyyMMdd")); string hostName = ConfigReader.ReadFromApplicationConfiguration("HostName"); int port = Convert.ToInt32(ConfigReader.ReadFromApplicationConfiguration("Port")); string networkUsername = ConfigReader.ReadFromApplicationConfiguration("NetworkUsername"); string networkPassword = ConfigReader.ReadFromApplicationConfiguration("NetworkPassword"); string fromMailId = ConfigReader.ReadFromApplicationConfiguration("FromMailId"); string[] allEmailRecipients = ConfigReader.ReadFromApplicationConfiguration("EmailRecipients").Split(';'); string mailBody = string.Format(_mailBody, reportDate.ToShortDateString(), reportFileFullName); using (DbContext candidateInfoDbContext = new DL.DataStore(ConfigReader.GetConnectionString("DefaultConnection"))) { IRepository<CandidateInformation> candidateInfoRepo = new DL.CandidateInformationRepository(candidateInfoDbContext); IReportGenerator reportGenerator = new ReportGenerator(reportDate, candidateInfoRepo); IReportWriter reportFileWriter = new ReportFileWriter(reportFileFullName, reportGenerator); allTasks.Add(reportFileWriter.WriteAsync()); ISmtpClientBuilder smtpClientBuilder = new SmtpClientBuilder(hostName, port, new System.Net.NetworkCredential(networkUsername, networkPassword), enableSsl: true); IMailMessageBuilder mailMessageBuilder = new MailMessageBuilder(fromMailId, allEmailRecipients, "Report generated", mailBody); INotifier mailNotifier = new EmailNotifier(smtpClientBuilder, mailMessageBuilder); allTasks.Add(mailNotifier.SendAsync()); try { Task.WaitAll(allTasks.ToArray()); } catch (AggregateException aEx) { foreach (var e in aEx.InnerExceptions) { Console.WriteLine(e.ToString()); } Console.WriteLine("Press any key to continue..."); Console.ReadLine(); } } Console.WriteLine("Completed the service."); }