Audit Object Changes 审核对象更改
Important 重要
The Audit Trail module is not supported by the Entity Framework ORM in the current version of XAF. If you are using EF, please skip this lesson and go to the next one.
当前版本的 XAF 中的实体框架 ORM 不支持审核跟踪模块。如果您使用的是 EF,请跳过本课程并转到下一课。
In this lesson, you will learn how to audit and analyze the changes that are made to business objects while running the application. For this purpose, the Audit Trail module will be added to the application. Changes made to the Contact object will be audited. Two techniques to analyze them will be used.
在本课中,您将学习如何审核和分析在运行应用程序时对业务对象所做的更改。为此,审核跟踪模块将添加到应用程序中。将审核对"联系人"对象所做的更改。将使用两种技术来分析它们。
Note 注意
Before proceeding, take a moment to review the Inherit from the Business Class Library Class (XPO) lesson.
在继续之前,请花点时间复习从商务舱库类 (XPO) 课程继承。
Audit Contact Objects
审核联系人对象
Add the AuditTrail module to your MySolution.Module project. For this purpose, find the Module.cs (Module.vb) file in the MySolution.Module project displayed in the Solution Explorer. Double-click this file to invoke the Module Designer. In the Toolbox, expand the DX.19.2: XAF Modules tab. Drag the AuditTrailModule item to the Designer's Required Modules section.
将审核跟踪模块添加到 MySolution.模块项目中。为此,在解决方案资源管理器中显示的 MySolution.模块项目中查找Module.cs(Module.vb)文件。双击此文件以调用模块设计器。在工具箱中,展开 DX.19.2:XAF 模块选项卡。将 AuditTrail 模块项目拖动到"设计器所需的模块"部分。
Now, all objects that are created in the application are audited. The Audit Trail System logs information on the change type (object was created, changed, etc.), who made this change, the object that was changed, the previous and new property values, etc. When an object is saved to the database, any changes between two sequential events are registered.
现在,将审核在应用程序中创建的所有对象。审核跟踪系统记录有关更改类型(对象已创建、更改等)、进行此更改的人员、已更改的对象、以前的属性值和新属性值等的信息。将对象保存到数据库时,将注册两个顺序事件之间的任何更改。
Analyze Audit Log in the Application
分析应用程序中的审核日志
Use the following approach to view object changes directly in the application.
使用以下方法直接在应用程序中查看对象更改。
-
Add a collection property to the Contact class. The collection's items will provide log information retrieved from the database.
-
将集合属性添加到联系人类。集合项将提供从数据库中检索到的日志信息。
[DefaultClassOptions] public class Contact : Person { //... private XPCollection<AuditDataItemPersistent> changeHistory; public XPCollection<AuditDataItemPersistent> ChangeHistory { get { if(changeHistory == null) { changeHistory = AuditedObjectWeakReference.GetAuditTrail(Session, this); } return changeHistory; } } }
-
Run the WinForms or ASP.NET application and invoke a Contact Detail View. Modify the Contact object to test the auditing capability, save the changes and click Refresh (
). The Change History collection will contain information on the previous Contact object changes.
-
运行 WinForms 或ASP.NET应用程序并调用联系人详细信息视图。修改"联系人"对象以测试审核功能,保存更改并单击"刷新(btn_refresh)。"更改历史记录"集合将包含有关以前的联系人对象更改的信息。
Note 注意
As you may remember, the Office property is declared in the Department class, not the Contact class. So, changes to the Office property made using the Contact Detail View are not displayed in the Contact's Change History. Instead, these changes appear in the corresponding Department object's Change History (if changes made to the Department objects are audited). You can acquire the audit log remotely using SQL queries to your database. See the Analyze the Audit Log topic.
您可能还记得,Office 属性在"部门"类中声明,而不是"联系人"类。因此,使用"联系人详细信息"视图对 Office 属性所做的更改不会显示在联系人的更改历史记录中。相反,这些更改将显示在相应的部门对象的更改历史记录中(如果对部门对象所做的更改被审核)。您可以使用对数据库的 SQL 查询远程获取审核日志。请参阅分析审核日志主题。
You can view the code demonstrated here in the Contact.cs (Contact.vb) file of the Main Demo installed with XAF. The MainDemo application is installed in %PUBLIC%\Documents\DevExpress Demos 19.2\Components\eXpressApp Framework\MainDemo by default. The ASP.NET version is available online at http://demos.devexpress.com/XAF/MainDemo/
您可以查看此处演示的带有 XAF 安装的主演示的 Contact.cs (Contact.vb) 文件中演示的代码。主演示应用程序安装在%PUBLIC%\Documents\DevExpress Demos 19.2\Components\eXpressApp Framework\MainDemo by default. The ASP.NET version is available online at http://demos.devexpress.com/XAF/MainDemo/
.
XAF开发成品案例参考
如果您觉得阅读本文对您有帮助,请点一下“推荐”按钮,您的“推荐”将是我最大的写作动力!欢迎各位转载,但是未经作者本人同意,转载文章之后必须在文章页面明显位置给出作者和原文连接,否则保留追究法律责任的权利。
作者博客: http://www.cnblogs.com/foreachlife
欢迎加入CIIP框架\XAF技术应用交流群: 336090194 群文件中有更多相关工具及文档资料
转载请注明出处。多谢!
欢迎加我微信: admiralcn 或扫码:

【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· 周边上新:园子的第一款马克杯温暖上架
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· Ollama——大语言模型本地部署的极速利器
· DeepSeek如何颠覆传统软件测试?测试工程师会被淘汰吗?
· 使用C#创建一个MCP客户端