public void GenerateResourceAllocationReport(string appTempDirectory) { logger.Info("Reading system settings"); string emailClientIP = ProcessorHelper.GetSettingsValue(ProcessorHelper.EMAIL_PROXY_SERVER); string ownerEmailID = ProcessorHelper.GetSettingsValue(ProcessorHelper.CONTRACTOR_REQ_EMAIL_OWNER); string templateFilePath = ProcessorHelper.GetSettingsValue(ProcessorHelper.TEMPLATE_FOLDER_PATH) + "\\ResourceAllocationReportTemplate.html"; string toEmailID = ProcessorHelper.GetSettingsValue(ProcessorHelper.MANAGERS_EMAIL_GROUP); string outlookPwd = ProcessorHelper.GetSettingsValue(ProcessorHelper.EMAIL_OWNERS_PASSWORD); string emailSubject = "Agilisium - Resource Allocation Report"; string bccEmailIDs = ProcessorHelper.GetSettingsValue(ProcessorHelper.CONTRACTOR_REQ_BCC_RECEIPIENTS); EmailHandler emailHandler = new EmailHandler(ownerEmailID, outlookPwd); string emailContent = GenerateEmailBody(templateFilePath); string attachmentFilePath = GenerateAllocationReportAsCsvFile(appTempDirectory); logger.Info("Sending email with attachment"); emailHandler.SendEmail(emailClientIP, toEmailID, emailSubject, emailContent, bccEmailIDs, attachmentFilePath); WindowsServiceSettingsDto windowsService = new WindowsServiceSettingsDto { ExecutionInterval = "Weekly", ServiceID = (int)WindowsServices.WeeklyAllocationsMailer, ServiceName = WindowsServices.WeeklyAllocationsMailer.ToString(), }; settingRepository.UpdateWindowsServiceStatus(windowsService); }
public int ProcessAllocations() { logger.Info($"Service Execution Time : {DateTime.Today.ToLongTimeString()}"); int newAllocations = 0; try { List <ProjectAllocationDto> activeAllocations = allocationRepo.GetAllRecords().ToList(); List <ProjectAllocationDto> allocationsToProcess = activeAllocations.Where(a => a.AllocationEndDate.Subtract(DateTime.Today).TotalDays <= 31 && a.ProjectName.ToLower().Contains("bench") == false).ToList(); logger.Info($"There are {allocationsToProcess.Count} allocations to be processed"); foreach (ProjectAllocationDto allocation in allocationsToProcess) { logger.Info($"Processing allocation entry with ID {allocation.AllocationEntryID}"); if (allocationRepo.AnyOtherActiveAllocation(allocation.AllocationEntryID, allocation.EmployeeID, allocation.AllocationEndDate)) { logger.Info("found another allocation with the extended date. Email alert will not be sent"); // found another allocation with the extended date. igore this allocation continue; } double daysDifference = allocation.AllocationEndDate.Subtract(DateTime.Today).TotalDays; logger.Info($"Allocation days difference {daysDifference}"); if ((daysDifference > 29 && daysDifference < 31) || (daysDifference > 14 && daysDifference < 16) || (daysDifference > 4 && daysDifference < 6) || (daysDifference > 0 && daysDifference < 2)) { logger.Info("Matching the criteria. Preparing email content"); SendAllocationEmail(allocation); logger.Info("Email sent"); } else if (daysDifference < 0 && daysDifference > -2) { logger.Info("Moving the resource under bench project"); MoveResourceToBenchProject(allocation.EmployeeID); } else { logger.Info("No Alerts will be sent today (only on 30, 15, 5, 1) "); continue; } WindowsServiceSettingsDto windowsService = new WindowsServiceSettingsDto { ExecutionInterval = "Daily", ServiceID = (int)WindowsServices.DailyAllocationsUpdater, ServiceName = WindowsServices.DailyAllocationsUpdater.ToString(), }; settingRepository.UpdateWindowsServiceStatus(windowsService); } } catch (Exception exp) { logger.Error(exp.Message, exp); } return(newAllocations); }
public void GenerateManagementNotifications(string appTempDirectory, int reportingDay) { logger.Info("Reading system settings"); string emailClientIP = ProcessorHelper.GetSettingsValue(ProcessorHelper.EMAIL_PROXY_SERVER); string ownerEmailID = ProcessorHelper.GetSettingsValue(ProcessorHelper.CONTRACTOR_REQ_EMAIL_OWNER); string templateFilePath = ProcessorHelper.GetSettingsValue(ProcessorHelper.TEMPLATE_FOLDER_PATH) + "\\PODWiseEmployees.html"; string toEmailID = null; string outlookPwd = ProcessorHelper.GetSettingsValue(ProcessorHelper.EMAIL_OWNERS_PASSWORD); string emailSubject = "RMT Alert - Please Confirm, Employees Under your POD"; try { logger.Info("Deleting old files"); FilesHandler.RemoveAllFilesFromDirectory(appTempDirectory); } catch (Exception exp) { logger.Error(exp); } List <PracticeDto> pods = practiceRepository.GetAll().ToList(); logger.Info($"There are {pods.Count} PODs"); foreach (PracticeDto pod in pods) { logger.Info("Generating CSV file"); string attachmentFilePath = CreateFileAttachment(appTempDirectory, pod.PracticeID); logger.Info("Generating email content"); string emailContent = GenerateEmailBody(templateFilePath, pod.PracticeID, pod.PracticeName, pod.ManagerName, reportingDay); string managerEmailID = null; if (pod.ManagerID.HasValue) { managerEmailID = empService.GetByID(pod.ManagerID.Value)?.EmailID; } if (string.IsNullOrWhiteSpace(managerEmailID)) { managerEmailID = dmEmailID; } toEmailID = managerEmailID; logger.Info("Sending email with attachment to " + pod.ManagerName); EmailHandler emailHandler = new EmailHandler(ownerEmailID, outlookPwd); emailHandler.SendEmail(emailClientIP, toEmailID, emailSubject, emailContent, dmEmailID, attachmentFilePath, System.Net.Mail.MailPriority.High); WindowsServiceSettingsDto windowsService = new WindowsServiceSettingsDto { ExecutionInterval = "Monthly", ServiceID = (int)WindowsServices.ManagementNotifications, ServiceName = WindowsServices.ManagementNotifications.ToString(), }; settingRepository.UpdateWindowsServiceStatus(windowsService); } }
public void UpdateWindowsServiceStatus(WindowsServiceSettingsDto serviceSettings) { WindowsServiceSettings winService = DataContext.WindowsServiceSettingEntries.FirstOrDefault(w => w.ServiceID == serviceSettings.ServiceID); winService.ExecutedDate = new DateTime(DateTime.Today.Year, DateTime.Today.Month, DateTime.Today.Day); winService.ExecutedTime = $"{DateTime.Today.Hour}:{DateTime.Today.Minute}"; winService.ExecutionInterval = serviceSettings.ExecutionInterval; winService.ServiceName = serviceSettings.ServiceName; winService.UpdateTimeStamp(serviceSettings.LoggedInUserName); DataContext.WindowsServiceSettingEntries.Add(winService); DataContext.Entry(winService).State = EntityState.Modified; DataContext.SaveChanges(); }
public static bool IsExecutionCompleted(WindowsServices serviceName) { WindowsServiceSettingsDto serviceSettings = settingsRepo.GetServiceSettings((int)serviceName); if (serviceSettings.ExecutionInterval == "Daily") { DateTime executedDate = serviceSettings.ExecutedDate.Value; return(executedDate.Day == DateTime.Today.Day && executedDate.Month == DateTime.Today.Month && executedDate.Year == DateTime.Today.Year); } if (serviceSettings.ExecutionInterval == "Weekly") { DateTime startDate = DateTime.Today, endDate = DateTime.Today; switch (DateTime.Today.DayOfWeek) { case DayOfWeek.Sunday: startDate = DateTime.Today; endDate = DateTime.Today.AddDays(6); break; case DayOfWeek.Monday: startDate = DateTime.Today.AddDays(-1); endDate = DateTime.Today.AddDays(5); break; case DayOfWeek.Tuesday: startDate = DateTime.Today.AddDays(-2); endDate = DateTime.Today.AddDays(4); break; case DayOfWeek.Wednesday: startDate = DateTime.Today.AddDays(-3); endDate = DateTime.Today.AddDays(3); break; case DayOfWeek.Thursday: startDate = DateTime.Today.AddDays(-4); endDate = DateTime.Today.AddDays(2); break; case DayOfWeek.Friday: startDate = DateTime.Today.AddDays(-5); endDate = DateTime.Today.AddDays(1); break; case DayOfWeek.Saturday: DateTime.Today.AddDays(-6); endDate = DateTime.Today; break; } return(serviceSettings.ExecutedDate.Value >= startDate && serviceSettings.ExecutedDate.Value <= endDate); } if (serviceSettings.ExecutionInterval == "Monthly") { DateTime startDate = new DateTime(DateTime.Today.Year, DateTime.Today.Month, 1); DateTime endDate = new DateTime(DateTime.Today.Year, DateTime.Today.Month, 28); return(serviceSettings.ExecutedDate.Value >= startDate && serviceSettings.ExecutedDate.Value <= endDate); } return(false); }