How to get values of all variables in scope RRS feed

  • Question

  • Hello,

    I'm looking at the Workflow Simulator sample that has been added as part of beta 2.  I tried to modify the sample code such that it displays the value of the variables in the workflow.  I did this by modifying the Microsoft.Samples.WorkflowSimulator.WorkflowDesignerHost class and the delegate for simTracker.TrackingRecordReceived.  I added the following code:

                                ActivityStateRecord activityStateRecord = ((ActivityStateRecord) trackingEventArgs.Record);
                                System.Diagnostics.Debug.WriteLine(">>>> Variables ***");
                                foreach (KeyValuePair<string, object> kvp in activityStateRecord.Variables)
                                    if (kvp.Value == null)
                                        System.Diagnostics.Debug.WriteLine("Name: " + kvp.Key + " Value: null");
                                        System.Diagnostics.Debug.WriteLine("Name: " + kvp.Key + " Value: " + kvp.Value.ToString());
                                System.Diagnostics.Debug.WriteLine("<<< Variables ***");
    What I found was that if the activtity being executed was the flowchart, then the "myStr" variable value was found in the tracking record, and I could report on it.  If one of the flowchart child activities was executing, then the tracking record did not contain the "myStr" variable, even though the variable is in scope for the child activity.

    A search of the workflow forum turned up this post, which says there is a behaviour change since beta 1, so that now only variables explicitly declared by an activity are reported in the tracking record (previously, it was all variables in scope of the activity).

    My goal is to create a rudimentary workflow debugger, when my workflow designer is rehosted.  An earlier post I created suggests that the Workflow Simulator sample could be the basis of such a solution.  However, with the behaviour change to how variables are reported in tracking records, I don't know how I can get information about all variables in scope.  Vikram suggests a workaround using arguments in the post describing the tracking record behaviour change, but I don't understand how that will help me achieve my goal of reporting on all activity variables that are in scope.  Please advise.

    Thank you,

    Monday, November 30, 2009 5:54 PM


  • In the beta2 code the variables can be tracked only when the activity that defined it is being tracked. The workaround using arguments will work if your variable is being passed in to the child activity as an argument, in which case you can track all the arguments for the child activity. The name of the argument will be different from the variable. In case the variable is passed in to the activity as in or out argument then you could use activityStateRecord.Arguments.
    In your profile if you specify extraction of arguments by using name="*" then variables that are passed in arguments can be tracked
    In profile
     new ActivityStateQuery()
                                    // Subscribe for track records from all activities for all states
                                    ActivityName = all,
                                    States = { all },

                                    // Extract arguments as a part of the activity tracking record
                                    // Argument Name = "*" allows for extraction of all arguments for the activity
                                    Arguments =
                                        { all }  

    When state="Executing" in arguments are extracted, for any other state all arguments are extracted.

    We have made a fix in post beta2 where you can get a variable in scope by extracting the variable by name. Note the fix post beta2 will not allow to get all variables in scope by specifying name="*"


    Monday, November 30, 2009 9:13 PM