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


C# Transaction.RollBack方法代码示例

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


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

示例1: deleteLinePatterns

        public void deleteLinePatterns(Document doc)
        {
            var collector = new FilteredElementCollector(doc)
                .OfClass(typeof(LinePatternElement)).Where(i => i.Name.StartsWith("IMPORT")).ToList();

            List<ElementId> ids = new List<ElementId>();
            for (int i = 0; i < collector.Count(); i++)
            {
                ids.Add(collector[i].Id);
            }

            using (Transaction t = new Transaction(doc, "Remove Pattern"))
            {
                t.Start();
                try
                {
                    doc.Delete(ids);
                }
                catch (Exception)
                {
                    t.RollBack();
                    return;
                }
                t.Commit();
            }
        }
开发者ID:dannysbentley,项目名称:Delete-Change-Line-Styles,代码行数:26,代码来源:getLines.cs

示例2: TestOne

        public void TestOne()
        {
            using (var t = new Transaction(DocumentManager.Instance.CurrentDBDocument))
            {
                if (t.Start("Test one.") == TransactionStatus.Started)
                {
                    //create a reference point
                    var pt = DocumentManager.Instance.CurrentDBDocument.FamilyCreate.NewReferencePoint(new XYZ(5, 5, 5));

                    if (t.Commit() != TransactionStatus.Committed)
                    {
                        t.RollBack();
                    }
                }
                else
                {
                    throw new Exception("Transaction could not be started.");
                }
            }

            //verify that the point was created
            var collector = new FilteredElementCollector(DocumentManager.Instance.CurrentDBDocument);
            collector.OfClass(typeof (ReferencePoint));

            Assert.AreEqual(1, collector.ToElements().Count);
        }
开发者ID:algobasket,项目名称:Dynamo,代码行数:26,代码来源:TestExamples.cs

示例3: getNumberOfRowsAndColumns

        /// <summary>
        /// An utility method to get the number of rows and columns of the section which is exporting.
        /// </summary>
        /// <param name="doc">Revit document.</param>
        /// <param name="psView">the exporting panel schedule view</param>
        /// <param name="sectionType">the exporting section of the panel schedule.</param>
        /// <param name="nRows">the number of rows.</param>
        /// <param name="nCols">the number of columns.</param>
        protected void getNumberOfRowsAndColumns(Autodesk.Revit.DB.Document doc, PanelScheduleView psView, SectionType sectionType, ref int nRows, ref int nCols)
        {
            Transaction openSectionData = new Transaction(doc, "openSectionData");
            openSectionData.Start();

            TableSectionData sectionData = psView.GetSectionData(sectionType);
            nRows = sectionData.NumberOfRows;
            nCols = sectionData.NumberOfColumns;

            openSectionData.RollBack();
        }
开发者ID:jamiefarrell,项目名称:Panel-Schedules-to-Excel,代码行数:19,代码来源:Translator.cs

示例4: DoWork

 public void DoWork()
 {
     RevitContext.Application.WriteJournalComment("Looping", false);
     using (var transaction = new Transaction(RevitContext.Document))
     {
         transaction.Start("looping");
         var fec = new FilteredElementCollector(RevitContext.Document).WhereElementIsNotElementType().OfClass(typeof(Wall));
         var idx = 1;
         foreach (Wall element in fec)
         {
             idx++;
             Thread.Sleep(50);
         }
         transaction.RollBack();
     }
 }
开发者ID:Redbolts,项目名称:R14Tests,代码行数:16,代码来源:FilterNoOutputWorker.cs

示例5: Execute

        /// <summary>
        /// Implement this method as an external command for Revit.
        /// </summary>
        /// <param name="commandData">An object that is passed to the external application 
        /// which contains data related to the command, 
        /// such as the application object and active view.</param>
        /// <param name="message">A message that can be set by the external application 
        /// which will be displayed if a failure or cancellation is returned by 
        /// the external command.</param>
        /// <param name="elements">A set of elements to which the external application 
        /// can add elements that are to be highlighted in case of failure or cancellation.</param>
        /// <returns>Return the status of the external command. 
        /// A result of Succeeded means that the API external method functioned as expected. 
        /// Cancelled can be used to signify that the user cancelled the external operation 
        /// at some point. Failure should be returned if the application is unable to proceed with 
        /// the operation.</returns>
        public Autodesk.Revit.UI.Result Execute(ExternalCommandData commandData, ref string message, Autodesk.Revit.DB.ElementSet elements)
        {
            Transaction tran = new Transaction(commandData.Application.ActiveUIDocument.Document, "CreateBeamSystem");
            tran.Start();

            try
            {
                GeometryUtil.CreApp = commandData.Application.Application.Create;

                // initialize precondition data of the program
                BeamSystemData data = new BeamSystemData(commandData);
                // display form to collect user's setting for beam system
                using (BeamSystemForm form = new BeamSystemForm(data))
                {
                    if (form.ShowDialog() != DialogResult.OK)
                    {
                        tran.RollBack();
                        return Autodesk.Revit.UI.Result.Cancelled;
                    }
                }

                // create beam system using the parameters saved in BeamSystemData
                BeamSystemBuilder builder = new BeamSystemBuilder(data);
                builder.CreateBeamSystem();
            }
            catch (ErrorMessageException errorEx)
            {
                // checked exception need to show in error messagebox
                message = errorEx.Message;
                tran.RollBack();
                return Autodesk.Revit.UI.Result.Failed;
            }
            catch(Exception ex)
            {
                // unchecked exception cause command failed
                message = "Command is failed for unexpected reason.";
                Trace.WriteLine(ex.ToString());
                tran.RollBack();
                return Autodesk.Revit.UI.Result.Failed;
            }

            tran.Commit();
            return Autodesk.Revit.UI.Result.Succeeded;
        }
开发者ID:AMEE,项目名称:revit,代码行数:60,代码来源:Command.cs

示例6: SaveNewCustomer

 public Customer SaveNewCustomer(Customer newCustomer)
 {
     Console.WriteLine("Entering SaveNewCustomer with {0}", newCustomer);
     using (var transaction = new Transaction())
     {
         try
         {
             var id = dal.SaveCustomer(newCustomer);
             var customer = dal.RetrieveCustomer(id);
             transaction.Commit();
             Console.WriteLine("Exiting SaveNewCustomer with {0}", customer);
             return customer;
         }
         catch (Exception ex)
         {
             Console.WriteLine("Exception occured : {0}", ex.Message);
             transaction.RollBack();
             throw;
         }
     }
 }
开发者ID:RhysC,项目名称:PerthDnugAopSample,代码行数:21,代码来源:DummyService.cs

示例7: SetParameterValue

        public bool SetParameterValue(string parameterName, string value)
        {
            if (!HasParameter(parameterName)) { return false; }

            Parameter theParam = GetParameterFromProjectInfo(parameterName);

            Transaction transaction = new Transaction(_doc, "updating parameter " + parameterName);
            if (transaction.Start() == TransactionStatus.Started)
            {
                try
                {
                    theParam.Set(value);
                    transaction.Commit();
                    return true;
                }
                catch (Exception ex)
                {
                    transaction.RollBack();
                }
            }
            return false;
        }
开发者ID:ArupAus,项目名称:RvtUnit,代码行数:22,代码来源:ParameterHelper.cs

示例8: Execute

        /// <summary>
        /// Implement this method as an external command for Revit.
        /// </summary>
        /// <param name="commandData">An object that is passed to the external application 
        /// which contains data related to the command, 
        /// such as the application object and active view.</param>
        /// <param name="message">A message that can be set by the external application 
        /// which will be displayed if a failure or cancellation is returned by 
        /// the external command.</param>
        /// <param name="elements">A set of elements to which the external application 
        /// can add elements that are to be highlighted in case of failure or cancellation.</param>
        /// <returns>Return the status of the external command. 
        /// A result of Succeeded means that the API external method functioned as expected. 
        /// Cancelled can be used to signify that the user cancelled the external operation 
        /// at some point. Failure should be returned if the application is unable to proceed with 
        /// the operation.</returns>
        public Autodesk.Revit.UI.Result Execute(ExternalCommandData commandData, ref string message, Autodesk.Revit.DB.ElementSet elements)
        {
            Transaction transaction = new Transaction(commandData.Application.ActiveUIDocument.Document, "External Tool");
            try
            {
                transaction.Start();

                Resolver resolver = new Resolver(commandData);
                resolver.Resolve();
            }
            catch (System.Exception e)
            {
                transaction.RollBack();
                message += e.ToString();
                return Autodesk.Revit.UI.Result.Failed;
            }
            finally
            {
                transaction.Commit();
            }
            return Autodesk.Revit.UI.Result.Succeeded;
        }
开发者ID:AMEE,项目名称:revit,代码行数:38,代码来源:Command.cs

示例9: Execute

        /// <summary>
        /// Implement this method as an external command for Revit.
        /// </summary>
        /// <param name="commandData">An object that is passed to the external application 
        /// which contains data related to the command, 
        /// such as the application object and active view.</param>
        /// <param name="message">A message that can be set by the external application 
        /// which will be displayed if a failure or cancellation is returned by 
        /// the external command.</param>
        /// <param name="elements">A set of elements to which the external application 
        /// can add elements that are to be highlighted in case of failure or cancellation.</param>
        /// <returns>Return the status of the external command. 
        /// A result of Succeeded means that the API external method functioned as expected. 
        /// Cancelled can be used to signify that the user cancelled the external operation 
        /// at some point. Failure should be returned if the application is unable to proceed with 
        /// the operation.</returns>
        public virtual Autodesk.Revit.UI.Result Execute(ExternalCommandData commandData
            , ref string message, Autodesk.Revit.DB.ElementSet elements)
        {
            Autodesk.Revit.DB.Document doc = commandData.Application.ActiveUIDocument.Document;

            Reference selected = commandData.Application.ActiveUIDocument.Selection.PickObject(ObjectType.Element);

            Transaction newInstanceView = new Transaction(doc, "Create instance view for an electrical panel.");
            newInstanceView.Start();
            PanelScheduleView instanceView = PanelScheduleView.CreateInstanceView(doc, doc.GetElement(selected).Id);
            if (null == instanceView)
            {
                newInstanceView.RollBack();
                message = "Please select one electrical panel.";
                return Result.Failed;
            }
            else
            {
                newInstanceView.Commit();
                return Result.Succeeded;
            }

        }
开发者ID:jamiefarrell,项目名称:Panel-Schedules-to-Excel,代码行数:39,代码来源:InstanceViewCreation.cs

示例10: Execute

 /// <summary>
 /// Implement this method as an external command for Revit.
 /// </summary>
 /// <param name="commandData">An object that is passed to the external application 
 /// which contains data related to the command, 
 /// such as the application object and active view.</param>
 /// <param name="message">A message that can be set by the external application 
 /// which will be displayed if a failure or cancellation is returned by 
 /// the external command.</param>
 /// <param name="elements">A set of elements to which the external application 
 /// can add elements that are to be highlighted in case of failure or cancellation.</param>
 /// <returns>Return the status of the external command. 
 /// A result of Succeeded means that the API external method functioned as expected. 
 /// Cancelled can be used to signify that the user cancelled the external operation 
 /// at some point. Failure should be returned if the application is unable to proceed with 
 /// the operation.</returns>
 public Autodesk.Revit.UI.Result Execute(Autodesk.Revit.UI.ExternalCommandData commandData,
                                        ref string message, Autodesk.Revit.DB.ElementSet elements)
 {
     Transaction tranSample = null;
     try
     {
         tranSample = new Transaction(commandData.Application.ActiveUIDocument.Document, "Sample Start");
         tranSample.Start();
         // create a form to display the information of Revit rooms and xls based rooms
         using (RoomScheduleForm infoForm = new RoomScheduleForm(commandData))
         {
             infoForm.ShowDialog();
         }
         tranSample.Commit();
         return Autodesk.Revit.UI.Result.Succeeded;
     }
     catch (Exception ex)
     {
         if (null != tranSample) tranSample.RollBack();
         // if there are something wrong, give error information and return failed
         message = ex.Message;
         return Autodesk.Revit.UI.Result.Failed;
     }
 }
开发者ID:AMEE,项目名称:revit,代码行数:40,代码来源:Command.cs

示例11: Execute

        /// <summary>
        /// Implement this method as an external command for Revit.
        /// </summary>
        /// <param name="commandData">An object that is passed to the external application 
        /// which contains data related to the command, 
        /// such as the application object and active view.</param>
        /// <param name="message">A message that can be set by the external application 
        /// which will be displayed if a failure or cancellation is returned by 
        /// the external command.</param>
        /// <param name="elements">A set of elements to which the external application 
        /// can add elements that are to be highlighted in case of failure or cancellation.</param>
        /// <returns>Return the status of the external command. 
        /// A result of Succeeded means that the API external method functioned as expected. 
        /// Cancelled can be used to signify that the user cancelled the external operation 
        /// at some point. Failure should be returned if the application is unable to proceed with 
        /// the operation.</returns>
        public Autodesk.Revit.UI.Result Execute(ExternalCommandData commandData,
                                                    ref string message, Autodesk.Revit.DB.ElementSet elements)
        {
            m_revit = commandData.Application.Application;
            Transaction documentTransaction = new Transaction(commandData.Application.ActiveUIDocument.Document, "Document");
            documentTransaction.Start();
            // Initialize the helper classes.
            m_combinationDeal = new LoadCombinationDeal(this);
            m_loadCaseDeal = new LoadCaseDeal(this);

            // Prepare some data for the form displaying
            PrepareData();

            // Display the form and wait for the user's operate.
            // This class give some public methods to add or delete LoadUsage and delete LoadCombination
            // The form will use these methods to add or delete dynamically.
            // If the user press cancel button, return Cancelled to roll back All the changes.
            using (LoadsForm displayForm = new LoadsForm(this))
            {
                if (DialogResult.OK != displayForm.ShowDialog())
                {
                    documentTransaction.RollBack();
                    return Autodesk.Revit.UI.Result.Cancelled;
                }
            }

            // If everything goes right, return succeeded.
            documentTransaction.Commit();
            return Autodesk.Revit.UI.Result.Succeeded;
        }
开发者ID:AMEE,项目名称:revit,代码行数:46,代码来源:Loads.cs

示例12: ExportToImage3

    /// <summary>
    /// New code as described in Revit API discussion 
    /// forum thread on how to export an image from a 
    /// specific view using Revit API C#,
    /// http://forums.autodesk.com/t5/revit-api/how-to-export-an-image-from-a-specific-view-using-revit-api-c/m-p/6424418
    /// </summary>
    static Result ExportToImage3( Document doc )
    {
      Result r = Result.Failed;

      using( Transaction tx = new Transaction( doc ) )
      {
        tx.Start( "Export Image" );

        string desktop_path = Environment.GetFolderPath( 
          Environment.SpecialFolder.Desktop );

        View view = doc.ActiveView;

        string filepath = Path.Combine( desktop_path, 
          view.Name );

        ImageExportOptions img = new ImageExportOptions();

        img.ZoomType = ZoomFitType.FitToPage;
        img.PixelSize = 32;
        img.ImageResolution = ImageResolution.DPI_600;
        img.FitDirection = FitDirectionType.Horizontal;
        img.ExportRange = ExportRange.CurrentView;
        img.HLRandWFViewsFileType = ImageFileType.PNG;
        img.FilePath = filepath;
        img.ShadowViewsFileType = ImageFileType.PNG;

        doc.ExportImage( img );

        tx.RollBack();

        filepath = Path.ChangeExtension( 
          filepath, "png" );

        Process.Start( filepath );

        r = Result.Succeeded;
      }
      return r;
    }
开发者ID:jeremytammik,项目名称:the_building_coder_samples,代码行数:46,代码来源:CmdExportImage.cs

示例13: GetElementsMatchingParameter

        /// <summary>
        /// Return a list of all elements with the 
        /// specified value in their shared parameter with 
        /// the given name oand group. They are retrieved
        /// using a parameter filter, and the required 
        /// parameter id is found by temporarily adding 
        /// the shared parameter to the project info.
        /// </summary>
        static IList<Element> GetElementsMatchingParameter(
            Document doc,
            string paramName,
            string paramGroup,
            string paramValue)
        {
            IList<Element> elems = new List<Element>();

              // Determine if definition for parameter binding exists

              Definition definition = null;
              BindingMap bm = doc.ParameterBindings;
              DefinitionBindingMapIterator it = bm.ForwardIterator();
              while( it.MoveNext() )
              {
            Definition def = it.Key;
            if( def.Name.Equals( paramName ) )
            {
              definition = def;
              break;
            }
              }
              if( definition == null )
              {
            return elems; // parameter binding not defined
              }

              using( Transaction tx = new Transaction( doc ) )
              {
            tx.Start( "Set temporary parameter" );

            // Temporarily set project information element
            // parameter in order to determine param.Id

            FilteredElementCollector collectorPI
              = new FilteredElementCollector( doc );

            collectorPI.OfCategory(
              BuiltInCategory.OST_ProjectInformation );

            Element projInfoElem
              = collectorPI.FirstElement();

            // using http://thebuildingcoder.typepad.com/blog/2012/04/adding-a-category-to-a-shared-parameter-binding.html

            Parameter param = null;

            //param = HelperParams.GetOrCreateElemSharedParam(
            //     projInfoElem, paramName, paramGroup,
            //     ParameterType.Text, false, true );

            if( param != null )
            {
              ElementId paraId = param.Id;

              tx.RollBack(); // discard project element change

              ParameterValueProvider provider
            = new ParameterValueProvider( paraId );

              FilterRule rule = new FilterStringRule(
            provider, new FilterStringEquals(),
            paramValue, true );

              ElementParameterFilter filter
            = new ElementParameterFilter( rule );

              FilteredElementCollector collector
            = new FilteredElementCollector(
              doc, doc.ActiveView.Id );

              elems = collector.WherePasses( filter )
            .ToElements();
            }
              }
              return elems;
        }
开发者ID:nbright,项目名称:the_building_coder_samples,代码行数:85,代码来源:CmdCollectorPerformance.cs

示例14: Execute

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

              Transaction t = new Transaction( doc );

              t.Start( "Create Steel Stair Beams" );

              // Check whether the required family is loaded:

              FilteredElementCollector collector
            = new FilteredElementCollector( doc )
              .OfClass( typeof( Family ) );

              // If the family is not already loaded, do so:

              if( !collector.Any<Element>(
            e => e.Name.Equals( FamilyName ) ) )
              {
            FamilySymbol symbol;

            if( !doc.LoadFamilySymbol(
              _family_path, SymbolName, out symbol ) )
            {
              message = string.Format(
            "Unable to load '{0}' from '{1}'.",
            SymbolName, _family_path );

              t.RollBack();

              return Result.Failed;
            }
              }

              try
              {
            // Create a couple of connected beams:

            SteelStairs s = new SteelStairs( doc );

            s.Run();

            t.Commit();

            return Result.Succeeded;
              }
              catch( Exception ex )
              {
            message = ex.Message;

            t.RollBack();

            return Result.Failed;
              }
        }
开发者ID:nbright,项目名称:the_building_coder_samples,代码行数:61,代码来源:CmdSteelStairBeams.cs

示例15: lock

        List<RevitParameter> ILyrebirdService.GetParameters(RevitObject revitFamily, string typeName)
        {
            lock (_locker)
            {
                TaskContainer.Instance.EnqueueTask(uiApp =>
                {
                    var doc = uiApp.ActiveUIDocument.Document;
                    parameters = new List<RevitParameter>();
                    if (revitFamily.CategoryId == -2000011)
                    {
                        // do stuff for walls
                        FilteredElementCollector wallCollector = new FilteredElementCollector(uiApp.ActiveUIDocument.Document);
                        wallCollector.OfClass(typeof(WallType));
                        wallCollector.OfCategory(BuiltInCategory.OST_Walls);
                        foreach (WallType wt in wallCollector)
                        {
                            if (wt.Name == typeName)
                            {
                                // Get the type parameters
                                List<Parameter> typeParams = new List<Parameter>();
                                foreach (Parameter p in wt.Parameters)
                                {
                                    if(!p.IsReadOnly)
                                        typeParams.Add(p);
                                }

                                // Get the instance parameters
                                List<Parameter> instParameters = new List<Parameter>();
                                using (Transaction t = new Transaction(doc, "temp family"))
                                {
                                    t.Start();
                                    Wall wall = null;
                                    try
                                    {
                                        Curve c = Line.CreateBound(new XYZ(0, 0, 0), new XYZ(1, 0, 0));
                                        FilteredElementCollector lvlCollector = new FilteredElementCollector(doc);
                                        Level l = lvlCollector.OfClass(typeof(Level)).ToElements().OfType<Level>().FirstOrDefault();
                                        if (l != null) wall = Wall.Create(doc, c, l.Id, false);
                                    }
                                    catch (Exception exception)
                                    {
                                        // Failed to create the wall, no instance parameters will be found
                                        Debug.WriteLine(exception.Message);
                                    }

                                    if (wall != null)
                                    {
                                        foreach (Parameter p in wall.Parameters)
                                        {
                                            //if(!p.IsReadOnly)
                                                instParameters.Add(p);
                                        }
                                    }
                                    t.RollBack();
                                }
                                typeParams.Sort((x, y) => String.CompareOrdinal(x.Definition.Name, y.Definition.Name));
                                instParameters.Sort((x, y) => String.CompareOrdinal(x.Definition.Name, y.Definition.Name));
                                foreach (Parameter p in typeParams)
                                {
                                    RevitParameter rp = new RevitParameter
                                    {
                                        ParameterName = p.Definition.Name,
                                        StorageType = p.StorageType.ToString(),
                                        IsType = true
                                    };
                                    parameters.Add(rp);
                                }
                                foreach (Parameter p in instParameters)
                                {
                                    RevitParameter rp = new RevitParameter
                                    {
                                        ParameterName = p.Definition.Name,
                                        StorageType = p.StorageType.ToString(),
                                        IsType = false
                                    };

                                    parameters.Add(rp);
                                }
                                break;
                            }
                        }
                    }
                    else if (revitFamily.CategoryId == -2000032)
                    {
                        // get parameters for floors
                        FilteredElementCollector floorCollector = new FilteredElementCollector(doc);
                        floorCollector.OfClass(typeof(FloorType));
                        floorCollector.OfCategory(BuiltInCategory.OST_Floors);
                        foreach (FloorType ft in floorCollector)
                        {
                            if (ft.Name == typeName)
                            {
                                // Get the type parameters
                                List<Parameter> typeParams = new List<Parameter>();
                                foreach (Parameter p in ft.Parameters)
                                {
                                    if(!p.IsReadOnly)
                                        typeParams.Add(p);
                                }

//.........这里部分代码省略.........
开发者ID:samuto,项目名称:Lyrebird,代码行数:101,代码来源:LyrebirdService.cs


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