Bug Report Q457937
Visible to All Users
Duplicate

We have closed this ticket because another page addresses its subject:

AuditTrail - Audit Module always tracks intermediate objects for many-to-many associations

Audit Trail - Many-to-Many associations are always audited despite of the settings

created 12 years ago

Hi,

i'm trying to audit only a few properties of certain business objects. When looking into my database i noticed some unexpected entries. Obviously the 'AddedToCollection' operation is always audited when adding a Resource to the DevExpress.Persistent.BaseImpl.Event.

In the attached demo project i disabled auditing by calling 'customizeAuditTrailSettingsEventArgs.AuditTrailSettings.Clear();' as shown in http://documentation.devexpress.com/#Xaf/CustomDocument2783. I expected nothing to be audited. But the 'AddedToCollection' entries are still there. Is this a bug?

Comments (1)
Anatol (DevExpress) 12 years ago

    This behavior looks like a bug. Our developers will work on it.

    Answers approved by DevExpress Support

    created 12 years ago (modified 12 years ago)

    Thank you for contacting us.
    I have checked the current implementation and found that objects of the DevExpress.Xpo.Metadata.Helpers.IntermediateObject type are always processed, and this behavior cannot be disabled using the AuditTrailSettings class. These objects are used to store Many-to-Many Relationships.
    To manually manage these objects, inherit a new class from the FillObjectAuditProcessor and override the IsObjectToAudit and ResolveManyToManyDiffsForIntermediateObject methods:

    Code
    public class MyFullObjectAuditProcessor : FullObjectAuditProcessor { public MyFullObjectAuditProcessor(DevExpress.Xpo.Session session, AuditTrailSettings settings) : base(session, settings) { } protected override bool IsObjectToAudit(object obj) { bool result = base.IsObjectToAudit(obj); if(result && (obj is DevExpress.Xpo.Metadata.Helpers.IntermediateObject)) { result = false; } return result; } protected override DiffCollection ResolveManyToManyDiffsForIntermediateObject(DevExpress.Xpo.Metadata.Helpers.IntermediateObject intermediateObject, System.Collections.Generic.List<AuditDataItem> listToResolve) { return new DiffCollection(); } }

    Replace the FillObjectAuditProcessor object with yours using the AuditTrailService.CustomCreateObjectAuditProcessorsFactory event:

    Code
    static class Program { static void Main() { ... AuditingTestWindowsFormsApplication winApplication = new AuditingTestWindowsFormsApplication(); AuditTrailService.Instance.CustomCreateObjectAuditProcessorsFactory += new EventHandler<CustomCreateObjectAuditProcessorsFactoryEventArgs>(Instance_CustomCreateObjectAuditProcessorsFactory); ... } static void Instance_CustomCreateObjectAuditProcessorsFactory(object sender, CustomCreateObjectAuditProcessorsFactoryEventArgs e) { e.Factory = new ObjectAuditProcessorsFactory(); e.Handled = true; } } public class ObjectAuditProcessorsFactory : IObjectAuditProcessorsFactory { public ObjectAuditProcessorsFactory() {} public virtual bool IsSuitableAuditProcessor(ObjectAuditProcessor processor, ObjectAuditingMode mode) { return true; } public virtual ObjectAuditProcessor CreateAuditProcessor(ObjectAuditingMode mode, DevExpress.Xpo.Session session, AuditTrailSettings settings) { if(mode != ObjectAuditingMode.Full) { throw new ArgumentException(); } return new MyFullObjectAuditProcessor(session, settings); } }

    We will see how to improve this situation, though I cannot promise any time frame.

      Show previous comments (5)

        Hi Dan, i finally upgraded to 12.2.7 and tried your proposed solution. Unfortunately now there is no auditing at all (I enabled auditing for a specific property via e.AuditTrailSettings.AddType(typeof(Event), "Subject");).
        I think the problem occurs, because in the overriden 'protected override bool IsObjectToAudit(object obj)' method you call 'bool result = base.IsObjectAudited(obj);' If I change this to 'bool result = base.IsObjectToAudit(obj);' everything seems to be fine. Can you confirm this?

        Anatol (DevExpress) 12 years ago

          You are right. This is a typo. It is required to use the base.IsObjectToAudit method.

          DevExpress Support Team 4 years ago

            Hello,
            In v20.1.7, we've made Audit Trail customization easier and now you don't need to implement your own Factory. Instead, you can use the following solution:

            C#
            static class Program { static void Main() { ... AuditingTestWindowsFormsApplication winApplication = new AuditingTestWindowsFormsApplication(); AuditTrailService.Instance.CustomCreateObjectAuditProcessorsFactory += new EventHandler<CustomCreateObjectAuditProcessorsFactoryEventArgs>(Instance_CustomCreateObjectAuditProcessorsFactory); ... } static void Instance_CustomCreateObjectAuditProcessorsFactory(object sender, CustomCreateObjectAuditProcessorsFactoryEventArgs e) { e.Factory = new ObjectAuditProcessorsFactory(ObjectAuditingMode.Full, typeof(MyFullObjectAuditProcessor)); } }

            Note that you will still need to implement your own ObjectAuditProcessor if you want to customize audit logic.

            Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

            Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.