public bool IsValid(IEntityWithRedundancyCheck entity) { var calculatedHash = this.CalculateHashForEntity(entity); var currentHash = entity.CRC ?? new byte[0]; return(calculatedHash.SequenceEqual(currentHash)); }
public byte[] CalculateHashForEntity(IEntityWithRedundancyCheck entity) { var seed = new StringBuilder(); var entityType = entity.GetType(); foreach (PropertyDescriptor propertyDescriptor in TypeDescriptor.GetProperties(entityType)) { var fieldMarkedForRc = propertyDescriptor.Attributes .OfType <FieldMarkedForRedundancyAttribute>() .FirstOrDefault(); if (fieldMarkedForRc != null) { //TODO: Verificar el orden del armado de la semilla var propertyValueSerialized = Convert.ToString(propertyDescriptor.GetValue(entity) ?? string.Empty); seed.Append(propertyValueSerialized); } } return(_hash.CreateHash(seed.ToString())); }
private static Type GetEntityType(IEntityWithRedundancyCheck entityWithCRC) { return(System.Data.Entity.Core.Objects.ObjectContext.GetObjectType(entityWithCRC.GetType())); }