how to create a .rules file in workflow foundation

2019-05-03 11:43发布

问题:

I am new to workflow foundation and I am using workflow foundation 4.5 (VS2012 RC). I want to build a workflow where i can add/remove rules on the run time. So i was thinking of using a set of rules on a separate .rules file and change this as and when I need it.

However, i can't find this on VS2012. Is there any way that I can uses dynamic rules in workflow foundation 4.5?

回答1:

This code block should allow you to load and execute your rules dynamically. You can see the rest of this post, which will also show you how to save those files dynamically, here.

static RuleSet Load(string filename)
{
    XmlTextReader reader = new XmlTextReader(filename);
    WorkflowMarkupSerializer serializer = new WorkflowMarkupSerializer();
    object results = serializer.Deserialize(reader);
    RuleSet ruleset = (RuleSet)results;

    if (ruleset == null)
    {
       Console.WriteLine("The rules file " + filename + " does not appear to contain a valid ruleset.");
    }
    return ruleset;
}