模型中发生的每一个变化都是事务的一部分,这是我们设计的核心。所有事务都是由 IModel 的实现创建的,并且从中被弱引用,因此当使用 using 语句模型时,只要保留事务,就只保留对该事务的引用。这意味着有一个单一的点,所有的变化都在发生,我们可以用它们来做一些事情。

  一件很重要的事情是记录所有的更改、以前的状态和下一个状态。将所有这些结合起来,您可以创建 back-log 或 forward-log。为了简化这个任务,我们实现了一个 xbim.io.delta.TransactionLog 类。在下面的示例中,我们将了解如何使用它。

using System;
using Xbim.Common;
using Xbim.Ifc;
using Xbim.Ifc4.Interfaces;
using Xbim.IO.Delta;
using Xbim.IO.Step21; var editor = new XbimEditorCredentials
{
ApplicationDevelopersName = "You",
ApplicationFullName = "Your app",
ApplicationIdentifier = "Your app ID",
ApplicationVersion = "4.0", EditorsFamilyName = "Santini Aichel",
EditorsGivenName = "Johann Blasius",
EditorsOrganisationName = "Independent Architecture"
}; using (var model = IfcStore.Open("SampleHouse.ifc", editor, true))
{
using (var txn = model.BeginTransaction("Modification"))
{
using (var log = new TransactionLog(txn))
{
// 修改一个已经存在的 墙 对象
var wall = model.Instances.FirstOrDefault<IIfcWall>();
wall.Name = "Unexpected name";
wall.GlobalId = Guid.NewGuid().ToPart21();
wall.Description = "New and more descriptive description"; // 打印所有由此引起的更改
PrintChanges(log);
txn.Commit();
}
Console.WriteLine();
}
}
private static void PrintChanges(TransactionLog log)
{
foreach (var change in log.Changes)
{
switch (change.ChangeType)
{
case ChangeType.New:
Console.WriteLine(@"New entity: {0}", change.CurrentEntity);
break;
case ChangeType.Deleted:
Console.WriteLine(@"Deleted entity: {0}", change.OriginalEntity);
break;
case ChangeType.Modified:
Console.WriteLine(@"Changed Entity: #{0}={1}", change.Entity.EntityLabel, change.Entity.ExpressType.ExpressNameUpper);
foreach (var prop in change.ChangedProperties)
Console.WriteLine(@" Property '{0}' changed from {1} to {2}", prop.Name, prop.OriginalValue, prop.CurrentValue);
break;
default:
break;
}
}
}

生成的更改日志将如下所示。它包含更多的更改,因为当您更改或创建任何ifcroot实体时,xbim会自动为您处理所有者历史记录。

Changed Entity: #=IFCWALL
Property 'Name' changed from 'Basic Wall:Wall-Ext_102Bwk-75Ins-100LBlk-12P:285330' to 'Unexpected name'
Property 'OwnerHistory' changed from # to #
Property 'GlobalId' changed from '3cUkl32yn9qRSPvBJVyWw5' to '0zxW3$9z95n8U_H9YOcyiE'
Property 'Description' changed from $ to 'New and more descriptive description'
New entity: #=IFCOWNERHISTORY(#,#,$,.MODIFIED.,$,$,$,);
New entity: #=IFCPERSON($,'Santini Aichel','Johann Blasius',$,$,$,$,$);
New entity: #=IFCORGANIZATION($,'Independent Architecture',$,$,$);
New entity: #=IFCPERSONANDORGANIZATION(#,#,$);
New entity: #=IFCORGANIZATION($,'You',$,$,$);
New entity: #=IFCAPPLICATION(#,$,'Your app','Your app ID');
 

最新文章

  1. Win Form程序线程点点
  2. iOS Address Book指南
  3. 工作随笔——一次简单的Maven加速构建实战
  4. ADT开发AndroidManifest.xml file missing错误
  5. 解决Ext.form.DateField在浏览器中显示可能有问题
  6. Fragment (一)
  7. How to customize authentication to my own set of tables in asp.net web api 2?
  8. JNI Java调用C代码 示例
  9. 让Xcode日志输出中文
  10. visual Studio 无法调试,提示程序跟踪已退出
  11. WebP 的前世今生
  12. phper的Go之旅(-)--书写前言
  13. 前端之DOM
  14. 如何在查看docker container内进程信息,与宿主机上进程信息的映射关系
  15. WordPress版微信小程序3.1.5版的新功能
  16. vue 饿了么项目笔记
  17. kmp基础 ekmp
  18. 记一次GRPC使用报错排查
  19. clickhouse安装使用文档
  20. C#自定义异常 统一异常处理

热门文章

  1. NSURLSession简介
  2. ROS-Gazebo-turtlebot3仿真
  3. Ubuntu14.04下初步使用MongoDB
  4. 流式计算新贵Kafka Stream设计详解--转
  5. SQL Server 从字符串中提取中文、英文、数字
  6. Android 对ScrollView滚动监听,实现美团、大众点评的购买悬浮效果
  7. 自定义view 之多个引导层动画效果
  8. iOS 11 APP 设计中的几个 UI 设计细节
  9. mysql update join优化update in查询效率
  10. 利用Windows2003 IP安全策略实现服务器远程桌面端口(3389)访问控制