2011年2月24日 下午 08:33
I have seen many question about how to get the workflow instance id in CodeActivity, Tracking participant etc'.
My problem is exactly the opposite.
I have the workflow instance id, and now i only need the root activity display name, or the workflow definition,
any one of these will suffice, but i just can't seem to find a simple solution without involving custom service hosts, or workflow extensions.
Thanks in advance.
2011年2月25日 上午 01:29
I'm a little confused what you are looking for.
seems you are looking xamlservices.
could you take a look at whether the sample code on this link?
please let me know if you are looking for something else.
2011年2月25日 上午 04:01
I'm looking for something else.
I have a workflow service, which root activity is a flowchart. I named that root activity "MyRootActivity".
I have registered tracking profiles, to log all ActivityStateRecord records.
The ActivityStateRecord has many useful properties, including the WorkflowInstanceID property which is fine.
What it lacks, is the Workflow Root Activity Name property (or something similar), so i can't log the the workflow name.
On the other hand, WorkflowInstanceRecord, has this property ActivityDefinitionID, which is exactly what i need.
My question is: How can i get the workflow root activity definition id (display name), if i only have the workflow instance id (Guid).
2011年2月25日 上午 05:10版主
Can you try to get the workflow instance from the WorkflowInstanceID. With the workflow instance, you can get the workflow definition and then all the information about the workflow definition. The code will be something like the below:
This posting is provided "AS IS" and confers no rights or warranties.
2011年2月25日 上午 11:17
You may want to use WorkflowInspectionServices, that, given an ActivityID can take you on the actual Activity definition which lets you navigate your definition model as you wish.
This post could help:
2011年2月25日 上午 11:44
Correct me if i'm wrong, but isn't workflow runtime belongs to the 3.5 WF, and not so relevant to WF 4.0?
If its not, how do i get the runtime from within a Tracking Participant?
2011年2月25日 上午 11:46
I'v seen this post before, and i don't think WorkflowInspectionServices can help me here.
In the sample, notice that the author uses WorkflowApplication to get the Activity definition.
I don't have that.
2011年2月27日 下午 07:04Well, i found a solution, but it's not pretty.I create a custom behavior, thats adds a tracking participant, with a profile of WorkflowInstanceQuery like so:
<trackingProfile name="All workflow instance records"> <workflow activityDefinitionId="*"> <workflowInstanceQueries> <workflowInstanceQuery> <states> <state name="*"/> </states> </workflowInstanceQuery> </workflowInstanceQueries> </workflow> </trackingProfile>
The tracking participant is added as singleton to the host extensions, and keeps a dictionary of WorkflowMetadata instances, a custom class to hold any relevant data about the workflow (like state, id, and the ActivityDefinitionID - which is what i really wanted all along). The key to the dictionary is the workflow instance id. The tracking participant, deletes workflow metadata entries whenever a terminal WorkflowInstanceRecord is received, like 'Completed', 'Terminated', 'Aborted' etc'.
Because the tracking participant is a singleton, other tracking participants can access it and get the workflow metadata by workflow instance id, and thus log the ActivityDefinitionID.
It is important to remember, that if you have other behaviors that add Tracking Participants to the host, and if the participants is using a ActivityStateRecord profile that tracks all activity state records, The metadata behavior i described above, must be declared first ( first in the app.config), otherwise The first TrackingRecord that your application will track is going to be an ActivityStateRecord, and not WorkflowInstanceRecord, and wil not be able to access the workflow metadata of that workflow, because it haven't been received yet.
Although this works OK, i would really prefer to use a built in approach, if there is any.
- 已標示為解答 Andrew_ZhuModerator 2011年3月3日 上午 03:05
2012年7月16日 上午 11:54
Hello. I have similar problem. Can you please tell where is dictionary of WorkflowMetadata is located? I can't find it from within tracking classes (participant, to be specific).
Thanx in advance.
2012年7月22日 下午 02:30
The WorklfowMetadata is a custom class i invented. You don't have that out of the box.
The tracking participant that i register creates a dictionary of WorkflowMetadata, and whenever encounters aa WorkflowInsatcneRecord, updates that dictionary.
The dictionary is saved as a singleton in the memory of the process, making it possible for any activity to access it.
Hope that helps.