示例#1
0
        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);
        }
示例#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);
        }
示例#3
0
文件: Startup.cs 项目: Alekseyya/SKEP
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        //Как приложение будет обрабатывать запрос
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, IApplicationLifetime lifetime,
                              IOptions <ADConfig> adOptions, IOptions <BitrixConfig> bitrixConfig, IOptions <OnlyOfficeConfig> onlyOfficeOptions,
                              IOptions <TimesheetConfig> timesheetOptions, IOptions <SMTPConfig> smtpOptions, IOptions <CommonConfig> commonOptions,
                              IServiceProvider serviceProvider)
        {
            InitializeDatabase(app);
            if (env.IsDevelopment())
            {
                //Раскоментить, когда сделаем кастомные ошибки!!!
                //app.UseDeveloperExceptionPage();
                app.UseDatabaseErrorPage();
                app.UseBrowserLink();
            }
            else
            {
                app.UseExceptionHandler("/Error");
                //Todo отображение ошибок в ProductionEnvironment - позже убрать!
                //app.UseDeveloperExceptionPage();
                //app.UseHsts();
            }
            //TODO В будущем убрать из продакшн версии отображение страницы девелопмент ошибок
            app.UseDeveloperExceptionPage();

            //Страницы ошибок
            app.UseStatusCodePages(async context =>
            {
                context.HttpContext.Response.ContentType = "text/plain";

                await context.HttpContext.Response.WriteAsync(
                    "Status code page, status code: " +
                    context.HttpContext.Response.StatusCode);
            });

            app.UseHttpsRedirection();
            app.UseStaticFiles();
            app.UseCookiePolicy();
            app.UseAuthentication();
            app.UseSession();

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "timesheetRoute",
                    template: "{area:exists}/{controller=Timesheet}/{action=Index}/{id?}"
                    );

                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });


            //Quartz
            //var quartz = new QuartZStartup(adOptions, bitrixConfig, onlyOfficeOptions, timesheetOptions);
            //lifetime.ApplicationStarted.Register(quartz.Start);
            //lifetime.ApplicationStopped.Register(quartz.Stop);
            //QuartzHelper.Configure(quartz.scheduler);



            RpcsControls.Configure(app.ApplicationServices.GetService <IServiceProvider>());
            AutocompleteControls.Configure(app.ApplicationServices.GetService <IServiceProvider>());
            PermissionControls.Configure(app.ApplicationServices.GetService <IServiceProvider>());
            RPCSHelper.Configure(app.ApplicationServices.GetService <IServiceProvider>());
            RPCSEmailHelper.Configure(app.ApplicationServices.GetService <IServiceProvider>());
            Daykassa.Configure(app.ApplicationServices.GetService <IServiceProvider>());
        }