예제 #1
0
 internal void WriteAuditLog()
 {
     if (AuditLogger != null)
     {
         using (IEnumerator <DbEntityEntry <ModelBase> > enumerator = ChangeTracker.Entries <ModelBase>().Where(delegate(DbEntityEntry <ModelBase> p)
         {
             if ((p.State != EntityState.Added) && (p.State != EntityState.Deleted))
             {
                 return(p.State == EntityState.Modified);
             }
             return(true);
         }).GetEnumerator())
         {
             while (enumerator.MoveNext())
             {
                 DbEntityEntry <ModelBase> dbEntry = enumerator.Current;
                 string operaterName;
                 if (dbEntry.Entity.GetType().GetCustomAttributes(typeof(AuditableAttribute), false).SingleOrDefault() is AuditableAttribute)
                 {
                     operaterName = WCFContext.Current.Operater.Name;
                     Task.Factory.StartNew(delegate
                     {
                         TableAttribute attribute = dbEntry.Entity.GetType().GetCustomAttributes(typeof(TableAttribute), false).SingleOrDefault() as TableAttribute;
                         string tableName         = (attribute != null) ? attribute.Name : dbEntry.Entity.GetType().Name;
                         string moduleName        = dbEntry.Entity.GetType().FullName.Split('.').Skip(1).FirstOrDefault();
                         AuditLogger.WriteLog(dbEntry.Entity.ID, operaterName, moduleName, tableName, dbEntry.State.ToString(), dbEntry.Entity);
                     });
                 }
             }
         }
     }
 }