2010-01-15 102 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仅用于持久性数据库。

相关问题