/// <summary> /// Validates the value given by the entity and property /// </summary> /// <param name="entity"></param> /// <param name="prop"></param> /// <returns></returns> public override ValidationResult Validate(DomainEntityBase entity, System.Reflection.PropertyInfo prop) { dynamic v = prop.GetValue(entity, null); return new ValidationResult() { Entity = entity, IsValid = (v != null ? v.Length <= MaxLength : true), Prop = prop, MemberValue = v, Validation = this, Level = ValidationLevel.Property }; }
/// <summary> /// Validates the value given by the entity and property /// </summary> /// <param name="entity"></param> /// <param name="prop"></param> /// <returns></returns> public override ValidationResult Validate(DomainEntityBase entity, PropertyInfo prop) { dynamic v = prop.GetValue(entity, null); return new ValidationResult() { Entity = entity, IsValid = (v != null ? MinQty <= v.Count : true), Prop = prop, MemberValue = v, Validation = this, Level = ValidationLevel.Property }; }
/// <summary> /// Validates the value given by the entity and property /// </summary> /// <param name="entity"></param> /// <param name="prop"></param> /// <returns></returns> public override ValidationResult Validate(DomainEntityBase entity, PropertyInfo prop) { object v = prop.GetValue(entity, null); return new ValidationResult() { Entity = entity, IsValid = (v != null), Prop = prop, MemberValue = v, Validation = this, Level = ValidationLevel.Property }; }
/// <summary> /// Validates the value given by the entity and property /// </summary> /// <param name="entity"></param> /// <param name="prop"></param> /// <returns></returns> public override ValidationResult Validate(DomainEntityBase entity, System.Reflection.PropertyInfo prop) { dynamic v = prop.GetValue(entity, null); var retval = new ValidationResult() { Entity = entity, Prop = prop, IsValid = (v != null ? MinValue <= v : true), MemberValue = v, Validation = this, Level = ValidationLevel.Property }; return retval; }
/// <summary> /// Checks <see cref=" Rad.Core.Util.Geo"/> to see if the ILocation is valid. If not, /// compiles a list of recommended spelling corrections. /// </summary> /// <param name="entity"></param> /// <returns></returns> public override ValidationResult Validate(DomainEntityBase entity) { ValidationResult result = new ValidationResult() { Entity = entity, Validation = this, Level = ValidationLevel.Class }; ILocation loc = entity as ILocation; if (loc != null) { if (!(result.IsValid = Geo.IsValid(loc))) { result.Message = Geo.GetRecommendedCorrections(loc); } } return result; }
/// <summary> /// Validates the value given by the entity and property /// </summary> /// <param name="entity"></param> /// <param name="prop"></param> /// <returns></returns> public override ValidationResult Validate(DomainEntityBase entity, PropertyInfo prop) { string v = prop.GetValue(entity, null) as string; ValidationResult result = new ValidationResult() { Entity = entity, MemberValue = v, Prop = prop, Validation = this, Level = ValidationLevel.Property }; if (String.IsNullOrWhiteSpace(v)) { result.IsValid = true; } else { SystemCode sc = SystemCodeManager.GetSystemCode(this.CodeType, v); if (sc == null) { result.IsValid = false; IEnumerable<string> possibleCodes = SystemCodeManager.GetSystemCodesOfType(this.CodeType).Select(a => a.Code); IEnumerable<string> scores = FuzzyStringMatcher.RankByScore(v, possibleCodes).Take(7); scores = scores.Select(s => "\"" + s + "\""); result.Message = String.Format("Possible matches? ({0})", String.Join(", ", scores)); } else { result.IsValid = true; } } return result; }
/// <summary> /// Meant to be used by class-level validation attributes /// </summary> /// <param name="entity"></param> /// <returns></returns> public virtual ValidationResult Validate(DomainEntityBase entity) { throw new NotImplementedException(); }
public bool Equals(DomainEntityBase <TPrimaryKey> other) { throw new NotImplementedException(); }
public int CompareTo(DomainEntityBase <TPrimaryKey> other) { throw new NotImplementedException(); }
private HtmlTableCell RenderReportValue(DomainEntityBase entity, PropertyInfo pi) { string name = pi.Name; object value = pi.GetValue(entity, null); PrettyPrintSettingsAttribute prettyPrintSettings = (PrettyPrintSettingsAttribute)pi.GetCustomAttributes(typeof(PrettyPrintSettingsAttribute), true).FirstOrDefault(); var validationFailures = from v in DomainEntityValidations where v.Prop == pi && v.Entity == entity && v.Level == ValidationLevel.Property select v; bool usemarkdown = prettyPrintSettings != null && prettyPrintSettings.Markdownable; HtmlTableCell retval = new HtmlTableCell(); if (validationFailures.Count() > 0) { retval.Attributes.Add("class", "failed_validation"); retval.ID = Guid.NewGuid().ToString().Replace("-", ""); _popups.Add(retval.ID, new QtipPopupInfo(retval.ID, RenderReportValidations(validationFailures))); } if (pi.IsDomainEntity()) { retval.InnerText = value != null ? ((DomainEntityBase)value).ReportName : "(None)"; } else if (pi.IsDomainCollection()) { IList<DomainEntityBase> expanded = TreeWalker.ExpandDomainEntityCollection(entity, pi); if (expanded.Count > 0) { foreach (var e in expanded) { var link = new HtmlLink(); link.Href = "#" + e.ReportUniqueId; retval.Controls.Add(link); } } else { retval.InnerText = "(Empty Collection)"; } } else if (value == null) { } else if (value is string && !String.IsNullOrEmpty((string)value)) { string s = (string)value; SystemCodeAttribute isca = pi.GetCustomAttributes(typeof(SystemCodeAttribute), true).Cast<SystemCodeAttribute>().FirstOrDefault(); // // It's a system code? // if (isca != null) { if (String.IsNullOrWhiteSpace(s)) { retval.InnerText = "-"; } else { SystemCode sc = SystemCodeManager.GetSystemCode(isca.CodeType, s); if (sc != null) retval.InnerText = "[" + sc.Code + "]"; else retval.InnerText = (string)value; } } else if (usemarkdown && (string)value != _mkdown.Transform((string)value)) { // // We find ourselves here if markdown is enabled and the markdown-transformation is different than the text itself (renders using markdown) // retval.ID = Guid.NewGuid().ToString().Replace("-", ""); _popups.Add(retval.ID, new QtipPopupInfo(retval.ID, _mkdown.Transform((string)value))); HtmlGenericControl pre = new HtmlGenericControl("pre"); HtmlGenericControl code = new HtmlGenericControl("code"); retval.Controls.Add(pre); pre.Controls.Add(code); code.InnerText = _mkdown.Transform((string)value); } else if ((string)value != HttpUtility.HtmlEncode((string)value)) { // // We find ourselves here if the value renders differently than the text itself (contains HTML special characters or tags) // retval.ID = Guid.NewGuid().ToString().Replace("-", ""); _popups.Add(retval.ID, new QtipPopupInfo(retval.ID, ((string)value))); HtmlGenericControl pre = new HtmlGenericControl("pre"); HtmlGenericControl code = new HtmlGenericControl("code"); retval.Controls.Add(pre); pre.Controls.Add(code); code.InnerText = (string)value; } else { retval.InnerText = (string)value; } } else { retval.InnerText = value.ToString(); } return retval; }
private HtmlTableCell RenderEntityName(DomainEntityBase entity) { HtmlTableCell retval = new HtmlTableCell(); HtmlAnchor anchor = new HtmlAnchor(); var failedClassValidations = DomainEntityValidations.Where(v => v.Entity == entity && v.Level == ValidationLevel.Class); retval.Controls.Add(anchor); anchor.InnerText = entity.ReportName; anchor.ID = entity.ReportUniqueId; if (failedClassValidations.Count() > 0) { retval.Attributes.Add("class", "entity_name_failed_validation"); _popups.Add(entity.ReportUniqueId, new QtipPopupInfo(entity.ReportUniqueId, RenderReportValidations(failedClassValidations))); } else { retval.Attributes.Add("class", "entity_name"); } return retval; }
/// <summary> /// /// </summary> /// <param name="entity"></param> /// <param name="prop"></param> /// <returns></returns> public override ValidationResult Validate(DomainEntityBase entity, PropertyInfo prop) { return null; }
/// <summary> /// Validates the value given by the entity and property. /// </summary> /// <param name="entity"></param> /// <param name="prop"></param> /// <returns></returns> public override ValidationResult Validate(DomainEntityBase entity, PropertyInfo prop) { string v = prop.GetValue(entity, null) as string ?? String.Empty; ValidationResult result = new ValidationResult() { Entity = entity, Validation = this, MemberValue = v, Prop = prop, Level = ValidationLevel.Property }; if (String.IsNullOrEmpty(v)) { result.IsValid = true; } else { System.Text.RegularExpressions.Regex r; switch (_stdRegex) { case StandardRegexes.Url: Uri u = null; result.IsValid = Uri.TryCreate(v, UriKind.Absolute, out u); break; case StandardRegexes.Email: if (String.IsNullOrWhiteSpace(v)) result.IsValid = true; else { try { MailAddress addr = new MailAddress(v); result.IsValid = true; } catch { result.IsValid = false; } } break; default: r = new System.Text.RegularExpressions.Regex(_regexString); result.IsValid = r.IsMatch(v); break; } } return result; }
/// <summary> /// /// </summary> /// <param name="parent"></param> /// <param name="entity"></param> public WalkingContext(WalkingContext parent, DomainEntityBase entity, PropertyInfo propWalked) { ParentContext = parent; Entity = entity; PropertyWalked = propWalked; }
public Save(DomainEntityBase unsavedEntity) { UnsavedEntity = unsavedEntity; }
public static void ApplyProfile(DomainEntityBase entity) { _ApplyProfile(entity); }
/// <summary> /// Validates the value given by the entity and property /// </summary> /// <param name="entity"></param> /// <param name="prop"></param> /// <returns></returns> public override ValidationResult Validate(DomainEntityBase entity, PropertyInfo prop) { string v = prop.GetValue(entity, null) as string; ValidationResult result = new ValidationResult() { Entity = entity, MemberValue = v, Prop = prop, Validation = this, Level = ValidationLevel.Property }; if (!(v is string)) { result.IsValid = false; return result; } if (Allowed.Contains((string)v, CaseSensitive ? StringComparer.InvariantCulture : StringComparer.InvariantCultureIgnoreCase)) { result.IsValid = true; return result; } else { result.IsValid = false; IEnumerable<string> scores = FuzzyStringMatcher.RankByScore(v, Allowed).Take(3); scores = scores.Select(s => "\"" + s + "\""); result.Message = String.Format("Possible matches? ({0})", String.Join(", ", scores)); } return result; }