public static ISBSFormField Create(ISBSForm form, string fieldTypeName) { if (string.IsNullOrEmpty(fieldTypeName) || fieldTypeName.Equals("text", StringComparison.OrdinalIgnoreCase)) { fieldTypeName = "edit"; } var fieldType = FormFieldTypeRepository.Get(fieldTypeName); if (fieldType == null) { string errorMsg = $"The field type {fieldTypeName} is not recognized"; throw new ApplicationException(errorMsg); } SBSFormField instance = Activator.CreateInstance(fieldType.DotNetType) as SBSFormField; if (instance != null) { instance.FieldTypeName = fieldTypeName; instance.Form = form; } return(instance); }
public override bool Validate(ISBSFormField field, ISBSForm form = null) { if (this.Rules == null) { return(true); } Engine expressionEvaluator = new Engine(); var substitutor = new StringSubstitutor(); foreach (var rule in this.Rules) { rule.CompiledRule = substitutor.PerformSubstitutions(rule.Rule, field, form, quotedStringValues: true); bool rc = expressionEvaluator.Execute((string)rule.CompiledRule).GetCompletionValue().AsBoolean(); if (!rc) { if (!string.IsNullOrEmpty(rule.ErrorMessage)) { this.ValidationFailedMessage = rule.ErrorMessage; } return(false); } } return(true); }
public override bool Validate(ISBSFormField field, ISBSForm form = null) { if (field?.Value == null) { return(false); } string val = field.Value.ToString(); int len = val.Length; switch (this.Comparator) { case LengthComparator.EQ: if (len != this.Length) { return(false); } break; case LengthComparator.NE: if (len == this.Length) { return(false); } break; case LengthComparator.LT: if (len >= this.Length) { return(false); } break; case LengthComparator.LE: if (len > this.Length) { return(false); } break; case LengthComparator.GT: if (len <= this.Length) { return(false); } break; case LengthComparator.GE: if (len < this.Length) { return(false); } break; default: throw new ArgumentOutOfRangeException(); } return(base.Validate(field, form)); }
public override bool Validate(ISBSFormField field, ISBSForm form = null) { if (field.Value == null && field.DefaultValue == null) { return(false); } return(base.Validate(field, form)); }
public override bool Validate(ISBSFormField field, ISBSForm form = null) { try { double dValue = Convert.ToDouble(field.Value); return(dValue >= this.Min && dValue <= this.Max); } catch (Exception) { return(false); } }
public override bool Validate(ISBSFormField field, ISBSForm form = null) { if (field?.Value == null) { return(false); } if (!this.CompiledRegex.IsMatch(field.Value.ToString())) { return(false); } return(base.Validate(field, form)); }
/// <summary> /// This will replace a term like ${field:fieldname} with a corresponding value. /// We pass in a lambda which is the evaluation function. /// The evaluation function takes what's on the right side of the colon, and returns a string to be substituted in. /// </summary> private string SubstituteTerm(string src, string templateKeyword, ISBSForm form, Func <string, object> fnValueGetter, bool quotedStringValues) { string template = $"${{{templateKeyword}:"; int templateLen = template.Length; int idx; while ((idx = src.IndexOf(template, StringComparison.OrdinalIgnoreCase)) >= 0) { int idxEnd = src.IndexOf("}", idx, StringComparison.OrdinalIgnoreCase); if (idxEnd < 0) { return(src); } object value; // Isolate the name of the field. // Note that the fieldName could be the name of this form, plus a property. string fieldName = src.Substring(idx + templateLen, idxEnd - (idx + templateLen)); if (fieldName.StartsWith(form.Name, StringComparison.OrdinalIgnoreCase) && fieldName.Contains(".")) { string propertyName = fieldName.Split('.')[1]; // Isolate the first-level property PropertyInfo propInfo = typeof(SBSForm).GetProperty(propertyName, BindingFlags.Public | BindingFlags.Instance | BindingFlags.GetProperty); value = propInfo?.GetValue(form); } else { value = fnValueGetter(fieldName); } if (value != null) { src = ReplaceStringWithValue(src, src.Substring(idx, idxEnd - idx + 1), value, quotedStringValues); } } return(src); }
public string PerformSubstitutions(string src, ISBSFormField field, ISBSForm form, bool quotedStringValues = false) { // Don't disturb the original string. string sNew = (new StringBuilder(src)).ToString(); // Process the {value} string if (field != null) { sNew = this.ReplaceStringWithValue(sNew, "${value}", field.Value, quotedStringValues); } // Process the {field:name} string if (form != null) { sNew = this.SubstituteTerm(sNew, "field", form, fieldName => form.FindField(fieldName)?.Value, quotedStringValues); } sNew = this.SubstituteTerm(sNew, "config", form, this.FindConfigurationValue, quotedStringValues); return(sNew); }
public SBSFormSubmissionWorkflowProcessor(ISBSForm form, Func <string, IFormSubmissionFunction, object> bodyExpressionEvaluator = null) { this.Form = form; this.BodyExpressionEvaluator = bodyExpressionEvaluator; }
protected SBSFormViewBase(ISBSForm form) { this.Form = form; this.Logger = LogManager.GetLogger(this.GetType()); }
public SBSFormSubmissionWorkflowProcessor(ISBSForm form) { this.Form = form; }
public IEnumerable <object> GetValuesInExpression(string src, string templateKeyword, ISBSForm form) { foreach (var field in this.GetFieldsInExpression(src, templateKeyword, form)) { yield return(field?.Value); } }
public IEnumerable <ISBSFormField> GetFieldsInExpression(string src, string templateKeyword, ISBSForm form) { foreach (string fieldName in this.GetFieldNamesInExpression(src, templateKeyword)) { yield return(form.FindField(fieldName)); // yields null if the fieldname is not in the form } }
public ConsoleFormView(ISBSForm form) : base(form) { }
public virtual bool Validate(ISBSFormField field, ISBSForm form = null) { return(true); }