当前位置: 首页>>代码示例>>C#>>正文


C# Transaction.Dispose方法代码示例

本文整理汇总了C#中Transaction.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# Transaction.Dispose方法的具体用法?C# Transaction.Dispose怎么用?C# Transaction.Dispose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Transaction的用法示例。


在下文中一共展示了Transaction.Dispose方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Build

        /// <summary>
        /// The build method is called back from the child class.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void Build(object sender, EventArgs e)
        {
            dynElement el = sender as dynElement;

            bool useTransaction = true;

            object[] attribs = el.GetType().GetCustomAttributes(typeof(RequiresTransactionAttribute), false);
            if (attribs.Length > 0)
            {
                if ((attribs[0] as RequiresTransactionAttribute).RequiresTransaction == false)
                {
                    useTransaction = false;
                }
            }

            #region using transaction
            if (useTransaction)
            {
                Transaction t = new Transaction(dynElementSettings.SharedInstance.Doc.Document, el.GetType().ToString() + " update.");
                TransactionStatus ts = t.Start();

                try
                {
                    FailureHandlingOptions failOpt = t.GetFailureHandlingOptions();
                    failOpt.SetFailuresPreprocessor(dynElementSettings.SharedInstance.WarningSwallower);
                    t.SetFailureHandlingOptions(failOpt);

                    el.Destroy();
                    el.Draw();

                    UpdateLayoutDelegate uld = new UpdateLayoutDelegate(CallUpdateLayout);
                    Dispatcher.Invoke(uld, System.Windows.Threading.DispatcherPriority.Background, new object[] { el });

                    elementsHaveBeenDeleted = false;

                    ts = t.Commit();

                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex.Message + " : " + ex.StackTrace);
                    dynElementSettings.SharedInstance.Bench.Log(ex.Message);

                    SetToolTipDelegate sttd = new SetToolTipDelegate(SetTooltip);
                    Dispatcher.Invoke(sttd, System.Windows.Threading.DispatcherPriority.Background,
                        new object[] { ex.Message});

                    MarkConnectionStateDelegate mcsd = new MarkConnectionStateDelegate(MarkConnectionState);
                    Dispatcher.Invoke(mcsd, System.Windows.Threading.DispatcherPriority.Background,
                        new object[] { true });

                    if (ts == TransactionStatus.Committed)
                    {
                        t.RollBack();
                    }

                    t.Dispose();

                    dynElementSettings.SharedInstance.Writer.WriteLine(ex.Message);
                    dynElementSettings.SharedInstance.Writer.WriteLine(ex.StackTrace);
                }

                try
                {
                    el.UpdateOutputs();
                }
                catch(Exception ex)
                {

                    //Debug.WriteLine("Outputs could not be updated.");
                    dynElementSettings.SharedInstance.Bench.Log("Outputs could not be updated.");
                    if (ts == TransactionStatus.Committed)
                    {
                        t.RollBack();
                    }

                    t.Dispose();

                    dynElementSettings.SharedInstance.Writer.WriteLine(ex.Message);
                    dynElementSettings.SharedInstance.Writer.WriteLine(ex.StackTrace);
                }
            }
            #endregion

            #region no transaction
            if (!useTransaction)
            {
                try
                {

                    el.Destroy();

                    el.Draw();

                    UpdateLayoutDelegate uld = new UpdateLayoutDelegate(CallUpdateLayout);
//.........这里部分代码省略.........
开发者ID:TCadorette,项目名称:dynamo,代码行数:101,代码来源:dynElement.xaml.cs

示例2: BuildModel

        public Result BuildModel(Grevit.Types.ComponentCollection components)
        {
            bool delete = false;

            if (components == null)
            {
                // Create new Grevit Client sending existing Families 
                Grevit.Client.ClientWindow grevitClientDialog = new Grevit.Client.ClientWindow(document.GetFamilies());
                //Grevit.Serialization.Client grevitClientDialog = new Grevit.Serialization.Client(document.GetFamilies());

                // Show Client Dialog
                grevitClientDialog.ShowWindow();
                //if (grevitClientDialog.ShowDialog() == System.Windows.Forms.DialogResult.Cancel) return Result.Cancelled;

                // Set the received component collection
                components = grevitClientDialog.componentCollection;

                delete = grevitClientDialog.componentCollection.delete;

                Scale = grevitClientDialog.componentCollection.scale;
            }



            // Set up a List for stalled components (with References)
            List<Component> componentsWithReferences = new List<Component>();

            // Get all existing Grevit Elements from the Document
            // If Update is false this will just be an empty List
            existing_Elements = document.GetExistingGrevitElements(components.update);

            // Set up an empty List for created Elements
            created_Elements = new Dictionary<string, ElementId>();


            #region createComponents

            Transaction trans = new Transaction(GrevitBuildModel.document, "GrevitCreate");
            trans.Start();

            // Walk thru all received components
            foreach (Component component in components.Items)
            {
                // If they are not reference dependent, create them directly
                // Otherwise add the component to a List of stalled elements
                if (!component.stalledForReference)
                    component.Build(false);       
                else
                    componentsWithReferences.Add(component);
            }

            // Walk thru all elements which are stalled because they are depending on
            // an Element which needed to be created first


            foreach (Component component in componentsWithReferences) component.Build(true);

            trans.Commit();
            trans.Dispose();

            #endregion


            // If Delete Setting is activated
            if (delete)
            {
                // Create a new transaction
                Transaction transaction = new Transaction(document, "GrevitDelete");
                transaction.Start();

                // get the Difference between existing and new elements to erase them
                IEnumerable<KeyValuePair<string, ElementId>> unused = 
                    existing_Elements.Except(created_Elements).Concat(created_Elements.Except(existing_Elements));

                // Delete those elements from the document
                foreach (KeyValuePair<string, ElementId> element in unused) document.Delete(element.Value);

                // commit and dispose the transaction
                transaction.Commit();
                transaction.Dispose();
            }



            return Result.Succeeded;
        }
开发者ID:samuto,项目名称:Grevit,代码行数:86,代码来源:Revit.cs

示例3: Dispose

 public void Dispose(Transaction tr)
 {
     if (!AC_blockTable.IsDisposed)
     {
         AC_blockTable.Dispose();
     }
     if (!AC_blockTableRecord.IsDisposed)
     {
         AC_blockTableRecord.Dispose();
     }
     if (!tr.IsDisposed)
     {
         tr.Commit();
         tr.Dispose();
     }
 }
开发者ID:darkimage,项目名称:utility_funcs,代码行数:16,代码来源:AC_Transations.cs

示例4: Execute

        public Autodesk.Revit.UI.Result Execute(Autodesk.Revit.UI.ExternalCommandData revit, ref string message, ElementSet elements)
        {
            try
            {

                //create a log file
                string tempPath = System.IO.Path.GetTempPath();
                string logPath = Path.Combine(tempPath, "dynamoLog.txt");

                if (File.Exists(logPath))
                    File.Delete(logPath);

                tw = new StreamWriter(logPath);
                tw.WriteLine("Dynamo log started " + System.DateTime.Now.ToString());

                m_revit = revit.Application;
                m_doc = m_revit.ActiveUIDocument;

                trans = new Transaction(m_doc.Document, "Dynamo");
                trans.Start();

                FailureHandlingOptions failOpt = trans.GetFailureHandlingOptions();
                failOpt.SetFailuresPreprocessor(new DynamoWarningSwallower());
                trans.SetFailureHandlingOptions(failOpt);

                m_revit.Idling += new EventHandler<IdlingEventArgs>(OnIdling);

                #region default level
                Level defaultLevel = null;
                FilteredElementCollector fecLevel = new FilteredElementCollector(m_doc.Document);
                fecLevel.OfClass(typeof(Level));
                for (int i = 0; i < fecLevel.ToElements().Count; i++)
                {
                    defaultLevel = fecLevel.ToElements()[i] as Level;
                    break;
                }

                #endregion

                DynamoWarningSwallower swallow = new DynamoWarningSwallower();

                dynElementSettings.SharedInstance.Revit = m_revit;
                dynElementSettings.SharedInstance.Doc = m_doc;
                dynElementSettings.SharedInstance.DefaultLevel = defaultLevel;
                dynElementSettings.SharedInstance.WarningSwallower = swallow;
                dynElementSettings.SharedInstance.MainTransaction = trans;
                dynElementSettings.SharedInstance.Writer = tw;
                //dynElementSettings settings = new dynElementSettings(m_revit, m_doc,
                    //defaultLevel, swallow, trans);

                //show the log
                dynamoForm = new dynBench();

                //get the window handle
                Process process = Process.GetCurrentProcess();
                new System.Windows.Interop.WindowInteropHelper(dynamoForm).Owner = process.MainWindowHandle;
                dynamoForm.Show();

                if (dynamoForm.DialogResult.HasValue && dynamoForm.DialogResult.Value == false)   //the WPF false is "cancel"
                {
                    tw.WriteLine("Dynamo log ended " + System.DateTime.Now.ToString());
                    tw.Close();

                    return Autodesk.Revit.UI.Result.Cancelled;
                }

            }
            catch (Exception e)
            {
                trans.Dispose();
                Debug.WriteLine(e.Message + ":" + e.StackTrace);
                Debug.WriteLine(e.InnerException);
                message = e.Message + " : " + e.StackTrace;

                if (tw != null)
                {
                    tw.WriteLine(e.Message);
                    tw.WriteLine(e.StackTrace);
                    tw.Close();
                }

                return Autodesk.Revit.UI.Result.Failed;
            }

            trans.Commit();

            return Autodesk.Revit.UI.Result.Succeeded;
        }
开发者ID:TCadorette,项目名称:dynamo,代码行数:88,代码来源:DynamoRevit.cs

示例5: Execute

        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            _uiApp = commandData.Application;
            Document doc = _uiApp.ActiveUIDocument.Document;
            UIDocument uidoc = _uiApp.ActiveUIDocument;

            // take care of AppDomain load issues
            AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve;

            Transaction trans = null;
            try
            {

                if (uidoc.ActiveGraphicalView.ViewType != ViewType.ThreeD) throw new ApplicationException("Please run this command from a 3D View!");

                string WebURL = "http://128.8.215.91";
                //DOCQRclient client = new DOCQRclient(WebURL);

                LogInFrm loginForm = new LogInFrm(WebURL, false);

                if (loginForm.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    DOCQRclient client = loginForm.DClient;

                    WebURL = client.Server;
                    ProjectSelectFrm ProjectSelectFrm = new ProjectSelectFrm(client);
                    if (ProjectSelectFrm.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                    {
                        List<SheetInfo> sheets = GetSheetViewInfo(doc);
                        List<ElementId> ViewsToDelete = new List<ElementId>();
                        ViewNames names = new ViewNames();
                        client.GetModelID(ProjectSelectFrm.SelectedProject.id);

                        ProgressForm progress = new ProgressForm(_viewCount * 3);
                        progress.Show();

                        trans = new Transaction(doc, "QR");
                        trans.Start();

                        // go through all the sheets and then views
                        // make a 3d view
                        // save each 3d view json file
                        foreach (SheetInfo sheet in sheets)
                        {
                            foreach (ViewPortInfo vpInfo in sheet.ViewPorts)
                            {
                                Spectacles.RevitExporter.Command cmd = new Spectacles.RevitExporter.Command();
                                string tempFile = System.IO.Path.Combine(System.IO.Path.GetTempPath(), doc.Title + vpInfo.view.Id + ".json");

                                if (progress.IsCancelled) throw new ApplicationException("DOCQR Cancelled...");
                                progress.SetStatus("Exporting View: " + vpInfo.view.Name + " to Spectacles...");
                                System.Diagnostics.Debug.WriteLine("Exporting View " + vpInfo.view.Name + " to Spectacles...");
                                View3D temp3dView = vpInfo.view.GetMatching3DView(doc);
                                cmd.ExportEntireModel(temp3dView, tempFile);
                                ViewsToDelete.Add(temp3dView.Id);

                                if (progress.IsCancelled) throw new ApplicationException("DOCQR Cancelled...");
                                progress.Step();
                                progress.SetStatus("Sending View: " + vpInfo.view.Name + " to DOCQR...");
                                vpInfo.docQRid = client.SendModelInfo(ProjectSelectFrm.SelectedProject, tempFile);            // send the model and view info to the web server
                                names.Views.Add(new ViewName() { Name = vpInfo.view.Name, ID = vpInfo.docQRid });
                                progress.Step();
                            }
                        }

                        //client.SendViewInfo(names);

                        progress.SetStatus("Adding QR Codes...");
                        foreach (SheetInfo sheet in sheets)
                        {
                            if (progress.IsCancelled) throw new ApplicationException("DOCQR Cancelled...");
                            progress.Step();
                            RevitQR QR = new RevitQR(doc, sheet, true, WebURL);                                                   // create QR codes
                        }

                        progress.Close();

                        doc.Delete(ViewsToDelete);

                        trans.Commit();
                        trans.Dispose();

                        TaskDialog.Show("DOCQR", "QR Codes added to " + _viewCount + " viewports!");
                    }
                }
            }
            catch (ApplicationException aex)
            {
                TaskDialog.Show("DOCQR", aex.Message);
                if ((trans != null) && (trans.HasStarted())) trans.RollBack();
                return Result.Cancelled;
            }
            catch (Exception ex)
            {
                TaskDialog td = new TaskDialog("Unexpected Issue");
                td.MainInstruction = ex.GetType().Name + ": " + ex.Message;
                string expanded = "";
                if (ex.InnerException != null)
                {
                    expanded += Environment.NewLine + "Inner: " + ex.InnerException.GetType().Name + ": " + ex.InnerException.Message;
//.........这里部分代码省略.........
开发者ID:DOCQR,项目名称:revit,代码行数:101,代码来源:Command.cs

示例6: Execute


//.........这里部分代码省略.........
                //}
                //Autodesk.Revit.DB.FamilySymbol beamType_2L6X6X12 = FindFamilySymbol(rvtDoc.Document, "LL-Double Angle", "2L6X6X1/2");
                //if (beamType_2L6X6X12 == null)
                //{
                //    MessageBox.Show("       The beam family is not loaded.        \n         Please load the 2L family.         \n       Action Cancelled.       ", "MKA Tieback Placer 2013_v1.0");
                //    tran.Dispose();
                //    return Autodesk.Revit.UI.Result.Failed;
                //}
                //Autodesk.Revit.DB.FamilySymbol beamType_2L8X8X12 = FindFamilySymbol(rvtDoc.Document, "LL-Double Angle", "2L8X8X1/2");
                //if (beamType_2L8X8X12 == null)
                //{
                //    MessageBox.Show("       The beam family is not loaded.        \n         Please load the 2L family.         \n       Action Cancelled.       ", "MKA Tieback Placer 2013_v1.0");
                //    tran.Dispose();
                //    return Autodesk.Revit.UI.Result.Failed;
                //}
                #endregion

                //display open file dialog
                String input = string.Empty;
                //apply restrictions to what displays in the file open dialog
                OpenFileDialog dialog = new OpenFileDialog();
                dialog.Filter = "csv files (*.csv)|*.csv";
                dialog.InitialDirectory = "C:";
                dialog.Title = "Select a .csv file";

                if (dialog.ShowDialog() == DialogResult.OK) //the user selected a csv file
                {
                    input = dialog.FileName;
                }
                if (input == String.Empty) //the user didn't select a csv file
                {
                    MessageBox.Show("       You didn't select a csv file.       \n       Action Cancelled.       ", "SkyRise Canopy Placer");
                    //kill the transaction and end the program
                    tran.Dispose();
                    return Autodesk.Revit.UI.Result.Failed;
                }

                //parse csv input and create list of strings
                List<string[]> csvoutput = new List<string[]>();
                csvparser parser = new csvparser();
                csvoutput = parser.parsecsv(input);
                //if the csv file was empty, cancel the operation
                if (csvoutput.Count == 0)
                {
                    MessageBox.Show("       The csv file is empty.       \n       Action Cancelled.       ", "SkyRise Canopy Placer");
                    tran.Dispose();
                    return Autodesk.Revit.UI.Result.Failed;
                }

                #region debugging code
                //Awesome deugging code that displays the array contents after parsing
                //String debug = "The contents of the csvoutput are: \n";
                //int rowcount = 0;
                //foreach (string[] row in csvoutput)
                //{
                //    debug = debug + "row " + rowcount.ToString() + " : ";
                //    foreach (string cells in row)
                //    {
                //        debug = debug + "[" + cells + "] ";
                //    }
                //    debug = debug + "\n";
                //    rowcount++;
                //}
                //MessageBox.Show(debug, "Debug");
                #endregion
开发者ID:kdaner,项目名称:04_ProjSpecificPanel_SkyRise-Canopy-Creator,代码行数:66,代码来源:Controller.cs

示例7: Execute


//.........这里部分代码省略.........

                        // Prompt for the upper curve
                        Reference refe = uidoc.Selection.PickObject(Autodesk.Revit.UI.Selection.ObjectType.Element, "Select upper");
                        DetailCurve upper = (DetailCurve)doc.GetElement(refe.ElementId);
                        Curve uppercurve = (Curve)upper.GeometryCurve;

                        // Collector for ElementIds for grouping
                        List<ElementId> Ids = new List<ElementId>();

                        // Initial location along the curve
                        double location = 0;

                        // Start with a left loop
                        bool left = true;

                        // Walk along the curve and draw loops
                        while ((location / lowercurve.Length) < 1)
                        {
                            location += drawInsulation(Ids, doc, lowercurve, location, uppercurve, ref left, new List<Interruption>(), insmat.zigzag);
                        }

                        // Create a group
                        doc.Create.NewGroup(Ids);

                    }

                    // Handle Walls
                    if (em.GetType() == typeof(Wall))
                    {
                        // Get the LocationCurve and cast the Wall
                        Wall wall = (Wall)em;
                        LocationCurve c = (LocationCurve)wall.Location;

                        // List for Interruptions like Doors and Windows
                        List<Interruption> Breaks = new List<Interruption>();

                        // Get the Compound Structure
                        CompoundStructure cs = wall.WallType.GetCompoundStructure();

                        // Id Collection for Grouping
                        List<ElementId> Ids = new List<ElementId>();

                        // Get the walls Startpoint
                        XYZ p1 = c.Curve.GetEndPoint(0);
                        double x2 = c.Curve.GetEndPoint(1).X;

                        // Retrieve Boundaries of the Insulation layer
                        Tuple<Curve, Curve> curves = getInsulationLayer(doc, wall);

                        if (curves != null)
                        {

                            // Collect Openings from the wall
                            removeOpenings(ref Breaks, wall, doc);

                            // initial Insulation location
                            double location = 0;

                            // Start with a left loop
                            bool left = true;

                            // Set this wall as banned from intersection checks
                            List<int> BannedWalls = new List<int>() { wall.Id.IntegerValue };

                            // Get extensions to left hand joined walls
                            Curve lowerExtendedLeft = handleJoinsLeft(doc, c, curves.Item2, ref BannedWalls);

                            // Get extensions to other layers
                            // adjust the interruptions if the insulation layer is extended
                            double offset = lowerExtendedLeft.Length - curves.Item2.Length;
                            if (offset > 0) foreach (Interruption ir in Breaks) ir.Extend(offset);

                            // Get Extensions to right hand joined walls
                            Tuple<Curve, Curve> extended = handleJoinsRight(doc, c, lowerExtendedLeft, curves.Item1, ref BannedWalls);

                            // draw insulation loops anlong the curve
                            while (location / extended.Item2.Length < 1)
                                location += drawInsulation(Ids, doc, extended.Item2, location, extended.Item1, ref left, Breaks, insmat.zigzag);

                            // Group loops
                            doc.Create.NewGroup(Ids);
                        }
                        else
                        {
                            MessageBox.Show("Could not find any insulation material layer in the selected wall. Please create a layer using a material named \"soft insulation\".");
                        }
                    }

                }

                trans.Commit();
                trans.Dispose();
            }
            catch (System.Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.Message);
                return Result.Failed;
            }
            return Result.Succeeded;
        }
开发者ID:moethu,项目名称:Insulator,代码行数:101,代码来源:Insulator.cs


注:本文中的Transaction.Dispose方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。