/// <summary> /// Validates the target. /// </summary> /// <param name="temp">The temporary.</param> /// <param name="current">The current.</param> /// <param name="rdr">The RDR.</param> /// <param name="mappings">The mappings.</param> /// <param name="session">The session.</param> /// <returns></returns> private ValidationStatus ValidateTarget(object temp, int current, IDataReader rdr, IDictionary <string, string> mappings, IStatelessSession session) { bool hasError = false; var validationResult = ValidationEngine.ValidateInstance(temp); var updateCount = validationResult.PropertyErrors.Count + validationResult.PropertyWarnings.Count; hasError = validationResult.PropertyErrors.Any() || validationResult.ClassErrors.Any(); if (validationResult.ClassErrors.Any()) { updateCount += validationResult.ClassErrors.Count; hasError = true; foreach (var res in validationResult.ClassErrors) { string member = string.Empty; string msg = null; object value = null; if (res.Property != null) { member = res.Property.Name; var column = mappings[member]; var ord = rdr.GetOrdinal(column); value = rdr.GetValue(ord); msg = string.Format("Value excluded: {0}", value == null ? "<<NULL>>" : string.IsNullOrEmpty(value.ToString()) ? @"""" : value.ToString()); } if (res.ErrorState == ValidationErrorState.ValidationError && !string.IsNullOrEmpty(res.Message)) { msg = string.Format("{1} (Value excluded: {0})", (value == null ? "<<NULL>>" : string.IsNullOrEmpty(value.ToString()) ? @"""" : value.ToString()), res.Message); } GuardError(member, msg, current, RecordState.ExcludedByCrosswalk, session); //TODO: Output messages to screen, other log file per import, someplace besited the main session.log //this.DataContextObject.Logger.Write(string.Format(VALIDATION_LOG_MESSAGE, DataContextObject.SelectedDataType.DataTypeName, DataContextObject.Title, "Class Error", msg), Category.Info, Priority.High); } } if (validationResult.PropertyErrors.Any()) { hasError = true; foreach (var err in validationResult.PropertyErrors) { Element elemTest; ElementDictionary.TryGetValue(err.Property.Name.ToLower(), out elemTest); if (elemTest != null) { GuardError(elemTest.Description, ElementMappingModel.ParseValueError(err.AttemptedValue, err.Message), current, RecordState.ValidationError, session); } //TODO: Output messages to screen, other log file per import, someplace besited the main session.log //this.DataContextObject.Logger.Write(string.Format(VALIDATION_LOG_MESSAGE, DataContextObject.SelectedDataType.DataTypeName, DataContextObject.Title, "Error", err.Message), Category.Info, Priority.High); } } if (validationResult.PropertyWarnings.Any()) { foreach (var err in validationResult.PropertyWarnings) { Element elemTest; ElementDictionary.TryGetValue(err.Property.Name.ToLower(), out elemTest); if (elemTest != null) { GuardError(elemTest.Description, ElementMappingModel.ParseValueError(err.AttemptedValue, err.Message), current, RecordState.Warning, session); } //TODO: Output messages to screen, other log file per import, someplace besited the main session.log //this.DataContextObject.Logger.Write(string.Format(VALIDATION_LOG_MESSAGE, DataContextObject.SelectedDataType.DataTypeName, DataContextObject.Title, "Warning", err.Message), Category.Info, Priority.High); } } var result = new ValidationStatus(); result.HasErrors = hasError; return(result); }
/// <summary> /// Validates the target. /// </summary> /// <param name="temp">The temporary.</param> /// <param name="current">The current.</param> /// <param name="rdr">The RDR.</param> /// <param name="mappings">The mappings.</param> /// <param name="session">The session.</param> /// <returns></returns> private ValidationStatus ValidateTarget(object temp, int current, IDataReader rdr, IDictionary <string, string> mappings, IStatelessSession session) { //bool hasError = false; var validationResult = ValidationEngine.ValidateInstance(temp); // var updateCount = validationResult.PropertyErrors.Count + validationResult.PropertyWarnings.Count; bool hasError = validationResult.PropertyErrors.Any() || validationResult.ClassErrors.Any(); if (validationResult.ClassErrors.Any()) { hasError = true; foreach (var res in validationResult.ClassErrors) { string member = string.Empty; string msg = null; object value = null; if (res.Property != null) { member = res.Property.Name; if (mappings.ContainsKey(member)) { var column = mappings[member]; var ord = rdr.GetOrdinal(column); value = rdr.GetValue(ord); msg = string.Format("Value excluded: {0}", value == null ? "<<NULL>>" : string.IsNullOrEmpty(value.ToString()) ? @"""" : value.ToString()); } } if (res.ErrorState == ValidationErrorState.ValidationError && !string.IsNullOrEmpty(res.Message)) { msg = string.Format("{1} (Value excluded: {0})", (value == null ? "<<NULL>>" : string.IsNullOrEmpty(value.ToString()) ? @"""" : value.ToString()), res.Message); } if (res.ErrorState == ValidationErrorState.ValidationError && !string.IsNullOrEmpty(res.Message)) { member = "Row Level"; msg = res.Message; } GuardError(member, msg, current, res.ErrorState == ValidationErrorState.ExcludedByCrosswalk ? RecordState.ExcludedByCrosswalk : RecordState.ValidationError, session); //RecordState.ExcludedByCrosswalk } } if (validationResult.PropertyErrors.Any()) { // updateCount += validationResult.PropertyErrors.Count; hasError = true; foreach (var err in validationResult.PropertyErrors.ToList()) { Element elemTest; ElementDictionary.TryGetValue(err.Property.Name.ToLower(), out elemTest); if (elemTest != null) { GuardError(elemTest.Description, ElementMappingModel.ParseValueError(err.AttemptedValue, err.Message), current, RecordState.ValidationError, session); } } } if (validationResult.PropertyWarnings.Any()) { foreach (var err in validationResult.PropertyWarnings) { Element elemTest; ElementDictionary.TryGetValue(err.Property.Name.ToLower(), out elemTest); if (elemTest != null) { GuardError(elemTest.Description, ElementMappingModel.ParseValueError(err.AttemptedValue, err.Message), current, RecordState.Warning, session); } } } var result = new ValidationStatus(); result.HasErrors = hasError; return(result); }
/////////////////////////////////////////////////////////////////////// public StringPairList ToStringPairList() { StringPairList result = new StringPairList(); if (variable != null) { result.Add(variable.Kind.ToString()); result.Add((IPair <string>)null); if (variable.Name != null) { result.Add("name", variable.Name); } else { result.Add("name", String.Empty); } if (EntityOps.IsArray2(variable)) { ElementDictionary arrayValue = variable.ArrayValue; if (arrayValue != null) { result.Add("<array>"); if (index != null) { object value; if (arrayValue.TryGetValue(index, out value)) { if (value != null) { result.Add("value", StringOps.GetStringFromObject( value, null, !(value is TraceInfo))); } else { result.Add("value", FormatOps.DisplayNull); } } else { result.Add("value", "<noValue>"); } } else { result.Add("value", "<noIndex>"); } } else { result.Add("<noArray>"); } } else { object value = variable.Value; if (value != null) { result.Add("value", StringOps.GetStringFromObject(value)); } else { result.Add("value", "<noValue>"); } } result.Add("flags", variable.Flags.ToString()); result.Add((IPair <string>)null); } result.Add("TraceInfo"); result.Add((IPair <string>)null); if (trace != null) { result.Add("trace", trace.ToString()); } else { result.Add("trace", "<noTrace>"); } result.Add("breakpointType", breakpointType.ToString()); if (frame != null) { result.Add("frame", (frame.Name != null) ? frame.Name : "<noFrameName>"); } else { result.Add("frame", "<noFrame>"); } if (name != null) { result.Add("name", name); } else { result.Add("name", "<noName>"); } if (index != null) { result.Add("index", index); } else { result.Add("index", "<noIndex>"); } result.Add("flags", flags.ToString()); if (oldValue != null) { result.Add("oldValue", StringOps.GetStringFromObject(oldValue)); } else { result.Add("oldValue", "<noOldValue>"); } if (newValue != null) { result.Add("newValue", StringOps.GetStringFromObject(newValue)); } else { result.Add("newValue", "<noNewValue>"); } if (oldValues != null) { result.Add("oldValues", oldValues.ToString()); } else { result.Add("oldValues", "<noOldValues>"); } if (newValues != null) { result.Add("newValues", newValues.ToString()); } else { result.Add("newValues", "<noNewValues>"); } if (list != null) { result.Add("list", list.ToString()); } else { result.Add("list", "<noList>"); } result.Add("cancel", cancel.ToString()); result.Add("postProcess", postProcess.ToString()); result.Add("returnCode", returnCode.ToString()); return(result); }