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("EsbMsgSampleRule.xml");
WorkflowMarkupSerializer serializer = new WorkflowMarkupSerializer();
StringReader stringReader = new StringReader(ruleSetXmlDefinition);
XmlTextReader reader = new XmlTextReader(stringReader);
return serializer.Deserialize(reader) as RuleSet;
}
No comments:
Post a Comment