How does the serialization work?
I have the code shown below to serialize a workflow to XML.
The workflow consists of custom activity classes, each having its own associated designer.
The resulting XML file only contains the names of the activities but not a single property of them.
Why are the built-in properties of the activity base classes not automatically serialized?
Do I need to create a custom serializer for each of my custom activities, even for the built-in properties?
Is serialization of the activity designer classes also managed by the WorkflowMarkupSerializer or does it only manage the serialization of the activity classes?
I have many properties for visual appearance in the designers, that I would like to be serialized so that the visual appearance of the workflow can be exactly restored on next reload.
I would like to thank you for your support so far.
protectedoverridevoid PerformFlush(IDesignerSerializationManager manager)
{
IDesignerHost host = (IDesignerHost)GetService(typeof(IDesignerHost));
Activity rootActivity = host.RootComponentasActivity;
if (host !=null && host.RootComponent !=null)
{
if (rootActivity !=null)
{
string fileName =@"c:\myfile.xoml";
XmlTextWriter xmlWriter =newXmlTextWriter(fileName,Encoding.Default);
try
{
WorkflowMarkupSerializer xomlSerializer =newWorkflowMarkupSerializer();
xomlSerializer.Serialize(xmlWriter, rootActivity);
}
finally
{
xmlWriter.Close();
}
}
}
}
I have the code shown below to serialize a workflow to XML.
The workflow consists of custom activity classes, each having its own associated designer.
The resulting XML file only contains the names of the activities but not a single property of them.
Why are the built-in properties of the activity base classes not automatically serialized?
Do I need to create a custom serializer for each of my custom activities, even for the built-in properties?
Is serialization of the activity designer classes also managed by the WorkflowMarkupSerializer or does it only manage the serialization of the activity classes?
I have many properties for visual appearance in the designers, that I would like to be serialized so that the visual appearance of the workflow can be exactly restored on next reload.
I would like to thank you for your support so far.
protected override void PerformFlush(IDesignerSerializationManager manager)
{
IDesignerHost host = (IDesignerHost)GetService(typeof(IDesignerHost));
Activity rootActivity = host.RootComponent as Activity;
if (host != null && host.RootComponent != null)
{
if (rootActivity != null)
{
string fileName = @"c:\myfile.xoml";
XmlTextWriter xmlWriter = new XmlTextWriter(fileName, Encoding.Default);
try
{
WorkflowMarkupSerializer xomlSerializer = new WorkflowMarkupSerializer();
xomlSerializer.Serialize(xmlWriter, rootActivity);
}
finally
{
xmlWriter.Close();
}
}
}
}
Hi Paul,
you wrote that all public properties are serialized but I am sure, that NONE of my designers properties are written to the XAML file, when the workflow is serialized.
Can someone please sched some light on how to to restore the visual appearance of a workflow when deserializing it from an XAML file?
For example, should I write all my custom activity designer property values to Isolated Storage or somewhere else? I hope, there is a better way to do this.
As an example of what I would like to restore at deserialization time: colors of the connector lines and borders.
Regards, Mario
Hi!
This is how I am saving the design of the workflow.
public
void PerformFlush()
{
IDesignerHost host = (IDesignerHost)GetService(typeof(IDesignerHost));
if (host != null && host.RootComponent != null)
{
Activity service = host.RootComponent as Activity;
if (service != null)
{
using (XmlWriter writer = XmlWriter.Create(this.xomlFile))
{
WorkflowMarkupSerializer xomlSerializer = new WorkflowMarkupSerializer();
xomlSerializer.Serialize(writer, service);
}
}
}
string layoutFile = Path.Combine(Path.GetDirectoryName(this.xomlFile), Path.GetFileNameWithoutExtension(this.xomlFile) + ".layout");
Activity rootActivity = host.RootComponent as Activity;
ActivityDesigner rootdesigner = host.GetDesigner(rootActivity) as ActivityDesigner;
XmlWriter layoutwriter = XmlWriter.Create(layoutFile);
IList errors = null;
SaveDesignerLayout(layoutwriter, rootdesigner, out errors);
layoutwriter.Close();
}