自定义Tracking


开张那天就被Teddy's Knowledge Base与TerryLee 两位说没条理,不认真,
看了两位的家,真的不错,其实我没搬家前了不错,(是朋友帮整理的(^_^))

从小条理性就不强,上学时写作文总跑题,现在写文章也喜欢乱侃,这不,说"用WF开发大富翁..."又被ccBoy笑话了。还好,各位老大没看见我超级恶搞的技术文章,否则.......各位老大一定吐血

有些懒,不准备写[自定义Tracking],想打个哈哈就过去,没想到让ccBoy揭穿了,看人家的留言都比我的内容多,真不好意思。

用ccBoy为开头,将[自定义Tracking]补上吧
--------------------Begin 引用(ccBoy)--------------
WF中Tracking 是非常有用的,你可以想想WF的工作流引擎是个黑箱子,所有有关工作流实例运行的情况或事件只有WF引擎知道,Hosting如果想知道,那么需要一个查询的界面。Tracking就是这个查询界面,一套API模型,在WF工作流引擎内部有一个Listener监听查询请求,Tracking Profile就是查询的SQL语句,而Tracking Provider只是放查询结果的地方,可以在数据库中也可以在内存或文本中,至于你说的什么触发器这个恐怕太生硬了:) 特别是人机交互(以前的HWS场景)和状态机方式的灵活跳转的工作流场景中,比如查询任务的执行情况,或是某种状态和事件下要怎样,Tracking 是最好帮手,WF把这部分的定制留给了开发人员自己控制了,它只做内核,它的增强版本表现形式就是Biztalk Server的BAM模块,WF的设计更正了Biztalk Server 中HWS的不足,但开发上,从Beta2之后它将Tracking功能的定制放到SDK中了
---------------------End 引用---------------------

对于ccBoy的说明,我画了一个图

U_t.JPG

自写义tracking服务,需要实现TrackingChannel TrackingServic这两个类

实现TrackingChannel (今天是单号,我用C#写)

None.gif public   class  Tracking通道 : TrackingChannel
ExpandedBlockStart.gifContractedBlock.gif    
dot.gif {
InBlock.gif        
private TrackingParameters 被跟踪的实例 = null;
InBlock.gif
InBlock.gif        
//构造-2
InBlock.gif
        protected Tracking通道()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{}
InBlock.gif      
InBlock.gif        
//构造-2
InBlock.gif
        public Tracking通道(TrackingParameters parameters)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
//该参数将得到TrackingParameters
InBlock.gif            
//有被跟踪的实例的信息(很多)
InBlock.gif

InBlock.gif            
this.被跟踪的实例 = parameters;
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
//override
InBlock.gif        
//Tracking runtime调用该方将实例完成的信息向外界抛
InBlock.gif
        protected override void InstanceCompletedOrTerminated()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            Console.WriteLine();
InBlock.gif            Console.WriteLine(
"-------------------------------------");
InBlock.gif            Console.WriteLine(
"实例已完成或终止");
InBlock.gif            Console.WriteLine(
"实例:" + 被跟踪的实例.InstanceId.ToString());
InBlock.gif            Console.WriteLine(
"实例为:" + 被跟踪的实例.WorkflowType.AssemblyQualifiedName);
InBlock.gif            Console.WriteLine(
"-------------------------------------");
InBlock.gif            Console.WriteLine();
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
//override
InBlock.gif        
//Tracking runtime调用该方法发送将监视到的各类tracking records向外界抛出
InBlock.gif
        protected override void Send(TrackingRecord record)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
// 对类型进行一下对象筛选,然后再跟据不同的对象进行不同的输出
InBlock.gif
InBlock.gif            
//筛选实例
InBlock.gif
            if (record is WorkflowTrackingRecord)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                WorkflowTrackingRecord obj1 
= (WorkflowTrackingRecord)record;
InBlock.gif
InBlock.gif                Console.WriteLine();
InBlock.gif                Console.WriteLine(
"-------------------------------------");
InBlock.gif                Console.WriteLine(
"实例记录");
InBlock.gif                Console.WriteLine(
"实例:" + 被跟踪的实例.InstanceId.ToString());
InBlock.gif                Console.WriteLine(
"时间: " + obj1.EventDateTime.ToString());
InBlock.gif                Console.WriteLine(
"实例状态: " + obj1.TrackingWorkflowEvent.ToString());
InBlock.gif                Console.WriteLine(
"-------------------------------------");
InBlock.gif                Console.WriteLine();
ExpandedSubBlockEnd.gif            }

InBlock.gif            
InBlock.gif            
//筛选结点
InBlock.gif
            if (record is ActivityTrackingRecord)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                ActivityTrackingRecord obj2 
= (ActivityTrackingRecord)record;
InBlock.gif
InBlock.gif                Console.WriteLine();
InBlock.gif                Console.WriteLine(
"-------------------------------------");
InBlock.gif                Console.WriteLine(
"Activity记录");
InBlock.gif                Console.WriteLine(
"实例:" + 被跟踪的实例.InstanceId.ToString());
InBlock.gif                Console.WriteLine(
"时间: " + obj2.EventDateTime.ToString());
InBlock.gif                Console.WriteLine(
"Activity名子: " + obj2.QualifiedName.ToString());
InBlock.gif                Console.WriteLine(
"Activity类型: " + obj2.ActivityType);
InBlock.gif                Console.WriteLine(
"信息: " + obj2.ExecutionStatus.ToString());
InBlock.gif                Console.WriteLine(
"-------------------------------------");
InBlock.gif                Console.WriteLine();
ExpandedSubBlockEnd.gif            }

InBlock.gif            
InBlock.gif            
//筛选业务状态点(用户状态点)
InBlock.gif
            if (record is UserTrackingRecord)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                UserTrackingRecord obj3
= (UserTrackingRecord)record;
InBlock.gif
InBlock.gif                Console.WriteLine();
InBlock.gif                Console.WriteLine(
"-------------------------------------");
InBlock.gif                Console.WriteLine(
"用户状态点");
InBlock.gif                Console.WriteLine(
"实例:" + 被跟踪的实例.InstanceId.ToString());
InBlock.gif                Console.WriteLine(
"时间: " + obj3.EventDateTime.ToString());
InBlock.gif                Console.WriteLine(
"产生该记录点所在的Activity: " + obj3.QualifiedName.ToString());          
InBlock.gif                Console.WriteLine(
"所在Activity的类型: " + obj3.ActivityType.FullName.ToString());         
InBlock.gif                Console.WriteLine(
"信息: " + obj3.UserData.ToString());
InBlock.gif
InBlock.gif                
//筛选业务状态点(用户状态点)中的规则
InBlock.gif
                if (obj3.UserData is System.Workflow.Activities.Rules.RuleActionTrackingEvent)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{   RuleActionTrackingEvent obj3_rule = (RuleActionTrackingEvent)obj3.UserData;
InBlock.gif                    Console.WriteLine(
"这是一个用户状态点的规则");
InBlock.gif                    Console.WriteLine(
"规则名: " + obj3_rule.RuleName.ToString());
InBlock.gif                    Console.WriteLine(
"规则状态: " + obj3_rule.ConditionResult.ToString());
InBlock.gif
InBlock.gif                    
//Policy绑定的规则集中的每个规则都会发送一组状态,Policy有点像职责链,具体以后讲
InBlock.gif                    
//Policy规则是自动将信息抛出的,但在类型上算上用户状态
ExpandedSubBlockEnd.gif
                }

InBlock.gif                Console.WriteLine(
"-------------------------------------");
InBlock.gif                Console.WriteLine();
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

ExpandedBlockEnd.gif    }

None.gif

实现TrackingServic(我把筛选也写在类里了)

None.gif public   class  自定义跟踪服务 : TrackingService
ExpandedBlockStart.gifContractedBlock.gif    
dot.gif {
InBlock.gif        
protected override bool TryGetProfile(Type workflowType, out TrackingProfile profile)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
//引擎通过该方法加载监视方案
InBlock.gif            
//可在该方法内为工作流模板与对应的筛选建一字典集合,
InBlock.gif            
//该演示设计成所有工作流都使用同一筛选规则方式
InBlock.gif
InBlock.gif            
//参数:workflowType,传入的类型,用于在字典集合中查找对应的筛选规则
InBlock.gif            
//参数:out profile,传地址抛出筛选规则
InBlock.gif
 
InBlock.gif            profile 
= 生成一个Profile();
InBlock.gif            
return true//表示找到所指定的类型对应的筛选规则
ExpandedSubBlockEnd.gif
        }

InBlock.gif    
InBlock.gif        
protected override TrackingProfile GetProfile(Guid workflowInstanceId)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
//跟据实例查对应的规则
InBlock.gif            
//可用字典集实现
InBlock.gif
            return 生成一个Profile();
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
protected override TrackingProfile GetProfile(Type workflowType, Version profileVersionId)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
//返回指定工作流模板的指定版本号的筛选规则
InBlock.gif            
//参数:profileVersionId,版本号
InBlock.gif            
//可用字典集实现
InBlock.gif
            return 生成一个Profile();
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
protected override bool TryReloadProfile(Type workflowType, Guid workflowInstanceId, out TrackingProfile profile)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
//重载指定工作流模板的筛选规则
InBlock.gif            
//参数:workflowType.,
InBlock.gif            
//参数:workflowInstanceId,
InBlock.gif            
//参数:out  profile,
InBlock.gif
           
InBlock.gif            profile 
= null;
InBlock.gif            
return false;  
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
protected override TrackingChannel GetTrackingChannel(TrackingParameters parameters)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
//用TrackingParameters参数初始化信道
InBlock.gif
            return new Tracking通道(parameters);
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif
InBlock.gif        
// 建立自定义的TrackingProfile  关于自定义TrackingProfile 见相关
InBlock.gif
        private static TrackingProfile 生成一个Profile()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{//一个全监视的profile
InBlock.gif
            TrackingProfile profile = new TrackingProfile();
InBlock.gif            profile.Version 
= new Version("4.3.2.1");
InBlock.gif            ActivityTrackPoint 结点跟踪点对象
= new ActivityTrackPoint();
InBlock.gif            ActivityTrackingLocation location 
= new ActivityTrackingLocation(typeof(Activity));
InBlock.gif            location.MatchDerivedTypes 
= true;
InBlock.gif            
foreach (ActivityExecutionStatus s in Enum.GetValues(typeof(ActivityExecutionStatus)))
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{ location.ExecutionStatusEvents.Add(s); }
InBlock.gif            结点跟踪点对象.MatchingLocations.Add(location);
InBlock.gif            profile.ActivityTrackPoints.Add(结点跟踪点对象);
InBlock.gif            UserTrackPoint 用户跟踪点对象
= new UserTrackPoint();
InBlock.gif            UserTrackingLocation UserTrackingLocation标记
= new UserTrackingLocation();
InBlock.gif            UserTrackingLocation标记.ActivityType 
= typeof(Activity);
InBlock.gif            UserTrackingLocation标记.ArgumentType 
= typeof(object);
InBlock.gif            UserTrackingLocation标记.MatchDerivedArgumentTypes 
= true;
InBlock.gif            UserTrackingLocation标记.MatchDerivedActivityTypes 
= true;
InBlock.gif            用户跟踪点对象.MatchingLocations.Add(UserTrackingLocation标记);
InBlock.gif            profile.UserTrackPoints.Add(用户跟踪点对象);
InBlock.gif            WorkflowTrackPoint 实例跟踪点对象
= new WorkflowTrackPoint();
InBlock.gif            实例跟踪点对象.MatchingLocation 
= new WorkflowTrackingLocation();
InBlock.gif            
foreach (TrackingWorkflowEvent workflowEvent in Enum.GetValues(typeof(TrackingWorkflowEvent)))
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{ 实例跟踪点对象.MatchingLocation.Events.Add(workflowEvent); }
InBlock.gif            profile.WorkflowTrackPoints.Add(实例跟踪点对象);
InBlock.gif            
return profile;
ExpandedSubBlockEnd.gif }

ExpandedBlockEnd.gif }

None.gif








 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值