Example #1
0
 private void BeginTransaction()
 {
     m_currentTransactionContext = GetCurrentTransactionContext();
     if (m_currentTransactionContext != null)
     {
         m_currentTransactionContext.Begin(Transaction);
     }
 }
Example #2
0
        /// <summary>
        /// Applies a replacement on the results of the last Query</summary>
        /// <returns>The list of objects on which we just performed a replacement</returns>
        public IEnumerable <object> Replace(object replaceInfo)
        {
            ITransactionContext currentTransaction = null;

            try
            {
                foreach (DomNodeQueryMatch match in m_results)
                {
                    DomNode             domNode        = match.DomNode;
                    ITransactionContext newTransaction = domNode != null?domNode.GetRoot().As <ITransactionContext>() : null;

                    if (newTransaction != currentTransaction)
                    {
                        {
                            if (currentTransaction != null)
                            {
                                currentTransaction.End();
                            }
                            currentTransaction = newTransaction;
                            if (currentTransaction != null)
                            {
                                currentTransaction.Begin(Localizer.Localize("Replace"));
                            }
                        }
                    }
                    // Apply replacement to all match items that predicates came up with on last search
                    foreach (IPredicateInfo predicateInfo in match.PredicateMatchResults.Keys)
                    {
                        predicateInfo.Replace(domNode, match.PredicateMatchResults[predicateInfo], replaceInfo);
                    }
                }
            }
            catch (InvalidTransactionException ex)
            {
                if (currentTransaction != null && currentTransaction.InTransaction)
                {
                    currentTransaction.Cancel();
                }

                if (ex.ReportError)
                {
                    Outputs.WriteLine(OutputMessageType.Error, ex.Message);
                }
            }
            finally
            {
                if (currentTransaction != null && currentTransaction.InTransaction)
                {
                    currentTransaction.End();
                }
            }

            Sce.Atf.Event.Raise(QueryResultsChanged, this, EventArgs.Empty);

            return((IEnumerable <Object>)m_results);
        }
        /// <summary>
        /// Performs the given action as a transaction with the given name</summary>
        /// <param name="context">Transaction context or null</param>
        /// <param name="transaction">Transaction action</param>
        /// <param name="transactionName">Transaction name</param>
        /// <returns>True if the transaction succeeded and false if it was cancelled (i.e.,
        /// InvalidTransactionException was thrown)</returns>
        /// <remarks>In the implementation of 'transaction', throw InvalidTransactionException
        /// to cancel the transaction and log a warning message to the user (unless the
        /// InvalidTransactionException's ReportError is false).</remarks>
        public static bool DoTransaction(this ITransactionContext context,
                                         Action transaction, string transactionName)
        {
            // If we are already in a transaction just perform the action
            // Let all exceptions "bubble up" and be handled by the outer transaction
            if (context != null && context.InTransaction)
            {
                transaction();
                return(true);
            }

            try
            {
                if (context != null)
                {
                    context.Begin(transactionName);
                }

                //Transactions can be canceled in the call to Begin. When this occurs,
                //we want to skip doing the transaction and the end calls.
                if (context != null && !context.InTransaction)
                {
                    return(false);
                }

                transaction();

                if (context != null)
                {
                    context.End();
                }
            }
            catch (InvalidTransactionException ex)
            {
                if (context != null && context.InTransaction)
                {
                    context.Cancel();
                }

                if (ex.ReportError)
                {
                    Outputs.WriteLine(OutputMessageType.Error, ex.Message);
                }
                return(false);
            }
            return(true);
        }
        /// <summary>
        /// Applies a replacement on the results of the last Query</summary>
        /// <param name="replaceInfo">Replacement information</param>
        /// <returns>The list of objects on which we just performed a replacement</returns>
        public IEnumerable <object> Replace(object replaceInfo)
        {
            ITransactionContext currentTransaction = null;

            try
            {
                foreach (DomNodeQueryMatch match in m_results)
                {
                    DomNode domNode = match.DomNode;

                    // Set up undo/redo for the replacement operation
                    ITransactionContext newTransaction = domNode != null?domNode.GetRoot().As <ITransactionContext>() : null;

                    if (newTransaction != currentTransaction)
                    {
                        {
                            if (currentTransaction != null)
                            {
                                currentTransaction.End();
                            }
                            currentTransaction = newTransaction;
                            if (currentTransaction != null)
                            {
                                currentTransaction.Begin("Replace".Localize());
                            }
                        }
                    }

                    // Apply replacement to all matching items that were found on last search
                    foreach (IQueryPredicate predicateInfo in match.PredicateMatchResults.Keys)
                    {
                        predicateInfo.Replace(match.PredicateMatchResults[predicateInfo], replaceInfo);
                    }
                }
            }
            catch (InvalidTransactionException ex)
            {
                // cancel the replacement transaction in the undo/redo queue
                if (currentTransaction != null && currentTransaction.InTransaction)
                {
                    currentTransaction.Cancel();
                }

                if (ex.ReportError)
                {
                    Outputs.WriteLine(OutputMessageType.Error, ex.Message);
                }
            }
            finally
            {
                // finish the replacement transaction for the undo/redo queue
                if (currentTransaction != null && currentTransaction.InTransaction)
                {
                    currentTransaction.End();
                }
            }

            ResultsChanged.Raise(this, EventArgs.Empty);

            return(m_results);
        }
Example #5
0
 private void BeginTransaction()
 {
     m_currentTransactionContext = GetCurrentTransactionContext();
     if (m_currentTransactionContext != null)
     {
         m_currentTransactionContext.Begin(Transaction);
     }
 }