How to load conditions from a .rules file in a designer hosting application?

I want to let my designer hosting application be able to read conditions from a .rules file after it reads a workflow from a .xoml file. What can I do

Answer this question

How to load conditions from a .rules file in a designer hosting application?

  • ChennaiRocks

    Yes, I am using your code. But it seems doesn't work.  :(

    Here is my code. Maybe you can find something wrong.

    public override TextReader GetFileReader(string filePath)

    {

    String string_rules = this._temp_rules_stream.ToString();

    if (!String.IsNullOrEmpty(string_rules))

    {

    StringReader reader_rules = new StringReader(string_rules);

    return reader_rules;

    }

    else

    return null;

    }

    public override TextWriter GetFileWriter(string filePath)

    {

    this._temp_rules_stream = new StringBuilder();

    StringWriter writer_rules = new StringWriter(this._temp_rules_stream);

    return writer_rules;

    }

    public override String FileName

    {

    get

    {

    return this._filename_xoml;

    }

    }


  • trt

    The rule editors and related classes use the WorkflowDesignerLoader. They call the FileName property to get the "name" of your workflow file (I put name is quotes since you don't really have to have a file - you might be storing your workflow in a database.

    Then they call GetFileReader - passing in that name with .xoml or .cs with .rules (so if you pass back foo.xoml - they will pass foo.rules to GetFileReader). You return a TextReader. They they call GetFileWriter to write the rules. You can always return an "empty" TextWriter from GetFileWriter as they will always write the whole RuleDefinition every time they write. Here is what I've been using lately:

    public override string FileName

    {

    get { return "foo.xoml"; }

    }

    public override System.IO.TextReader GetFileReader(string filePath)

    {

    string xoml = _currentRules.ToString();

    if (String.IsNullOrEmpty(xoml))

    return null;

    else

    return new StringReader(xoml);

    }

    StringBuilder _currentRules = new StringBuilder();

    public override System.IO.TextWriter GetFileWriter(string filePath)

    {

    _currentRules = new StringBuilder();

    return new StringWriter(_currentRules);

    }



  • TelecoCaixa

    Can you tell me what is happening Are you getting an exception

  • mahernandez

    But if I just store the imported conditions in a member StringBuilder of WorkflowDesignerLoader, these conditions can never be resolved by the Rule dialogs. What else should I do to make them resolvable
  • Gopal R

    For example, I create Condition1 in my workflow and save the workflow to MyWF.xoml and MyWF.rules. Then I restart my designer and load the workflow from MyWF.xoml. Then the Rules dialog tells me that Condition1 cannot be found.
  • Gagandeep Singh

    If I import conditions from a .rules file and store them into _currentRules, each time

    _currentRules = new StringBuilder();

    is reached, all the imported conditions will be lost.

    So How can I combine the imported conditions and the conditions created in the designer


  • Nagas

    Do you read from the rules file when you load the workflow

    // Read from rules file if one exists

    string rulesFile = Path.Combine(Path.GetDirectoryName(this.xoml), Path.GetFileNameWithoutExtension(this.xoml) + ".rules");

    if (File.Exists(rulesFile))

    {

    StreamReader rulesReader = new StreamReader(rulesFile);

    this.tempRulesStream = new StringBuilder(rulesReader.ReadToEnd());

    rulesReader.Close();

    }

    There is a sample code which demonstrates this and can be found at http://msdn.microsoft.com/windowsvista/default.aspx pull=/library/en-us/dnlong/html/WFDsgnRehst.asp



  • mightymephisto

    That is why I said that the rule infrastructure writes the whole ruledefinitions each time. You don't have to do the combining - the Rule dialogs will do that for you.

  • Martin Ottosen

    The Designer Rehosting sample works well with the rules. It seems that I have some problems in my program. I will check it tomorrow and give an end to this topic.
    Thank you all for replies.

  • David Scherf

    Yes, I have these code reading the .rules file.
    In fact, my designer is based on this Designer Rehosting sample.
    Didn't you have the similar problem with this sample

  • ZHiquan

    Why don't you try my code. I think it does everything you want - the only thing you have to do is decide how you are going to store the data once you want to save it. If you are storing the data in a file you can modify my code to return a TextReader or TextWriter that wraps the file.

  • How to load conditions from a .rules file in a designer hosting application?