public override void Execute() { MessageItem deliveredMessage = base.Context.DeliveredMessage; StorePropertyDefinition propertyDefinitionForTag = base.Context.GetPropertyDefinitionForTag(this.value.PropTag); if (!RuleUtil.IsMultiValueTag(this.value.PropTag)) { base.Context.TraceDebug <PropTag, object>("Setting single value property '{0}' to '{1}'", this.value.PropTag, this.value.Value ?? "null"); deliveredMessage[propertyDefinitionForTag] = this.value.Value; return; } Array array = this.value.Value as Array; if (RuleUtil.IsNullOrEmpty(array)) { base.Context.TraceDebug <PropTag>("Clearing the existing multi-value property '{0}' since new value specified in rule was null or empty.", this.value.PropTag); deliveredMessage[propertyDefinitionForTag] = this.value.Value; return; } Array array2 = deliveredMessage.TryGetProperty(propertyDefinitionForTag) as Array; if (RuleUtil.IsNullOrEmpty(array2)) { base.Context.TraceDebug <PropTag, int>("Setting multi-value property '{0}' to {1} elements, since no existing value were found.", this.value.PropTag, array.Length); deliveredMessage[propertyDefinitionForTag] = array; return; } Type elementType = array2.GetType().GetElementType(); Array array3 = Array.CreateInstance(elementType, array2.Length + array.Length); array2.CopyTo(array3, 0); array.CopyTo(array3, array2.Length); base.Context.TraceDebug <PropTag, int>("Setting multi-value property '{0}' to {1} elements, which contains the concatenated array of existing and new values.", this.value.PropTag, array3.Length); deliveredMessage[propertyDefinitionForTag] = array3; }
private static void ValidatePropertyRestriction(Restriction.PropertyRestriction restriction) { if (!RestrictionEvaluator.IsSupportedOperation(restriction.Op)) { throw new InvalidRuleException(string.Format("Operation {0} is not supported", restriction.Op)); } if (RuleUtil.IsMultiValueTag(restriction.PropValue.PropTag)) { if (restriction.MultiValued) { throw new InvalidRuleException("At most one tag can be multi-valued"); } if (restriction.Op != Restriction.RelOp.Equal && restriction.Op != Restriction.RelOp.NotEqual) { throw new InvalidRuleException("Restriction has multi-valued value only support Equal or NotEqual operation"); } } if (!RuleUtil.IsSameType(restriction.PropTag, restriction.PropValue.PropTag)) { throw new InvalidRuleException("Tag and value are of different type"); } if (RuleUtil.IsBooleanTag(restriction.PropTag) && restriction.Op != Restriction.RelOp.Equal && restriction.Op != Restriction.RelOp.NotEqual) { throw new InvalidRuleException("Boolean tag only support Equal or NotEqual operation"); } RestrictionEvaluator.ValidateRestrictionValue(restriction.PropValue); }
private static bool EvaluatePropertyRestriction(Restriction.PropertyRestriction restriction, IRuleEvaluationContext context) { RestrictionEvaluator.ValidatePropertyRestriction(restriction); PropTag propTag = restriction.PropTag; if (restriction.MultiValued) { propTag = RuleUtil.GetMultiValuePropTag(propTag); } context.TraceFunction <PropTag, Restriction.RelOp, object>("PropertyRestriction [{0}] {1} [{2}]", propTag, restriction.Op, restriction.PropValue.Value); object obj = context[propTag]; bool flag; if (obj == null) { flag = false; } else if (restriction.MultiValued) { flag = RestrictionEvaluator.CompareMultiValueWithValue(context, RuleUtil.GetSingleValuePropTag(restriction.PropTag), restriction.Op, obj, restriction.PropValue.Value); } else if (RuleUtil.IsMultiValueTag(restriction.PropValue.PropTag)) { flag = RestrictionEvaluator.CompareValueWithMultiValue(context, restriction.PropTag, restriction.Op, obj, restriction.PropValue.Value); } else { flag = context.CompareSingleValue(restriction.PropTag, restriction.Op, obj, restriction.PropValue.Value); } context.TraceFunction <bool, object>("PropertyRestriction evaluated to {0} with property value [{1}]", flag, obj); return(flag); }
private static void ValidateContentRestriction(Restriction.ContentRestriction restriction) { if (!RuleUtil.IsTextProp(restriction.PropTag) && !RuleUtil.IsBinaryProp(restriction.PropTag)) { throw new InvalidRuleException(string.Format("Content Restriction is not supported on tag {0}", restriction.PropTag)); } if (!RuleUtil.IsSameType(restriction.PropTag, restriction.PropValue.PropTag)) { throw new InvalidRuleException("Tag and value are of different type"); } if (RuleUtil.IsMultiValueTag(restriction.PropValue.PropTag)) { throw new InvalidRuleException("Content Restriction does not support multi-valued value"); } }
private static void ValidateComparePropertyRestriction(Restriction.ComparePropertyRestriction restriction) { if (!RestrictionEvaluator.IsSupportedOperation(restriction.Op)) { throw new InvalidRuleException(string.Format("Operation {0} is not supported", restriction.Op)); } if (!RuleUtil.IsSameType(restriction.TagLeft, restriction.TagRight)) { throw new InvalidRuleException("Tag and value are of different type"); } if (RuleUtil.IsBooleanTag(restriction.TagLeft) && restriction.Op != Restriction.RelOp.Equal && restriction.Op != Restriction.RelOp.NotEqual) { throw new InvalidRuleException("Boolean tag only support Equal or NotEqual operation"); } if (RuleUtil.IsMultiValueTag(restriction.TagLeft) || RuleUtil.IsMultiValueTag(restriction.TagRight)) { throw new InvalidRuleException("Multi-valued prop or value is not supported in CompareProperty Restriction"); } }
private static bool EvaluateSizeRestriction(Restriction.SizeRestriction restriction, IRuleEvaluationContext context) { RestrictionEvaluator.ValidateSizeRestriction(restriction); context.TraceFunction <PropTag, Restriction.RelOp, int>("SizeRestriction [{0}] {1} [{2}]", restriction.Tag, restriction.Op, restriction.Size); PropType type = restriction.Tag.ValueType(); int num = 0; bool flag = false; object obj = null; if (RuleUtil.GetPropTypeSize(type, out num)) { flag = RestrictionEvaluator.GetOperationResultFromOrder(restriction.Op, num.CompareTo(restriction.Size)); } else if (RuleUtil.IsMultiValueTag(restriction.Tag)) { obj = context[restriction.Tag]; object[] array = obj as object[]; if (array != null) { foreach (object value in array) { int size = RuleUtil.GetSize(value); if (RestrictionEvaluator.GetOperationResultFromOrder(restriction.Op, size.CompareTo(restriction.Size))) { flag = true; break; } } } } else { obj = context[restriction.Tag]; int size2 = RuleUtil.GetSize(obj); flag = RestrictionEvaluator.GetOperationResultFromOrder(restriction.Op, size2.CompareTo(restriction.Size)); } context.TraceFunction <bool, object>("SizeRestriction evaluated to {0} with property value [{1}]", flag, obj); return(flag); }