WF4.0 Beta1 自定义跟踪
WF4.0 Beta1 自定义跟踪
public class myTracking : TrackingParticipant { public override void Track(TrackingRecord record, TimeSpan timeout) {
Console.WriteLine("*"); Console.WriteLine("RecordNumber:[{2}], Track:[{0}],Level:[{1}]", record.GetType().FullName, record.Level, record.RecordNumber); Console.WriteLine("------------------------ content ----------------------------"); //-------------------WorkflowInstanceRecord--------------------------- WorkflowInstanceRecord workflowInstanceRecord = record as WorkflowInstanceRecord; if (workflowInstanceRecord != null) { Console.WriteLine("[workflowInstanceRecord]"); Console.WriteLine("InstanceID: {0} , instance state: {1}", record.InstanceId, workflowInstanceRecord.State);
}
//-------------ActivityTrackingRecord----------------------- ActivityTrackingRecord activityTrackingRecord = record as ActivityTrackingRecord; if (activityTrackingRecord != null) { Console.WriteLine("[ActivityTrackingRecord]"); Console.WriteLine("ActivityDisplayName: {0} :ActivityInstanceState: {1} ", activityTrackingRecord.Name, activityTrackingRecord.State);
IDictionary<String, object> variables = activityTrackingRecord.Variables; if (variables.Count > 0) { Console.WriteLine("Variables:"); foreach (KeyValuePair<string, object> variable in variables) { Console.WriteLine("key: {0} , Value: {1}", variable.Key, variable.Value); } }
}
//----------------UserTrackingRecord---------------------- UserTrackingRecord userTrackingRecord = record as UserTrackingRecord; if ((userTrackingRecord != null) && (userTrackingRecord.Data.Count > 0)) { Console.WriteLine("[UserTrackingRecord]");
foreach (string data in userTrackingRecord.Data.Keys) { Console.WriteLine( "{0} : {1}", data, userTrackingRecord.Data[data]); }
}
//---------------End---------------------- Console.WriteLine("======================== end ==============================="); Console.WriteLine("");
} } |
一个具备UserTrackingRecord的Activity
public class myActivity : CodeActivity { protected override void Execute(CodeActivityContext context) { Console.WriteLine("myActivity Execute");
UserTrackingRecord userRecord = new UserTrackingRecord("myUserTrackingRecord");
userRecord.Data.Add("wxd", 12345);
userRecord.Data.Add("wxwinter", "lzm");
context.Track(userRecord); } } |
一个用于测试的流程
使用
class Program { static void Main(string[] args) {
System.Console.WindowWidth = 120;
myTracking tracking = new myTracking();
tracking.TrackingProfile = getTrackingProfile();
WorkflowInstance myInstance = new WorkflowInstance(new myTestWorkflow());
myInstance.Extensions.Add(tracking);
myInstance.Run();
System.Console.Read(); }
static TrackingProfile getTrackingProfile() {
TrackingProfile myTrackingProfile = new TrackingProfile(); myTrackingProfile.Name = "wxwinterTrackingProfile";
// UserTrackingQuery myUserTrackingQuery = new UserTrackingQuery(); myUserTrackingQuery.Name = "*"; myUserTrackingQuery.ActivityName = "*";
// WorkflowInstanceQuery myWorkflowInstanceQuery = new WorkflowInstanceQuery(); myWorkflowInstanceQuery.States.Add(WorkflowInstanceRecord.AbortedEvent); myWorkflowInstanceQuery.States.Add(WorkflowInstanceRecord.CompletedEvent); myWorkflowInstanceQuery.States.Add(WorkflowInstanceRecord.DeletedEvent); myWorkflowInstanceQuery.States.Add(WorkflowInstanceRecord.IdleEvent); myWorkflowInstanceQuery.States.Add(WorkflowInstanceRecord.PersistedEvent); myWorkflowInstanceQuery.States.Add(WorkflowInstanceRecord.ResumedEvent); myWorkflowInstanceQuery.States.Add(WorkflowInstanceRecord.StartedEvent); myWorkflowInstanceQuery.States.Add(WorkflowInstanceRecord.UnhandledExceptionEvent); myWorkflowInstanceQuery.States.Add(WorkflowInstanceRecord.UnloadedEvent);
// ActivityQuery myActivityQuery = new ActivityQuery(); myActivityQuery.ActivityName = "*"; myActivityQuery.States.Add("*"); myActivityQuery.EnvironmentQueries.Add("*"); myActivityQuery.VariableQueries.Add(new VariableQuery{VariableName ="*"});
// myTrackingProfile.Queries.Add(myActivityQuery); myTrackingProfile.Queries.Add(myUserTrackingQuery); myTrackingProfile.Queries.Add(myWorkflowInstanceQuery);
// return myTrackingProfile; } } |