public static void MainLoop(Config.Config config, CancellationToken token) { var scheduler = StdSchedulerFactory.GetDefaultScheduler(); CronJob(scheduler, config.FtpExportPlan, typeof(FtpExportJob)); CronJob(scheduler, config.FtpImportPlan, typeof(FtpImportJob)); scheduler.Start(); token.Register(() => scheduler.Shutdown()); while (!token.IsCancellationRequested) { try { var logger = new MemorableLogger(log); IList <object[]> users; using (var session = Factory.OpenSession()) { users = session.CreateSQLQuery("select Id, FtpFileType from Customers.Users where UseFtpGateway = 1") .List <object[]>(); } foreach (var user in users) { var userId = (uint)user[0]; var ftpFileType = (ProtocolType)Convert.ToInt16(user[1]); try { log.Debug($"Обработка пользователя {userId}"); token.ThrowIfCancellationRequested(); ProcessUser(config, userId, ftpFileType); logger.Forget(userId); } catch (Exception e) { if (e is OperationCanceledException) { return; } logger.Error($"Ошибка при обработке пользователя {userId}", e, userId); } } token.WaitHandle.WaitOne(config.LookupTime); token.ThrowIfCancellationRequested(); } catch (Exception e) { if (e is OperationCanceledException) { return; } log.Error("Ошибка при обработке", e); } } }
public override void ProcessData() { using (new SessionScope()) { var sources = CertificateSource.Queryable.Where(s => !s.IsDisabled).ToArray(); foreach (var source in sources) { var ftpSource = source.GetCertificateSource() as IRemoteFtpSource; if (ftpSource == null) { continue; } try { using (var cleaner = new FileCleaner()) { Cleanup(); Ping(); var catalogFile = GetCatalogFile(source, cleaner); if (catalogFile == null) { continue; } cleaner.Watch(catalogFile.LocalFileName); Ping(); ImportCatalogFile(catalogFile, source, ftpSource); Ping(); doNotSmapLogger.Forget(source.Id); } } catch (Exception e) { doNotSmapLogger.Error( String.Format("Не удалось загрузить перекодировочную таблица сертификатов {0}", source.DecodeTableUrl), e, source.Id); } } } }