none
Converting xaml workflow to C# workflow

    Question

  • Is there any way to get a C# version of a xaml workflow and then run the C# version?  Also, how would you convert C# into a xaml workflow?  I don't mean just a single object, I mean an object graph containing multiple activities.

    Bob
    Saturday, June 06, 2009 5:57 AM

Answers

All replies

  • Bob.

    - have a look at MSDN Doc WorkflowXamlServices.Load and WorkflowDesigner.DeserializeString

    Thanks
    Roman
    Roman Kiss, MVP Connected System Developer
    Saturday, June 06, 2009 6:42 AM
  • Roman,

         Thanks for pointing out these methods, but I was wondering if anyone has demonstrated their use anywhere.  I'll check them out.

    Thanks again,

    Bob
    Saturday, June 06, 2009 7:02 AM
  • Bob  (it's a little late in Seattle, so I don't have a code editor handy, so there may be some minor errors below),

    If you want to serialize any object graph to xaml, simply look at the XamlServices.Save() api that's in System.Xaml.  I'm sure there are a few SDK samples around that as well.  It takes in a file name to output to, a text writer or a stream, so you get to pick your poison for destination.  Similarly, if you want to get an object graph deserialized from Xaml, you can just use XamlServices.Load() again, with overloads for files, streams, text, xml, and xaml readers.

    To see this API, just do something like

    Sequence s = new Sequence { Activities = { new Persist(), new Persist() } };
    XamlServices.Save(fileNameVar, s);
    If you want to read, basically do the reverse.

    Save and Load are convinient helper functions to operate on the whole of the doc, there Xaml stack surfaces much more programmability and has a nice node stream style API that lets you plug in while nodes are being read and written.

    Now, if you want to deserialize a Xaml file that contains an x:Class directive, you are going to need to do a bit more work (and it depends what you want to serialize to or from).  I'll try to blog about that in the next week or so.
    Program Manager -- Modeling Platform and Tools http://blogs.msdn.com/mwinkle
    Saturday, June 06, 2009 8:18 AM
  • Bob  (it's a little late in Seattle, so I don't have a code editor handy, so there may be some minor errors below),

    If you want to serialize any object graph to xaml, simply look at the XamlServices.Save() api that's in System.Xaml.  I'm sure there are a few SDK samples around that as well.  It takes in a file name to output to, a text writer or a stream, so you get to pick your poison for destination.  Similarly, if you want to get an object graph deserialized from Xaml, you can just use XamlServices.Load() again, with overloads for files, streams, text, xml, and xaml readers.

    To see this API, just do something like

    Sequence s = new
     Sequence { Activities = { new
     Persist(), new
     Persist() } };
    XamlServices.Save(fileNameVar, s);
    
    If you want to read, basically do the reverse.

    Save and Load are convinient helper functions to operate on the whole of the doc, there Xaml stack surfaces much more programmability and has a nice node stream style API that lets you plug in while nodes are being read and written.

    Now, if you want to deserialize a Xaml file that contains an x:Class directive, you are going to need to do a bit more work (and it depends what you want to serialize to or from).  I'll try to blog about that in the next week or so.
    Program Manager -- Modeling Platform and Tools http://blogs.msdn.com/mwinkle
    Actually, your last statement is really what I am looking for here, so I will look forward to your blog post on this.
    Saturday, June 06, 2009 4:47 PM
  • WorkflowXamlServices.Load can help you load an x:Class document. It gives you back a DynamicActivity.
    See this:
    http://blogs.msdn.com/xiaowen/archive/2009/06/06/windows-workflow-foundation-loading-an-activity-dynamically.aspx

    Senior Lead Program Manager, Windows Workflow Foundation http://blogs.msdn.com/kavitak
    Monday, June 08, 2009 4:50 PM
  • Bob,

    As promised, here's a blog post on the subject. 

    http://blogs.msdn.com/mwinkle/archive/2009/06/10/types-metatypes-and-bears-oh-my.aspx


    Program Manager -- Modeling Platform and Tools http://blogs.msdn.com/mwinkle
    Tuesday, June 09, 2009 11:25 PM
  • Kavita,

         That's a really useful link.  Thanks for posting it!

    Bob
    Tuesday, June 09, 2009 11:32 PM
  • Matt,

         That is a very thorough and very useful blog post!  It will take me a week to absorb all the info in it.

    Thanks again,

    Bob
    Tuesday, June 09, 2009 11:34 PM