Registering custom tracking participants through code in workflow foundation 4.0

…衆ロ難τιáo~ 提交于 2019-12-10 11:21:28

问题


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>

回答1:


Just add it as a workflow extension to the WorkflowServiceHost.

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


来源:https://stackoverflow.com/questions/2400993/registering-custom-tracking-participants-through-code-in-workflow-foundation-4-0

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!