Exemplo n.º 1
0
 protected virtual void Dispose(bool disposing)
 {
     if (!this.disposed)
     {
         if (disposing)
         {
             _transactionScope?.Dispose();
             context.Dispose();
         }
     }
     this.disposed = true;
 }
        // ReSharper disable once UnusedParameter.Local
        private void Dispose(bool disposing)
        {
            if (!_disposed)
            {
                _disposed = true;

                if (disposing)
                {
                    _dbContextTransaction?.Dispose();
                    _entities.Dispose();
                }
            }
        }
Exemplo n.º 3
0
 /// <summary>
 /// Verifica se o contexto atual tem uma transação aberta, então verifica se o método que está tentando fazer Rollback foi o método que iniciou a transação
 /// </summary>
 /// <returns>Retorna "True" se a transação foi desfeita, ou falso caso não tenha sido pois não há transação aberta ou quem está tentando desfazer não deu inicio a mesma</returns>
 public bool TryRollBackTransaction()
 {
     try
     {
         if (blnEmTransacao)
         {
             if (GetMethod() == metodoOrigemTransacao)
             {
                 transacao.Rollback();
                 transacao.Dispose();
                 blnEmTransacao        = false;
                 metodoOrigemTransacao = null;
                 return(true);
             }
         }
     }
     catch (Exception ex)
     {
         Util.LogErro(ex);
         return(true);
     }
     return(false);
 }
Exemplo n.º 4
0
 public ActionResult Edit([Bind(Include = "MaPhieuChi,Ngay,NoiDung,SoTien")] PhieuChi phieuChi)
 {
     if (ModelState.IsValid)
     {
         DbContextTransaction tran = db.Database.BeginTransaction();
         try
         {
             TempData["notice"]       = "Successfully edit";
             TempData["ma"]           = phieuChi.MaPhieuChi;
             db.Entry(phieuChi).State = EntityState.Modified;
             db.SaveChanges();
             tran.Commit();
             tran.Dispose();
         }
         catch
         {
             tran.Rollback();
             tran.Dispose();
         }
         return(RedirectToAction("Index"));
     }
     return(View(phieuChi));
 }
Exemplo n.º 5
0
 protected virtual void Dispose(bool disposing)
 {
     if (!this._disposed)
     {
         if (disposing)
         {
             if (_transaction != null)
             {
                 _transaction.Dispose();
             }
         }
     }
     _disposed = true;
 }
Exemplo n.º 6
0
        public void Dispose()
        {
            lock (this)
            {
                if (isDisposed)
                {
                    return;
                }

                isDisposed = true;
            }

            transaction.Dispose();
        }
Exemplo n.º 7
0
 public static void save(DbContextTransaction transaction)
 {
     try
     {
         migraineContext.SaveChanges();
         transaction.Commit();
     }
     catch (Exception ex)
     {
         transaction.Rollback();
         transaction.Dispose();
         throw;
     }
 }
 public void Dispose()
 {
     try
     {
         _sourceTransaction.Commit();
     }
     catch
     {
         _sourceTransaction.Rollback();
         throw;
     }
     _sourceTransaction.Dispose();
     GC.SuppressFinalize(this);
 }
Exemplo n.º 9
0
 public ActionResult Edit([Bind(Include = "MaGiai,TenGiai,SoTienNhan,Flag")] Giai giai)
 {
     if (ModelState.IsValid)
     {
         DbContextTransaction tran = db.Database.BeginTransaction();
         try
         {
             TempData["notice"]   = "Successfully edit";
             TempData["tengiai"]  = giai.TenGiai;
             db.Entry(giai).State = EntityState.Modified;
             db.SaveChanges();
             tran.Commit();
             tran.Dispose();
         }
         catch
         {
             tran.Rollback();
             tran.Dispose();
         }
         return(RedirectToAction("Index"));
     }
     return(View(giai));
 }
Exemplo n.º 10
0
        public async Task <int> CommitAsync(CancellationToken cancelToken)
        {
            if (cancelToken == null)
            {
                throw new ArgumentNullException(nameof(cancelToken));
            }
            if (_disposed)
            {
                throw new ObjectDisposedException(nameof(DbContextCollection));
            }
            if (_completed)
            {
                throw new InvalidOperationException("You can't call Commit() or Rollback() more than once on a DbContextCollection. All the changes in the DbContext instances managed by this collection have already been saved or rollback and all database transactions have been completed and closed. If you wish to make more data changes, create a new DbContextCollection and make your changes there.");
            }

            ExceptionDispatchInfo lastError = null;
            var c = 0;

            foreach (DbContext dbContext in _initializedDbContexts.Values)
            {
                try
                {
                    if (_readOnly)
                    {
                        c += await dbContext.SaveChangesAsync(cancelToken).ConfigureAwait(false);
                    }
                    DbContextTransaction transition = GetValueOrDefault(_transactions, dbContext);
                    if (transition != null)
                    {
                        transition.Commit();
                        transition.Dispose();
                    }
                }
                catch (Exception e)
                {
                    lastError = ExceptionDispatchInfo.Capture(e);
                }
            }

            _transactions.Clear();
            _completed = true;

            if (lastError != null)
            {
                lastError.Throw();
            }

            return(c);
        }
Exemplo n.º 11
0
        private void Dispose(bool disposing)
        {
            if (_disposed)
            {
                return;
            }

            if (disposing)
            {
                _transaction?.Dispose();
                _context?.Dispose();
            }

            _disposed = true;
        }
        private void Dispose(bool disposing)
        {
            if (!_isDisposed && disposing)
            {
                if (_dbContextTransaction != null)
                {
                    _dbContextTransaction.Dispose();
                    _dbContextTransaction = null;
                }

                ModelConfiguration.SuspendExecutionStrategy = false;
            }

            _isDisposed = true;
        }
Exemplo n.º 13
0
        private bool disposedValue = false; // To detect redundant calls

        protected virtual void Dispose(bool disposing)
        {
            if (disposedValue)
            {
                return;
            }

            if (disposing)
            {
                _transaction?.Dispose();
                Context.Dispose();
            }

            disposedValue = true;
        }
Exemplo n.º 14
0
 protected virtual void Dispose(bool disposing)
 {
     if (!this.disposed)
     {
         if (disposing)
         {
             _context.Dispose();
             if (_dbContextTransaction != null)
             {
                 _dbContextTransaction.Dispose();
             }
         }
     }
     this.disposed = true;
 }
 public void RollbackTransaction()
 {
     try
     {
         DbContextTransaction?.Rollback();
     }
     finally
     {
         if (DbContextTransaction != null)
         {
             DbContextTransaction.Dispose();
             DbContextTransaction = null;
         }
     }
 }
Exemplo n.º 16
0
 protected virtual void Dispose(bool disposing)
 {
     if (!this.disposed)
     {
         if (disposing)
         {
             _context.Dispose();
             if (_atomicTran != null)
             {
                 _atomicTran.Dispose();
             }
         }
     }
     this.disposed = true;
 }
Exemplo n.º 17
0
        protected virtual void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (transactionScope != null)
                {
                    transactionScope.Dispose();
                }

                if (contextBuilder != null)
                {
                    contextBuilder.Dispose();
                }
            }
        }
Exemplo n.º 18
0
        public void RollbackTransaction()
        {
            if (_currentTransaction == null)
            {
                throw new ApplicationException("Cannot rollback when no transaction was started");
            }

            try
            {
                _currentTransaction.Rollback();
            }
            catch (Exception rollbackEx)
            {
                System.Diagnostics.Trace.WriteLine(rollbackEx);
            }
            finally
            {
                if (_currentTransaction != null)
                {
                    _currentTransaction.Dispose();
                    _currentTransaction = null;
                }
            }
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnSalvar_Alterar_Click(object sender, RoutedEventArgs e)
        {
            using (DbContextTransaction tran = db.Database.BeginTransaction(System.Data.IsolationLevel.ReadCommitted))
            {
                try
                {
                    if (doc == null)
                    {
                        doc = new Model.ImportaDocumento();
                    }
                    doc.NumeroDocumento = Convert.ToInt64(this.txtNumeroDocumento.Text);
                    doc.Nome            = this.txtNomeDocumento.Text;
                    if (this.chkArquivoMorto.IsChecked == true)
                    {
                        doc.ArquivoMortoSN = true;
                    }
                    else
                    {
                        doc.ArquivoMortoSN = false;
                    }

                    doc.DataRegistro     = Convert.ToDateTime(this.dtpRegistroCadastro.Text);
                    doc.UsuarioSistemaId = View.MenuWindow.InstanceUsuario.Id;


                    db.ImportaDocumentos.Add(doc);
                    db.SaveChanges();
                    this.ProcessandoDocumentos(doc.Id.ToString());

                    this.btnNovo_Click(sender, e);
                    MessageBox.Show("Documento(s) salvo(s) com sucesso.", "Informação",
                                    MessageBoxButton.OK, MessageBoxImage.Information);

                    tran.Commit();
                    this.CarrgarImportDocumentos();
                }

                catch (Exception ex)
                {
                    tran.Rollback();
                    MessageBox.Show(ex.Message, "Alerta", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                }
                finally
                {
                    tran.Dispose();
                }
            }
        }
Exemplo n.º 20
0
        public void Dispose()
        {
            if (Transaction != null)
            {
                Transaction.Dispose();
            }
            if (Context != null)
            {
                Context.Database.Connection.Close();

                Context.Dispose();
                Context = null;
                //DbInterception.Remove(intercepter);
                //DbInterception.Remove(treeIntercepter);
            }
        }
Exemplo n.º 21
0
        protected virtual void Dispose(bool disposing)
        {
            if (Disposed)
            {
                return;
            }

            if (disposing)
            {
                Handle.Dispose();
                ConnectionTransaction?.Dispose();
                ContextTransaction?.Dispose();
                Context.Dispose();
                Disposed = true;
            }
        }
        protected virtual void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (_transaction != null)
                {
                    //roll back the transaction, so the database is clean for the next test run
                    _transaction.Rollback();
                    _transaction.Dispose();
                }

                if (Context != null)
                {
                    Context.Dispose();
                }
            }
        }
        public void Dispose()
        {
            if (DbContextTransaction != null)
            {
                DbContextTransaction.Dispose();
            }

            if (DbContext != null)
            {
                DbContext.Dispose();
            }

            if (AttendedDbContexts != null)
            {
                AttendedDbContexts.Clear();
            }
        }
Exemplo n.º 24
0
        public void Rollback()
        {
            if (this._isDisposed)
            {
                throw new ObjectDisposedException("DbContextCollection");
            }

            if (this._isCompleted)
            {
                throw new InvalidOperationException("You can't call Commit() or Rollback() more than once on a DbContextCollection. All the changes in the DbContext instances managed by this collection have already been saved or rollback and all database transactions have been completed and closed. If you wish to make more data changes, create a new DbContextCollection and make your changes there.");
            }

            ExceptionDispatchInfo lastError = null;

            foreach (var dbContext in _initializedDbContexts.Values)
            {
                // There's no need to explicitly rollback changes in a DbContext as
                // DbContext doesn't save any changes until its SaveChanges() method is called.
                // So "rolling back" for a DbContext simply means not calling its SaveChanges()
                // method.

                // But if we've started an explicit database transaction, then we must roll it back.
                DbContextTransaction transaction = null;
                bool succeed = this._transactions.TryGetValue(dbContext, out transaction);
                if (succeed)
                {
                    try
                    {
                        transaction.Rollback();
                        transaction.Dispose();
                    }
                    catch (Exception e)
                    {
                        lastError = ExceptionDispatchInfo.Capture(e);
                    }
                }
            }

            this._transactions.Clear();
            this._isCompleted = true;

            if (lastError != null)
            {
                lastError.Throw(); // Re-throw while maintaining the exception's original stack track
            }
        }
Exemplo n.º 25
0
            private void Dispose(bool disposing)
            {
                if (_disposed)
                {
                    return;
                }

                // If you need thread safety, use a lock around these
                // operations, as well as in your methods that use the resource.
                if (disposing)
                {
                    _transaction?.Dispose();
                }

                // Indicate that the instance has been disposed.
                _disposed = true;
            }
Exemplo n.º 26
0
        public void EndTransaction(object tran)
        {
            DbContextTransaction dbtran = tran as DbContextTransaction;

            try
            {
                dbtran.Commit();
            }
            catch (Exception ex)
            {
                dbtran.Rollback();
                throw ex;
            }
            finally
            {
                dbtran.Dispose();
            }
        }
Exemplo n.º 27
0
        protected override void OnDisposing(bool disposing)
        {
            if (!disposing)
            {
                return;
            }

            var dbContext = RetrieveValidContext();

            DbContextTransaction transaction = null;

            if (_transaction.IsNotNull())
            {
                _transaction.TryGetTarget(out transaction);
            }

            if (transaction.IsNull())
            {
                if (_disposeDbContext)
                {
                    dbContext.Dispose();
                }
                return;
            }

            try
            {
                transaction.Commit();
            }
            catch
            {
                transaction.Rollback();
                throw;
            }
            finally
            {
                transaction.Dispose();
                if (_disposeDbContext)
                {
                    dbContext.Dispose();
                }
            }
        }
Exemplo n.º 28
0
        private void Dispose(bool isDisposing)
        {
            if (_isDisposed)
            {
                return;
            }

            if (isDisposing)
            {
                if (_transaction.UnderlyingTransaction.Connection != null)
                {
                    _transaction.Rollback();
                }

                _transaction.Dispose();
            }

            _isDisposed = true;
        }
Exemplo n.º 29
0
        public void Dispose()
        {
            if (mMode == UnitOfWorkMode.Tracking && mTransaction != null)
            {
                mTransaction.Dispose();
                mTransaction = null;

                if (!mIsTransactionFinalized)
                {
                    //error
                }
            }

            if (mContext != null)
            {
                mContext.Dispose();
                mContext = null;
            }
        }
Exemplo n.º 30
0
        /// <summary>
        /// Dispose
        /// </summary>
        public void Dispose()
        {
            // Roll Back判定
            if (_trans != null)
            {
                if (_rollBack)
                {
                    _trans.Rollback();
                }
                else
                {
                    _trans.Commit();
                }

                _trans.Dispose();
            }

            // Close
            _db.Dispose();
        }