开发者

Registering custom tracking participants through code in workflow foundation 4.0

开发者 https://www.devze.com 2022-12-22 11:10 出处:网络
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 m

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>
     开发者_Python百科 </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();
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号