WF Custom SQL Tracking Service Stopped Working for old workflows?
Asked Answered
D

1

6

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);
                    }
            }                    
    }
}
Daytoday answered 6/11, 2011 at 9:56 Comment(3)
The 'assembly' tag is for low level programming, not for .NET assemblies.Amiss
Hard to tell without seeing more of your custom tracking service.Psittacosis
@kay.herzam: I've added the tracking service code, and a note about why I don't think it's to do with the tracking code itself.Daytoday
D
0

It turns out that the final step is an easy one. The issue is a bug in WF and microsoft have outlined the answer here.

You basically have to decorate your custom tracking service class with an attribute that allows you to resolve old tracking service references, like so:

[System.Workflow.Runtime.Tracking.PreviousTrackingService("myNamespace.Workflow.StateMachineTrackingService, myNamespace.Workflow.StateMachineTracking, Version=1.2.0.1, Culture=neutral, PublicKeyToken=gr4b2191f58h9e0d")]
public class StateMachineTrackingService : TrackingService
       {
         //Body of your custom tracking service here
       }

Low and behold, my previously persisted workflows now resolve the new version of the Tracking Service.

Daytoday answered 4/1, 2012 at 17:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.