private static void enlistInstancesInState(WorkflowInstanceStatus status) { enlistAllScopes(null, (client) => { var cnt = client.Instances.GetCount(); if (cnt > 0) { foreach (var wfInst in client.Instances.Get(0, cnt)) { if (WorkflowInstanceStatus.NotSpecified != status && wfInst.WorkflowStatus == status) traceOutWorkflow(wfInst); else if (WorkflowInstanceStatus.NotSpecified == status) traceOutWorkflow(wfInst); } } }); } /// <summary> /// Enlists all scopes starting at root. /// </summary> /// <param name="scopeRoot">Scope to be enlisted.</param> private static void enlistAllScopes(WorkflowManagementClient client, Action<WorkflowManagementClient> action) { if(client == null) client = getWfMgmClient(null);
if (action != null) action(client); var scopes = client.CurrentScope.GetChildScopes(); foreach (var childScope in scopes) { enlistAllScopes(getWfMgmClient(Path.Combine(m_Root.TrimEnd('/') + childScope.Path)), action); } } /// <summary> /// Creates the instance of the WF-client. /// </summary> private static WorkflowManagementClient getWfMgmClient(string scope) { WorkflowManagementClient client; if (scope == null) client = new WorkflowManagementClient(m_Root); else client = new WorkflowManagementClient(scope); return client; } |