简体   繁体   中英

Registering custom tracking participants through code in workflow foundation 4.0

I'm having trouble trying to attach a custom tracking participant in workflow foundation 4.0. I have a class that inherits from TrackingParticipant but I cannot see any other way of attaching it to my WorkflowServiceHost other than through lots of messy app.config entries like the SDK example demonstrates below (in the system.servicemodel element). This option seems to require a lot of extra overhead and classes to be created, when I just want a simple custom tracking participant to listen to my CustomTrackingRecord.Data.Add(key, value) calls.

public class CustomTracking : TrackingParticipant
{
    protected override void Track(TrackingRecord record, TimeSpan timeout)
    {
        CustomTrackingRecord innerRecord = (CustomTrackingRecord)record;
        var workflowInstanceId = innerRecord.InstanceId;

        Console.WriteLine("Track called for workflow '{0}'", workflowInstanceId);
    }
}

How can I register my above custom tracking participant through code (and not config like below) to a workflowServiceHost instance?

  <extensions>
    <behaviorExtensions>
      <add name="historyFileTracking" type="Microsoft.Samples.HistoryFileTrackingExtensionElement, HiringRequestProcessDefinition, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />     
    </behaviorExtensions>
  </extensions>
  <behaviors>
    <serviceBehaviors>
      <behavior>
        <historyFileTracking profileName="RequestStoryTracking" path="..\..\..\Data\RequestHistory\"/>
      </behavior>
    </serviceBehaviors>
  </behaviors>

  <tracking>
    <profiles>
      <trackingProfile name="RequestStoryTracking">
        <workflow activityDefinitionId="*">
          <customTrackingQueries>
            <customTrackingQuery name="*" activityName="*" />
          </customTrackingQueries>
        </workflow>
      </trackingProfile>
    </profiles>
  </tracking>

Just add it as a workflow extension to the WorkflowServiceHost.

var host = new WorkflowServiceHost(....);
var tracker = new CustomTracking();
host.WorkflowExtensions.Add(tracker);
host.Open();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM