tags:

views:

284

answers:

7

I am using WorkflowMarkupSerializer to save a statemachine workflow - it saves the states OK, but does not keep their positions. The code to write the workflow is here:

        using (XmlWriter xmlWriter = XmlWriter.Create(fileName))
        {
            WorkflowMarkupSerializer markupSerializer
                = new WorkflowMarkupSerializer();
            markupSerializer.Serialize(xmlWriter, workflow);
        }

The code to read the workflow is:

            DesignerSerializationManager dsm
            = new DesignerSerializationManager();
        using (dsm.CreateSession())
        {
            using (XmlReader xmlReader
                = XmlReader.Create(fileName))
            {
                //deserialize the workflow from the XmlReader
                WorkflowMarkupSerializer markupSerializer
                    = new WorkflowMarkupSerializer();
                workflow = markupSerializer.Deserialize(
                    dsm, xmlReader) as Activity;

                if (dsm.Errors.Count > 0)
                {
                    WorkflowMarkupSerializationException error
                        = dsm.Errors[0]
                          as WorkflowMarkupSerializationException;
                    throw error;
                }
            }
         }
A: 

Hah, even the stupid workflow designer hosted in Visual Studio 2008 loses the positions of states randomly. This tells me it's probably not an easy task, and is information external to the Activities that comprise it. I'd dig more around the host for information; if I find something, I'll post back.

x0n
A: 

The position of all the states is kept in a separate file. You'll need to drag it around with the markup of the workflow itself. Luckily, it's just XML as well, so you might be able to reuse most of the code you have up there. If memory serves, I believe it's simply NameOfYourWorkflow.layout.

I agree with x0n - the designer is really bad in Visual Studio.

Nicolas Webb
A: 

OK, this tutorial gives good information on how to do it - although so far I am only able to save the layout, I haven't been able to correctly use the layout. The information in question is about 2/3rds down (or just do a search for .layout)

(How does one close his own question?)

Khadaji
A: 

Note that there is a bug in either the serialize or deserialize of the XML created (named in the example with an extension of .layout.)

It produces the following xml as the first line of the file:

<?xml version="1.0" encoding="utf-8"?><StateMachineWorkflowDesigner xmlns:ns0="clr-namespace:System.Drawing;Assembly=System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" Name="New" Location="30, 30" Size="519, 587" AutoSizeMargin="16, 24" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/workflow"&gt;

When reading this back in, the size attribute causes an exception. I removed Size="519, 587" from the file and the workflow is loaded back correctly. Right now, I write the file, open it and remove the size, then close it. I need to think about a more elegant solution, but at least I am now saving and restoring a state machine workflow.

Khadaji
A: 

I have experienced that too on my workflow designer. I have a lot of state machine workflow on my project and sometimes it shows incorrectly. I have found the cause. The workflow designer does not show state machine workflow correctly because of the change of character from "," to ";" in ".layout" file.

Example:

Incorrect: Name="C211Workflow" Location="30; 30" Size="2162; 2954" AutoSizeMargin="16; 24"

Correct: Name="C211Workflow" Location="30, 30" Size="2162, 2954" AutoSizeMargin="16, 24"

Incorrect: <StateDesigner Name="stateKelengkapanBerkasFormD5" Location="1834; 2453" Size="222; 80" AutoSizeMargin="16; 24">

Correct: <StateDesigner Name="stateKelengkapanBerkasFormD5" Location="1834, 2453" Size="222, 80" AutoSizeMargin="16, 24">

So, my temporary solution is to open the .layout file in text editor and replace the ";" with "," in Location, Size, and AutoSizeMargin attributes.

Does anyone have more practical solution?

Thx

Rizky Januar Akbar

Rizky Januar Akbar
A: 

Nice answer !!! i think it can solve my problem ...

supri
+1  A: 

Open Control Panel -> "Regional and language options" and set list separator to ',' (comma) and workflow serializer will use ',' (comma) as separator for X,Y coordinates for struct SizeF

then select ';' and workflow serializer will use ';' (semicolon) as separator.

This really stupid that serializer use regional setting for serialize markup.

Evgeny Zyuzin