Auditing Code Not Executing

Posts   
 
    
bjacobs
User
Posts: 73
Joined: 20-Aug-2008
# Posted on: 17-Aug-2010 06:13:57   

I have read several posts as well as the documentation and cannot see what I am doing wrong: 1. I am using adapter. V2.6 latest build. (SD.LLBLGen.Pro.ORMSupportClasses.NET20, Version=2.6.0.0) VS 2010. .Net Framework 4.0. SQL Server DB. 2. I have a web application which references my 2 llblgen code generated dlls. 3. I have a 4th dll for auditing. 4. This auditing dll is referenced by the web applicaiton, so the dll is in the bin folder of the web application. 5. The auditing dll references the Database Generic llblgen'd dll. 6. My web.config has the following: (NOTE: I have tried with and without the app setting: <add key="autoDependencyInjectionDiscovery" value="true"/>)


  <configSections>
    <section name="dependencyInjectionInformation" type="SD.LLBLGen.Pro.ORMSupportClasses.DependencyInjectionSectionHandler, SD.LLBLGen.Pro.ORMSupportClasses.NET20, Version=2.6.0.0, Culture=neutral, PublicKeyToken=ca73b74ba4e3ff27"/>
  </configSections>
  <appSettings />
  <dependencyInjectionInformation>
    <additionalAssemblies>
      <assembly fullName="SmartEducationAuditors, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"/>
    </additionalAssemblies>
  </dependencyInjectionInformation>

Everything runs with no errors but my auditing code does not fire.

The following is my auditing code:


namespace SmartEducationAuditors
{
    [DependencyInjectionInfo(typeof(StudentAttendanceEntity), "AuditorToUse")]
    [Serializable]
    class StudentAttendanceAuditor : AuditorBase
    {
        List<AuditAttendanceEntity> _auditAtendanceEntities;
        private enum AuditType
        {
            DeleteOfEntry = 1,
            InsertOfNewEntity = 2,
            UpdateOfExistingEntity = 3
        }
        public StudentAttendanceAuditor()
        {
            _auditAtendanceEntities = new List<AuditAttendanceEntity>();
        }
        public override bool RequiresTransactionForAuditEntities(SingleStatementQueryAction actionToStart)
        {
            return true;
        }
        public override void AuditUpdateOfExistingEntity(IEntityCore entity)
        {
            AuditEntity(entity, AuditType.UpdateOfExistingEntity);
        }
        public override void AuditInsertOfNewEntity(IEntityCore entity)
        {
            AuditEntity(entity, AuditType.InsertOfNewEntity);
        }
        public override void AuditDeleteOfEntity(IEntityCore entity)
        {
            AuditEntity(entity, AuditType.DeleteOfEntry);
        }

        private void AuditEntity(IEntityCore entity, AuditType auditType)
        {
            StudentAttendanceEntity attendanceEntity = entity as StudentAttendanceEntity;
            if (attendanceEntity != null)
            {
                AuditAttendanceEntity auditEntity = new AuditAttendanceEntity { Id = Guid.NewGuid() };
                auditEntity.UpdateTime = DateTime.Now;
                auditEntity.UpdateUser= Utility.GetCurrentUserName();
                auditEntity.StudentAttendance_ = attendanceEntity;
                _auditAtendanceEntities.Add(auditEntity);
            }
        }
        public override void AuditEntityFieldSet(IEntityCore entity, int fieldIndex, object originalValue)
        {
            if (entity is AuditAttendanceEntity)
                return;
        }
        public override System.Collections.IList GetAuditEntitiesToSave()
        {
            return _auditAtendanceEntities;
        }
        public override void TransactionCommitted()
        {
            _auditAtendanceEntities.Clear();
        }
    }
}

Thanks in advance,

Billy Jacobs

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 17-Aug-2010 08:40:32   

Please make sure the assemblyFullname matches what can be found in Visual Studio (the assembly name can be viewed and changed through the project's property pages dialog box). Also make sure you are using the correct version and PublicKeyToken.

bjacobs
User
Posts: 73
Joined: 20-Aug-2008
# Posted on: 17-Aug-2010 15:08:57   

I copied it directly out of reflector and I just double checked it, so it is correct.

MTrinder
User
Posts: 1461
Joined: 08-Oct-2008
# Posted on: 17-Aug-2010 20:35:38   

Hmm. Couple of things to try. Does the auditing work if you call your LLBLGen generated code and the auditor from a winforms app...?

And it may be worth strong naming the auditor and LLBLGen dlls, and then making sure that the public key token is in the web.config file.

Matt

bjacobs
User
Posts: 73
Joined: 20-Aug-2008
# Posted on: 17-Aug-2010 23:57:22   

I recreated the problem with a WPF application. I am uploading the application including the database.

confused Well I tried to upload it but it crashed because my file was too big. Is there anywhere I can post a 3 mg zip file?

Thanks,

Billy Jacobs

bjacobs
User
Posts: 73
Joined: 20-Aug-2008
# Posted on: 18-Aug-2010 06:09:33   

Got it down to 956 kb.

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 18-Aug-2010 09:24:36   

Haven't been able to test your solution.

But would you please make your Auditor class public.

bjacobs
User
Posts: 73
Joined: 20-Aug-2008
# Posted on: 18-Aug-2010 14:32:28   

frowning That was the problem. Thanks, even though I feel like an idiot for wasting your time.

Billy

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39903
Joined: 17-Aug-2003
# Posted on: 18-Aug-2010 14:35:04   

bjacobs wrote:

frowning That was the problem. Thanks, even though I feel like an idiot for wasting your time.

Billy

Oh, no worries simple_smile . The class has to be public because reflection is done only on public members to be sure it will work in partial trust. (reflection on other access levels requires full trust, hence the limitation wink )

Frans Bouma | Lead developer LLBLGen Pro