/// <summary>Constructor.</summary> /// <param name="parent">The audit entry parent.</param> /// <param name="propertyName">Name of the property audited.</param> /// <param name="oldValue">The old value audited.</param> /// <param name="newValue">The new value audited.</param> public AuditEntryProperty(AuditEntry parent, string propertyName, object oldValue, object newValue) { NewValue = newValue; OldValue = oldValue; Parent = parent; PropertyName = propertyName; }
/// <summary>Audit entity added.</summary> /// <param name="objectStateEntry">The object state entry.</param> public static void AuditEntityAdded(AuditEntry entry, EntityEntry objectStateEntry) { foreach (var propertyEntry in objectStateEntry.Metadata.GetProperties()) { var property = objectStateEntry.Property(propertyEntry.Name); if (property.Metadata.IsKey() || entry.Parent.CurrentOrDefaultConfiguration.IsAuditedProperty(entry.Entry, propertyEntry.Name)) { var auditEntryProperty = entry.Parent.Configuration.AuditEntryPropertyFactory != null? entry.Parent.Configuration.AuditEntryPropertyFactory(new AuditEntryPropertyArgs(entry, objectStateEntry, propertyEntry.Name, null, property.CurrentValue)) : new AuditEntryProperty(); var value = property.CurrentValue; if (entry.Parent.CurrentOrDefaultConfiguration.IgnoreEntityAddedDefaultValue && property.Metadata.FieldInfo != null && property.Metadata.FieldInfo.FieldType != typeof(object) && property.CurrentValue != null) { var checkDefaultValue = DefaultValue(property.Metadata.FieldInfo.FieldType); if (checkDefaultValue != null && checkDefaultValue.Equals(property.CurrentValue)) { value = null; } } auditEntryProperty.Build(entry, propertyEntry.Name, null, value); entry.Properties.Add(auditEntryProperty); } } }
public void Build(AuditEntry parent, string relationName, string propertyName, object oldValue, DbUpdatableDataRecord dbUpdatableDataRecord, int dbUpdatableDataRecordPosition) { InternalPropertyName = propertyName; if (!IsValueSet) { DbUpdatableDataRecord = dbUpdatableDataRecord; DbUpdatableDataRecordPosition = dbUpdatableDataRecordPosition; OldValue = oldValue; } if (Parent == null) { Parent = parent; } if (PropertyName == null) { PropertyName = parent.Parent.CurrentOrDefaultConfiguration.PropertyNameFactory != null? parent.Parent.CurrentOrDefaultConfiguration.PropertyNameFactory(ObjectContext.GetObjectType(parent.Entry.Entity.GetType()), propertyName) : propertyName; } if (RelationName == null) { RelationName = relationName; } }
/// <summary>Constructor.</summary> /// <param name="parent">The audit entry parent.</param> /// <param name="propertyName">Name of the property audited.</param> /// <param name="oldValue">The old value audited.</param> /// <param name="newValue">The new value audited.</param> public AuditEntryProperty(AuditEntry parent, string propertyName, object oldValue, object newValue) { NewValue = newValue; OldValue = oldValue; Parent = parent; PropertyName = propertyName; }
/// <summary>Audit entity added.</summary> /// <param name="auditEntry">The audit entry.</param> /// <param name="objectStateEntry">The object state entry.</param> /// <param name="record">The record.</param> /// <param name="prefix">The prefix.</param> public static void AuditEntityAdded(AuditEntry auditEntry, ObjectStateEntry objectStateEntry, DbUpdatableDataRecord record, string prefix = "") { for (var i = 0; i < record.FieldCount; i++) { var name = record.GetName(i); var value = record.GetValue(i); if (auditEntry.Parent.Configuration.UseNullForDBNullValue && value == DBNull.Value) { value = null; } var valueRecord = value as DbUpdatableDataRecord; if (valueRecord != null) { // Complex Type AuditEntityAdded(auditEntry, objectStateEntry, valueRecord, string.Concat(prefix, name, ".")); } else if (objectStateEntry.EntitySet.ElementType.KeyMembers.Any(x => x.Name == name) || auditEntry.Parent.CurrentOrDefaultConfiguration.IsAuditedProperty(auditEntry.Entry, string.Concat(prefix, name))) { var auditEntryProperty = auditEntry.Parent.Configuration.AuditEntryPropertyFactory != null? auditEntry.Parent.Configuration.AuditEntryPropertyFactory(new AuditEntryPropertyArgs(auditEntry, objectStateEntry, string.Concat(prefix, name), null, value)) : new AuditEntryProperty(); auditEntryProperty.Build(auditEntry, string.Concat(prefix, name), null, value); auditEntry.Properties.Add(auditEntryProperty); } } }
public static void AuditEntityAdded(Audit audit, EntityEntry objectStateEntry) #endif { var entry = new AuditEntry(audit, objectStateEntry) { State = AuditEntryState.EntityAdded }; // CHECK if the key should be resolved in POST Action #if EF5 || EF6 if (objectStateEntry.EntityKey.IsTemporary) { entry.DelayedKey = objectStateEntry; } AuditEntityAdded(entry, objectStateEntry.CurrentValues); #elif EF7 // TODO: We must check if the key IsTemporary! We can maybe use flag... //if (!objectStateEntry.IsKeySet) //{ entry.DelayedKey = objectStateEntry; //} AuditEntityAdded(entry, objectStateEntry); #endif audit.Entries.Add(entry); }
public void Build(AuditEntry parent, string relationName, string propertyName, object oldValue, object newValue) { InternalPropertyName = propertyName; if (!IsValueSet) { NewValue = newValue; OldValue = oldValue; } if (Parent == null) { Parent = parent; } if (PropertyName == null) { PropertyName = propertyName; } if (RelationName == null) { RelationName = relationName; } }
/// <summary>Audit entity modified.</summary> /// <param name="objectStateEntry">The object state entry.</param> public static void AuditEntityModified(Audit audit, AuditEntry entry, EntityEntry objectStateEntry) { bool hasModified = false; foreach (var propertyEntry in objectStateEntry.Metadata.GetProperties()) { var property = objectStateEntry.Property(propertyEntry.Name); if (property.Metadata.IsKey() || entry.Parent.CurrentOrDefaultConfiguration.IsAuditedProperty(entry.Entry, propertyEntry.Name)) { if (!audit.Configuration.IgnorePropertyUnchanged || property.Metadata.IsKey() || property.IsModified) { var auditEntryProperty = entry.Parent.Configuration.AuditEntryPropertyFactory != null? entry.Parent.Configuration.AuditEntryPropertyFactory(new AuditEntryPropertyArgs(entry, objectStateEntry, propertyEntry.Name, property.OriginalValue, property.CurrentValue)) : new AuditEntryProperty(); auditEntryProperty.Build(entry, propertyEntry.Name, property.OriginalValue, property); entry.Properties.Add(auditEntryProperty); if (property.IsModified) { hasModified = true; } } } } if (audit.Configuration.IgnoreEntityUnchanged) { if (!hasModified) { entry.Properties.Clear(); } } }
public void Build(AuditEntry parent, string relationName, string propertyName, object oldValue, PropertyEntry propertyEntry) { InternalPropertyName = propertyName; if (!IsValueSet) { PropertyEntry = propertyEntry; OldValue = oldValue; } if (Parent == null) { Parent = parent; } if (PropertyName == null) { #if EF5 || EF6 PropertyName = parent.Parent.CurrentOrDefaultConfiguration.PropertyNameFactory != null? parent.Parent.CurrentOrDefaultConfiguration.PropertyNameFactory(ObjectContext.GetObjectType(parent.Entry.Entity.GetType()), propertyName) : propertyName; #elif EFCORE PropertyName = parent.Parent.CurrentOrDefaultConfiguration.PropertyNameFactory != null? parent.Parent.CurrentOrDefaultConfiguration.PropertyNameFactory(parent.Entry.Entity.GetType(), propertyName) : propertyName; #endif } if (RelationName == null) { RelationName = relationName; } }
/// <summary>Audit entity modified.</summary> /// <param name="audit">The audit to use to add changes made to the context.</param> /// <param name="entry">The entry.</param> /// <param name="objectStateEntry">The object state entry.</param> /// <param name="orginalRecord">The orginal record.</param> /// <param name="currentRecord">The current record.</param> /// <param name="prefix">The prefix.</param> public static void AuditEntityModified(Audit audit, AuditEntry entry, ObjectStateEntry objectStateEntry, DbDataRecord orginalRecord, DbUpdatableDataRecord currentRecord, string prefix = "") { for (var i = 0; i < orginalRecord.FieldCount; i++) { var name = orginalRecord.GetName(i); var originalValue = orginalRecord.GetValue(i); var currentValue = currentRecord.GetValue(i); var valueRecord = originalValue as DbDataRecord; if (valueRecord != null) { // Complex Type AuditEntityModified(audit, entry, objectStateEntry, valueRecord, currentValue as DbUpdatableDataRecord, string.Concat(prefix, name, ".")); } else if (objectStateEntry.EntityKey.EntityKeyValues.Any(x => x.Key == name) || entry.Parent.CurrentOrDefaultConfiguration.IsAuditedProperty(entry.Entry, name)) { if (!audit.Configuration.IgnorePropertyUnchanged || objectStateEntry.EntityKey.EntityKeyValues.Any(x => x.Key == name) || !Equals(currentValue, originalValue)) { var auditEntryProperty = entry.Parent.Configuration.AuditEntryPropertyFactory != null? entry.Parent.Configuration.AuditEntryPropertyFactory(new AuditEntryPropertyArgs(entry, objectStateEntry, string.Concat(prefix, name), originalValue, currentValue)) : new AuditEntryProperty(); auditEntryProperty.Build(entry, string.Concat(prefix, name), originalValue, currentValue); entry.Properties.Add(auditEntryProperty); } } } }
public static void AuditEntityAdded(Audit audit, EntityEntry objectStateEntry) #endif { var entry = new AuditEntry(audit, objectStateEntry) { State = AuditEntryState.EntityAdded }; // CHECK if the key should be resolved in POST Action #if EF5 || EF6 if (objectStateEntry.EntityKey.IsTemporary) { entry.DelayedKey = objectStateEntry; } AuditEntityAdded(entry, objectStateEntry.CurrentValues); #elif EF7 // TODO: We must check if the key IsTemporary! We can maybe use flag... //if (!objectStateEntry.IsKeySet) //{ entry.DelayedKey = objectStateEntry; //} AuditEntityAdded(entry, objectStateEntry); #endif audit.Entries.Add(entry); }
/// <summary>Audit entity deleted.</summary> /// <param name="audit">The audit to use to add changes made to the context.</param> /// <param name="objectStateEntry">The object state entry.</param> public static void AuditEntityDeleted(Audit audit, ObjectStateEntry objectStateEntry) { var entry = new AuditEntry(objectStateEntry) { State = AuditEntryState.EntityDeleted }; AuditEntityDeleted(entry, objectStateEntry.OriginalValues); audit.Entries.Add(entry); }
/// <summary>Audit entity deleted.</summary> /// <param name="audit">The audit to use to add changes made to the context.</param> /// <param name="objectStateEntry">The object state entry.</param> public static void AuditEntityDeleted(Audit audit, ObjectStateEntry objectStateEntry) { var entry = new AuditEntry(objectStateEntry) { State = AuditEntryState.EntityDeleted }; AuditEntityDeleted(entry, objectStateEntry.OriginalValues); audit.Entries.Add(entry); }
/// <summary>Audit entity deleted.</summary> /// <param name="objectStateEntry">The object state entry.</param> public static void AuditEntityDeleted(AuditEntry entry, EntityEntry objectStateEntry) { foreach (var propertyEntry in objectStateEntry.Metadata.GetProperties()) { var property = objectStateEntry.Property(propertyEntry.Name); if (entry.Parent.CurrentOrDefaultConfiguration.IsAuditedProperty(entry.Entry, propertyEntry.Name)) { entry.Properties.Add(new AuditEntryProperty(entry, propertyEntry.Name, property.OriginalValue, null)); } } }
/// <summary>Audit entity deleted.</summary> /// <param name="objectStateEntry">The object state entry.</param> public static void AuditEntityDeleted(AuditEntry entry, EntityEntry objectStateEntry) { foreach (var propertyEntry in objectStateEntry.Metadata.GetProperties()) { var property = objectStateEntry.Property(propertyEntry.Name); if (entry.Parent.CurrentOrDefaultConfiguration.IsAuditedProperty(entry.Entry, propertyEntry.Name)) { entry.Properties.Add(new AuditEntryProperty(entry, propertyEntry.Name, property.OriginalValue, null)); } } }
public static void AuditEntityModified(Audit audit, EntityEntry objectStateEntry, AuditEntryState state) #endif { var entry = new AuditEntry(audit, objectStateEntry) { State = state }; #if EF5 || EF6 AuditEntityModified(audit, entry, objectStateEntry, objectStateEntry.OriginalValues, objectStateEntry.CurrentValues); #elif EFCORE AuditEntityModified(audit, entry, objectStateEntry); #endif audit.Entries.Add(entry); }
public AuditEntryPropertyArgs(AuditEntry parent, EntityEntry entityEntry, string relationName, string propertyName, object oldValue, object newValue) #endif { AuditEntry = parent; NewValue = newValue; OldValue = oldValue; PropertyName = propertyName; RelationName = relationName; #if EF5 || EF6 ObjectStateEntry = objectStateEntry; #elif EFCORE EntityEntry = entityEntry; #endif }
/// <summary>Audit entity modified.</summary> /// <param name="objectStateEntry">The object state entry.</param> public static void AuditEntityModified(Audit audit, AuditEntry entry, EntityEntry objectStateEntry) { foreach (var propertyEntry in objectStateEntry.Metadata.GetProperties()) { var property = objectStateEntry.Property(propertyEntry.Name); if (entry.Parent.CurrentOrDefaultConfiguration.IsAuditedProperty(entry.Entry, propertyEntry.Name)) { if (!audit.Configuration.IgnorePropertyUnchanged || property.Metadata.IsKey() || property.IsModified) { entry.Properties.Add(new AuditEntryProperty(entry, propertyEntry.Name, property.OriginalValue, property.CurrentValue)); } } } }
public static void AuditEntityDeleted(Audit audit, EntityEntry objectStateEntry) #endif { var entry = new AuditEntry(audit, objectStateEntry) { State = AuditEntryState.EntityDeleted }; #if EF5 || EF6 AuditEntityDeleted(entry, objectStateEntry.OriginalValues); #elif EFCORE AuditEntityDeleted(entry, objectStateEntry); #endif audit.Entries.Add(entry); }
/// <summary>Audit entity added.</summary> /// <param name="audit">The audit to use to add changes made to the context.</param> /// <param name="objectStateEntry">The object state entry.</param> public static void AuditEntityAdded(Audit audit, ObjectStateEntry objectStateEntry) { var entry = new AuditEntry(objectStateEntry) { State = AuditEntryState.EntityAdded }; // CHECK if the key should be resolved in POST Action if (objectStateEntry.EntityKey.IsTemporary) { entry.DelayedKey = objectStateEntry; } AuditEntityAdded(entry, objectStateEntry.CurrentValues); audit.Entries.Add(entry); }
public static void AuditEntityDeleted(Audit audit, EntityEntry objectStateEntry) #endif { var entry = new AuditEntry(audit, objectStateEntry) { State = AuditEntryState.EntityDeleted }; #if EF5 || EF6 AuditEntityDeleted(entry, objectStateEntry.OriginalValues); #elif EFCORE AuditEntityDeleted(entry, objectStateEntry); #endif audit.Entries.Add(entry); }
/// <summary>Audit entity added.</summary> /// <param name="audit">The audit to use to add changes made to the context.</param> /// <param name="objectStateEntry">The object state entry.</param> public static void AuditEntityAdded(Audit audit, ObjectStateEntry objectStateEntry) { var entry = new AuditEntry(objectStateEntry) { State = AuditEntryState.EntityAdded }; // CHECK if the key should be resolved in POST Action if (objectStateEntry.EntityKey.IsTemporary) { entry.DelayedKey = objectStateEntry; } AuditEntityAdded(entry, objectStateEntry.CurrentValues); audit.Entries.Add(entry); }
public static Entity.AuditEntry Import(Z.EntityFramework.Plus.AuditEntry entry) { var customAuditEntry = new Entity.AuditEntry { EntitySetName = entry.EntitySetName, EntityTypeName = entry.EntityTypeName, State = (int)entry.State, StateName = entry.StateName, CreatedBy = entry.CreatedBy, CreatedDate = entry.CreatedDate }; customAuditEntry.AuditEntryProperties = entry.Properties.Select(x => Import(x)).ToList(); return(customAuditEntry); }
/// <summary>Audit entity added.</summary> /// <param name="objectStateEntry">The object state entry.</param> public static void AuditEntityAdded(AuditEntry entry, EntityEntry objectStateEntry) { foreach (var propertyEntry in objectStateEntry.Metadata.GetProperties()) { var property = objectStateEntry.Property(propertyEntry.Name); if (property.Metadata.IsKey() || entry.Parent.CurrentOrDefaultConfiguration.IsAuditedProperty(entry.Entry, propertyEntry.Name)) { var auditEntryProperty = entry.Parent.Configuration.AuditEntryPropertyFactory != null? entry.Parent.Configuration.AuditEntryPropertyFactory(new AuditEntryPropertyArgs(entry, objectStateEntry, propertyEntry.Name, null, property.CurrentValue)) : new AuditEntryProperty(); auditEntryProperty.Build(entry, propertyEntry.Name, null, property.CurrentValue); entry.Properties.Add(auditEntryProperty); } } }
public static void AuditEntityAdded(AuditEntry entry, DbUpdatableDataRecord record, string prefix = "") { for (var i = 0; i < record.FieldCount; i++) { var name = record.GetName(i); var value = record.GetValue(i); var valueRecord = value as DbUpdatableDataRecord; if (valueRecord != null) { // Complex Type AuditEntityAdded(entry, valueRecord, string.Concat(prefix, name, ".")); } else { entry.Properties.Add(new AuditEntryProperty(string.Concat(prefix, name), null, value)); } } }
/// <summary>Audit entity deleted.</summary> /// <param name="entry">The entry.</param> /// <param name="record">The record.</param> /// <param name="prefix">The prefix.</param> public static void AuditEntityDeleted(AuditEntry entry, DbDataRecord record, string prefix = "") { for (var i = 0; i < record.FieldCount; i++) { var name = record.GetName(i); var value = record.GetValue(i); var valueRecord = value as DbDataRecord; if (valueRecord != null) { // Complex Type AuditEntityDeleted(entry, valueRecord, string.Concat(prefix, name, ".")); } else if (entry.Parent.CurrentOrDefaultConfiguration.IsAuditedProperty(entry.Entry, name)) { entry.Properties.Add(new AuditEntryProperty(entry, string.Concat(prefix, name), value, null)); } } }
/// <summary>Audit entity modified.</summary> /// <param name="audit">The audit to use to add changes made to the context.</param> /// <param name="objectStateEntry">The object state entry.</param> public static void AuditEntityModified(Audit audit, ObjectStateEntry objectStateEntry) { var entry = new AuditEntry(objectStateEntry) { State = AuditEntryState.EntityModified }; if (audit.Configuration.IsSoftAdded != null && audit.Configuration.IsSoftAdded(objectStateEntry.Entity)) { entry.State = AuditEntryState.EntitySoftAdded; } else if (audit.Configuration.IsSoftDeleted != null && audit.Configuration.IsSoftDeleted(objectStateEntry.Entity)) { entry.State = AuditEntryState.EntitySoftDeleted; } AuditEntityModified(audit, entry, objectStateEntry.OriginalValues, objectStateEntry.CurrentValues); audit.Entries.Add(entry); }
/// <summary>Audit entity modified.</summary> /// <param name="audit">The audit to use to add changes made to the context.</param> /// <param name="objectStateEntry">The object state entry.</param> public static void AuditEntityModified(Audit audit, ObjectStateEntry objectStateEntry) { var entry = new AuditEntry(objectStateEntry) { State = AuditEntryState.EntityModified }; if (audit.Configuration.IsSoftAdded != null && audit.Configuration.IsSoftAdded(objectStateEntry.Entity)) { entry.State = AuditEntryState.EntitySoftAdded; } else if (audit.Configuration.IsSoftDeleted != null && audit.Configuration.IsSoftDeleted(objectStateEntry.Entity)) { entry.State = AuditEntryState.EntitySoftDeleted; } AuditEntityModified(audit, entry, objectStateEntry.OriginalValues, objectStateEntry.CurrentValues); audit.Entries.Add(entry); }
public static void AuditEntityDeleted(AuditEntry entry, DbDataRecord record, string prefix = "") { for (var i = 0; i < record.FieldCount; i++) { var name = record.GetName(i); var value = record.GetValue(i); var valueRecord = value as DbDataRecord; if (valueRecord != null) { // Complex Type AuditEntityDeleted(entry, valueRecord, string.Concat(prefix, name, ".")); } else { entry.Properties.Add(new AuditEntryProperty(string.Concat(prefix, name), value, null)); } } }
/// <summary>Audit entity added.</summary> /// <param name="auditEntry">The audit entry.</param> /// <param name="record">The record.</param> /// <param name="prefix">The prefix.</param> public static void AuditEntityAdded(AuditEntry auditEntry, DbUpdatableDataRecord record, string prefix = "") { for (var i = 0; i < record.FieldCount; i++) { var name = record.GetName(i); var value = record.GetValue(i); var valueRecord = value as DbUpdatableDataRecord; if (valueRecord != null) { // Complex Type AuditEntityAdded(auditEntry, valueRecord, string.Concat(prefix, name, ".")); } else if (auditEntry.Parent.CurrentOrDefaultConfiguration.IsAuditedProperty(auditEntry.Entry, name)) { auditEntry.Properties.Add(new AuditEntryProperty(auditEntry, string.Concat(prefix, name), null, value)); } } }
public static void AuditRelationDeleted(Audit audit, EntityEntry objectStateEntry) #endif { var entry = new AuditEntry(audit, objectStateEntry) { State = AuditEntryState.RelationshipDeleted }; var values = objectStateEntry.OriginalValues; for (var i = 0; i < values.FieldCount; i++) { var relationName = values.GetName(i); var value = (EntityKey) values.GetValue(i); foreach (var keyValue in value.EntityKeyValues) { entry.Properties.Add(new AuditEntryProperty(entry, relationName, keyValue.Key, keyValue.Value, null)); } } audit.Entries.Add(entry); }
public static void AuditRelationDeleted(Audit audit, EntityEntry objectStateEntry) #endif { var entry = new AuditEntry(audit, objectStateEntry) { State = AuditEntryState.RelationshipDeleted }; var values = objectStateEntry.OriginalValues; for (var i = 0; i < values.FieldCount; i++) { var relationName = values.GetName(i); var value = (EntityKey)values.GetValue(i); foreach (var keyValue in value.EntityKeyValues) { entry.Properties.Add(new AuditEntryProperty(entry, relationName, keyValue.Key, keyValue.Value, null)); } } audit.Entries.Add(entry); }
/// <summary>Audit relationship deleted.</summary> /// <param name="audit">The audit to use to add changes made to the context.</param> /// <param name="objectStateEntry">The object state entry.</param> public static void AuditRelationDeleted(Audit audit, ObjectStateEntry objectStateEntry) { var entry = new AuditEntry(objectStateEntry) { State = AuditEntryState.RelationshipDeleted }; var values = objectStateEntry.OriginalValues; for (var i = 0; i < values.FieldCount; i++) { var relationName = values.GetName(i); var value = (EntityKey) values.GetValue(i); foreach (var keyValue in value.EntityKeyValues) { // todo: better add a new property association? var keyName = string.Concat(relationName, ";", keyValue.Key); entry.Properties.Add(new AuditEntryProperty(keyName, keyValue.Value, null)); } } audit.Entries.Add(entry); }
public static void AuditEntityModified(Audit audit, AuditEntry entry, DbDataRecord orginalRecord, DbUpdatableDataRecord currentRecord, string prefix = "") { for (var i = 0; i < orginalRecord.FieldCount; i++) { var name = orginalRecord.GetName(i); var originalValue = orginalRecord.GetValue(i); var currentValue = currentRecord.GetValue(i); var valueRecord = originalValue as DbDataRecord; if (valueRecord != null) { // Complex Type AuditEntityModified(audit, entry, valueRecord, currentValue as DbUpdatableDataRecord, string.Concat(prefix, name, ".")); } else { if (audit.Configuration.IncludePropertyUnchanged || !Equals(currentValue, originalValue)) { entry.Properties.Add(new AuditEntryProperty(string.Concat(prefix, name), originalValue, currentValue)); } } } }
public static void AuditEntityModified(Audit audit, AuditEntry entry, DbDataRecord orginalRecord, DbUpdatableDataRecord currentRecord, string prefix = "") { for (var i = 0; i < orginalRecord.FieldCount; i++) { var name = orginalRecord.GetName(i); var originalValue = orginalRecord.GetValue(i); var currentValue = currentRecord.GetValue(i); var valueRecord = originalValue as DbDataRecord; if (valueRecord != null) { // Complex Type AuditEntityModified(audit, entry, valueRecord, currentValue as DbUpdatableDataRecord, string.Concat(prefix, name, ".")); } else { if (audit.Configuration.IncludePropertyUnchanged || !Equals(currentValue, originalValue)) { entry.Properties.Add(new AuditEntryProperty(string.Concat(prefix, name), originalValue, currentValue)); } } } }
/// <summary>Audit relationship deleted.</summary> /// <param name="audit">The audit to use to add changes made to the context.</param> /// <param name="objectStateEntry">The object state entry.</param> public static void AuditRelationDeleted(Audit audit, ObjectStateEntry objectStateEntry) { var entry = new AuditEntry(objectStateEntry) { State = AuditEntryState.RelationshipDeleted }; var values = objectStateEntry.OriginalValues; for (var i = 0; i < values.FieldCount; i++) { var relationName = values.GetName(i); var value = (EntityKey)values.GetValue(i); foreach (var keyValue in value.EntityKeyValues) { // todo: better add a new property association? var keyName = string.Concat(relationName, ";", keyValue.Key); entry.Properties.Add(new AuditEntryProperty(keyName, keyValue.Value, null)); } } audit.Entries.Add(entry); }
/// <summary>Audit relationship added.</summary> /// <param name="audit">The audit to use to add changes made to the context.</param> /// <param name="objectStateEntry">The object state entry.</param> public static void AuditRelationAdded(Audit audit, ObjectStateEntry objectStateEntry) { var entry = new AuditEntry(objectStateEntry) { State = AuditEntryState.RelationshipAdded }; var values = objectStateEntry.CurrentValues; var value_0 = (EntityKey)values.GetValue(0); var value_1 = (EntityKey)values.GetValue(1); if (value_0.IsTemporary || value_1.IsTemporary) { entry.DelayedKey = objectStateEntry; } else { var relationName_0 = values.GetName(0); var relationName_1 = values.GetName(1); foreach (var keyValue in value_0.EntityKeyValues) { var keyName = string.Concat(relationName_0, ";", keyValue.Key); entry.Properties.Add(new AuditEntryProperty(keyName, null, keyValue.Value)); } foreach (var keyValue in value_1.EntityKeyValues) { var keyName = string.Concat(relationName_1, ";", keyValue.Key); entry.Properties.Add(new AuditEntryProperty(keyName, null, keyValue.Value)); } } audit.Entries.Add(entry); }
/// <summary>Audit relationship added.</summary> /// <param name="audit">The audit to use to add changes made to the context.</param> /// <param name="objectStateEntry">The object state entry.</param> public static void AuditRelationAdded(Audit audit, ObjectStateEntry objectStateEntry) { var entry = new AuditEntry(objectStateEntry) { State = AuditEntryState.RelationshipAdded }; var values = objectStateEntry.CurrentValues; var value_0 = (EntityKey) values.GetValue(0); var value_1 = (EntityKey) values.GetValue(1); if (value_0.IsTemporary || value_1.IsTemporary) { entry.DelayedKey = objectStateEntry; } else { var relationName_0 = values.GetName(0); var relationName_1 = values.GetName(1); foreach (var keyValue in value_0.EntityKeyValues) { var keyName = string.Concat(relationName_0, ";", keyValue.Key); entry.Properties.Add(new AuditEntryProperty(keyName, null, keyValue.Value)); } foreach (var keyValue in value_1.EntityKeyValues) { var keyName = string.Concat(relationName_1, ";", keyValue.Key); entry.Properties.Add(new AuditEntryProperty(keyName, null, keyValue.Value)); } } audit.Entries.Add(entry); }
/// <summary>Audit entity deleted.</summary> /// <param name="entry">The entry.</param> /// <param name="record">The record.</param> /// <param name="prefix">The prefix.</param> public static void AuditEntityDeleted(AuditEntry entry, ObjectStateEntry objectStateEntry, DbDataRecord record, string prefix = "") { for (var i = 0; i < record.FieldCount; i++) { var name = record.GetName(i); var value = record.GetValue(i); var valueRecord = value as DbDataRecord; if (valueRecord != null) { // Complex Type AuditEntityDeleted(entry, objectStateEntry, valueRecord, string.Concat(prefix, name, ".")); } else if (objectStateEntry.EntityKey.EntityKeyValues.Any(x => x.Key == name) || entry.Parent.CurrentOrDefaultConfiguration.IsAuditedProperty(entry.Entry, name)) { var auditEntryProperty = entry.Parent.Configuration.AuditEntryPropertyFactory != null? entry.Parent.Configuration.AuditEntryPropertyFactory(new AuditEntryPropertyArgs(entry, objectStateEntry, string.Concat(prefix, name), value, null)) : new AuditEntryProperty(); auditEntryProperty.Build(entry, string.Concat(prefix, name), value, null); entry.Properties.Add(auditEntryProperty); } } }
public static void AuditRelationAdded(Audit audit, EntityEntry objectStateEntry) #endif { var entry = new AuditEntry(audit, objectStateEntry) { State = AuditEntryState.RelationshipAdded }; var values = objectStateEntry.CurrentValues; var leftKeys = (EntityKey) values.GetValue(0); var rightKeys = (EntityKey) values.GetValue(1); if (leftKeys.IsTemporary || rightKeys.IsTemporary) { entry.DelayedKey = objectStateEntry; } else { var leftRelationName = values.GetName(0); var rightRelationName = values.GetName(1); foreach (var keyValue in leftKeys.EntityKeyValues) { entry.Properties.Add(new AuditEntryProperty(entry, leftRelationName, keyValue.Key, null, keyValue.Value)); } foreach (var keyValue in rightKeys.EntityKeyValues) { entry.Properties.Add(new AuditEntryProperty(entry, rightRelationName, keyValue.Key, null, keyValue.Value)); } } audit.Entries.Add(entry); }
public static void AuditRelationAdded(Audit audit, EntityEntry objectStateEntry) #endif { var entry = new AuditEntry(audit, objectStateEntry) { State = AuditEntryState.RelationshipAdded }; var values = objectStateEntry.CurrentValues; var leftKeys = (EntityKey)values.GetValue(0); var rightKeys = (EntityKey)values.GetValue(1); if (leftKeys.IsTemporary || rightKeys.IsTemporary) { entry.DelayedKey = objectStateEntry; } else { var leftRelationName = values.GetName(0); var rightRelationName = values.GetName(1); foreach (var keyValue in leftKeys.EntityKeyValues) { entry.Properties.Add(new AuditEntryProperty(entry, leftRelationName, keyValue.Key, null, keyValue.Value)); } foreach (var keyValue in rightKeys.EntityKeyValues) { entry.Properties.Add(new AuditEntryProperty(entry, rightRelationName, keyValue.Key, null, keyValue.Value)); } } audit.Entries.Add(entry); }
public void Build(AuditEntry parent, string propertyName, object oldValue, DbUpdatableDataRecord dbUpdatableDataRecord, int dbUpdatableDataRecordPosition) { Build(parent, null, propertyName, oldValue, dbUpdatableDataRecord, dbUpdatableDataRecordPosition); }
public void Build(AuditEntry parent, string propertyName, object oldValue, PropertyEntry propertyEntry) { Build(parent, null, propertyName, oldValue, propertyEntry); }
/// <summary>Constructor.</summary> /// <param name="parent">The audit entry parent.</param> /// <param name="propertyName">Name of the property audited.</param> /// <param name="oldValue">The old value audited.</param> /// <param name="newValue">The new value audited.</param> public void Build(AuditEntry parent, string propertyName, object oldValue, object newValue) { Build(parent, null, propertyName, oldValue, newValue); }