none
WF SqlTrackingService 详解(2) RRS feed

  • 常规讨论

  • 5.
    拖一个codeAcivity到workflow,并改名为working


    6.
    给code Acivity加入代码
    Private
    void working_ExecuteCode (object sender, EventArgs e)
    {

    Console.WriteLine("Here in working_ExecuteCode.");
    }

    7.
    在Program.cs中加入static 变量

    class Program


    {



    static string connectionString = "Initial Catalog=TrackingStore;Data Source=localhost; Integrated Security=SSPI;";


    ……


    }

    7.
    修改Main函数如下:



    static void Main(string[] args)



    {



    using(WorkflowRuntime workflowRuntime = new WorkflowRuntime())



    {



    SqlTrackingService trackingServer = new SqlTrackingService(connectionString);




    workflowRuntime.AddService(trackingServer);




    AutoResetEvent waitHandle = new AutoResetEvent(false);



    workflowRuntime.WorkflowCompleted += delegate(object sender, WorkflowCompletedEventArgs e) {waitHandle.Set();};



    workflowRuntime.WorkflowTerminated += delegate(object sender, WorkflowTerminatedEventArgs e)



    {



    Console.WriteLine(e.Exception.Message);




    waitHandle.Set();



    };




    WorkflowInstance instance = workflowRuntime.CreateWorkflow(typeof(DefaultSQLServices.Workflow99));



    instance.Start();




    instance.Suspend("Reason we are suspending the workflow.");




    instance.Resume();


    waitHandle.WaitOne();



    //
    取得Insance的运行情况



    GetInstanceTrackingEvents(instance.InstanceId);



    Console.WriteLine("Workflow Completed - press ENTER to continue");



    Console.Read();



    }




    }

    8.
    完成函数GetInstanceTrackingEvents


    static void GetInstanceTrackingEvents(Guid instanceId)



    {



    Console.WriteLine("\r\nInstance Tracking Events :");




    SqlTrackingQuery sqlTrackingQuery = new SqlTrackingQuery(connectionString);



    SqlTrackingWorkflowInstance sqlTrackingWorkflowInstance;



    sqlTrackingQuery.TryGetWorkflow(instanceId, out sqlTrackingWorkflowInstance);




    try



    {



    foreach (WorkflowTrackingRecord workflowTrackingRecord in sqlTrackingWorkflowInstance.WorkflowEvents)



    {



    Console.WriteLine("EventDescription : {0}
    DateTime : {1}"
    ,



    workflowTrackingRecord.TrackingWorkflowEvent, workflowTrackingRecord.EventDateTime);



    }



    }



    catch (Exception)



    {



    Console.WriteLine("No Instance Tracking Events Found");



    }



    }

    8.
    GetInstanceTrackingEvents函数,主要使用SqlTrackingQuery类,取得WorkflowInstance的运行情况
    9.
    运行后显示情况如下:


    10.涉及的表


    表名称
    用途
    备注
    TrackingProfile
    存储Tracking 的配置,现在使用的是缺省配置,不需要设置.

    vw_Workflow
    Workflow的基本信息

    vw_WorkflowInstance
    已经或者正在运行的WorkflowInstance

    vw_Activity
    Activity的基本信息

    vw_ActivityInstance
    已经或者正在运行的ActivityInstance




    11.总结:这是最简单的对workflow的跟踪,笔者将继续完成其他的部分。

    参考资料
    WinFx
    Windows workflow foundation
    Hands-On Lab 03
    转自:http://blog.csdn.net/mnm0756/
    2009年6月25日 8:01