学习014-03-01-04 Disable the Audit Trail Module(禁用审计跟踪模块)

Disable the Audit Trail Module(禁用审计跟踪模块)

Disable the Module Permanently(永久禁用该模块)

This technique allows you to stop tracking changes throughout the application. To do this, use the standard DbContextFactory instead of AuditedDbContextFactory when you create EFCoreObjectSpaceProvider.
此技术可让您停止跟踪整个应用程序中的更改。为此,在创建EFCoreObjectSpaceProvider 时,请使用标准的DbContextFactory,而不是AuditedDbContextFactory。

Note
With this technique, you cannot change the state of the Module during application execution.

使用这种技术,在应用程序执行期间,你无法更改模块的状态。

The following example demonstrates how to declare an additional field to switch between the audited and standard DbContext factories:
以下示例展示了如何声明一个额外字段,以便在经过审计的和标准的DbContext工厂之间进行切换:

ASP.NET Core Blazor

File: MySolution.Blazor.Server\BlazorApplication.cs.

C# 
using DevExpress.ExpressApp.AuditTrail.EFCore;
// ...
public partial class MySolutionBlazorApplication : BlazorApplication {
    // ...
    bool UseStandardDbContectFactory = true;
    protected override void CreateDefaultObjectSpaceProvider(CreateCustomObjectSpaceProviderEventArgs args) {
        IDbContextFactory<MySolutionEFCoreDbContext> dbContextFactory = 
            UseStandardDbContectFactory ?
            ServiceProvider.GetService<IDbContextFactory<MySolutionEFCoreDbContext>>() :
            ServiceProvider.GetService<IXafDbContextFactory<MySolutionEFCoreDbContext>>();
        //...
    }
}

WinForms

File: MySolution.Win\WinApplication.cs.

C# 
using DevExpress.ExpressApp.AuditTrail.EFCore;
// ...
public partial class MySolutionWindowsFormsApplication : WinApplication {
    // ...
    protected override void CreateDefaultObjectSpaceProvider(CreateCustomObjectSpaceProviderEventArgs args) {
        bool UseStandardDbContectFactory = true;
        IDbContextFactory<DbContext> dbContextFactory;
        if(UseStandardDbContectFactory) {
            dbContextFactory = new EFCoreDbContextFactory<MySolutionDbContext>(args.ConnectionString,
            (builder, connectionString) => {
                builder.UseSqlServer(connectionString);
                // ...
            });
        }
        else {
            dbContextFactory = AuditedDbContextFactory.CreateFactory<MySolutionDbContext>(args.ConnectionString,
            (builder, connectionString) => {
                builder.UseSqlServer(connectionString);
                // ...
            });
        }
        //...
    }
}

Disable the Module Temporarily(暂时禁用该模块)

The AuditTrailService.Enabled property allows you to disable the Audit Trail Module for a specific scenario. You can use this technique in different parts of your application (for example, in Controllers).
AuditTrailService.Enabled属性允许您针对特定场景禁用审计跟踪模块。您可以在应用程序的不同部分(例如,在控制器中)使用此方法。

The following example demonstrates this technique:
以下示例展示了这种技术:

C# 
using DevExpress.ExpressApp;
using DevExpress.ExpressApp.Actions;
using DevExpress.ExpressApp.EFCore;
using DevExpress.Persistent.Base;
using DevExpress.Persistent.BaseImpl.EFCore.AuditTrail;
// ...
public class CustomController : ViewController<DetailView> {
    public CustomController() {
        SimpleAction customAction = new SimpleAction(this, "CustomAction", PredefinedCategory.View);
        customAction.Execute += CustomAction_Execute;
    }
    private void CustomAction_Execute(object sender, SimpleActionExecuteEventArgs e) {
        AuditTrailService auditTrailService = ((EFCoreObjectSpace)ObjectSpace).GetAuditTrailService();
        auditTrailService.Enabled = false;
        // non-tracked actions or changes
        auditTrailService.Enabled = true;
    }
}

Note

  • The AuditTrailService.SaveCustomData method ignores the AuditTrailService.Enabled property. You can use this method when the property is set to false.
    AuditTrailService.SaveCustomData方法忽略了AuditTrailService.Enabled属性。当该属性设置为false时,仍可使用此方法。
  • If you use one Object Space in multiple places simultaneously, the Audit Trail Module does not track changes throughout the application when AuditTrailService.Enabled is set to false.
    如果在多个地方同时使用同一个对象空间,当AuditTrailService.Enabled设置为false时,审计跟踪模块不会跟踪整个应用程序中的更改。

你可能感兴趣的:(XAF,学习,.net,XAF,Dev,C#,Security,Audit)