【问题标题】:Windows Workflow Foundation 4.0 and TrackingWindows Workflow Foundation 4.0 和跟踪
【发布时间】:2010-01-15 13:25:00
【问题描述】:

我正在使用 Beta 2 版本的 Visual Studio 2010 来获得一些使用 WF4 的高级学习。我一直在使用 WF_WCF_Samples SDK 中的 SqlTracking 示例,并且非常了解如何在 SQL 数据库中发出和存储跟踪数据,但还没有看到任何关于如何在需要时查询数据的内容。有谁知道是否有任何 .Net 类可用于查询跟踪数据,如果有,是否有任何已知的示例、教程或文章来描述如何查询跟踪数据?

【问题讨论】:

    标签: windows workflow-foundation tracking


    【解决方案1】:

    据微软 WF4 团队的 Matt Winkler 所说,没有任何用于查询跟踪数据的内置 API,开发人员必须自己编写。

    【讨论】:

      【解决方案2】:

      【讨论】:

      • 感谢您的帖子,但我想我很困惑。在我看来,上面的链接都是如何发出跟踪数据然后将其存储在某处(如数据库或事件日志)的示例。我正在寻找一种在数据存储后查询数据的机制。在 .Net 3.5 中,我们使用了 SqlTrackingQuery 及其 TryGetWorkflow() 方法来执行此操作。这就是我想要找到的那种东西——一种查询存储数据的机制。也许 WF4 中不包含这些,我可能必须编写自己的查询。
      • 可能是,由于文档数量有限,我无法确定,但至少,该类在跟踪配置文件中用于发出跟踪记录,可以然后被 TrackingParticipant 用来将它们存储在某个地方。一旦跟踪记录被存储,它可能会也可能不会用于查询跟踪记录——就像我说的那样,由于缺乏文档,很难说清楚。
      【解决方案3】:

      老问题,我知道,但实际上在 AppFabric 中或多或少有一个官方 API:Windows Server AppFabric Class Library

      您必须在 %SystemRoot%\AppFabric 中找到实际的 DLL(当然是在安装 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 仅适用于持久性数据库。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-01-03
        相关资源
        最近更新 更多