Beispiel #1
0
        /// <summary>
        /// Prepare outer and inner
        /// </summary>
        /// <exception cref="TransactionException">If Prepare fails.</exception>
        private void Prepare()
        {
            TransactionException toBeThrown = null;
            var abortOuter = false;
            var abortInner = false;

            //Prepare OUTER
            try
            {
                Outer.Prepare();
            }
            catch (TransactionException txEx)
            {
                abortOuter = true;
                Log.Debug("Prepare transaction failed.");
                Log.Trace(Outer.TraceTransaction());
                toBeThrown = new TransactionException("Prepare Outer transaction failed.", txEx);
            }

            //IF OK THEN PREPARE INNER
            if (!abortOuter)
            {
                try
                {
                    Inner.Prepare();
                }
                catch (TransactionException txEx)
                {
                    abortInner = true;
                    Log.Debug("Prepare transaction failed.");
                    Log.Trace(Inner.TraceTransaction());
                    toBeThrown = new TransactionException("Prepare Inner transaction failed.", txEx);
                }
            }

            //IF NOT OK INNER and OUTER ABBORT
            if (abortInner || abortOuter)
            {
                try
                {
                    Inner.Abort();
                    Outer.Abort();
                }
                catch { /*IGNORE*/ }
                throw toBeThrown;
            }
        }