private string CurrentCultureStringToValueSetString(string currentCultureString) { var defaultValue = ValueSetConverter.DefaultObject(this.SelectedParameterType); if (currentCultureString == null) { return((string)defaultValue); } if (!currentCultureString.Equals(defaultValue)) { if (new[] { ClassKind.DateTimeParameterType, ClassKind.DateParameterType, ClassKind.TimeOfDayParameterType }.Contains(this.SelectedParameterType.ClassKind)) { if (!DateTime.TryParse(currentCultureString, out var dateTimeObject)) { throw new Cdp4ModelValidationException($"{currentCultureString} is not a valid value for a {this.SelectedParameterType.ClassKind}."); } var validationResult = ParameterValueValidator.Validate(dateTimeObject, this.SelectedParameterType, this.SelectedScale); if (validationResult != null) { throw new Cdp4ModelValidationException(validationResult); } return(dateTimeObject.ToValueSetString(this.SelectedParameterType)); } } return(currentCultureString); }
/// <summary> /// Gets the error message for the property with the given name. /// </summary> /// <returns> /// The error message for the property. The default is an empty string (""). /// </returns> /// <param name="columnName">The name of the property whose error message to get. </param> /// <remarks> /// Used by the view through the IDataErrorInfo interface to validate a field onPropertyChanged /// </remarks> public override string this[string columnName] { get { if (columnName == ManualPropertyName) { var propertyCode = this.RowCode + ManualPropertyName; var rule = this.DialogViewModel.ValidationErrors.SingleOrDefault(x => x.PropertyName == propertyCode); if (rule != null) { this.DialogViewModel.ValidationErrors.Remove(rule); } var validationMsg = ParameterValueValidator.Validate(this.Manual, this.ParameterType, this.Scale); if (!string.IsNullOrWhiteSpace(validationMsg)) { var validationRule = new ValidationService.ValidationRule { ErrorText = validationMsg, PropertyName = propertyCode }; this.DialogViewModel.ValidationErrors.Add(validationRule); return(validationMsg); } return(validationMsg); } if (columnName == ReferencePropertyName) { var propertyCode = this.RowCode + ReferencePropertyName; var rule = this.DialogViewModel.ValidationErrors.SingleOrDefault(x => x.PropertyName == propertyCode); if (rule != null) { this.DialogViewModel.ValidationErrors.Remove(rule); } var validationMsg = ParameterValueValidator.Validate(this.Reference, this.ParameterType, this.Scale); if (!string.IsNullOrWhiteSpace(validationMsg)) { var validationRule = new ValidationService.ValidationRule { ErrorText = validationMsg, PropertyName = propertyCode }; this.DialogViewModel.ValidationErrors.Add(validationRule); return(validationMsg); } return(validationMsg); } return(string.Empty); } }
public void VerifyThatValidatorWorksForBooleanParameterType() { var boolPt = new BooleanParameterType(); Assert.That(ParameterValueValidator.Validate(true, boolPt), Is.Null.Or.Empty); Assert.That(ParameterValueValidator.Validate(false, boolPt), Is.Null.Or.Empty); Assert.That(ParameterValueValidator.Validate(null, boolPt), Is.Null.Or.Empty); Assert.That(ParameterValueValidator.Validate("hoho", boolPt), Is.Not.Null.Or.Empty); }
/// <summary> /// Gets the error message for the property with the given name. /// </summary> /// <param name="columnName">The name of the property whose error message to get</param> /// <param name="newValue">The new value for the row</param> /// <returns>The error message for the property. The default is an empty string ("").</returns> /// <remarks> /// Used when inline-editing, the values are updated on focus lost /// </remarks> public override string ValidateProperty(string columnName, object newValue) { if (columnName == "Manual" || columnName == "Reference") { return(ParameterValueValidator.Validate(newValue, this.ParameterType, this.Thing.Scale)); } return(null); }