2010-01-15 104 views
2

我正在使用Visual Studio 2010的Beta 2版本來獲得一些使用WF4的高級學習。我一直在使用WF_WCF_Samples SDK中的SqlTracking示例,並且已經很好地理解如何在SQL數據庫中發送和存儲跟蹤數據,但是在需要時沒有看到如何查詢數據。有沒有人知道是否有任何.Net類用於查詢跟蹤數據,如果有的話,是否有任何已知的示例,教程或文章描述瞭如何查詢跟蹤數據?Windows Workflow Foundation 4.0和跟蹤

回答

1

根據馬特·溫克勒,從Microsoft WF4團隊,沒有任何內置的API進行查詢跟蹤數據,開發者必須寫他/她自己的。

0
+0

感謝您的帖子,但我想我很困惑。它在我看來,上面的鏈接都是如何發出跟蹤數據的樣本,然後將其存儲在某處(如數據庫或事件日誌)。我正在尋找一種機制來查詢存儲後的數據。在.Net 3.5中,我們使用了SqlTrackingQuery,並且它是TryGetWorkflow()方法來完成此操作。這就是我試圖找到的那種東西 - 一種查詢存儲數據的機制。也許這不包括在WF4中,我可能不得不編寫自己的查詢。 – 2010-01-15 16:20:56

+0

與WorkflowInstanceQuery沒有關係嗎?我沒有深入研究wf4 ... – 2010-01-15 16:35:07

+0

這可能是我無法確定的,因爲文檔數量有限,但至少在跟蹤配置文件中使用該類來發射跟蹤記錄,然後由TrackingParticipant使用它將其存儲在某處。它可能,也可能不會被用來查詢跟蹤記錄,一旦它們被存儲 - 就像我說的,由於缺乏文檔,很難說。 – 2010-01-15 17:36:14

0

老問題,我知道,但實際上是有或多或少的官方API中的AppFabric:當然Windows Server AppFabric Class Library

你必須找到實際的DLL文件位於%SystemRoot%\的AppFabric(安裝後的AppFabric, )。很奇怪的地方放它。

要查看的關鍵類是SqlInstanceQueryProvider,InstanceQueryExecuteArgs。查詢API是異步的,可以使用像這樣(C#):

public InstanceInfo GetWorkflowInstanceInformation(Guid workflowInstanceId, string connectionString) 
{ 
    var instanceQueryProvider = new SqlInstanceQueryProvider(); 

    // Connection string to the instance store needs to be set like this: 
    var parameters = new NameValueCollection() 
    { 
     {"connectionString", connectionString} 
    }; 
    instanceQueryProvider.Initialize("Provider", parameters); 

    var queryArgs = new InstanceQueryExecuteArgs() 
    { 
     InstanceId = new List<Guid>() { workflowInstanceId } 
    }; 

    // Total ruin the asynchronous advantages and use a Mutex to lock on. 
    var waitEvent = new ManualResetEvent(false); 
    IEnumerable<InstanceInfo> retrievedInstanceInfos = null; 
    var query = instanceQueryProvider.CreateInstanceQuery(); 
    query.BeginExecuteQuery(
     queryArgs, 
     TimeSpan.FromSeconds(10), 
     ar => 
     { 
      lock (synchronizer) 
      { 
       retrievedInstanceInfos = query.EndExecuteQuery(ar).ToList(); 
      } 
      waitEvent.Set(); 
     }, 
     null); 

    var waitResult = waitEvent.WaitOne(5000); 
    if (waitResult) 
    { 
     List<InstanceInfo> instances = null; 
     lock (synchronizer) 
     { 
      if (retrievedInstanceInfos != null) 
      { 
       instances = retrievedInstanceInfos.ToList(); 
      } 
     } 

     if (instances != null) 
     { 
      if (instances.Count() == 1) 
      { 
       return instances.Single(); 
      } 

      if (!instances.Any()) 
      { 
       Log.Warning("Request for non-existing WorkflowInstanceInfo: {0}.", workflowInstanceId); 
       return null; 
      } 

      Log.Error("More than one(!) WorkflowInstanceInfo for id: {0}.", workflowInstanceId); 
     } 
    } 

    Log.Error("Time out retrieving information for id: {0}.", workflowInstanceId); 
    return null; 
} 

而只是爲了澄清 - 這不給你訪問到的跟蹤數據,它們存儲在監控數據庫中。該API僅用於持久性數據庫。

相關問題