I have a custom tracking service that has been running for a while now with over 1500 live workflows ticking along, I'm now in the process of versioning the workflows so that I can release some change requests.
Unfortunately the system was not initially deployed with strongly typed assemblies, so I'm in the process of sorting this mess out.
I'm having to use a mixture of a custom SerializationBinder to translate the PublicKeyToken=null to my new PublicKeyToken, and a AppDomain_AssemblyResolve delegate to help point the host to the now strongly typed assemblies - Referenced here.
I've also had to replace the contents of the related rows within the [Type] table that comes with the default SqlTrackingService to reference the new PublicKeyToken, so:
some.namespace.foobar, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
is replaced with:
some.namespace.foobar, Version=1.0.0.0, Culture=neutral, PublicKeyToken=123456789acb
I seemed to be making good progress, however when I transition my State Machine workflow, the Custom Tracking Service that I have added as a service is no longer firing for version 1.0.0.0 workflows, but is working for newly created version 2.0.0.0 workflows.
Note: The default SqlTrackingService is still running fine on both versions of the workflow, this is just a problem with the custom tracking service on existing persisted workflows.
The Custom Tracking Service has always been added through the app.config like this:
<Services>
...other services here...
<add type="some.namespace.ActiveStateTrackingService, some.namespace.extensions" assembly="uk.gov.gsi.cma.extensions" />
</Services>
Any ideas on what else I need to change to get this working for the already existing workflows?
As requested, here is the custom tracking service, although the problem is to do with the host "binding" the custom tracking service, not the tracking service itself - I know this because in the instance where the custom tracking service isn't fired, none of the methods, including the constructor get called.
public class ActiveStateTrackingService : TrackingService
{
protected override TrackingProfile GetProfile(Guid workflowInstanceId)
{
return GetDefaultProfile();
}
protected override TrackingProfile GetProfile(Type workflowType, Version profileVersionId)
{
return GetDefaultProfile();
}
protected override TrackingChannel GetTrackingChannel(TrackingParameters parameters)
{
return new ActiveStateTrackingChannel(parameters);
}
protected override bool TryGetProfile(Type workflowType, out TrackingProfile profile)
{
profile = GetDefaultProfile();
return true;
}
protected override bool TryReloadProfile(Type workflowType, Guid workflowInstanceId, out TrackingProfile profile)
{
profile = null;
return false;
}
private TrackingProfile GetDefaultProfile()
{
TrackingProfile profile = new TrackingProfile();
profile.Version = new Version(1, 0);
// Add tracking point for state activity executing
ActivityTrackPoint statePoint = new ActivityTrackPoint();
ActivityTrackingLocation location = new ActivityTrackingLocation(typeof(StateActivity), new ActivityExecutionStatus[] { ActivityExecutionStatus.Executing });
statePoint.MatchingLocations.Add(location);
profile.ActivityTrackPoints.Add(statePoint);
return profile;
}
}
public class ActiveStateTrackingChannel : TrackingChannel
{
private TrackingParameters param;
public ActiveStateTrackingChannel(TrackingParameters parameters)
{
param = parameters;
}
protected override void InstanceCompletedOrTerminated()
{
return;
}
protected override void Send(TrackingRecord record)
{
// get the tracking record and write out the name of the state.
var r = record as ActivityTrackingRecord;
if (r != null)
if (!string.IsNullOrEmpty(r.QualifiedName))
{
using (ICaseService caseService = new CaseService())
{
SomeServiceLayer.UpdateCurrentStateOutsideOfTheWorkflow(param.ContextGuid, r.ParentContextGuid, r.QualifiedName);
Console.WriteLine("*** Current State: {0} ***", r.QualifiedName);
}
}
}
}