簡體   English   中英

WF通過加載和卸載訪問工作流實例變量

[英]WF Access the workflow instance variables from load and unload

在workflowRuntime_WorkflowUnloaded和Loaded等中。我能獲得的唯一沒用的是工作流程實例ID。 我希望能夠訪問根活動上的某些DP,每當我執行GetWorkFlowDefintion()並強制轉換為根活動時,我傳入的所有屬性都為null。

您必須使用TrackingServices以獲得不僅僅是基本信息的信息。 參見http://msdn.microsoft.com/zh-cn/library/ms735887(VS.85).aspx

我們使用默認的sqlTrackingService,將工作流托管在Windows服務中,使用wcf公開,它是狀態機工作流。

這是我們在一種情況下使用它的方式:

SqlTrackingWorkflowInstance instance = null;
//wfServiceHost is an instance of WorkflowServiceHost
WorkflowRuntimeBehavior workflowRuntimeBehaviour = wfServiceHost.Description.Behaviors.Find<WorkflowRuntimeBehavior>();
WorkflowRuntime wfRuntime = workflowRuntimeBehaviour.WorkflowRuntime;

if (wfRuntime != null)
{
        SqlTrackingService trackingService = (SqlTrackingService)wfRuntime.GetService(typeof(SqlTrackingService));
        SqlTrackingQuery sqlTrackingQuery = new SqlTrackingQuery(trackingService.ConnectionString);

         sqlTrackingQuery.TryGetWorkflow(instanceId, out instance);
}

好的,我已經設法使用上述方法檢索工作流程中的業務數據(即ID),但是我必須添加一個

this.TrackData("name", myObject)

進入我在工作流程中的初始活動。

那時,我可以通過以下代碼從myObjectJob )獲取ID。 pp!

foreach (UserTrackingRecord userTrackingRecord in
    sqlTrackingWorkflowInstance.UserEvents)
{
    Console.WriteLine("Key : {0}  Data : {1}",
        userTrackingRecord.UserDataKey,
        userTrackingRecord.UserData.ToString());
    if (userTrackingRecord.UserDataKey == "Job")
    {
        OrderRequest request = userTrackingRecord.UserData as OrderRequest;
        if (request != null)
        {
            Console.WriteLine("\nJob ID: {0}", request.JobID);
        }
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM