public EvaluationResult evaluateExpression(XmlElement expressionDoc, IContext context) { // first deserialize expression into a RequiresTopic instance RequiresTopic expression = null; try { XmlNodeReader reader = new XmlNodeReader(expressionDoc); expression = (RequiresTopic)serializer.Deserialize(reader); } catch (Exception e) { throw new PolicyManagerException("Could not deserialize RequiresTopic node", e); } // check if we should do a direct or regular expression match bool isMatch; if (expression.IsRegexSpecified && expression.IsRegex) { // do regex match Regex regex = new Regex(expression.Topic, RegexOptions.IgnoreCase); isMatch = regex.IsMatch(context.Topic, 0); } else { // do direct match isMatch = context.Topic.ToLower().Equals(expression.Topic.ToLower()); } string match = "\"" + expression.Topic + "\" " + (expression.IsRegexSpecified && expression.IsRegex ? "(regex match)" : "(exact match)"); if (isMatch) { return(new EvaluationResult(TAG, true, "Context topic matches " + match)); } else { return(new EvaluationResult(TAG, false, "Context topic does NOT match " + match)); } }
public static void Main(String[] args) { RequiresTopic rt = new RequiresTopic(); rt.Topic = "foobar"; RequiresParticipants rp = new RequiresParticipants(); rp.Participant = new String[] { "joe", "bob" }; All all = new All(); all.Any = new XmlElement[] { Util.getXmlElement(rt), Util.getXmlElement(rp) }; Policy policy = new Policy(); policy.Any = Util.getXmlElement(all); StreamWriter writer = new StreamWriter("testpolicy2.xml"); Util.serialize(policy, writer); writer.Close(); Console.Out.WriteLine("done"); }