public PropertyFilterComponent(IAuditProperty <TProp> prop, TProp value, PropertyValueComparison comparison) { Property = prop; Comparison = comparison; Value = value; Expression <Func <AuditPropertyValue, bool> > valuePredicate; if (typeof(TProp) == typeof(string) && (comparison == PropertyValueComparison.Contains || comparison == PropertyValueComparison.NotContains)) { var asStr = Convert.ToString(value); valuePredicate = comparison == PropertyValueComparison.Contains ? Expr.Create(( AuditPropertyValue v ) => v.StringValue.Contains(asStr)) : Expr.Create(( AuditPropertyValue v ) => !v.StringValue.Contains(asStr)); } else { var valueAccessor = AuditPropertyValue.GetAccessorExpression <TProp>(); valuePredicate = Expression.Lambda <Func <AuditPropertyValue, bool> >( Expression.MakeBinary(Op(Comparison), valueAccessor.Body, Expression.Constant(Value)), valueAccessor.Parameters); } Filter = e => e.PropertyValues.Any(p => p.PropertyId == Property.ID && valuePredicate.Invoke(p)); Filter = Filter.Expand(); }
public static IAuditEventBuilder With <T>(this IAuditEventBuilder builder, IAuditProperty <T> prop, T value) { var pv = new AuditPropertyValue { PropertyId = prop.ID }; pv.SetValue(value); return(builder.With(pv)); }
public System.Web.WebPages.HelperResult Dropdowns(string id, IAuditProperty selectedProperty, PropertyValueComparison selectedComp) { #line default #line hidden return(new System.Web.WebPages.HelperResult(__razor_helper_writer => { #line 89 "..\..\Views\PropertyFilterUI.cshtml" #line default #line hidden #line 90 "..\..\Views\PropertyFilterUI.cshtml" WriteTo(__razor_helper_writer, Html.DropDownList("p" + id, Model.AllPossibleProperties.Select(x => new SelectListItem { Text = x.Name, Value = x.ID.ToString(), Selected = x == selectedProperty }) .StartWith(new SelectListItem { Selected = selectedProperty == null, Value = "", Text = "select property" }), new { @class = "Property" })); #line default #line hidden #line 93 "..\..\Views\PropertyFilterUI.cshtml" #line default #line hidden #line 94 "..\..\Views\PropertyFilterUI.cshtml" WriteTo(__razor_helper_writer, Html.DropDownList("c" + id, Enum.GetValues(typeof(PropertyValueComparison)).Cast <PropertyValueComparison>().Select(c => new SelectListItem { Text = c.ToString(), Value = c.ToString(), Selected = selectedComp == c }), new { @class = "Comparison", style = "display: none" })); #line default #line hidden #line 96 "..\..\Views\PropertyFilterUI.cshtml" #line default #line hidden })); #line 97 "..\..\Views\PropertyFilterUI.cshtml" }
public IPropertyFilter ParseComponent <TDomain>(ICompositionService comp, PropertyFilterFactory <TDomain> factory, IPropertyFilter sourceFilter, IAuditProperty p, PropertyValueComparison cmp, string value) { var res = from prop in Maybe.Value(p as IAuditProperty <TProp>) from selector in comp.Get <PropertyValueSelectorCache <TProp> >().GetSelector(prop) from parsed in Maybe.SafeValue(() => selector.ParsePostedValue(value)) select sourceFilter == null?factory.Create(prop, parsed, cmp) : sourceFilter.And(prop, parsed, cmp); return(res.ValueOrNull() ?? sourceFilter); }
public ClientControlDisplay RenderSelector(ICompositionService comp, IAuditProperty p, object value) { var selector = comp.Get <PropertyValueSelectorCache <TProp> >().GetSelector(p as IAuditProperty <TProp>); return(selector == null ? null : selector.RenderSelector(value == null ? default(TProp) : (TProp)value)); }
static IHelper HelperFor(IAuditProperty prop) { return(Memoizer.Memoize(prop.Type, _ => Activator.CreateInstance(typeof(Helper <>).MakeGenericType(prop.Type)) as IHelper)); }
public static IPropertyFilter ParsePostedValue <TDomain>(ICompositionService comp, PropertyFilterFactory <TDomain> factory, IPropertyFilter sourceFilter, IAuditProperty p, PropertyValueComparison cmp, string value) { return(HelperFor(p).ParseComponent(comp, factory, sourceFilter, p, cmp, value)); }
public static ClientControlDisplay RenderSelector(ICompositionService comp, IAuditProperty p, object value) { return(HelperFor(p).RenderSelector(comp, p, value)); }
public IAuditPropertyValueSelector <TProp> GetSelector(IAuditProperty <TProp> prop) { return(prop == null ? null : _cache.Value[prop.ID].FirstOrDefault() ?? _universal.Value); }
public IPropertyFilter And <TProp>(IAuditProperty <TProp> prop, TProp value, PropertyValueComparison comparison) { return(new PropertyFilter(Components.Concat(new[] { new PropertyFilterComponent <TProp>(prop, value, comparison) }), Factory)); }
public IPropertyFilter Create <TProp>(IAuditProperty <TProp> prop, TProp value, PropertyValueComparison comparison = PropertyValueComparison.Eq) { return(new PropertyFilter(new[] { new PropertyFilterComponent <TProp>(prop, value, comparison) }, this)); }
public int CompareTo(IAuditProperty <T> other) { return(CompareTo(other as IAuditProperty)); }
public int CompareTo(IAuditProperty other) { return(ReferenceEquals(other, null) ? 1 : ID.CompareTo(other.ID)); }