Пример #1
0
        public static void ProcessTransaction(IDbConnection conn, DelegateProcessTransaction dpt)
        {
            DateTime dtStart = DateTime.Now;

            try
            {
                // Check Stack to find nested transaction
                StackTrace st = new StackTrace();

                StackFrame[] sfArray = st.GetFrames();

                MethodBase mbThis = sfArray[0].GetMethod();

                for (int i = 1; i < sfArray.Length; i++)
                {
                    MethodBase mbStack = sfArray[i].GetMethod();

                    // If nested transaction detected then throw exception
                    ExcpHelper.ThrowIf(mbThis == mbStack, "Incorrect Operation: ProcessTransaction been called inside other ProcessTransaction. We do not support nested transactions:\r\n{0}\r\n", st);
                }

                // Delcare Transaction
                IDbTransaction transaction = null;

                try
                {
                    transaction = conn.BeginTransaction();

                    // Here we execute nHibernate statements
                    dpt(conn, transaction);

                    transaction.Commit();

                    DateTime dtEnd = DateTime.Now;
                    m_Logger.DebugFormat("ProcessTransaction({0}) Succeeded at {1} (Transaction Time: {2})", dpt.Method, dtEnd, dtEnd - dtStart);
                }
                catch (System.Exception excp1)
                {
                    m_Logger.ErrorFormat("ProcessTransaction({0}) ERROR:\r\n{1}\r\n{2}", excp1, dpt.Method, excp1.Message, excp1.StackTrace);

                    if (transaction != null)
                    {
                        try
                        {
                            transaction.Rollback();
                            m_Logger.WarnFormat("ProcessTransaction({0}) is ROLLED BACK", dpt.Method);
                        }
                        catch (Exception excp2)
                        {
                            m_Logger.ErrorFormat("ProcessTransaction({0}) Rollback Exception:\r\n{1}\r\n{2}", excp2, dpt.Method, excp2.Message, excp2.StackTrace);
                        }
                    }
                }
            }
            catch (Exception excp3)
            {
                m_Logger.ErrorFormat("ProcessTransaction({0}) General ERROR:\r\n{1}\r\n{2}", excp3, dpt.Method, excp3.Message, excp3.StackTrace);
                throw;
            }
        }
Пример #2
0
        public static void ProcessTransaction(DelegateProcessTransaction dpt)
        {
            DateTime dtStart = DateTime.Now;

            try
            {
                using (IDbConnection conn = GetConnection())
                {
                    ProcessTransaction(conn, dpt);
                }
            }
            catch (Exception excp3)
            {
                m_Logger.ErrorFormat("ProcessTransaction({0}) General ERROR:\r\n{1}\r\n{2}", excp3, dpt.Method, excp3.Message, excp3.StackTrace);
                throw;
            }
        }