Statemachine and Data

Mar 28, 2013 at 12:25 PM
Hello,

I have a basic question to StateMachines in WF4.
How is it possible to pass data to the StateMachine?
This is from the WaitForNotificationExtension.cs from Rjacobs:
protected void RaiseNotification(TNotification notification, TValue data)
        {
            // Ignore if the workflow instance is not set yet
            if (this.workflowInstanceProxy == null)
            {
                return;
            }

            // If a bookmark is pending for this notification resume it
            this.workflowInstanceProxy.BeginResumeBookmark(
                new Bookmark(notification.ToString()),
                data,
                (asr) =>
                {
                    // If the bookmark cannot be resumed, queue the event
                    if (this.workflowInstanceProxy.EndResumeBookmark(asr) != BookmarkResumptionResult.Success)
                    {
                        this.QueueNotification(notification, data);
                    }
                },
                null);
        }
When I debug into this, I see that the "data" is sent, but I don't know how this "data" has to be.
I tried it with a Dictionary<string, object>, where my String is the InArgument of my CodeActivity. But this was alway null.
Now my question(s):
  • Can I pass data in the StateMachine.Explicit Example from Ron Jacobs?
  • In which Entity can I pass data? Transition, State oder CodeActivity?
  • How has this data to be built?
Thanks in advance.

Tobi
Apr 3, 2013 at 12:38 PM
I can answer my own question for posterity.
The WaitForNotificationBase Class has a Result, which is correctly written with my data.
And here comes the general part on how to bring data from one Activity to another:
  • SourceActivity: write Data in Result (this is a normal OutArgument)
  • In Destination create a variable (eg MyVariable) which has to have the same type as the OutArgument of Source
  • Assign: InArgument = MyVariable (this sounds pretty weird, but it really has to be this way)
Look here for further info from Guru of Workflow: http://blogs.msdn.com/b/rjacobs/archive/2011/05/25/passing-values-between-workflow-activities.aspx