public Task Execute(IJobExecutionContext context) { try { _logger.LogInformation("Запуск синхронизации с AD!"); var iRPCSDbAccessor = (IRPCSDbAccessor) new RPCSSingletonDbAccessor(_dbContextOptions); var rPCSRepositoryFactory = (IRepositoryFactory) new RPCSRepositoryFactory(iRPCSDbAccessor); var userService = new UserService(rPCSRepositoryFactory, _httpContextAccessor); var departmentService = new DepartmentService(rPCSRepositoryFactory, userService); var employeeService = new EmployeeService(rPCSRepositoryFactory, departmentService, userService); var taskSyncWithAD = new SyncWithADTask(employeeService, _adConfigOptions); string id = Guid.NewGuid().ToString(); ADSyncResult adSyncResult = null; if (taskSyncWithAD.Add(id, true) == true) { try { adSyncResult = taskSyncWithAD.ProcessLongRunningAction("", id, true); _memoryCache.Set(adSyncResult.fileId, adSyncResult.fileHtmlReport); } catch (Exception) { } taskSyncWithAD.Remove(id); } if (adSyncResult != null && String.IsNullOrEmpty(adSyncResult.fileHtmlReport) == false && !string.IsNullOrEmpty(_adConfig.SyncEmailRecievers)) { RPCSEmailHelper.SendHtmlEmailViaSMTP(_adConfig.SyncEmailRecievers, "Отчет о синхронизации данных с Active Directory " + DateTime.Now.ToString(), null, null, adSyncResult.fileHtmlReport, null, null); } } catch (Exception e) { _logger.LogError(e.Message); string errorMessage = e.Message; } _logger.LogInformation("Окончание процесса синхронизации с AD"); return(Task.CompletedTask); }
public Task Execute(IJobExecutionContext context) { try { var iRPCSDbAccessor = (IRPCSDbAccessor) new RPCSSingletonDbAccessor(_dbOptions); var rPCSRepositoryFactory = (IRepositoryFactory) new RPCSRepositoryFactory(iRPCSDbAccessor); var userService = (IUserService) new UserService(rPCSRepositoryFactory, _httpContextAccessor); var tsAutoHoursRecordService = (ITSAutoHoursRecordService) new TSAutoHoursRecordService(rPCSRepositoryFactory, userService); var vacationRecordService = (IVacationRecordService) new VacationRecordService(rPCSRepositoryFactory, userService); var reportingPeriodService = (IReportingPeriodService) new ReportingPeriodService(rPCSRepositoryFactory); var productionCalendarService = (IProductionCalendarService) new ProductionCalendarService(rPCSRepositoryFactory); var tsHoursRecordService = (ITSHoursRecordService) new TSHoursRecordService(rPCSRepositoryFactory, userService, _tsHoursRecordServiceLogger); var projectService = (IProjectService) new ProjectService(rPCSRepositoryFactory, userService); var departmentService = new DepartmentService(rPCSRepositoryFactory, userService); var employeeService = (IEmployeeService) new EmployeeService(rPCSRepositoryFactory, departmentService, userService); var projectMembershipService = (IProjectMembershipService) new ProjectMembershipService(rPCSRepositoryFactory); var employeeCategoryService = new EmployeeCategoryService(rPCSRepositoryFactory); var projectReportRecords = new ProjectReportRecordService(rPCSRepositoryFactory); var applicationUserService = new ApplicationUserService(rPCSRepositoryFactory, employeeService, userService, departmentService, _httpContextAccessor, _memoryCache, projectService, _onlyOfficeOptions); var appPropertyService = new AppPropertyService(rPCSRepositoryFactory, _adConfigOptions, _bitrixConfigOptions, _onlyOfficeOptions, _timesheetConfigOptions); var ooService = new OOService(applicationUserService, _onlyOfficeOptions); var financeService = new FinanceService(rPCSRepositoryFactory, iRPCSDbAccessor, applicationUserService, appPropertyService, ooService); var timesheetService = new TimesheetService(employeeService, employeeCategoryService, tsAutoHoursRecordService, tsHoursRecordService, projectService, projectReportRecords, vacationRecordService, productionCalendarService, financeService, _timesheetConfigOptions); var projectExternalWorkspace = new ProjectExternalWorkspaceService(rPCSRepositoryFactory); var jiraService = new JiraService(userService, _jiraConfigOptions, projectExternalWorkspace, projectService); var taskTimesheetProcessing = new TimesheetProcessingTask(tsAutoHoursRecordService, vacationRecordService, reportingPeriodService, productionCalendarService, tsHoursRecordService, userService, projectService, employeeService, projectMembershipService, timesheetService, _timesheetConfigOptions, _smtpConfigOptions, _jiraConfigOptions, jiraService, projectExternalWorkspace); _timesheetJobLogger.LogInformation("Начало синхронизации с Timesheet!"); string id = Guid.NewGuid().ToString(); TimesheetProcessingResult timesheetProcessingResult = null; var fileHtmlReport = string.Empty; if (taskTimesheetProcessing.Add(id, true) == true) { try { bool syncWithExternalTimesheet = false; bool processVacationRecords = false; bool processTSAutoHoursRecords = false; bool sendTSEmailNotifications = false; bool syncWithJIRA = false; bool syncWithJIRASendEmailNotifications = false; try { syncWithExternalTimesheet = _timesheetConfig.ProcessingSyncWithExternalTimesheets; } catch (Exception) { } try { processVacationRecords = _timesheetConfig.ProcessingProcessVacationRecords; } catch (Exception) { } try { processTSAutoHoursRecords = _timesheetConfig.ProcessingProcessTSAutoHoursRecords; } catch (Exception) { } try { sendTSEmailNotifications = _timesheetConfig.ProcessingSendTSEmailNotifications; } catch (Exception) { } try { syncWithJIRA = _timesheetConfig.ProcessingSyncWithJIRA; } catch (Exception) { } timesheetProcessingResult = taskTimesheetProcessing.ProcessLongRunningAction("", id, syncWithExternalTimesheet, DateTime.MinValue, DateTime.MinValue, false, true, true, true, false, 350, processVacationRecords, processTSAutoHoursRecords, sendTSEmailNotifications, DateTime.Today, syncWithJIRA, DateTime.MinValue, DateTime.MinValue, false, DateTime.Today, syncWithJIRASendEmailNotifications); foreach (var html in timesheetProcessingResult.fileHtmlReport) { fileHtmlReport += html; } _memoryCache.Set(timesheetProcessingResult.fileId, fileHtmlReport); } catch (Exception) { } taskTimesheetProcessing.Remove(id); } if (timesheetProcessingResult != null && String.IsNullOrEmpty(fileHtmlReport) == false && !string.IsNullOrEmpty(_timesheetConfig.ProcessingReportEmailReceivers)) { byte[] binFileHtmlReport = Encoding.UTF8.GetPreamble().Concat(Encoding.UTF8.GetBytes(fileHtmlReport)).ToArray(); using (MemoryStream streamFileHtmlReport = new MemoryStream(binFileHtmlReport)) { try { string subject = "Отчет об обработке данных Таймшит " + DateTime.Now.ToString(); string bodyHtml = RPCSEmailHelper.GetSimpleHtmlEmailBody("Отчет об обработке данных Таймшит", "Отчет об обработке данных Таймшит во вложении.", null); RPCSEmailHelper.SendHtmlEmailViaSMTP(_timesheetConfig.ProcessingReportEmailReceivers, subject, null, null, bodyHtml, null, null, streamFileHtmlReport, "TimesheetProcessingReport" + DateTime.Now.ToString("ddMMyyHHmmss") + ".html"); } catch (Exception) { } } } } catch (Exception e) { _timesheetJobLogger.LogError(e.Message); Console.WriteLine(e); throw; } _timesheetJobLogger.LogInformation("Синхронизация с Timesheet закончена!"); return(Task.CompletedTask); }