/// <summary> /// Default Constructor. /// Creates a new instance of the <see cref="ValidationError" /> data structure. /// </summary> /// <param name="message">string. The validation error message.</param> /// <param name="property">string. The property that was validated.</param> /// <param name="errorState">State of the error.</param> public ValidationError(string message, PropertyInfo property, ValidationErrorState errorState = ValidationErrorState.ValidationError) { AttemptedValue = null; Message = message; Property = property; ErrorState = errorState; }
/// <summary> /// Initializes a new instance of the <see cref="ValidationError" /> struct. /// </summary> /// <param name="message">The message.</param> /// <param name="property">The property.</param> /// <param name="value">The value.</param> /// <param name="errorState">State of the error.</param> public ValidationError(string message, PropertyInfo property, object value, ValidationErrorState errorState = ValidationErrorState.ValidationError) { Message = message; Property = property; AttemptedValue = value; ErrorState = errorState; }
public ValidationError(ValidationErrorState errorState, int lineIndex, int charIndex, string message) { m_errorState = errorState; m_lineIndex = lineIndex; m_charIndex = charIndex; m_message = message; }
private static void MergeValidationError(ValidationErrorState originalError, ValidationError newError) { if (originalError.ValidationState == ValidationState.ChildInvalid) { // If original error is due to child's issue, clear the error list, // as we don't care about its child's issues anymore and want to add its own issues. originalError.ErrorMessages.Clear(); } ValidationState errorState = GetValidationState(newError); if (originalError.ValidationState < errorState) { // Promote to the higher level of violation. originalError.ValidationState = errorState; } if (newError.IsWarning) { originalError.ErrorMessages.Add(string.Format(CultureInfo.CurrentUICulture, SR.WarningFormat, newError.Message)); } else { originalError.ErrorMessages.Add(newError.Message); } }
ValidationErrorState GetValidationError(ModelItem modelItem) { ValidationErrorState validationError = null; this.ValidationErrors.TryGetValue(modelItem.GetCurrentValue(), out validationError); return(validationError); }
public ValidationError(ValidationErrorState errorState, IDocPosition docPosition, string message) { m_errorState = errorState; if (docPosition != null) { m_lineIndex = docPosition.LineIndex; m_charIndex = docPosition.CharIndex; } m_message = message; }
ValidationState GetValidationState(ModelItem modelItem) { ValidationState validationState = ValidationState.Valid; ValidationErrorState validationError = GetValidationError(modelItem); if (validationError != null) { validationState = validationError.ValidationState; } return(validationState); }
// Mark a single error on the culprit private void MarkCulprit(object errorSource, ValidationError validationError) { ValidationErrorState currentError; if (!this.ValidationErrors.TryGetValue(errorSource, out currentError)) { currentError = new ValidationErrorState(new List <string>(), ValidationState.Valid); this.ValidationErrors.Add(errorSource, currentError); } MergeValidationError(currentError, validationError); this.NotifyValidationPropertiesChanged(errorSource); }
string GetValidationMessage(ModelItem modelItem) { string errorMessage = string.Empty; ValidationErrorState validationError = GetValidationError(modelItem); if (validationError != null) { if (validationError.ErrorMessages != null) { ValidationService.ErrorBuilder.Clear(); foreach (string message in validationError.ErrorMessages) { ValidationService.ErrorBuilder.AppendLine(message.Trim()); } errorMessage = ValidationService.ErrorBuilder.ToString().Trim(); } } return(errorMessage); }
//readonly ILoggerFacade logger = ServiceLocator.Current.GetInstance<ILoggerFacade>(LogNames.Session); private void BuildClassResults(object entity, IList <ValidationError> errors) { if (ClassValidators == null || !ClassValidators.Any()) { return; } //var timer = new Stopwatch(); #if DEBUG var timer2 = new Stopwatch(); #endif // timer.Start(); var ctxt = new ValidationContext(entity); foreach (var attr in ClassValidators) { #if DEBUG timer2.Start(); #endif var result = attr.GetValidationResult(entity, ctxt); #if DEBUG timer2.Stop(); var message = string.Format("IP/ED dataset imports - Time of Execution of class validation {2}: {0}:{1}", timer2.Elapsed.Seconds, timer2.Elapsed.Milliseconds, attr.GetType().Name); Trace.WriteLine(message); timer2.Reset(); #endif if (result != null && !string.IsNullOrEmpty(result.ErrorMessage)) { #if DEBUG timer2.Start(); #endif ValidationErrorState errorState = (attr.GetType() == typeof(RejectIfAnyPropertyHasValueAttribute)) ? ValidationErrorState.ExcludedByCrosswalk : ValidationErrorState.ValidationError; if (result.MemberNames != null && result.MemberNames.Any()) { foreach (var memberName in result.MemberNames.ToList()) { PropertyDescriptor propDesc; if (PropertyDescriptors.TryGetValue(memberName, out propDesc)) { errors.Add(new ValidationError(result.ErrorMessage, PropertyDescriptors[memberName].Property, errorState)); } else { errors.Add(new ValidationError(result.ErrorMessage, null, errorState)); } } } else { errors.Add(new ValidationError(result.ErrorMessage, null, errorState)); } #if DEBUG timer2.Stop(); var message2 = string.Format("IP/ED dataset imports - Time of Execution of message processing: {0}:{1}", timer2.Elapsed.Seconds, timer2.Elapsed.Milliseconds); Trace.WriteLine(message2); #endif } } // timer.Stop(); // var message3 = string.Format("IP/ED dataset imports - Overall Time of Execution of all class validations: {0}:{1}", // timer.Elapsed.Seconds, timer.Elapsed.Milliseconds); // Trace.WriteLine(message3); //if(logger != null) // logger.Write(message, Category.Debug, Priority.High); }
private void OnValidationWorkCompleted(Tuple <ValidationReason, ValidationResults, Exception> input) { ValidationReason reason = input.Item1; ValidationResults results = input.Item2; Exception exception = input.Item3; Fx.Assert(results != null ^ exception != null, "result and exception should not both be null"); bool needsToMarkValidationErrors = false; ValidationErrorInfo validationErrorInfo = null; if (exception != null) { ModelItem rootModelItem = this.modelService.Root; Activity rootActivity = rootModelItem.GetRootActivity(); if (rootActivity != null) { // We don't want any crash propagating from here as it causes VS to crash. if (!this.ValidationErrors.ContainsKey(rootActivity)) { ValidationErrorState validationError = new ValidationErrorState(new List <string>(), ValidationState.Error); this.ValidationErrors.Add(rootActivity, validationError); } else { this.ValidationErrors[rootActivity].ValidationState = ValidationState.Error; } this.ValidationErrors[rootActivity].ErrorMessages.Add(exception.ToString()); // Notify an update to the attached properties this.NotifyValidationPropertiesChanged(rootModelItem); } validationErrorInfo = new ValidationErrorInfo(exception.ToString()); needsToMarkValidationErrors = true; } DesignerPerfEventProvider perfProvider = this.context.Services.GetService <DesignerPerfEventProvider>(); perfProvider.WorkflowDesignerValidationStart(); List <ValidationError> validationErrors = null; if (results != null) { validationErrors = new List <ValidationError>(results.Errors); validationErrors.AddRange(results.Warnings); Activity rootActivity = this.modelService.Root.GetRootActivity(); needsToMarkValidationErrors = this.MarkErrors(validationErrors, reason, rootActivity); } if (this.errorService != null && needsToMarkValidationErrors) // Error service could be null if no implementation has been provided { List <ValidationErrorInfo> errors = new List <ValidationErrorInfo>(); if (validationErrors != null) { foreach (ValidationError validationError in validationErrors) { Activity currentActivity = validationError.Source; ValidationErrorInfo error = new ValidationErrorInfo(validationError); // The acquired activity reference will be release in the Main AppDomain when it clear the error list if (validationError.SourceDetail != null) { error.SourceReferenceId = this.objectReferenceService.AcquireObjectReference(validationError.SourceDetail); } else if (validationError.Source != null) { error.SourceReferenceId = this.objectReferenceService.AcquireObjectReference(validationError.Source); } else { error.SourceReferenceId = Guid.Empty; } errors.Add(error); } } if (validationErrorInfo != null) { errors.Add(validationErrorInfo); } foreach (Guid acquiredObjectReference in this.AcquiredObjectReferences) { this.objectReferenceService.ReleaseObjectReference(acquiredObjectReference); } this.AcquiredObjectReferences.Clear(); foreach (ValidationErrorInfo error in errors) { if (error.SourceReferenceId != Guid.Empty) { this.AcquiredObjectReferences.Add(error.SourceReferenceId); } } this.errorService.ShowValidationErrors(errors); } perfProvider.WorkflowDesignerValidationEnd(); this.OnValidationCompleted(); }
private Brush GetBrush(ValidationErrorState errorState) { //TODO move colors to settings switch (errorState) { case ValidationErrorState.Good: return new SolidColorBrush(Color.FromArgb(0xA5, 0x00, 0x80, 0x00)); case ValidationErrorState.NotInSchema: return new SolidColorBrush(Color.FromArgb(0xA5, 0x80, 0x00, 0x80)); case ValidationErrorState.WrongData: return new SolidColorBrush(Color.FromArgb(0xA5, 0xFF, 0x14, 0x93)); case ValidationErrorState.NotCorrectJson: return new SolidColorBrush(Color.FromArgb(0xA5, 0xFF, 0x00, 0x00)); case ValidationErrorState.Unknown: return new SolidColorBrush(Color.FromArgb(0x55, 0xAD, 0xD8, 0xE6)); case ValidationErrorState.ToMany: return new SolidColorBrush(Color.FromArgb(0xA5, 0x00, 0x00, 0xCD)); case ValidationErrorState.MissingChild: return new SolidColorBrush(Color.FromArgb(0xA5, 0xFF, 0xA5, 0x00)); default: throw new ArgumentOutOfRangeException("errorState"); } }
// Mark a single error on the culprit private void MarkCulprit(object errorSource, ValidationError validationError) { ValidationErrorState currentError; if (!this.ValidationErrors.TryGetValue(errorSource, out currentError)) { currentError = new ValidationErrorState(new List<string>(), ValidationState.Valid); this.ValidationErrors.Add(errorSource, currentError); } MergeValidationError(currentError, validationError); this.NotifyValidationPropertiesChanged(errorSource); }
private void OnValidationWorkCompleted(Tuple<ValidationReason, ValidationResults, Exception> input) { ValidationReason reason = input.Item1; ValidationResults results = input.Item2; Exception exception = input.Item3; Fx.Assert(results != null ^ exception != null, "result and exception should not both be null"); bool needsToMarkValidationErrors = false; ValidationErrorInfo validationErrorInfo = null; if (exception != null) { ModelItem rootModelItem = this.modelService.Root; Activity rootActivity = rootModelItem.GetRootActivity(); if (rootActivity != null) { // We don't want any crash propagating from here as it causes VS to crash. if (!this.ValidationErrors.ContainsKey(rootActivity)) { ValidationErrorState validationError = new ValidationErrorState(new List<string>(), ValidationState.Error); this.ValidationErrors.Add(rootActivity, validationError); } else { this.ValidationErrors[rootActivity].ValidationState = ValidationState.Error; } this.ValidationErrors[rootActivity].ErrorMessages.Add(exception.ToString()); // Notify an update to the attached properties this.NotifyValidationPropertiesChanged(rootModelItem); } validationErrorInfo = new ValidationErrorInfo(exception.ToString()); needsToMarkValidationErrors = true; } DesignerPerfEventProvider perfProvider = this.context.Services.GetService<DesignerPerfEventProvider>(); perfProvider.WorkflowDesignerValidationStart(); List<ValidationError> validationErrors = null; if (results != null) { validationErrors = new List<ValidationError>(results.Errors); validationErrors.AddRange(results.Warnings); Activity rootActivity = this.modelService.Root.GetRootActivity(); needsToMarkValidationErrors = this.MarkErrors(validationErrors, reason, rootActivity); } if (this.errorService != null && needsToMarkValidationErrors) // Error service could be null if no implementation has been provided { List<ValidationErrorInfo> errors = new List<ValidationErrorInfo>(); if (validationErrors != null) { foreach (ValidationError validationError in validationErrors) { Activity currentActivity = validationError.Source; ValidationErrorInfo error = new ValidationErrorInfo(validationError); // The acquired activity reference will be release in the Main AppDomain when it clear the error list if (validationError.SourceDetail != null) { error.SourceReferenceId = this.objectReferenceService.AcquireObjectReference(validationError.SourceDetail); } else if (validationError.Source != null) { error.SourceReferenceId = this.objectReferenceService.AcquireObjectReference(validationError.Source); } else { error.SourceReferenceId = Guid.Empty; } errors.Add(error); } } if (validationErrorInfo != null) { errors.Add(validationErrorInfo); } foreach (Guid acquiredObjectReference in this.AcquiredObjectReferences) { this.objectReferenceService.ReleaseObjectReference(acquiredObjectReference); } this.AcquiredObjectReferences.Clear(); foreach (ValidationErrorInfo error in errors) { if (error.SourceReferenceId != Guid.Empty) { this.AcquiredObjectReferences.Add(error.SourceReferenceId); } } this.errorService.ShowValidationErrors(errors); } perfProvider.WorkflowDesignerValidationEnd(); this.OnValidationCompleted(); }