0
votes

I am using Windows Workflow Foundation on a project, specifically the StateTracker, Instance Store and tracking components. The tracking for each instanciated workflow gets serialized to the database, and additionally I am able to deserialize this data using the following technique:

https://msdn.microsoft.com/library/ee960223(v=vs.100).aspx

The tracking deserializes into a large XML tree, representing the current state of the long running workflow, ie:

//...brevity
<activities z:Id="5" xmlns="http://schemas.datacontract.org/2010/02/System.Activities">
      <SerializedInstanceLists z:Id="6" z:Size="4" xmlns:a="http://schemas.datacontract.org/2004/07/System.Activities.Runtime">
        <a:ActivityInstanceMap.InstanceList z:Id="7">
          <singleItem z:Id="8" z:Type="System.Activities.ActivityInstance" z:Assembly="System.Activities, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" xmlns="http://schemas.datacontract.org/2004/07/System.Activities">
//...brevity

However, I have come across an issue where occasionally when our system code changes, the system-assigned ActivityIds of a particular Workflow design change as well. Since these IDs are referenced in the tracking, the workflows then refuse to load.

For example, before the code update:

Activity 1 ID: 1.2170
Activity 2 ID: 1.2337
Activity 3 ID: 1.2215

After the code update:

Activity 1 ID: 1.2170
Activity 2 ID: **1.2338**
Activity 3 ID: **1.2216**

A workflow that is currently at Activity 3 will have tracking that deserializes as:

            <a:ActivityInstanceMap.InstanceList z:Id="129">
          <singleItem z:Ref="11" i:nil="true" xmlns="http://schemas.datacontract.org/2004/07/System.Activities"></singleItem>
          <a:ActivityId z:Id="130">AQE=</a:ActivityId>
        </a:ActivityInstanceMap.InstanceList>
        <a:ActivityInstanceMap.InstanceList z:Id="131">
          <singleItem z:Ref="109" i:nil="true" xmlns="http://schemas.datacontract.org/2004/07/System.Activities"></singleItem>
          <a:ActivityId z:Id="132">AacR</a:ActivityId>
        </a:ActivityInstanceMap.InstanceList>
        <a:ActivityInstanceMap.InstanceList z:Id="133">
          <singleItem z:Ref="95" i:nil="true" xmlns="http://schemas.datacontract.org/2004/07/System.Activities"></singleItem>
          <a:ActivityId z:Id="134">AaMR</a:ActivityId>
        </a:ActivityInstanceMap.InstanceList>

I have found that by comparing to a workflow whose tracking was instantiated with the new code, the difference is in the AacR and AaMR ActivityIds. Updating these to the correct values successfully repair the workflow.

My question is this:

Does anyone recognise the encoding used for these AacR and AaMR ActivityIds? If I can work out how to convert the 1.2216 ActivityId into this serialized tracking value, I will be able to programmatically repair workflows on the fly when this occurs.

I have found that the Ids are initially serialized into byte arrays via the following reference source, however I can't work out how they go from this into the above 4 character strings.

http://referencesource.microsoft.com/#System.Activities/System/Activities/Runtime/ActivityInstanceMap.cs

The following article explains how ActivityIds are generated:

http://blogs.msdn.com/b/tilovell/archive/2011/06/08/wf4-visual-workflow-tracking-and-workflowinspectionservices.aspx

Any help greatly appreciated!

1

1 Answers

0
votes

Found it!

Convert.ToBase64String(activity.QualifiedId.AsByteArray())

:-)