关于微软Workflow foundation 中的Tracking Service的一些理解

做项目的时候,有这样一个要求,把对象传入,作为HandleExternalEventActivity的事件参数的一部分传入workflow,然后在其中改变它的某一个property的值。  但是发现这样一个问题,就是对象作为事件参数的一部分传入workflow是要被序列化的,而相当于复制了一份对象导致了里面所做的修改无法反映到外面,无奈,只有想办法从workflow中拿到什么信息,然后通过这个拿到的值在外面修改这个属性的值。但是,但是发现从workflow中拿到一个property值居然是如此的麻烦。到网上找了解决方案,答案有两种,第一种我忘了,现在通过Tracking Service来解决这个问题。

 

首先,Tracking Service推荐最好是和PersistenceService使用同一个数据库和同一个服务器。否则会导致引入昂贵的分布式事务处理。不受只能同时运行一个Tracking Service的限制,可以在运行时中添加多个跟踪服务,每个服务都有机会保存相同的跟踪数据。

 

定义几个概念:

1。跟踪配置 ,相当于一个过滤器,定义了什么该跟踪,什么不该跟踪,可以自定义 多个,但是对于一个workflowtype只能指定一个。这样对于一个workflow的多个tracking service就使用这个跟踪配置来过滤数据。如果我们使用WF提供的SqlTrackingService,那么我们就可以利用其提供的持久性服务来保存我们的自定义跟踪配置,当然其默认的跟踪配置也放在其中。如果没有利用默认的SqlTrackingService,那么我们可能要自己考虑如何持久化跟踪配置了。想要使用自定义的跟踪配置,仅仅在内存中创建一个配置是不够的。在使用它之前,必须将其持久化到SQL跟踪数据库中。所有跟踪配置都包含一个版本号,每次修改现有的配置,都必须增加版本号。

Each TrackingProfile object contains three properties (WorkflowTrackPoints,
ActivityTrackPoints, UserTrackPoints) that correspond to the three types of tracking data. Each
one of these properties is a collection of tracking point objects of a type that corresponds to each
property (WorkflowTrackPoint, ActivityTrackPoint, UserTrackPoint).
Each of these tracking point objects has a MatchingLocations property that you use to identify
the tracking locations that qualify tracking data. Think of the MatchingLocations property as your
primary filter. For instance, for a WorkflowTrackPoint, you can use the MatchingLocations property
to identify the workflow events (for example, Created, Started, and so on) that you wish to match.
The ActivityTrackPoint and UserTrackPoint extend this concept by also providing an
ExcludedLocations property. As the name implies, you use this property to specify conditions that
will disqualify the tracking data.
The ActivityTrackPoint and UserTrackPoint both support an Extracts property. This is the
property that you use to define the individual fields or properties to extract. Also included is an
Annotations property that allows you to add descriptions of the extracted data.

 

2。跟踪事件的类型,分为3种。工作流事件,活动事件,用户事件。工作流事件基本上是指工作流的start,complete,abort,suspend的时候发生一个事件供tracking service记录。活动事件基本上指的是当活动开始,关闭,初始化的时候,发出一个事件供tracking service记录。用户事件顾名思义,是用户自定义的事件,当满足条件时候触发。可以使用TrackData方法触发,也可以在跟踪配置里面添加UserTrackPoint,这样当条件匹配的时候就会发生事件供tracking service记录。

 

 

使用SqlTrackingQuery类来获取数据。

 

 

但是后来终究没有使用Tracking Service来用于host与workflow的交互。

我用的是wf中的local service来做的。因为host可以根据workflow runtime来拿到localservice的实例,而workflow可以在加载的时候加载local service的实例。所以我们就可以通过方法调用的办法来达到数据交互。例如:如果localservice中有一个变量,在wf中用localservice中的方法设置这个变量的值,而在host中通过另外一个方法得到这个变量的值,就可以达到交互。反之亦然。如图:

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值