WF4.0 基础篇 (二十二) Tracking

Tracking 介绍


WF跟踪是用来记录工作流执行情况

WF跟踪由以下几部分组成:

跟踪记录

Tracking Records

从工作流运行时发出

跟踪配置

Tracking Profile

用来筛选从工作流实例中发出的跟踪记录

跟踪参与者

Tracking Participants

用来订阅跟踪记录。跟踪参与者包括处理来自跟踪记录的负载的逻辑

ActivityInfo

System.Activities.Tracking.ActivityInfo

image.png

TrackingProvider

System.Activities.Tracking.TrackingProvider

image.png

 


跟踪记录 TrackingRecord


跟踪记录[TrackingRecord]

DLL:System.Activities.dll

类名:System.Activities.Tracking.TrackingRecord

 

TrackingRecord为[Abstract],WF4自带了以下功能[TrackingRecord]

020510_0632_WF403.png

 

CustomTrackingRecord

可在Activity中使用[context.Track(CustomTrackingRecord)]方式添加自定义跟踪记录















 

 


跟踪配置 TrackingProfile


跟踪配置[TrackingProfile]

DLL:System.Activities.dll

类名:System.Activities.Tracking.TrackingProfile

 

image.png

Queries类型为[System.Collections.ObjectModel.Collection<System.Activities.Tracking.TrackingQuery>],,WF4自带了以下功能[TrackingQuery]

 

工作流追踪包括两个主要组件:追踪参与和追踪配置。追踪配置定义了您希望运行时需要追踪的事件和数据,配置(Profiles)包括以下三种重要的查询类型:

 

 

 

image.png

 

 

ActivityStateQuery

用于指定活动的状态(如关闭)、提取数据的变量和参数

 

[States属性]:由System.Activities.Tracking.ActivityStates的[Fieldes]提供

image.png

WorkflowInstanceQuery

用于指定工作流事件

 

[States属性]:由System.Activities.Tracking.WorkflowInstanceStates的[Fieldes]提供

image.png

CustomTrackingQuery

用于指定对追踪数据的明确调用,常用语自定义的活动中

 

 

 

 

 


跟踪参与者TrackingParticipant


跟踪参与者 [TrackingParticipant]

DLL:System.Activities.dll

类名:System.Activities.Tracking.TrackingProfile

abstract

image.png

要自定义[跟踪参与者]要从该类继承

 

 

 


自定义跟踪参与者


例子下载:

http://files.cnblogs.com/foundation/CustomTrackingSample.rar

自定义跟踪参与者

public class myTrackingParticipant : System.Activities.Tracking.TrackingParticipant

{

private const String participantName = "wxwinter_myTrackingParticipant";

 

public myTrackingParticipant()

{

Console.WriteLine( "{0} Created", participantName);

}

 

 

protected override void Track(System.Activities.Tracking.TrackingRecord record, TimeSpan timeout)

{

Console.Write( "{0} emitted trackRecord: {1} Level: {2}, RecordNumber: {3}", participantName, record.GetType().FullName, record.Level, record.RecordNumber);

 

System.Activities.Tracking.WorkflowInstanceRecord workflowInstanceRecord = record as System.Activities.Tracking.WorkflowInstanceRecord;

if (workflowInstanceRecord != null)

{

Console.WriteLine( " Workflow InstanceID: {0} Workflow instance state: {1}", record.InstanceId, workflowInstanceRecord.State);

}

 

System.Activities.Tracking.ActivityStateRecord activityStateRecord = record as System.Activities.Tracking.ActivityStateRecord;

if (activityStateRecord != null)

{

IDictionary<Stringobject> variables = activityStateRecord.Variables;

 

StringBuilder vars = new StringBuilder();

 

if (variables.Count > 0)

{

vars.AppendLine("\n\tVariables:");

foreach (KeyValuePair<stringobject> variable in variables)

{

vars.AppendLine(String.Format( "\t\tName: {0} Value: {1}", variable.Key, variable.Value));

}

}

Console.WriteLine( " :Activity DisplayName: {0} :ActivityInstanceState: {1} {2}", activityStateRecord.Activity.Name, activityStateRecord.State, ((variables.Count > 0) ? vars.ToString() : String.Empty));

}

 

System.Activities.Tracking.CustomTrackingRecord customTrackingRecord = record as System.Activities.Tracking.CustomTrackingRecord;

if ((customTrackingRecord != null) && (customTrackingRecord.Data.Count > 0))

{

Console.WriteLine("\n\tUser Data:");

foreach (string data in customTrackingRecord.Data.Keys)

{

Console.WriteLine(" \t\t {0} : {1}", data, customTrackingRecord.Data[data]);

}

}

Console.WriteLine();

 

}

}

 

定义Profile

public class myTrackingTools

{

public static System.Activities.Tracking.TrackingParticipant getTracking()

{

//(1) TrackingProfile

System.Activities.Tracking.TrackingProfile trackingProfile = new System.Activities.Tracking.TrackingProfile();

trackingProfile.Name = "wxwinterTrackingProfile";

 

//(1.1)

System.Activities.Tracking.CustomTrackingQuery customQuery = new System.Activities.Tracking.CustomTrackingQuery();

customQuery.Name = "*";

customQuery.ActivityName = "*";

 

//(1.2)

System.Activities.Tracking.WorkflowInstanceQuery instanceQuery = new System.Activities.Tracking.WorkflowInstanceQuery();

instanceQuery.States.Add(System.Activities.Tracking.WorkflowInstanceStates.Aborted);

instanceQuery.States.Add(System.Activities.Tracking.WorkflowInstanceStates.Canceled);

instanceQuery.States.Add(System.Activities.Tracking.WorkflowInstanceStates.Completed);

instanceQuery.States.Add(System.Activities.Tracking.WorkflowInstanceStates.Idle);

instanceQuery.States.Add(System.Activities.Tracking.WorkflowInstanceStates.Persisted);

instanceQuery.States.Add(System.Activities.Tracking.WorkflowInstanceStates.Resumed);

instanceQuery.States.Add(System.Activities.Tracking.WorkflowInstanceStates.Started);

instanceQuery.States.Add(System.Activities.Tracking.WorkflowInstanceStates.Suspended);

instanceQuery.States.Add(System.Activities.Tracking.WorkflowInstanceStates.Terminated);

instanceQuery.States.Add(System.Activities.Tracking.WorkflowInstanceStates.UnhandledException);

instanceQuery.States.Add(System.Activities.Tracking.WorkflowInstanceStates.Unloaded);

instanceQuery.States.Add(System.Activities.Tracking.WorkflowInstanceStates.Unsuspended);

 

//(1.3)

System.Activities.Tracking.ActivityStateQuery activityQuery = new System.Activities.Tracking.ActivityStateQuery();

activityQuery.ActivityName = "*";

activityQuery.States.Add("*"); // System.Activities.Tracking.ActivityStates.Executing // System.Activities.Tracking.ActivityStates.Canceled

 

activityQuery.Variables.Add("*");

activityQuery. Arguments.Add("*");

 

//(1.4)

trackingProfile.Queries.Add(customQuery);

trackingProfile.Queries.Add(instanceQuery);

trackingProfile.Queries.Add(activityQuery);

 

 

//(2)

myTrackingParticipant myTracking = new myTrackingParticipant();

myTracking.TrackingProfile = trackingProfile;

 

return myTracking;

}

}

 

具有CustomTrackingRecord功能的Activity

public sealed class myActivity : CodeActivity

{

protected override void Execute(CodeActivityContext context)

{

Console.WriteLine("myActivity Execute");

 

System.Activities.Tracking.CustomTrackingRecord myRecord = new System.Activities.Tracking.CustomTrackingRecord("myActivity_CustomTrackingRecord");

 

myRecord.Data.Add("wxd"12345);

 

myRecord.Data.Add("wxwinter""lzm");

 

context.Track(myRecord);

 

}

}

 

 

使用

工作流

image.png

宿主

class Program

{

static void Main(string[] args)

{

System.Console.WindowWidth = 150;

 

//-----------------------------------------------------------------------------------

//WorkflowApplication

WorkflowApplication instance = new WorkflowApplication(new testWorkflow());

 

instance.Extensions.Add(myTrackingTools.getTracking());

 

instance.Run();

 

//------------------------------------- or ------------------------------------------

//WorkflowInvoke

// WorkflowInvoker invoker = new WorkflowInvoker(new testWorkflow());

 

// invoker.Extensions.Add(myTrackingTools.getTracking());

 

// invoker.Invoke();

//---------------------------------------------------------------------------------

 

System.Console.Read();

}

 

}

结果

image.png

 

 


EtwTrackingParticipant


 

[EtwTrackingParticipant]:(ETW:Enterprise Trace for Windows)

DLL:System.Activities.dll

类名:ystem.Activities.Tracking.EtwTrackingParticipant

image.png

ETW是Windows里本地组件的一个追踪系统,由操作系统中的包括驱动程序、其它核心级代码等很多组件和服务调用。写入到ETW的数据可以通过定制代码或者诸如即将推出的Windows服务AppFabric等工具来使用。AppFabric将同ETW一起搜集ETW数据并将它存储到SQL数据库。

 


#转载请注明出处 www.skcircle.com 《少有人走的路》勇哥的工业自动化技术网站。如果需要本贴图片源码等资源,请向勇哥索取。
扫码加本站公众号

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

会员中心
搜索
«   2021年2月   »
1234567
891011121314
15161718192021
22232425262728
网站分类
标签列表
最新留言
    热门文章 | 热评文章 | 随机文章
文章归档
友情链接
  • 订阅本站的 RSS 2.0 新闻聚合
  • 扫描加本站机器视觉QQ群,验证答案为:halcon勇哥的机器视觉
  • 扫描加站长微信:站长微信:abc496103864
  • 扫描加站长QQ:
  • 扫描赞赏本站:

Powered By Z-BlogPHP 1.6.0 Valyria

Copyright Your skcircle.com Rights Reserved.

鄂ICP备18008319号


站长QQ:496103864 微信:abc496103864