Beispiel #1
0
        protected void CommitTransaction(DB.Document doc, DB.Transaction transaction)
        {
            var options = transaction.GetFailureHandlingOptions();

#if !DEBUG
            options = options.SetClearAfterRollback(true);
#endif
            options = options.SetDelayedMiniWarnings(true);
            options = options.SetForcedModalHandling(true);
            options = options.SetFailuresPreprocessor(this);
            options = options.SetTransactionFinalizer(this);

            // Disable Rhino UI if any warning-error dialog popup
            {
                External.EditScope editScope = null;
                EventHandler <DialogBoxShowingEventArgs> _ = null;
                try
                {
                    Revit.ApplicationUI.DialogBoxShowing += _ = (sender, args) =>
                    {
                        if (editScope is null)
                        {
                            editScope = new External.EditScope();
                        }
                    };

                    if (transaction.GetStatus() == DB.TransactionStatus.Started)
                    {
                        OnBeforeCommit(doc, transaction.GetName());

                        transaction.Commit(options);
                    }
                    else
                    {
                        transaction.RollBack(options);
                    }
                }
                finally
                {
                    Revit.ApplicationUI.DialogBoxShowing -= _;

                    if (editScope is IDisposable disposable)
                    {
                        disposable.Dispose();
                    }
                }
            }
        }
Beispiel #2
0
        static void ProcessWriteActions()
        {
            lock (docWriteActions)
            {
                if (docWriteActions.Count > 0)
                {
                    using (var trans = new Transaction(ActiveDBDocument))
                    {
                        try
                        {
                            isCommitting = true;

                            if (trans.Start("RhinoInside") == TransactionStatus.Started)
                            {
                                while (docWriteActions.Count > 0)
                                {
                                    docWriteActions.Dequeue().Invoke(ActiveDBDocument);
                                }

                                var options = trans.GetFailureHandlingOptions();
#if !DEBUG
                                options = options.SetClearAfterRollback(true);
#endif
                                options = options.SetDelayedMiniWarnings(true);
                                options = options.SetForcedModalHandling(true);
                                options = options.SetFailuresPreprocessor(new FailuresPreprocessor());

                                // Hide Rhino UI in case any warning-error dialog popups
                                {
                                    External.EditScope editScope = null;
                                    EventHandler <DialogBoxShowingEventArgs> _ = null;
                                    try
                                    {
                                        ApplicationUI.DialogBoxShowing += _ = (sender, args) =>
                                        {
                                            if (editScope == null)
                                            {
                                                editScope = new External.EditScope();
                                            }
                                        };

                                        trans.Commit(options);
                                    }
                                    finally
                                    {
                                        ApplicationUI.DialogBoxShowing -= _;

                                        if (editScope is IDisposable disposable)
                                        {
                                            disposable.Dispose();
                                        }
                                    }
                                }

                                if (trans.GetStatus() == TransactionStatus.Committed)
                                {
                                    foreach (GH_Document definition in Instances.DocumentServer)
                                    {
                                        if (definition.Enabled)
                                        {
                                            definition.NewSolution(false);
                                        }
                                    }
                                }
                            }
                        }
                        catch (Exception e)
                        {
                            Debug.Fail(e.Source, e.Message);
                            docWriteActions.Clear();
                        }
                        finally
                        {
                            isCommitting = false;
                        }
                    }
                }
            }
        }