开发者

Windows Workflow Foundation 4.0 and Tracking

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开发者_JS百科 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?


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.


These can help:

  • WorkflowInstanceQuery Class
  • Workflow Tracking and Tracing
  • Tracking Participants in .NET 4 Beta 1


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜