Exemple #1
0
        /// <summary>
        /// Validate the changeset.
        /// </summary>
        /// <param name="validationContext">The ValidationContext to use.</param>
        /// <returns>True if the changeset is valid, false otherwise.</returns>
        internal bool Validate(ValidationContext validationContext)
        {
            bool success = true;

            foreach (Entity entity in this)
            {
                entity.VerifyNotEditing();
                bool         entityRequiresValidation = entity.MetaType.RequiresValidation;
                EntityAction customMethod             = entity.EntityActions.SingleOrDefault();

                if (!entityRequiresValidation && customMethod == null)
                {
                    continue;
                }

                if (entity.EntityState == EntityState.Deleted)
                {
                    // skip validation for Deleted entities here since the entity is going to be deleted anyway
                    continue;
                }

                // first validate the entity
                List <ValidationResult> validationResults = new List <ValidationResult>();
                if (entityRequiresValidation)
                {
                    ValidationUtilities.TryValidateObject(entity, validationContext, validationResults);
                }

                // validate any Custom Method invocations
                if (customMethod != null)
                {
                    // validate the method call
                    object[]          parameters = customMethod.HasParameters ? customMethod.Parameters.ToArray() : null;
                    ValidationContext customMethodValidationContext = ValidationUtilities.CreateValidationContext(entity, validationContext);
                    ValidationUtilities.TryValidateCustomUpdateMethodCall(customMethod.Name, customMethodValidationContext, parameters, validationResults);
                }

                if (validationResults.Count > 0)
                {
                    // replace the validation errors for the entity
                    IEnumerable <ValidationResult> entityErrors = new ReadOnlyCollection <ValidationResult>(validationResults.Select(err => new ValidationResult(err.ErrorMessage, err.MemberNames)).Distinct(new ValidationResultEqualityComparer()).ToList());
                    ValidationUtilities.ApplyValidationErrors(entity, entityErrors);
                    success = false;
                }
                else
                {
                    // clear the errors for the entity
                    entity.ValidationErrors.Clear();
                }
            }

            return(success);
        }
Exemple #2
0
        /// <summary>
        /// Commit the edits made to this instance since the last call
        /// to BeginEdit
        /// </summary>
        protected void EndEdit()
        {
            if (!this.IsEditing)
            {
                return;
            }

            // TODO : Check if this old comment is still true and if this is something we should manage
            // " The desktop version of the framework doesn't currently do deep validation."

            // Validate the instance itself (cross-field validation happens here)
            List <ValidationResult> validationResults = new List <ValidationResult>();

            ValidationUtilities.TryValidateObject(this, this.CreateValidationContext(), validationResults);

            // Replace all errors for this instance and notify our parent
            ValidationUtilities.ApplyValidationErrors(this, validationResults);
            this.NotifyParentMemberValidationChanged(null, validationResults);

            this._editSession = null;
        }
Exemple #3
0
        /// <summary>
        /// Commit the edits made to this instance since the last call
        /// to BeginEdit
        /// </summary>
        protected void EndEdit()
        {
            if (!this.IsEditing)
            {
                return;
            }

#if SILVERLIGHT
            // Validate the instance itself (cross-field validation happens here)
            List <ValidationResult> validationResults = new List <ValidationResult>();
            ValidationUtilities.TryValidateObject(this, this.CreateValidationContext(), validationResults);

            // Replace all errors for this instance and notify our parent
            ValidationUtilities.ApplyValidationErrors(this, validationResults);
            this.NotifyParentMemberValidationChanged(null, validationResults);
#else
            // Validate the instance itself (cross-field validation happens here)
            // TODO : The desktop version of the framework doesn't currently do
            // deep validation.
            Validator.ValidateObject(this, this.CreateValidationContext(), /*validateAllProperties*/ true);
#endif
            this._editSession = null;
        }