public async Task ExportAsync <T, TClassMap>(string tableName, IEnumerable <T> source, string exportPath, OleDbConnection connection, OleDbTransaction transaction, CancellationToken cancellationToken) where TClassMap : ClassMap { if (typeof(T) == typeof(ValidationError)) { var identity = 1; var validationErrors = ((IEnumerable <ValidationError>)source).ToList(); foreach (var validationError in validationErrors) { validationError.Id = identity++; } await _export.ExportAsync <T, TClassMap>(tableName, validationErrors as IEnumerable <T>, exportPath, connection, transaction, cancellationToken); } else { await _export.ExportAsync <T, TClassMap>(tableName, source, exportPath, connection, transaction, cancellationToken); } }
public async Task ExportAsync <T, TClassMap>(string tableName, IEnumerable <T> source, string exportPath, OleDbConnection connection, OleDbTransaction transaction, CancellationToken cancellationToken) where TClassMap : ClassMap { using (var writer = new StreamWriter(await _fileService.OpenWriteStreamAsync($"{tableName}.csv", exportPath, cancellationToken))) using (var csv = new CsvWriter(writer)) { csv.Configuration.IgnoreReferences = true; csv.Configuration.ShouldQuote = (field, context) => true; csv.WriteRecords(source); csv.Configuration.UnregisterClassMap <TClassMap>(); } await _decoratedExport.ExportAsync <T, TClassMap>(tableName, source, exportPath, connection, transaction, cancellationToken); }
protected async Task ExportTableAsync <T, TClassMap>(string exportPath, IDataStoreCache cache, OleDbConnection connection, CancellationToken cancellationToken) where TClassMap : ClassMap <T> { using (var transaction = connection.BeginTransaction()) { try { await _export.ExportAsync <T, TClassMap>(_context.GetTableName <T>(), cache.Get <T>(), exportPath, connection, transaction, cancellationToken); transaction.Commit(); } catch (Exception ex) { transaction.Rollback(); _logger.LogError(ex.Message); throw; } } }