NMF

Hi,
is there a way to convert an existing workflow that is code based to a xoml based definition

Thanks

--
Nuno


Re: Windows Workflow Foundation Converting existing workflow from code based definition to xoml

NMF

Anyone knows if it's possible or not




Re: Windows Workflow Foundation Converting existing workflow from code based definition to xoml

Tom Lake

Yes, it is fairly easy to accomplish. Try the following changing Workflow1 to the workflow type that you want to serialize to XOML:

using System;

using System.Workflow.Activities;

using System.Workflow.ComponentModel.Serialization;

using System.ComponentModel.Design.Serialization;

using System.Xml;

namespace WorkflowConsoleApplication5

{

class Program

{

static void Main(string[] args)

{

Workflow1 workflow1 = Activator.CreateInstance<Workflow1>();

WorkflowMarkupSerializer serializer = new WorkflowMarkupSerializer();

DesignerSerializationManager serializationManager = new DesignerSerializationManager();

using (XmlWriter xmlWriter = XmlWriter.Create(@"c:\SerializedWorkflow.xoml"))

{

using (serializationManager.CreateSession())

{

serializer.Serialize(serializationManager, xmlWriter, workflow1);

if (serializationManager.Errors.Count > 0)

{

throw new Exception("Serialization errors");

}

}

}

}

}

}






Re: Windows Workflow Foundation Converting existing workflow from code based definition to xoml

NMF

Thanks Tom, but it doesn't work.
I tried it with a fairly complex workflow we have defined and I get this as output:

< xml version="1.0" encoding="utf-8" >
<ns0:Checks InitialStateName="WaitingCheck" WebServiceResponse="{p1:Null}"
CentrallyCapturedInput_docNumber1="{p1:Null}" AmountModifiedInput_type1="{p1:Null}"
LockCheckInput_auditUser1="{p1:Null}" CentrallyCapturedInput_account1="{p1:Null}"
DynamicUpdateCondition="{p1:Null}"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/workflow" xmlns:ns1="clr-namespace:Datacomp.PMFramework.Activities;Assembly=Datacomp.PMFramework.Activities, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:p1="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:ns0="clr-namespace:Datacomp.Workflow.StateMachineLibrary;Assembly=Datacomp.Workflow.StateMachineLibrary, Version=3.0.0.0, Culture=neutral, PublicKeyToken=null">
<ns0:Checks.ManualInput_submitterInfo1>
<ns0:SubmitterInfo />
</ns0:Checks.ManualInput_submitterInfo1>
</ns0:Checks>





Re: Windows Workflow Foundation Converting existing workflow from code based definition to xoml

Saurabh Chechi - MSFT

HI,

Are you still stuck because of this Following forum post might be useful to you:

http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=221919&SiteID=1

Do let us know if this solves your problem or not

Thanks

Saurabh






Re: Windows Workflow Foundation Converting existing workflow from code based definition to xoml

NMF

Well, the post you referred to basically says that what I want is impossible, so yes, I'm still stuck...

I made a bad decision at the start of the project (using a code based workflow) and now there is no automated way to convert the workflow. Not a critical problem, more of an annoyance.

Thanks
--
Nuno




Re: Windows Workflow Foundation Converting existing workflow from code based definition to xoml

Tom Lake - MSFT

Add the following code to the bottom of the InitializeComponent method in the designer.cs file:

using (XmlTextWriter xmlWriter = new XmlTextWriter(path, Encoding.Unicode))

{

WorkflowMarkupSerializer xomlSerializer = new WorkflowMarkupSerializer();

xomlSerializer.Serialize(xmlWriter, this);

}