AuditorBase and new entities

Posts   
 
    
yowl
User
Posts: 271
Joined: 11-Feb-2008
# Posted on: 13-Apr-2010 23:39:52   

Hi,

I have a client/server app using remoting and I attach an auditor deriving from AuditorBase using DI. I create new "audit" records for creating new entities and for changing properties. On the client the audited entity is created and passed to the server in a UnitOfWork which is then processed:


            using(var tsw = new TransactionScopeWrapper(methodName))
            {
                uow.Commit(tsw.DataAccessAdapter);
                tsw.Complete();
            }

(TransactionScopeWrapper is a wrapper around TransactionScope which exposes a DataAccessAdapter). When Commit is called AuditInsertOfNewEntity is called in the auditor, so far so good. I have overrides on AuditEntityFieldSet and AuditInsertOfNewEntity I record the current time using this (for AuditEntityFieldSet):

            var change = new WorkflowAuditEntity
                            {
                                WorkflowRunKey = state.WorkflowRunKey,
                                FieldName = state.Fields[fieldIndex].Name,
                                EventUtcDateTime = DateTime.UtcNow,
                                EventTypeCode = "UPD",
                                UserId = CurrentUserId
                            };

and this for AuditInsertOfNewEntity

            var change = new WorkflowAuditEntity
            {
                WorkflowRunKey = (int)state.Fields[WorkflowEntityStateFields.WorkflowRunKey.FieldIndex].CurrentValue,
                EventUtcDateTime = DateTime.UtcNow,
                StatusCode = (string)state.Fields[WorkflowEntityStateFields.StatusCode.FieldIndex].CurrentValue,
                EventTypeCode = "INS",
                UserId = CurrentUserId
            };

However this gives the odd looking, but understandable, results where the insert audit record has a datetime after the updates. Can anything be done about that, such as introduce an audit method for the construction of the entity?

Updated: Using version 2.6 with SQL Server and Adapters (not self servicing)

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 14-Apr-2010 04:09:24   

I don't understand your problem. Please elaborate more on what you are trying to achieve.

David Elizondo | LLBLGen Support Team
yowl
User
Posts: 271
Joined: 11-Feb-2008
# Posted on: 14-Apr-2010 22:15:02   

Using this code and inserting the audit entries into a db gives this in the table:

34 19 2010-04-14 12:10:58.817 UPD 35 19 2010-04-14 12:11:02.680 UPD 36 19 2010-04-14 12:11:05.190 INS 37 19 2010-04-14 12:11:24.550 UPD

So, looking at the third and fourth columns only (the timestamp and the INS/UPD values) you can see that the INS has a later time than the UPD. I understand this is because the AuditInsertOfNewEntity is called when the db record is inserted whereas AuditEntityFieldSet is called as when the property is set and as the db record is not inserted until after some properties have been set, it has a later time. My point is just that this looks a bit odd and if there was an audit method for the construction (outside of remoting construction), then you could get an audit trail reflected the non db operations of construction and then property updates.

I'm not asking for a change to the existing functionality, more of a request to add a construction method to IAuditor if possible.

Thanks.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 15-Apr-2010 04:29:27   

Having a creation method in IAuditor doesn't have the behavior of an Auditor because it grabs actions made in the entity. Create an entity in memory doesnt correspond to that. You however can extend AuditorBase or build your own IAuditor class. Anyway I see 2 options:

  1. Do it in the Auditor's constructor. When the Auditor is instantiated because it was injected to an entity, you can grab the time, then you can use that time in your UPD and INS.

  2. Update all the instances of WorkflowAuditEntity in the AuditInsertOfNewEntity method so all the instances have the same time.

David Elizondo | LLBLGen Support Team