Windows Workflow Foundation 4.0 和跟踪

发布于 2024-08-17 14:42:22 字数 218 浏览 4 评论 0原文

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

I'm working with the Beta 2 version of Visual Studio 2010 to get some advanced learning using WF4. I've been working with the SqlTracking Sample in the WF_WCF_Samples SDK, and have gotten a pretty good understanding of how to emit and store tracking data in a SQL Database, but haven't seen anything on how to query the data when needed. Does anyone know if there are any .Net classes that are to be used for querying the tracking data, and if so are there any known samples, tutorials, or articles that describe how to query the tracking data?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

孤独患者 2024-08-24 14:42:22

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

According to Matt Winkler, from the Microsoft WF4 Team, there isn't any built in API for querying the tracking data, the developer must write his/her own.

就像说晚安 2024-08-24 14:42:22

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

您必须在 %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仅适用于持久性数据库。

Old question, I know, but there is actually a more or less official API in AppFabric: Windows Server AppFabric Class Library

You'll have to find the actual DLL's in %SystemRoot%\AppFabric (after installing AppFabric, of course). Pretty weird place to put it.

The key classes to look are at are SqlInstanceQueryProvider, InstanceQueryExecuteArgs. The query API is asynchronous and can be used something like this (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;
}

And just to clarify - this does NOT give you access to the tracking data, which are stored in the Monitoring Database. This API is only for the Persistence Database.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文