通过工作流基础4.0中的代码注册自定义跟踪参与者

发布于 2024-08-24 10:48:18 字数 1681 浏览 3 评论 0原文

我在尝试在工作流基础 4.0 中附加自定义跟踪参与者时遇到问题。我有一个继承自 TrackingParticipant 的类,但除了通过大量混乱的 app.config 条目(如下面的 SDK 示例(在 system.servicemodel 元素中)所示)之外,我看不到将其附加到我的 WorkflowServiceHost 的任何其他方式。当我只想要一个简单的自定义跟踪参与者来监听我的 CustomTrackingRecord.Data.Add(key, value) 调用时,此选项似乎需要大量额外的开销和创建类。

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);
    }
}

如何通过代码(而不是如下配置)将上述自定义跟踪参与者注册到工作流服务主机实例?

  <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>

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>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

网名女生简单气质 2024-08-31 10:48:18

只需将其作为工作流扩展添加到 WorkflowServiceHost 即可。

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

Just add it as a workflow extension to the WorkflowServiceHost.

var host = new WorkflowServiceHost(....);
var tracker = new CustomTracking();
host.WorkflowExtensions.Add(tracker);
host.Open();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文