Exemplo n.º 1
0
        private static void ValidateAll(EntityBase bob)
        {
            if (bob == null)
                return;

            bob.Validate(); // validate the object itself.

            // validate any bob properties of the object, (and walk into those objects)

            foreach (string s in bob._entityProperties)
            {
                EntityBase nestedObject = GetBusinessObjectFromProperty(s, bob);
                ValidateAll(nestedObject);
            }

            // validate any bob collections on the object, (and walk into those collections)

            foreach (string s in bob._entityCollectionProperties)
            {
                IList<EntityBase> list = GetBusinessObjectCollectionFromProperty(s, bob);
                foreach (EntityBase bobItem in list)
                {
                    ValidateAll(bobItem);
                }
            }
        }
Exemplo n.º 2
0
        private static int BrokenRulesCount(EntityBase bob)
        {
            if (bob == null)
                return 0;

            int broken = 0;

            broken += bob._broken.Count;

            foreach (string s in bob._entityProperties)
            {
                broken += BrokenRulesCount(GetBusinessObjectFromProperty(s, bob));
            }

            foreach (string s in bob._entityCollectionProperties)
            {
                IList<EntityBase> bobList = GetBusinessObjectCollectionFromProperty(s, bob);
                foreach (EntityBase bobItem in bobList)
                {
                    broken += BrokenRulesCount(bobItem);
                }
            }

            return broken;
        }
Exemplo n.º 3
0
        public static string ValidationErrorMessage(EntityBase bob, bool includeNestedObjects)
        {
            if (bob == null)
                return string.Empty;

            string message = string.Empty;

            foreach (ValidationRuleBase r in bob._broken)
            {
                if (!string.IsNullOrEmpty(message))
                    message += Environment.NewLine;

                message += string.Format("{0}: {1}", r.PropertyName, r.RuleBrokenMessage);
            }

            if (!includeNestedObjects)
                return message;

            foreach (string s in bob._entityProperties)
            {
                message += ValidationErrorMessage(GetBusinessObjectFromProperty(s, bob), includeNestedObjects);
            }

            foreach (string s in bob._entityCollectionProperties)
            {
                IList<EntityBase> bobList = GetBusinessObjectCollectionFromProperty(s, bob);
                foreach (EntityBase bobItem in bobList)
                {
                    message += ValidationErrorMessage(bobItem, includeNestedObjects);
                }
            }

            return message;
        }
Exemplo n.º 4
0
        /// <summary>
        /// Helper method that fetches a collection based on a property name.
        /// </summary>
        private static IList<EntityBase> GetBusinessObjectCollectionFromProperty(string collectionProperty, EntityBase bob)
        {
            Type t = Core.Data.Connection.GetConcreteType(bob);

            PropertyInfo p = t.GetProperty(collectionProperty,
                BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.GetProperty);

            if (p == null)
                throw new ArgumentException("Property " + collectionProperty + " does not exist or is inaccessable.");

            object o = p.GetValue(bob, BindingFlags.GetProperty, null, null, null);

            if (o is IList<EntityBase>)
                return (IList<EntityBase>)o;
            else
            {
                IList list = o as IList;

                List<EntityBase> genericList = new List<EntityBase>();
                foreach (EntityBase bobItem in list)
                {
                    genericList.Add(bobItem);
                }

                return genericList;
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Helper method to get the business object value
        /// of a property by name.
        /// </summary>
        private static EntityBase GetBusinessObjectFromProperty(string property, EntityBase bob)
        {
            Type t = Core.Data.Connection.GetConcreteType(bob);

            PropertyInfo p = t.GetProperty(property,
                BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.GetProperty);

            if (p == null)
                throw new ArgumentException("Property " + property + " does not exist or is inaccessable.");

            object o = p.GetValue(bob, BindingFlags.GetProperty, null, null, null);

            return (EntityBase)o;
        }
Exemplo n.º 6
0
 /// <summary>
 /// Checks if given object has the same
 /// business signature as the object.
 /// </summary>
 /// <param name="obj"></param>
 /// <returns></returns>
 protected bool HasSameBusinessSignature(EntityBase obj)
 {
     return GetHashCode().Equals(obj.GetHashCode());
 }
Exemplo n.º 7
0
 /// <summary>
 /// Determines if a given object has been persisted to the database.
 /// </summary>
 /// <param name="entity">The object to examine.</param>
 /// <returns>True if the object has been persisted, otherwise false.</returns>
 public static bool IsTransient(EntityBase entity)
 {
     return entity.ID == null;
 }
Exemplo n.º 8
0
 /// <summary>
 /// Determines if the given entity complies with this rule.
 /// </summary>
 /// <returns>True if the entity complies; otherwise false.</returns>
 public abstract bool IsValid(EntityBase entity);