SenseNet.ContentRepository.Storage.TransactionScope.Rollback C# (CSharp) Method

Rollback() public static method

Rollbacks the current transaction.
public static Rollback ( ) : void
return void
        public static void Rollback()
        {
            if(_notSupported)
                return;

            ITransactionProvider tran = ContextHandler.GetTransaction();
            if(tran == null) // Means: !IsActive (Transaction is not Active)
                throw new InvalidOperationException("Transaction is not active");

            try
            {
                tran.Rollback();

				var queue = ContextHandler.GetTransactionQueue();
				if (queue != null)
					queue.Rollback();

                OnRollbackTransaction(tran, EventArgs.Empty);
            }
            finally
            {
                ////Cache.Clear(); // State "rollback" in cache. TODO: cache clear in cluster must be ensured.
                ////CACHE: Ez sose mûködött jól... Cache.Clear kéne.
                //DistributedApplication.Cache.Reset();

                ContextHandler.SetTransaction(null);
                ContextHandler.SetTransactionQueue(null);
                tran.Dispose();
            }
        }

Usage Example

        /// <summary>
        /// Marks orphaned file records (the ones that do not have a referencing binary record anymore) as Deleted.
        /// </summary>
        public void CleanupFilesSetDeleteFlag()
        {
            var isLocalTransaction = false;

            if (!TransactionScope.IsActive)
            {
                TransactionScope.Begin();
                isLocalTransaction = true;
            }

            try
            {
                using (var proc = new SqlProcedure {
                    CommandText = CleanupFileSetIsdeletedScript, CommandType = CommandType.Text
                })
                {
                    proc.CommandType = CommandType.Text;
                    proc.ExecuteNonQuery();
                }

                if (isLocalTransaction && TransactionScope.IsActive)
                {
                    TransactionScope.Commit();
                }
            }
            catch (Exception ex)
            {
                if (isLocalTransaction && TransactionScope.IsActive)
                {
                    TransactionScope.Rollback();
                }

                throw new DataException("Error during setting deleted flag on files.", ex);
            }
        }
All Usage Examples Of SenseNet.ContentRepository.Storage.TransactionScope::Rollback