StateMachineWorkflowInstance(WorkflowRuntime, Guid) Constructor
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Initializes a new instance of the StateMachineWorkflowInstance class.
public:
StateMachineWorkflowInstance(System::Workflow::Runtime::WorkflowRuntime ^ runtime, Guid instanceId);
public StateMachineWorkflowInstance (System.Workflow.Runtime.WorkflowRuntime runtime, Guid instanceId);
new System.Workflow.Activities.StateMachineWorkflowInstance : System.Workflow.Runtime.WorkflowRuntime * Guid -> System.Workflow.Activities.StateMachineWorkflowInstance
Public Sub New (runtime As WorkflowRuntime, instanceId As Guid)
Parameters
- runtime
- WorkflowRuntime
The current workflow runtime.
- instanceId
- Guid
The Guid that indicates the instance of the StateMachineWorkflowActivity.
Exceptions
Examples
The following example shows how to create a new instance of a StateMachineWorkflowInstance object. This example is from the Ordering State Machine SDK sample. For more information, see Ordering State Machine 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);
}