Exemplo n.º 1
0
        public void CommitOuter()
        {
            if (disposed)
            {
                throw new ObjectDisposedException($"{nameof(TransactionManager<TInner, TOuter>)}");
            }

            if (complete || outerComplete)
            {
                throw new InvalidOperationException("Outer Transaction already completed!");
            }

            if (timedOut)
            {
                throw new InvalidOperationException("Transaction timed out!");
            }

            try
            {
                //outerComplete = true;
                //complete = innerComplete && outerComplete;
                Outer.Commit();
            }
            catch (TransactionException txEx)
            {
                Log.Debug("Outer Commit transaction failed.");
                Rollback();
                throw new TransactionException("Outer Commit  transaction failed", txEx);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// helper method for commit.
        /// </summary>
        private void commit()
        {
            TransactionException toBeThrown = null;
            var innerFailed = false;
            var outerFailed = false;

            //commit inner transaction
            try
            {
                Inner.Commit();
            }
            catch (TransactionException txEx)
            {
                innerFailed = true;
                Log.Debug("Commit transaction failed.");
                Log.Trace(Inner.TraceTransaction());
                toBeThrown = new TransactionException("Commit Inner transaction failed", txEx);
            }

            //if ok commit outer transaction
            if (!innerFailed)
            {
                try
                {
                    Outer.Commit();
                }
                catch (TransactionException txEx)
                {
                    outerFailed = true;
                    Log.Debug("Commit transaction failed.");
                    Log.Trace(Outer.TraceTransaction());
                    toBeThrown = new TransactionException("Commit Outer transaction failed", txEx);
                }
            }

            //something bad happened
            if (innerFailed || outerFailed)
            {
                throw toBeThrown;
            }

            complete = true;
        }