Serialize and deserialize a workflow ruleset

Serailze

private void SerializeRuleSet(RuleSet ruleSet)
{
StringBuilder ruleDefinition = new StringBuilder();
WorkflowMarkupSerializer serializer = new WorkflowMarkupSerializer();

if (ruleSet != null)
{
try
{
StringWriter stringWriter = new StringWriter(ruleDefinition, CultureInfo.InvariantCulture);
XmlTextWriter writer = new XmlTextWriter(stringWriter);
serializer.Serialize(writer, ruleSet);
writer.Flush();
writer.Close();
stringWriter.Flush();
stringWriter.Close();
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine(ex.ToString());
}
}
else
{

}

XmlDocument rule = new XmlDocument();
rule.LoadXml(ruleDefinition.ToString());
rule.Save(“c:\\message.xml”);
}

Deserialize

public static RuleSet GetSampleRule(string type)
{

ruleSetXmlDefinition = GetEmbeddedTextFileContent(“SampleRule.xml”);

WorkflowMarkupSerializer serializer = new WorkflowMarkupSerializer();

StringReader stringReader = new StringReader(ruleSetXmlDefinition);
XmlTextReader reader = new XmlTextReader(stringReader);
return serializer.Deserialize(reader) as RuleSet;
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: