public IEnumerable<ValidationResult> Validate(object value, PreValueCollection preValues, PropertyEditor editor) { var json = value as JArray; if (json == null) yield break; //validate each item which is a json object for (var index = 0; index < json.Count; index++) { var i = json[index]; var jItem = i as JObject; if (jItem == null || jItem["value"] == null) continue; //NOTE: we will be removing empty values when persisting so no need to validate var asString = jItem["value"].ToString(); if (asString.IsNullOrWhiteSpace()) continue; if (Regex.IsMatch(asString, "^([0-9a-f]{3}|[0-9a-f]{6})$", RegexOptions.IgnoreCase) == false) { yield return new ValidationResult("The value " + asString + " is not a valid hex color", new[] { //we'll make the server field the index number of the value so it can be wired up to the view "item_" + index.ToInvariantString() }); } } }
/// <summary> /// Used when configured as an IPropertyValidator /// </summary> /// <param name="value"></param> /// <param name="preValues"></param> /// <param name="editor"></param> /// <returns></returns> public IEnumerable<ValidationResult> Validate(object value, PreValueCollection preValues, PropertyEditor editor) { if (_regex == null) { throw new InvalidOperationException("This validator is not configured as a " + typeof(IPropertyValidator)); } return Validate(value, _regex, preValues, editor); }
public override IEnumerable<ValidationResult> Validate(object value, string config, PreValueCollection preValues, PropertyEditor editor) { if (value != null && value.ToString() != string.Empty) { var result = value.TryConvertTo<int>(); if (result.Success == false) { yield return new ValidationResult("The value " + value + " is not a valid integer", new[] { "value" }); } } }
public override IEnumerable<ValidationResult> Validate(object value, string config, PreValueCollection preValues, PropertyEditor editor) { var asString = value.ToString(); var emailVal = new EmailAddressAttribute(); if (emailVal.IsValid(asString) == false) { //TODO: localize these! yield return new ValidationResult("Email is invalid", new[] { "value" }); } }
public override IEnumerable<ValidationResult> Validate(object value, string config, PreValueCollection preValues, PropertyEditor editor) { //TODO: localize these! if (config.IsNullOrWhiteSpace() == false && value != null) { var asString = value.ToString(); var regex = new Regex(config); if (regex.IsMatch(asString) == false) { yield return new ValidationResult("Value is invalid, it does not match the correct pattern", new[] { "value" }); } } }
public override IEnumerable<ValidationResult> Validate(object value, string config, PreValueCollection preValues, PropertyEditor editor) { //TODO: localize these! if (value == null) { yield return new ValidationResult("Value cannot be null", new[] {"value"}); } else { var asString = value.ToString(); if (asString.IsNullOrWhiteSpace()) { yield return new ValidationResult("Value cannot be empty", new[] { "value" }); } } }
/// <summary> /// Performs the validation /// </summary> /// <param name="value"></param> /// <param name="config">Can be a json formatted string containing properties: 'delimiter' and 'pattern'</param> /// <param name="preValues">The current pre-values stored for the data type</param> /// <param name="editor"></param> /// <returns></returns> public override IEnumerable<ValidationResult> Validate(object value, string config, PreValueCollection preValues, PropertyEditor editor) { //TODO: localize these! if (value != null) { var delimiter = ","; Regex regex = null; if (config.IsNullOrWhiteSpace() == false) { var json = JsonConvert.DeserializeObject<JObject>(config); if (json["delimiter"] != null) { delimiter = json["delimiter"].ToString(); } if (json["pattern"] != null) { var regexPattern = json["pattern"].ToString(); regex = new Regex(regexPattern); } } var stringVal = value.ToString(); var split = stringVal.Split(new[] { delimiter }, StringSplitOptions.RemoveEmptyEntries); for (var i = 0; i < split.Length; i++) { var s = split[i]; //next if we have a regex statement validate with that if (regex != null) { if (regex.IsMatch(s) == false) { yield return new ValidationResult("The item at index " + i + " did not match the expression " + regex, new[] { //make the field name called 'value0' where 0 is the index "value" + i }); } } } } }
public IEnumerable<ValidationResult> Validate(object value, PreValueCollection preValues, PropertyEditor editor) { //don't validate if empty if (value == null || value.ToString().IsNullOrWhiteSpace()) { yield break; } DateTime dt; if (DateTime.TryParse(value.ToString(), out dt) == false) { yield return new ValidationResult(string.Format("The string value {0} cannot be parsed into a DateTime", value), new[] { //we only store a single value for this editor so the 'member' or 'field' // we'll associate this error with will simply be called 'value' "value" }); } }
public IEnumerable<ValidationResult> Validate(object value, PreValueCollection preValues, PropertyEditor editor) { //now check the file type var asJson = value as JObject; if (asJson == null) yield break; if (asJson["selectedFiles"] == null) yield break; var fileNames = asJson["selectedFiles"].ToString().Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries); foreach (var fileName in fileNames) { if (ValidateFileExtension(fileName) == false) { yield return new ValidationResult(ui.Text("errors", "dissallowedMediaType"), new[] { //we only store a single value for this editor so the 'member' or 'field' // we'll associate this error with will simply be called 'value' "value" }); } } }
protected bool Equals(PropertyEditor other) { return string.Equals(Alias, other.Alias); }
public override IEnumerable <ValidationResult> Validate(object value, string config, PreValueCollection preValues, PropertyEditor editor) { //TODO: localize these! if (value == null) { yield return(new ValidationResult("Value cannot be null", new[] { "value" })); } else { var asString = value.ToString(); if (editor.ValueEditor.ValueType.InvariantEquals("JSON")) { if (asString.DetectIsEmptyJson()) { yield return(new ValidationResult("Value cannot be empty", new[] { "value" })); } } if (asString.IsNullOrWhiteSpace()) { yield return(new ValidationResult("Value cannot be empty", new[] { "value" })); } } }
/// <summary> /// Performs the validation against the value /// </summary> /// <param name="value"> /// Depending on what is being validated, this value can be a json structure (JObject, JArray, etc...) representing an editor's model, it could be a single /// string representing an editor's model. /// </param> /// <param name="config"> /// An object that is used to configure the validator. An example could be a regex /// expression if the validator was a regex validator. This is defined in the manifest along with /// the definition of the validator. /// </param> /// <param name="preValues">The current pre-values stored for the data type</param> /// <param name="editor">The property editor instance that is being validated</param> /// <returns> /// Returns a list of validation results. If a result does not have a field name applied to it then then we assume that /// the validation message applies to the entire property type being validated. If there is a field name applied to a /// validation result we will try to match that field name up with a field name on the item itself. /// </returns> public abstract IEnumerable <ValidationResult> Validate(object value, string config, PreValueCollection preValues, PropertyEditor editor);
public IEnumerable<ValidationResult> Validate(object value, PreValueCollection preValues, PropertyEditor editor) { return Validate(value, null, preValues, editor); }
public static SupportTagsAttribute GetAttribute(PropertyEditor propEd) { var tagSupport = propEd.GetType().GetCustomAttribute<SupportTagsAttribute>(false); return tagSupport; }
/// <summary> /// Performs the validation against the value /// </summary> /// <param name="value"> /// Depending on what is being validated, this value can be a json structure (JObject, JArray, etc...) representing an editor's model, it could be a single /// string representing an editor's model. /// </param> /// <param name="config"> /// An object that is used to configure the validator. An example could be a regex /// expression if the validator was a regex validator. This is defined in the manifest along with /// the definition of the validator. /// </param> /// <param name="preValues">The current pre-values stored for the data type</param> /// <param name="editor">The property editor instance that is being validated</param> /// <returns> /// Returns a list of validation results. If a result does not have a field name applied to it then then we assume that /// the validation message applies to the entire property type being validated. If there is a field name applied to a /// validation result we will try to match that field name up with a field name on the item itself. /// </returns> public abstract IEnumerable<ValidationResult> Validate(object value, string config, PreValueCollection preValues, PropertyEditor editor);
/// <summary> /// Validates the object with the resolved ValueValidator found for this type /// </summary> /// <param name="value"></param> /// <param name="preValues">The current pre-values stored for the data type</param> /// <param name="editor">The property editor instance that we are validating for</param> /// <returns></returns> public IEnumerable<ValidationResult> Validate(object value, PreValueCollection preValues, PropertyEditor editor) { return ValidatorInstance.Validate(value, Config, preValues, editor); }
public IEnumerable<ValidationResult> Validate(object value, PreValueCollection preValues, PropertyEditor editor) { var json = value as JArray; if (json == null) yield break; //get all values in the array that are not empty (we'll remove empty values when persisting anyways) var groupedValues = json.OfType<JObject>() .Where(jItem => jItem["value"] != null) .Select((jItem, index) => new {value = jItem["value"].ToString(), index = index}) .Where(asString => asString.value.IsNullOrWhiteSpace() == false) .GroupBy(x => x.value); foreach (var g in groupedValues.Where(g => g.Count() > 1)) { yield return new ValidationResult("The value " + g.Last().value + " must be unique", new[] { //we'll make the server field the index number of the value so it can be wired up to the view "item_" + g.Last().index.ToInvariantString() }); } }
/// <summary> /// Performs the validation /// </summary> /// <param name="value"></param> /// <param name="config">Can be a json formatted string containing properties: 'delimiter' and 'pattern'</param> /// <param name="preValues">The current pre-values stored for the data type</param> /// <param name="editor"></param> /// <returns></returns> public override IEnumerable <ValidationResult> Validate(object value, string config, PreValueCollection preValues, PropertyEditor editor) { //TODO: localize these! if (value != null) { var delimiter = ","; Regex regex = null; if (config.IsNullOrWhiteSpace() == false) { var json = JsonConvert.DeserializeObject <JObject>(config); if (json["delimiter"] != null) { delimiter = json["delimiter"].ToString(); } if (json["pattern"] != null) { var regexPattern = json["pattern"].ToString(); regex = new Regex(regexPattern); } } var stringVal = value.ToString(); var split = stringVal.Split(new[] { delimiter }, StringSplitOptions.RemoveEmptyEntries); for (var i = 0; i < split.Length; i++) { var s = split[i]; //next if we have a regex statement validate with that if (regex != null) { if (regex.IsMatch(s) == false) { yield return(new ValidationResult("The item at index " + i + " did not match the expression " + regex, new[] { //make the field name called 'value0' where 0 is the index "value" + i })); } } } } }
public IEnumerable <ValidationResult> Validate(object value, PreValueCollection preValues, PropertyEditor editor) { return(Validate(value, "", preValues, editor)); }
public override IEnumerable <ValidationResult> Validate(object value, string config, PreValueCollection preValues, PropertyEditor editor) { if (value != null && value.ToString() != string.Empty) { var result = value.TryConvertTo <decimal>(); if (result.Success == false) { yield return(new ValidationResult("The value " + value + " is not a valid decimal", new[] { "value" })); } } }