public void Commit() { if (_state == UnitOfWorkState.Committed) { throw new UnitOfWorkException("Can't commit unit of work that was already committed."); } if (_unitOfWorkScope.State == UnitOfWorkState.RolledBack) { throw new UnitOfWorkException("Can't commit unit of work that was already rolled back."); } foreach (var action in _preCommitActions) { action.Invoke(); } if (IsScopeWrapper) { _unitOfWorkScope.Commit(); } _transactionScope.Complete(); _state = UnitOfWorkState.Committed; }
protected override void Dispose(bool isDisposing) { if (State == UnitOfWorkState.Active) State = UnitOfWorkState.Canceled; if (Manager.IsRoot(this)) Manager.Clear(); base.Dispose(isDisposing); }
public void Enter() { if (State == UnitOfWorkState.Nothing) { _transaction = _context.Database.BeginTransaction(); State = UnitOfWorkState.Entered; } }
public void Rollback() { if (State == UnitOfWorkState.Entered) { _transaction?.Rollback(); State = UnitOfWorkState.Rollback; } }
public void Commit() { if (State == UnitOfWorkState.Entered) { _transaction?.Commit(); State = UnitOfWorkState.Committed; } }
public void Begin( IsolationLevel transactionIsolationLevel = IsolationLevel.ReadCommitted) { ThrowIfInvalidState(UnitOfWorkState.Ready); Log.Debug(BEGIN_INFO_MESSAGE); BeginTransaction(transactionIsolationLevel); State = UnitOfWorkState.Begun; }
private void ThrowIfInvalidState(UnitOfWorkState expectedState) { if (expectedState != State) { throw new InvalidOperationException( $"The unit of work is required " + $"to be in {expectedState} state for this action. " + $"Current state is {State}" ); } }
internal void Commit() { if (State == UnitOfWorkState.RolledBack) { throw new UnitOfWorkException("Can't commit unit of work that was already rolled back."); } _repository.Transaction.Commit(); if (Transaction.Current != null && Transaction.Current.TransactionInformation.Status != TransactionStatus.Aborted) { Transaction.Current.EnlistVolatile(new TransactionCommitHandler(_postCommitActions), EnlistmentOptions.None); } State = UnitOfWorkState.Committed; }
public virtual void Rollback() { ThrowIfInvalidState(UnitOfWorkState.Begun); try { RollbackTransaction(); State = UnitOfWorkState.Rollbacked; } catch (Exception exception) { Log.Error( exception: exception, messageTemplate: ROLLBACK_ERROR_MESSAGE ); throw; } }
public void Complete() { if (!Manager.CanComplete(this)) throw new UnitOfWorkWasNotCompletedException(); if (Manager.IsRoot(this) && DataContext.IsDirty) { try { DataContext.SaveChanges(); } catch (UserException ex) { throw new UnitOfWorkWasNotCompletedException(ex.Message, ex); } } State = UnitOfWorkState.Completed; }
public virtual void Commit() { ThrowIfInvalidState(UnitOfWorkState.Begun); try { CommitTransaction(); State = UnitOfWorkState.Committed; } catch (Exception exception) { Log.Error( exception: exception, messageTemplate: COMMIT_ERROR_MESSAGE ); RollbackTransaction(); throw; } }
public void Rollback() { if (_unitOfWorkScope.State == UnitOfWorkState.RolledBack) { return; } if (_unitOfWorkScope.State == UnitOfWorkState.Committed) { throw new UnitOfWorkException("Can't rollback unit of work that was already committed."); } _unitOfWorkScope.Rollback(); _state = UnitOfWorkState.RolledBack; if (!IsScopeWrapper) { throw new UnitOfWorkException("Rolling back inner unit of work will break outer unit of work."); } }
public void Rollback() { if (State == UnitOfWorkState.RolledBack) { return; } if (State == UnitOfWorkState.Committed) { throw new UnitOfWorkException("Can't rollback unit of work that was already committed."); } _repository.Transaction.Rollback(); if (Transaction.Current != null) { Transaction.Current.EnlistVolatile(new TransactionRollbackHandler(_postRollbackActions), EnlistmentOptions.None); Transaction.Current.Rollback(); } State = UnitOfWorkState.RolledBack; }
public void Rollback() { if (_unitOfWorkScope.State == UnitOfWorkState.RolledBack) return; if (_unitOfWorkScope.State == UnitOfWorkState.Committed) { throw new UnitOfWorkException("Can't rollback unit of work that was already committed."); } _unitOfWorkScope.Rollback(); _state = UnitOfWorkState.RolledBack; if (!IsScopeWrapper) { throw new UnitOfWorkException("Rolling back inner unit of work will break outer unit of work."); } }
public InvalidStateForActionException(UnitOfWorkState currentState, string action) : base($"The state [{currentState}] of UnitOfWork is not valid for action [{action}]") { }