Exemple #1
0
        public bool TryRollbackSafe()
        {
            if (_disposed)
            {
                Logger.Warning("Tried to rollback actions for disposed scope. Rollback will not be perform.");
                return(false);
            }

            Logger.Warning($"Performing {_rollbackActions.Count.ToString()} rollback actions.");

            bool isSuccessfulRollback = true;

            while (_rollbackActions.Count > 0 && isSuccessfulRollback)
            {
                IRollbackAction rollbackAction = _rollbackActions.Pop();
                isSuccessfulRollback = rollbackAction.TryRollbackSafe();
            }

            _rollbackActions.TrimExcess();
            return(isSuccessfulRollback);
        }
Exemple #2
0
        private bool InternalRollbackSafe(IRollbackAction rollbackAction)
        {
            try
            {
                Logger.Debug(
                    "Trying to rollback action. If exception will occur, this will be considered " +
                    "as a failed rollback."
                    );
                return(rollbackAction.TryRollbackSafe());
            }
            catch (Exception ex)
            {
                string lastPartOfMessage = _continueRollbackOnFailed
                    ? "Continue rollback on failed option is enabled, the rollback will continue."
                    : "Continue rollback on failed option is disabled, the rest of rollback " +
                                           "actions will be skipped.";

                Logger.Exception(
                    ex, $"Failed to perform safe rollback for action. {lastPartOfMessage}"
                    );
                return(false);
            }
        }