コード例 #1
0
        protected void InitTasks()
        {
            var iRPCSDbAccessor       = (IRPCSDbAccessor) new RPCSSingletonDbAccessor(_rpcsContextOptions);
            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 departmemtService         = new DepartmentService(rPCSRepositoryFactory, userService);
            var employeeService           = (IEmployeeService) new EmployeeService(rPCSRepositoryFactory, departmemtService, userService);
            var projectMembershipService  = (IProjectMembershipService) new ProjectMembershipService(rPCSRepositoryFactory);
            var projectReportRecords      = new ProjectReportRecordService(rPCSRepositoryFactory);
            var employeeCategoryService   = new EmployeeCategoryService(rPCSRepositoryFactory);
            var applicationUserService    = new ApplicationUserService(rPCSRepositoryFactory, employeeService, userService, departmemtService,
                                                                       _httpContextAccessor, _memoryCache, projectService, _onlyofficeOptions);
            var appPropertyService = new AppPropertyService(rPCSRepositoryFactory, _adOptions, _bitrixOptions, _onlyofficeOptions, _timesheetOptions);
            var financeService     = new FinanceService(rPCSRepositoryFactory, iRPCSDbAccessor, applicationUserService, appPropertyService, _ooService);
            var timesheetService   = new TimesheetService(employeeService, employeeCategoryService, tsAutoHoursRecordService,
                                                          tsHoursRecordService, projectService, projectReportRecords, vacationRecordService, productionCalendarService, financeService, _timesheetOptions);
            var projectExternalWorkspaceService = new ProjectExternalWorkspaceService(rPCSRepositoryFactory);
            var jiraService = new JiraService(userService, _jiraOptions, projectExternalWorkspaceService, projectService);

            _taskTimesheetProcessing = new TimesheetProcessingTask(tsAutoHoursRecordService, vacationRecordService, reportingPeriodService,
                                                                   productionCalendarService, tsHoursRecordService, userService, projectService, employeeService, projectMembershipService,
                                                                   timesheetService, _timesheetOptions, _smtpOptions, _jiraOptions, jiraService, projectExternalWorkspaceService);
        }
コード例 #2
0
        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);
        }