Esempio n. 1
0
        private TReturn PerformWork <TReturn>(Func <TReturn> unitOfWork, IDbContextSession <TContext> contextSession)
        {
            TReturn returnValue;

            if (contextSession.HasCurrentTransaction())
            {
                returnValue = unitOfWork();
                contextSession.CommitChanges();
            }
            else
            {
                using (var transaction = contextSession.StartNewTransaction())
                {
                    try
                    {
                        returnValue = unitOfWork();
                        contextSession.CommitChanges();
                        transaction.Commit();
                    }
                    catch
                    {
                        try
                        {
                            transaction.Rollback();
                        }
                        catch
                        {
                            //swallow
                        }

                        try
                        {
                            contextSession.RevertChanges();
                        }
                        catch
                        {
                            // swallow;
                        }

                        // throw original
                        throw;
                    }
                }
            }

            return(returnValue);
        }
Esempio n. 2
0
        private void PerformWork(Action unitOfWork, IDbContextSession <TContext> contextSession)
        {
            if (contextSession.HasCurrentTransaction())
            {
                unitOfWork();
                contextSession.CommitChanges();
            }
            else
            {
                using (var transaction = contextSession.StartNewTransaction())
                {
                    try
                    {
                        unitOfWork();
                        contextSession.CommitChanges();
                        transaction.Commit();
                    }
                    catch
                    {
                        try
                        {
                            transaction.Rollback();
                        }
                        catch
                        {
                            //swallow
                        }

                        try
                        {
                            contextSession.RevertChanges();
                        }
                        catch
                        {
                            // swallow;
                        }

                        // throw original
                        throw;
                    }
                }
            }
        }