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();

}

}

}

}

[5232 byte] By [mario.muja] at [2007-12-24]
# 1

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();

}

}

}

}

mario.muja at 2007-8-31 > top of Msdn Tech,Software Development for Windows Vista,Windows Workflow Foundation...
# 2

All public properties are serialized and they have to be serializable or you will get an exception. Most .NET types are already serializable so you don't need to write custom serializers for them.

Designer serialization is nothing to do with instance serialization. Designer serialization means serializaing the model as XAML where instance serialization

Regards,
Paul

PaulAndrew at 2007-8-31 > top of Msdn Tech,Software Development for Windows Vista,Windows Workflow Foundation...
# 3

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

mario.muja at 2007-8-31 > top of Msdn Tech,Software Development for Windows Vista,Windows Workflow Foundation...
# 4

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();

}

FassaBortolo at 2007-8-31 > top of Msdn Tech,Software Development for Windows Vista,Windows Workflow Foundation...
# 5

Hi Mario,

Could you share a snippet of the xaml that gets serialized? Could you also outline the definition of the custom activities you have added to the root activity?

What build numbers of WF are you using?

VishalKalra at 2007-8-31 > top of Msdn Tech,Software Development for Windows Vista,Windows Workflow Foundation...
# 6
Thanks for your help. It works now. I am using RC1. I had to add the DesignerSerializationVisibilityAttribute to all my properties to get them serialized.
mario.muja at 2007-8-31 > top of Msdn Tech,Software Development for Windows Vista,Windows Workflow Foundation...

Software Development for Windows Vista

Site Classified