Found a blog post detailing something similar
public class AuditInterceptor : EmptyInterceptor
{
public int UpdateCount { get; private set; }
public int CreateCount { get; private set; }
public int DeleteCount { get; private set; }
public int TotalCount { get { return UpdateCount + CreateCount + DeleteCount; } }
public override void OnDelete(object entity, object id, object[] state, string[] propertyNames, IType[] types)
{
DeleteCount++;
}
public override bool OnFlushDirty(object entity, object id, object[] currentState, object[] previousState, string[] propertyNames, IType[] types)
{
UpdateCount++;
//if (entity is IAuditable)
//{
// for (int i = 0; i < propertyNames.Length; i++)
// {
// if ("lastUpdateTimestamp".Equals(propertyNames[i]))
// {
// currentState[i] = new DateTime();
// return true;
// }
// }
//}
return false;
}
public override bool OnSave(object entity, object id, object[] state, string[] propertyNames, IType[] types)
{
CreateCount++;
//if (entity is IAuditable)
//{
// for (int i = 0; i < propertyNames.Length; i++)
// {
// if ("createTimestamp".Equals(propertyNames[i]))
// {
// state[i] = new DateTime();
// return true;
// }
// }
//}
return false;
}
public override void AfterTransactionCompletion(ITransaction tx)
{
//if (tx.WasCommitted)
// Console.Write("Committed: ");
//else
// Console.Write("Rolled back: ");
//Console.WriteLine(" Creations: " + creates + ", Updates: " + updates + ", Deletes: " + deletes);
//updates = creates = deletes = 0;
}
}
|