本文整理汇总了C#中Transaction.HasStarted方法的典型用法代码示例。如果您正苦于以下问题:C# Transaction.HasStarted方法的具体用法?C# Transaction.HasStarted怎么用?C# Transaction.HasStarted使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Transaction
的用法示例。
在下文中一共展示了Transaction.HasStarted方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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 newTran = null;
try
{
if (null == commandData)
{
throw new ArgumentNullException("commandData");
}
Document doc = commandData.Application.ActiveUIDocument.Document;
ViewsMgr view = new ViewsMgr(doc);
newTran = new Transaction(doc);
newTran.Start("AllViews_Sample");
AllViewsForm dlg = new AllViewsForm(view);
if (dlg.ShowDialog() == DialogResult.OK)
{
view.GenerateSheet(doc);
}
newTran.Commit();
return Autodesk.Revit.UI.Result.Succeeded;
}
catch (Exception e)
{
message = e.Message;
if ((newTran != null) && newTran.HasStarted() && !newTran.HasEnded())
newTran.RollBack();
return Autodesk.Revit.UI.Result.Failed;
}
}
示例2: UpdateSavedConfigurations
/// <summary>
/// Updates the setups to save into the document.
/// </summary>
public void UpdateSavedConfigurations()
{
// delete the old schema and the DataStorage.
if (m_schema == null)
{
m_schema = Schema.Lookup(s_schemaId);
}
if (m_schema != null)
{
IList<DataStorage> oldSavedConfigurations = GetSavedConfigurations(m_schema);
if (oldSavedConfigurations.Count > 0)
{
Transaction deleteTransaction = new Transaction(IFCCommandOverrideApplication.TheDocument,
Properties.Resources.DeleteOldSetups);
try
{
deleteTransaction.Start();
List<ElementId> dataStorageToDelete = new List<ElementId>();
foreach (DataStorage dataStorage in oldSavedConfigurations)
{
dataStorageToDelete.Add(dataStorage.Id);
}
IFCCommandOverrideApplication.TheDocument.Delete(dataStorageToDelete);
deleteTransaction.Commit();
}
catch (System.Exception)
{
if (deleteTransaction.HasStarted())
deleteTransaction.RollBack();
}
}
}
// update the configurations to new map schema.
if (m_mapSchema == null)
{
m_mapSchema = Schema.Lookup(s_mapSchemaId);
}
// Are there any setups to save or resave?
List<IFCExportConfiguration> setupsToSave = new List<IFCExportConfiguration>();
foreach (IFCExportConfiguration configuration in m_configurations.Values)
{
if (configuration.IsBuiltIn)
continue;
// Store in-session settings in the cached in-session configuration
if (configuration.IsInSession)
{
IFCExportConfiguration.SetInSession(configuration);
continue;
}
setupsToSave.Add(configuration);
}
// If there are no setups to save, and if the schema is not present (which means there are no
// previously existing setups which might have been deleted) we can skip the rest of this method.
if (setupsToSave.Count <= 0 && m_mapSchema == null)
return;
if (m_mapSchema == null)
{
SchemaBuilder builder = new SchemaBuilder(s_mapSchemaId);
builder.SetSchemaName("IFCExportConfigurationMap");
builder.AddMapField(s_configMapField, typeof(String), typeof(String));
m_mapSchema = builder.Finish();
}
// Overwrite all saved configs with the new list
Transaction transaction = new Transaction(IFCCommandOverrideApplication.TheDocument, Properties.Resources.UpdateExportSetups);
try
{
transaction.Start();
IList<DataStorage> savedConfigurations = GetSavedConfigurations(m_mapSchema);
int savedConfigurationCount = savedConfigurations.Count<DataStorage>();
int savedConfigurationIndex = 0;
foreach (IFCExportConfiguration configuration in setupsToSave)
{
DataStorage configStorage;
if (savedConfigurationIndex >= savedConfigurationCount)
{
configStorage = DataStorage.Create(IFCCommandOverrideApplication.TheDocument);
}
else
{
configStorage = savedConfigurations[savedConfigurationIndex];
savedConfigurationIndex++;
}
Entity mapEntity = new Entity(m_mapSchema);
IDictionary<string, string> mapData = new Dictionary<string, string>();
mapData.Add(s_setupName, configuration.Name);
mapData.Add(s_setupVersion, configuration.IFCVersion.ToString());
mapData.Add(s_setupFileFormat, configuration.IFCFileType.ToString());
mapData.Add(s_setupSpaceBoundaries, configuration.SpaceBoundaries.ToString());
mapData.Add(s_setupQTO, configuration.ExportBaseQuantities.ToString());
//.........这里部分代码省略.........