示例#1
0
        public bool IsValid(IEntityWithRedundancyCheck entity)
        {
            var calculatedHash = this.CalculateHashForEntity(entity);
            var currentHash    = entity.CRC ?? new byte[0];

            return(calculatedHash.SequenceEqual(currentHash));
        }
示例#2
0
        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()));
        }
示例#3
0
 private static Type GetEntityType(IEntityWithRedundancyCheck entityWithCRC)
 {
     return(System.Data.Entity.Core.Objects.ObjectContext.GetObjectType(entityWithCRC.GetType()));
 }