public static bool Evaluate(Restriction restriction, IRuleEvaluationContext context) { if (restriction == null) { context.TraceDebug <string>("Empty restriction evaluated to true in rule {0}", context.CurrentRule.Name); return(true); } Restriction.ResType type = restriction.Type; switch (type) { case Restriction.ResType.And: return(RestrictionEvaluator.EvaluateAndRestriction((Restriction.AndRestriction)restriction, context)); case Restriction.ResType.Or: return(RestrictionEvaluator.EvaluateOrRestriction((Restriction.OrRestriction)restriction, context)); case Restriction.ResType.Not: return(RestrictionEvaluator.EvaluateNotRestriction((Restriction.NotRestriction)restriction, context)); case Restriction.ResType.Content: return(RestrictionEvaluator.EvaluateContentRestriction((Restriction.ContentRestriction)restriction, context)); case Restriction.ResType.Property: return(RestrictionEvaluator.EvaluatePropertyRestriction((Restriction.PropertyRestriction)restriction, context)); case Restriction.ResType.CompareProps: return(RestrictionEvaluator.EvaluateComparePropertyRestriction((Restriction.ComparePropertyRestriction)restriction, context)); case Restriction.ResType.BitMask: return(RestrictionEvaluator.EvaluateBitMaskRestriction((Restriction.BitMaskRestriction)restriction, context)); case Restriction.ResType.Size: return(RestrictionEvaluator.EvaluateSizeRestriction((Restriction.SizeRestriction)restriction, context)); case Restriction.ResType.Exist: return(RestrictionEvaluator.EvaluateExistRestriction((Restriction.ExistRestriction)restriction, context)); case Restriction.ResType.SubRestriction: if (restriction is Restriction.AttachmentRestriction) { return(RestrictionEvaluator.EvaluateAttachmentRestriction((Restriction.AttachmentRestriction)restriction, context)); } if (restriction is Restriction.RecipientRestriction) { return(RestrictionEvaluator.EvaluateRecipientRestriction((Restriction.RecipientRestriction)restriction, context)); } throw new InvalidRuleException(string.Format("SubRestriction Type {0} is not supported!", restriction.GetType())); case Restriction.ResType.Comment: return(RestrictionEvaluator.EvaluateCommentRestriction((Restriction.CommentRestriction)restriction, context)); case Restriction.ResType.Count: return(RestrictionEvaluator.EvaluateCountRestriction((Restriction.CountRestriction)restriction, context)); default: switch (type) { case Restriction.ResType.True: context.TraceFunction("True Restriction"); return(true); case Restriction.ResType.False: context.TraceFunction("False Restriction"); return(false); default: throw new InvalidRuleException(string.Format("Restriction Type {0} is not supported!", restriction.Type)); } break; } }
private static void DumpRestriction(StringBuilder sb, Restriction restriction) { if (restriction == null) { return; } sb.Append("("); Restriction.ResType type = restriction.Type; switch (type) { case Restriction.ResType.And: { Restriction.AndRestriction andRestriction = (Restriction.AndRestriction)restriction; sb.Append("AND "); foreach (Restriction restriction2 in andRestriction.Restrictions) { GetFolderRestriction.DumpRestriction(sb, restriction2); } break; } case Restriction.ResType.Or: { Restriction.OrRestriction orRestriction = (Restriction.OrRestriction)restriction; sb.Append("OR "); foreach (Restriction restriction3 in orRestriction.Restrictions) { GetFolderRestriction.DumpRestriction(sb, restriction3); } break; } case Restriction.ResType.Not: { Restriction.NotRestriction notRestriction = (Restriction.NotRestriction)restriction; sb.Append("NOT "); GetFolderRestriction.DumpRestriction(sb, notRestriction.Restriction); break; } case Restriction.ResType.Content: { Restriction.ContentRestriction contentRestriction = (Restriction.ContentRestriction)restriction; sb.AppendFormat("CONTENT flags:{0} mv:{1} propTag:{2:X} propValue:(", contentRestriction.Flags, contentRestriction.MultiValued, contentRestriction.PropTag); GetFolderRestriction.DumpPropValue(sb, contentRestriction.PropValue); sb.Append(")"); break; } case Restriction.ResType.Property: { Restriction.PropertyRestriction propertyRestriction = (Restriction.PropertyRestriction)restriction; sb.AppendFormat("PROPERTY Op:{0}, propTag:{1:X} propValue:", propertyRestriction.Op, propertyRestriction.PropTag); GetFolderRestriction.DumpPropValue(sb, propertyRestriction.PropValue); break; } case Restriction.ResType.CompareProps: { Restriction.ComparePropertyRestriction comparePropertyRestriction = (Restriction.ComparePropertyRestriction)restriction; sb.AppendFormat("COMPPROPS Op:{0} propTag1:{1:X} propTag2:{2:X}", comparePropertyRestriction.Op, comparePropertyRestriction.TagLeft, comparePropertyRestriction.TagRight); break; } case Restriction.ResType.BitMask: { Restriction.BitMaskRestriction bitMaskRestriction = (Restriction.BitMaskRestriction)restriction; sb.AppendFormat("BITMASK Bmr:{0} Mask:{1:X} propTag:{2:X}", bitMaskRestriction.Bmr, bitMaskRestriction.Mask, bitMaskRestriction.Tag); break; } case Restriction.ResType.Size: { Restriction.SizeRestriction sizeRestriction = (Restriction.SizeRestriction)restriction; sb.AppendFormat("SIZE propTag:{0:X} Op:{1} size:{2}", sizeRestriction.Tag, sizeRestriction.Op, sizeRestriction.Size); break; } case Restriction.ResType.Exist: { Restriction.ExistRestriction existRestriction = (Restriction.ExistRestriction)restriction; sb.AppendFormat("EXIST propTag:{0:X}", existRestriction.Tag); break; } case Restriction.ResType.SubRestriction: { Restriction.SubRestriction subRestriction = (Restriction.SubRestriction)restriction; sb.Append("SUBRESTRICTION "); GetFolderRestriction.DumpRestriction(sb, subRestriction.Restriction); break; } case Restriction.ResType.Comment: { Restriction.CommentRestriction commentRestriction = (Restriction.CommentRestriction)restriction; sb.AppendFormat("COMMENT values:{0} ", commentRestriction.Values.Length); foreach (PropValue v in commentRestriction.Values) { GetFolderRestriction.DumpPropValue(sb, v); } GetFolderRestriction.DumpRestriction(sb, commentRestriction.Restriction); break; } case Restriction.ResType.Count: { Restriction.CountRestriction countRestriction = (Restriction.CountRestriction)restriction; sb.AppendFormat("COUNT {0} ", countRestriction.Count); GetFolderRestriction.DumpRestriction(sb, countRestriction.Restriction); break; } default: switch (type) { case Restriction.ResType.True: sb.Append("TRUE"); break; case Restriction.ResType.False: sb.Append("FALSE"); break; default: sb.AppendFormat("<UNKNOWN RESTYPE:{0}>", restriction.Type); break; } break; } sb.Append(")"); }
private void WriteRestriction(Restriction restriction) { this.writer.WriteStartElement("Restriction"); if (restriction != null) { Restriction.ResType type = restriction.Type; this.writer.WriteAttributeString("Type", type.ToString()); Restriction.ResType resType = type; switch (resType) { case Restriction.ResType.And: this.WriteRestrictions("And", ((Restriction.AndRestriction)restriction).Restrictions); break; case Restriction.ResType.Or: this.WriteRestrictions("Or", ((Restriction.OrRestriction)restriction).Restrictions); break; case Restriction.ResType.Not: this.writer.WriteStartElement("Not"); this.WriteRestriction(((Restriction.NotRestriction)restriction).Restriction); this.writer.WriteEndElement(); break; case Restriction.ResType.Content: { Restriction.ContentRestriction contentRestriction = (Restriction.ContentRestriction)restriction; this.writer.WriteAttributeString("ContentFlags", RuleWriter.EnumToString(contentRestriction.Flags)); this.writer.WriteAttributeString("PropTag", RuleWriter.EnumToString(contentRestriction.PropTag)); this.writer.WriteAttributeString("MultiValued", contentRestriction.MultiValued.ToString()); this.WritePropValue(contentRestriction.PropValue); break; } case Restriction.ResType.Property: { Restriction.PropertyRestriction propertyRestriction = (Restriction.PropertyRestriction)restriction; this.writer.WriteAttributeString("Operation", propertyRestriction.Op.ToString()); this.writer.WriteAttributeString("PropTag", RuleWriter.EnumToString(propertyRestriction.PropTag)); this.writer.WriteAttributeString("MultiValued", propertyRestriction.MultiValued.ToString()); this.WritePropValue(propertyRestriction.PropValue); break; } case Restriction.ResType.CompareProps: { Restriction.ComparePropertyRestriction comparePropertyRestriction = (Restriction.ComparePropertyRestriction)restriction; this.writer.WriteAttributeString("Operation", comparePropertyRestriction.Op.ToString()); this.writer.WriteAttributeString("PropTagLeft", RuleWriter.EnumToString(comparePropertyRestriction.TagLeft)); this.writer.WriteAttributeString("PropTagRight", RuleWriter.EnumToString(comparePropertyRestriction.TagRight)); break; } case Restriction.ResType.BitMask: { Restriction.BitMaskRestriction bitMaskRestriction = (Restriction.BitMaskRestriction)restriction; this.writer.WriteAttributeString("PropTag", RuleWriter.EnumToString(bitMaskRestriction.Tag)); this.writer.WriteAttributeString("Operation", bitMaskRestriction.Bmr.ToString()); this.writer.WriteAttributeString("Mask", bitMaskRestriction.Mask.ToString("X08")); break; } case Restriction.ResType.Size: { Restriction.SizeRestriction sizeRestriction = (Restriction.SizeRestriction)restriction; this.writer.WriteAttributeString("Operation", sizeRestriction.Op.ToString()); this.writer.WriteAttributeString("PropTag", RuleWriter.EnumToString(sizeRestriction.Tag)); this.writer.WriteAttributeString("Size", sizeRestriction.Size.ToString("X08")); break; } case Restriction.ResType.Exist: { Restriction.ExistRestriction existRestriction = (Restriction.ExistRestriction)restriction; this.writer.WriteAttributeString("PropTag", RuleWriter.EnumToString(existRestriction.Tag)); break; } case Restriction.ResType.SubRestriction: { Restriction.SubRestriction subRestriction = (Restriction.SubRestriction)restriction; this.writer.WriteAttributeString("SubType", subRestriction.GetType().Name); this.WriteRestriction(subRestriction.Restriction); break; } case Restriction.ResType.Comment: { Restriction.CommentRestriction commentRestriction = (Restriction.CommentRestriction)restriction; this.WritePropValues("Comment", commentRestriction.Values); this.WriteRestriction(commentRestriction.Restriction); break; } case Restriction.ResType.Count: { Restriction.CountRestriction countRestriction = (Restriction.CountRestriction)restriction; this.writer.WriteAttributeString("Count", countRestriction.Count.ToString()); this.WriteRestriction(countRestriction.Restriction); break; } default: switch (resType) { } this.writer.WriteAttributeString("Error", "Unsupported restriction type: " + type.ToString()); break; } } this.writer.WriteEndElement(); }