Why is the Activity ContextGuid not public???  
Author Message
Nate Garvey





PostPosted: Windows Workflow Foundation, Why is the Activity ContextGuid not public??? Top

The execution context of an activity is an important piece of the workflow. So why is this important piece of information hidden Currently, there is no way for me to correctly obtain a specific instance of an activity.

The main issue I am running into is with tracking. I need to track additional information that is supplied by custom activities. Also, can see the need for a workflow to be able to access other activities in a specific context in order to complete.



Software Development for Windows Vista19  
 
 
Jon Flanders





PostPosted: Windows Workflow Foundation, Why is the Activity ContextGuid not public??? Top

you can do this :

Guid contextGuid = (Guid)activity.GetValue(Activity.ActivityContextGuidProperty);



 
 
Nate Garvey





PostPosted: Windows Workflow Foundation, Why is the Activity ContextGuid not public??? Top

Ok, so that helped with the first part. Now another problem. When I try to find a specific activity in the tracking service based on the root activity, the qualified name, and context guid, I get nothing. The reason for this is the ContextGuid passed into the ActivityTrackingRecord does not match any guids returned from the dependency property. I am using a simple sequential workflow. Any Idea why this is
 
 
Michael Herman -Parallelspace-





PostPosted: Windows Workflow Foundation, Why is the Activity ContextGuid not public??? Top

When I try using

Guid contextGuid = (Guid)activity.GetValue(Activity.ActivityContextGuidProperty);

in the ExecuteCode() method for a CodeActivity, I'm getting the "zero Guid" being returned.

Any ideas

Here's my code:

private void codeActivity1_ExecuteCode(object sender, EventArgs e)

{

Activity oCode = (Activity)sender;

Guid contextGuid = (Guid)(oCode.GetValue(Activity.ActivityContextGuidProperty));

Console.WriteLine("codeActivity1_ExecuteCode:"

+ " " + "e.GetType " + e.GetType().ToString()

+ " " + "sender.GetType " + (sender == null "null" : sender.GetType().ToString())

+ " " + "contextGuid " + contextGuid.ToString()

);

}



 
 
Nate Garvey





PostPosted: Windows Workflow Foundation, Why is the Activity ContextGuid not public??? Top

The context is not always set. You need to walk the activity tree until you find an activity that has it set. From what I was told, it may only be set on Activities that spawn new contexts.
 
 
Jon Flanders





PostPosted: Windows Workflow Foundation, Why is the Activity ContextGuid not public??? Top

Yes - this is why it is only a useful pattern during persistence of an spawned execution context.

 
 
Joel West





PostPosted: Windows Workflow Foundation, Why is the Activity ContextGuid not public??? Top

Specifically you should walk activity.Parent looking for the closest parent with a non empty guid value for context guid. The reason this is not set on every activity is to reduce the persistence size.

Thanks,
Joel West
MSFTE - SDE in WF runtime and hosting

This posting is provided "AS IS" with no warranties, and confers no rights


 
 
Joel West





PostPosted: Windows Workflow Foundation, Why is the Activity ContextGuid not public??? Top

Ok, so that helped with the first part. Now another problem. When I try to find a specific activity in the tracking service based on the root activity, the qualified name, and context guid, I get nothing. The reason for this is the ContextGuid passed into the ActivityTrackingRecord does not match any guids returned from the dependency property. I am using a simple sequential workflow. Any Idea why this is

Are you seeing that the values are different and both values are not empty guids These guids should be the same, the intention is to be able to align up activity code with tracking data.

Thanks,
Joel West
MSFTE - SDE in WF runtime and hosting

This posting is provided "AS IS" with no warranties, and confers no rights


 
 
Michael Herman -Parallelspace-





PostPosted: Windows Workflow Foundation, Why is the Activity ContextGuid not public??? Top

The reason why I (think I) need the activity ContextGuid is that I would my client (hosting) application to use the activity ContextGuid value as a correlation value for signaling a specific activity in a state machine workflow.

Based on this brief explanation, does using the activity ContextGuid make sense

Michael.



 
 
Michael Herman -Parallelspace-





PostPosted: Windows Workflow Foundation, Why is the Activity ContextGuid not public??? Top

Here's some code (based on Joel's explanation) that found the non-zero ContextGuid following the chain of parent activities:

private void codeActivity1_ExecuteCode(object sender, EventArgs e)

{

Guid contextGuid = Guid.Empty;

for (Activity oActivity = (Activity)sender; oActivity != null; oActivity = oActivity.Parent)

{

contextGuid = (Guid)oActivity.GetValue(Activity.ActivityContextGuidProperty);

if (!contextGuid.Equals(Guid.Empty)) break;

}

Console.WriteLine("codeActivity1_ExecuteCode:"

+ " " + "contextGuid " + contextGuid.ToString()

);

}