private async Task ProcessFailureAsync <TEntity>( SqlOperation operation, FailureStrategies currentFailureStrategy, Exception ex, NpgsqlTransaction transaction, ICollection <TEntity> operatedElements, ICollection <TEntity> notOperatedElements, ICollection <TEntity> problemElements, CancellationToken cancellationToken) where TEntity : class { if (ex == null) { throw new ArgumentNullException(nameof(ex)); } _logger.LogError(ex, "Bulk command execution failed"); if (transaction != null) { await transaction.RollbackAsync(cancellationToken); } if (currentFailureStrategy == FailureStrategies.StopEverything || currentFailureStrategy == FailureStrategies.StopEverythingAndRollback) { throw new SqlBulkExecutionException <TEntity>(ex, operation, currentFailureStrategy, problemElements, notOperatedElements, operatedElements); } }
/// <summary> /// Exception occured during operating a portion of elements /// </summary> /// <param name="innerException">Exception that impeded to operate successfully</param> /// <param name="operation">Operation that caused the exception</param> /// <param name="usedStrategy">Strategy that was used to manage the failed bulk operation</param> /// <param name="problemElements"> /// A portion of elements that caused an exception /// <see cref="BulkServiceOptions.IsProblemElementsEnabled"/> /// <see cref="EntityProfile.IsProblemElementsEnabled"/> /// </param> /// <param name="notOperated"> /// Elements that were not operated as an inner exception was thrown. /// All changes with these elements were rollbacked. /// <see cref="BulkServiceOptions.IsNotOperatedElementsEnabled"/> /// <see cref="EntityProfile.IsNotOperatedElementsEnabled"/> /// </param> /// <param name="operated"> /// Elements that were successfully operated. /// <see cref="BulkServiceOptions.IsOperatedElementsEnabled"/> /// <see cref="EntityProfile.IsOperatedElementsEnabled"/> /// </param> public SqlBulkExecutionException( Exception innerException, SqlOperation operation, FailureStrategies usedStrategy, ICollection <TEntity> problemElements, ICollection <TEntity> notOperated, ICollection <TEntity> operated) : base(innerException.Message, innerException) { Operation = operation; UsedStrategy = usedStrategy; NotOperatedElements = notOperated; OperatedElements = operated; ProblemElements = problemElements; }