public override void ProcessData() { // Заполняем таблицу с данными о поставщиках. FillSourcesTable(); foreach (var row in dtSources.Rows.Cast <DataRow>()) { var supplierId = Convert.ToUInt32(row[WaybillSourcesTable.colFirmCode]); drCurrent = row; try { _currentDocumentType = null; var clazz = row[WaybillSourcesTable.colReaderClassName].ToString(); if (String.IsNullOrEmpty(clazz)) { _logger.WarnFormat("Игнорирую источник для поставщика с кодом {0} тк не задан формат разбора имени документа", supplierId); continue; } var documentReader = ReflectionHelper.GetDocumentReader <BaseDocumentReader>(clazz); foreach (var documentType in _documentTypes) { try { _currentDocumentType = documentType; // Получаем список файлов из папки var files = GetFileFromSource(supplierId, documentReader); foreach (var sourceFileName in files) { GetCurrentFile(sourceFileName); if (String.IsNullOrEmpty(CurrFileName)) { continue; } var correctArchive = PriceProcessor.FileHelper.ProcessArchiveIfNeeded(CurrFileName, ExtrDirSuffix); if (correctArchive) { if (!ProcessWaybillFile(CurrFileName, row, documentReader)) { using (var mm = new MailMessage( Settings.Default.FarmSystemEmail, Settings.Default.DocumentFailMail, String.Format("{0} ({1})", row[WaybillSourcesTable.colShortName], SourceType), String.Format("Код поставщика : {0}\nФирма: {1}\nТип: {2}\nДата: {3}\nПричина: {4}", row[WaybillSourcesTable.colFirmCode], row[SourcesTableColumns.colShortName], _currentDocumentType.GetType().Name, DateTime.Now, "Не удалось сопоставить документ клиентам. Подробнее смотрите в таблице logs.document_logs."))) { if (!String.IsNullOrEmpty(CurrFileName)) { mm.Attachments.Add(new Attachment(CurrFileName)); } var sc = new SmtpClient(Settings.Default.SMTPHost); sc.Send(mm); } } //После обработки файла удаляем его из папки if (!String.IsNullOrEmpty(sourceFileName) && File.Exists(sourceFileName)) { File.Delete(sourceFileName); } } else { DocumentReceiveLog.Log(supplierId, null, Path.GetFileName(CurrFileName), documentType.DocType, String.Format("Не удалось распаковать файл '{0}'", Path.GetFileName(CurrFileName))); //Распаковать файл не удалось, поэтому удаляем его из папки if (!String.IsNullOrEmpty(sourceFileName) && File.Exists(sourceFileName)) { File.Delete(sourceFileName); } } Cleanup(); } } catch (Exception e) { //Обрабатываем ошибку в случае обработки одного из типов документов var message = String.Format("Источник : {0}\nТип : {1}", supplierId, documentType.GetType().Name); Log(e, message); } } } catch (Exception ex) { Log(ex, String.Format("Источник : {0}", supplierId)); } } }