แก้ไข

แชร์ผ่าน


SqlTrackingQueryOptions.WorkflowStatus Property

Definition

Gets or sets the WorkflowStatus value that is used to constrain the set of SqlTrackingWorkflowInstance objects returned by a call to GetWorkflows(SqlTrackingQueryOptions).

public:
 property Nullable<System::Workflow::Runtime::WorkflowStatus> WorkflowStatus { Nullable<System::Workflow::Runtime::WorkflowStatus> get(); void set(Nullable<System::Workflow::Runtime::WorkflowStatus> value); };
public System.Workflow.Runtime.WorkflowStatus? WorkflowStatus { get; set; }
member this.WorkflowStatus : Nullable<System.Workflow.Runtime.WorkflowStatus> with get, set
Public Property WorkflowStatus As Nullable(Of WorkflowStatus)

Property Value

One of the WorkflowStatus values or null (Nothing in Visual Basic). The default is null (Nothing).

Examples

The following example demonstrates setting the WorkflowStatus property. This example is from the Workflow Monitor SDK sample. For more information, see Workflow Monitor Sample.

try
{
    List<SqlTrackingWorkflowInstance> queriedWorkflows = new List<SqlTrackingWorkflowInstance>();
    SqlTrackingQuery sqlTrackingQuery = new SqlTrackingQuery(connectionString);
    SqlTrackingQueryOptions sqlTrackingQueryOptions = new SqlTrackingQueryOptions();
    sqlTrackingQueryOptions.StatusMinDateTime = from.ToUniversalTime();
    sqlTrackingQueryOptions.StatusMaxDateTime = until.ToUniversalTime();
    // If QualifiedName, FieldName, or DataValue is not supplied, we will not query since they are all required to match
    if (!((string.Empty == trackingDataItemValue.QualifiedName) || (string.Empty == trackingDataItemValue.FieldName) || ((string.Empty == trackingDataItemValue.DataValue))))
        sqlTrackingQueryOptions.TrackingDataItems.Add(trackingDataItemValue);

    queriedWorkflows.Clear();

    if ("created" == workflowEvent.ToLower(CultureInfo.InvariantCulture))
    {
        sqlTrackingQueryOptions.WorkflowStatus = WorkflowStatus.Created;
        queriedWorkflows.AddRange(sqlTrackingQuery.GetWorkflows(sqlTrackingQueryOptions));
    }
    else if ("completed" == workflowEvent.ToLower(CultureInfo.InvariantCulture))
    {
        sqlTrackingQueryOptions.WorkflowStatus = WorkflowStatus.Completed;
        queriedWorkflows.AddRange(sqlTrackingQuery.GetWorkflows(sqlTrackingQueryOptions));
    }
    else if ("running" == workflowEvent.ToLower(CultureInfo.InvariantCulture))
    {
        sqlTrackingQueryOptions.WorkflowStatus = WorkflowStatus.Running;
        queriedWorkflows.AddRange(sqlTrackingQuery.GetWorkflows(sqlTrackingQueryOptions));
    }
    else if ("suspended" == workflowEvent.ToLower(CultureInfo.InvariantCulture))
    {
        sqlTrackingQueryOptions.WorkflowStatus = WorkflowStatus.Suspended;
        queriedWorkflows.AddRange(sqlTrackingQuery.GetWorkflows(sqlTrackingQueryOptions));
    }
    else if ("terminated" == workflowEvent.ToLower(CultureInfo.InvariantCulture))
    {
        sqlTrackingQueryOptions.WorkflowStatus = WorkflowStatus.Terminated;
        queriedWorkflows.AddRange(sqlTrackingQuery.GetWorkflows(sqlTrackingQueryOptions));
    }
    else if (("all" == workflowEvent.ToLower(CultureInfo.InvariantCulture)) || string.IsNullOrEmpty(workflowEvent))
    {
        sqlTrackingQueryOptions.WorkflowStatus = WorkflowStatus.Created;
        queriedWorkflows.AddRange(sqlTrackingQuery.GetWorkflows(sqlTrackingQueryOptions));

        sqlTrackingQueryOptions.WorkflowStatus = WorkflowStatus.Completed;
        queriedWorkflows.AddRange(sqlTrackingQuery.GetWorkflows(sqlTrackingQueryOptions));

        sqlTrackingQueryOptions.WorkflowStatus = WorkflowStatus.Running;
        queriedWorkflows.AddRange(sqlTrackingQuery.GetWorkflows(sqlTrackingQueryOptions));

        sqlTrackingQueryOptions.WorkflowStatus = WorkflowStatus.Suspended;
        queriedWorkflows.AddRange(sqlTrackingQuery.GetWorkflows(sqlTrackingQueryOptions));

        sqlTrackingQueryOptions.WorkflowStatus = WorkflowStatus.Terminated;
        queriedWorkflows.AddRange(sqlTrackingQuery.GetWorkflows(sqlTrackingQueryOptions));
    }
    return queriedWorkflows;
}
catch (Exception exception)
{
    throw new Exception("Exception in GetWorkflows", exception);
}

Remarks

SqlTrackingQueryOptions constrains the set of SqlTrackingWorkflowInstance objects returned by a call to SqlTrackingQuery.GetWorkflows to those workflow instances that have the Type specified by WorkflowType, that have the status specified by WorkflowStatus during the period specified by StatusMinDateTime and StatusMaxDateTime, and that have extracted data that matches at least one of the TrackingDataItemValue objects specified by TrackingDataItems.

A workflow instance is considered to have a status that matches WorkflowStatus if the last WorkflowTrackingRecord received for that workflow instance before or during the specified time period has its WorkflowTrackingRecord.TrackingWorkflowEvent property set to a TrackingWorkflowEvent value that maps to the System.Workflow.Runtime.WorkflowStatus value specified by WorkflowStatus. Therefore, the TrackingProfile for the workflow instance must have a WorkflowTrackPoint that is configured for the appropriate System.Workflow.Runtime.Tracking.TrackingWorkflowEvent value. Only TrackingWorkflowEvent values that have been sent in workflow tracking records can be matched. If no workflow tracking records have been sent for the workflow instance, the workflow instance is considered to have a status of WorkflowStatus.Created.

The following table shows the mapping between TrackingWorkflowEvent values and WorkflowStatus values.

TrackingWorkflowEvent value WorkflowStatus value
Aborted Running
Changed Running
Completed Completed
Created Created
Exception Running
Idle Running
Loaded Running
Persisted Running
Resumed Running
Started Running
Suspended Suspended
Terminated Terminated
Unloaded Running

If WorkflowStatus is null (Nothing), the set of SqlTrackingWorkflowInstance objects returned will not be constrained by status; in other words, a SqlTrackingWorkflowInstance object will be returned for any workflow instance that matches the parameters specified by the other properties of SqlTrackingQueryOptions.

Applies to