How to load conditions from a .rules file in a designer hosting application?
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
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
mahernandez
Gopal R
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
Martin Ottosen
Thank you all for replies.
David Scherf
In fact, my designer is based on this Designer Rehosting sample.
Didn't you have the similar problem with this sample
ZHiquan