Search

Search:

Namespace:

Search Result
.

Whenever the execution status of an activity changes, the WorkflowInstance emits an activity status event to the runtime tracking infrastructure. An ActivityTrackPoint defines a point of interest in the potential execution path of a workflow, qualified by such an activity status event. An ActivityTrackPoint contains locations that are included in matching, locations that are excluded from matching, and the data that should be extracted from the WorkflowInstance when the track point is matched. You can add an ActivityTrackPoint to ActivityTrackPoints to instruct the runtime tracking infrastructure to send an ActivityTrackingRecord to the tracking service when the specified set of activity status events occur. A single ActivityTrackPoint may be matched at multiple points in the workflow instance.

.
Summary
.

http://msdn.microsoft.com/en-us/library/system.workflow.runtime.workflowinstance.applyworkflowchanges.aspx

.
        Dim state As New SendSomeDataState(WorkflowEnvironment.WorkflowInstanceId, theData)
.

The typical use of the CodeActivity is to examine WorkflowInstance state, and change local variables and messages.

.

To ensure consistency between the WorkflowInstance and the database being updated the TransactionScopeActivity is adorned with the PersistOnCloseAttribute. When the TransactionScopeActivity is used the WorkflowRuntime must be configured with a WorkflowPersistenceService. This could be the build in SqlWorkflowPersistenceService or another custom WorkflowPersistenceService.

.

A host can subscribe to the workflow runtime's WorkflowSuspended event and retrieve the error message using the Error property of the WorkflowSuspendedEventArgs parameter. Another property of this parameter is the WorkflowInstance property. A host can recommence execution using the Resume method of the WorkflowInstance class, or bring about a sad, but early ending with the Terminate method.

.
  id = this.WorkflowInstanceId;
.

Most of the time there isn't much of a problem when developing custom activities and workflow persistence. After all when an external system send a message, the service retrieves this, extracts the WorkflowInstanceId and queue name and signals the workflow. Everything's works just fine and if the workflow runtime restarts the message received will cause the workflow to be reloaded.

.

TimerEventSubscription item = new TimerEventSubscription(WorkflowInstanceId, DateTime.UtcNow);

.

http://msdn.microsoft.com/en-us/library/system.workflow.runtime.workflowinstance.enqueueitem.aspx

.

http://msdn.microsoft.com/en-us/library/system.workflow.runtime.workflowinstance.enqueueitemonidle.aspx

.

Dim workflowInstance As WorkflowInstance

.
        workflowInstance = workflowRuntime.CreateWorkflow(reader)
.
        workflowInstance.Start()
.
        Dim state As New SendSomeDataState(WorkflowEnvironment.WorkflowInstanceId, theData)
.

A host can subscribe to the workflow runtime's WorkflowSuspended event and retrieve the error message using the Error property of the WorkflowSuspendedEventArgs parameter. Another property of this parameter is the WorkflowInstance property. A host can recommence execution using the Resume method of the WorkflowInstance class, or bring about a sad, but early ending with the Terminate method.

.
  id = this.WorkflowInstanceId;
.

Part of the WorkflowInstance object.

.

http://msdn.microsoft.com/en-us/library/system.workflow.runtime.workflowinstance.getworkflownexttimerexpiration.aspx

.

http://msdn2.microsoft.com/en-us/library/system.workflow.runtime.workflowinstance.getworkflowqueuedata.aspx

.
Summary
The LoadWorkflowInstanceState method of the WorkflowPersistenceService class is used to load a saved workflow instance back into memory
.
        WorkflowInstance instance = workflowRuntime.CreateWorkflow(typeof(WorkflowConsoleApplication1.Workflow1));
.

The important part if to use the WorkflowInstance GetWorkflowNextTimerExpiration function that returns the DateTime (in UTC) that the next timer expires. If thers is no pending DelayActivity it returns December 31th 9999 23:59:59.

.
Summary
.

It is often beneficial for a WorkflowInstance state to be saved to disk. Not only when a workflow is long running is this required but also to ensure consistency when performing transactions.

.
  • Before the WorkflowInstance is completed.
.
  • Before the WorkflowInstance is terminated.
.
  • When the WorkflowInstance Unload or TryUnload functions are called.
.
  • When the WorkflowInstance goes idle and the UnloadOnIdle property if the WorkflowPersistenceService is set.
.

When one of these PersistencePoints is reached the WorkflowRuntime will call the WorkflowPersistenceService SaveWorkflowInstanceState function to persist the workflow.

.

Part of the StateMachineWorkflowInstance class.

.

StateMachineWorkflowInstance instance = new StateMachineWorkflowInstance(runtime, instanceId);

.

So what gives? Well the WCF service needs to know which workflow the request needs to be routed to and uses the WorkflowInstanceId to do so. When you create a proxu and do the first call this WorkflowInstanceId is automatically added and resent with the next request. So we need to retrieve this WorkflowInstanceId and, when we create the second proxy object, add it again. Doing so turns out to be pretty simple and only takes a few extra lines of code:

.

So what do we actually need to change an executing WorkflowInstance? The class to start with is the WorkflowChanges. This WorkflowChanges object has a property named TransientWorkflow that lets us get to the actual workflow definition. Now we can use this to add the activities we want. In fact we can also change or remove activities as well.

.

The most important thing to notice is that the ApplyWorkflowChanges is the one that actually changes the running WorkflowInstance. And if the update fails for some reason an WorkflowValidationFailedException is thrown with a property Errors that is a collection of ValidationError objects.

.
        WorkflowInstance instance = workflowRuntime.CreateWorkflow(
.

Member of the StateMachineWorkflowInstance class.

.

When working with state machine workflow's the SetStateActivity is one of the more important activities to use. The main reason is that is the one used to transition from one state to another. You can actually transition state in a different way as well using the StateMachineWorkflowInstance.SetState() function but the SetStateActivity is by far the most often used.

.
                Dim workflowInstance As WorkflowInstance
.
                workflowInstance = workflowRuntime.CreateWorkflow(GetType(Workflow1))
.
                workflowInstance.Start()
.
                WorkflowInstance instance = workflowRuntime.CreateWorkflow(typeof(Workflow1));
.

If you want to see the tracking data itself you might start running SQL queries against the database. An easier way is to use the SqlTrackingQuery.TryGetWorkflow() to load an SqlTrackingWorkflowInstance instance with the tracking data. The SqlTrackingWorkflowInstance object as properties to inspect the workflow status, the workflow events, the activity events and more.

.

SqlTrackingQuery provides methods and properties that you can use in order to access certain kinds of tracking data stored in a SQL database by the SqlTrackingService. Access to this data is provided through SqlTrackingWorkflowInstance objects. You can call TryGetWorkflow to try to get a SqlTrackingWorkflowInstance for a specific workflow instance. You can call GetWorkflows to get a collection of SqlTrackingWorkflowInstance objects that correspond workflow instances that have tracking data that matches a set of query parameters contained in a SqlTrackingQueryOptions that is passed as a parameter to the method. See the SqlTrackingWorkflowInstance class for more information about the kind of tracking data available and see the SqlTrackingQueryOptions class for more information about the kind of queries that can be performed.

.

Use the PartitionCompletedWorkflowInstances stored proc to move data from the live table to the partitioned tables

.

Is a member of the StateMachineWorkflowInstance object.

.
        WorkflowInstance instance = workflowRuntime.CreateWorkflow(typeof(WorkflowConsoleApplication2.Workflow1));
.
    StateMachineWorkflowInstance instance = new StateMachineWorkflowInstance(runtime, e.WorkflowInstance.InstanceId);
.

http://msdn2.microsoft.com/en-us/library/system.workflow.activities.statemachineworkflowinstance.aspx

.
Summary
.

To ensure consistency between the WorkflowInstance and the database being updated the TransactionScopeActivity is adorned with the PersistOnCloseAttribute. When the TransactionScopeActivity is used the WorkflowRuntime must be configured with a WorkflowPersistenceService. This could be the build in SqlWorkflowPersistenceService or another custom WorkflowPersistenceService.

.
        Guid instanceId = WorkflowEnvironment.WorkflowInstanceId;
.
        WorkflowInstance instance = GetWorkflow(instanceId);
.
    private WorkflowInstance GetWorkflow(Guid instanceId)
.
        WorkflowInstance result = Runtime.GetWorkflow(instanceId);
.
    WorkflowInstance instance = RecorderManager.CreateMockedObject<WorkflowInstance>();
.
        Guid instanceId = WorkflowEnvironment.WorkflowInstanceId;
.

The most important thing here is that we can mock the WorkflowInstance object just as easy as the ActivityExecutionContext in the previous tests. I am actually telling TypeMock to wait for 10 seconds with the [VerifyMocks(10000)] attribute. This allows the delay in the service to remain there and still check if the expected response was queued. One thing to note is that I had to create an extra GetWorkflow() function to wrap the real function on the WorkflowRuntime object. I was unable to mock the latter however I am unsure why this is the case and if mocking it is really impossible.

.

Most people consider unit testing of custom workflow activities to pretty much impossible. Sure you can create a dummy test workflow containing your new activity, new up a WorkflowRuntime, create a WorkflowInstance and start it. But just think about all the dependencies here with the extra dummy workflow and the complete WorkflowRuntime with all its dependencies. Hardly a unit test for an activity but more like an integration test. Now there is nothing wrong with integration tests, they are very useful and necessary, but they do not give the speedy and dynamic test coverage you expect and need from a unit test.

.

Setting the WaitForIdle property to true result in the WorkflowInstance EnqueueItemOnIdle being called instead of the EnqueueItem.

.

A workflow instance is considered Aborted when the WorkflowRuntime engine throws away the in-memory instance. This is done by calling WorkflowInstance.Abort. Aborted workflow instances can be resumed from their last persistence point by calling WorkflowInstance.Resume. Aborting workflows is only valid when there is a persistence service. Aborting workflows is used in extreme situations where applications decide to discard all the work that is done from the last persistence point till abort is called.

.

You can abort a workflow using the WorkflowInstance Abort function.

.
Summary
A WorkflowInstance has just been created.
.

Most often used from an external service called from an CallExternalMethodActivity. It provides access to the calling WorkflowInstanceId and WorkBatch.

.

The WorkflowInstance is idle when it is waiting on an external event (e.g. timer, message, etc) to continue execution. An application can set their Unload policy to unload the workflow instance from memory when it is idle in order to save system resources.

.
Summary
A WorkflowInstance is an actual executing copy of a WorkflowDefinition.
.

Use the WorkflowRuntime CreateWorkflow function to create the WorkflowInstance or the GetWorkflow function to retreive an existing.

. .

http://msdn2.microsoft.com/en-us/library/system.workflow.runtime.workflowinstance.aspx

.

workflowInstance = workflowRuntime.CreateWorkflow(GetType(Workflow1), parameters)

.

workflowInstance = workflowRuntime.CreateWorkflow(GetType(Workflow1), parameters.GetParameters())

.

workflowInstance = workflowRuntime.CreateWorkflow(GetType(Workflow1), parameters.GetParameters())

.

workflowInstance.FirstName = "Maurice"

.

workflowInstance.LastName = "de Beijer"

.

workflowInstance.Start()

.

The workflowInstance variable doesn’t point to an object of the workflow type itself but to a wrapper containing the workflow definition. So it simply doesn’t have the properties you defined in the workflow.

.
  • LoadWorkflowInstanceState
.
.

Use the RaiseServicesExceptionNotHandledEvent function to notify the WorkflowRuntime that an exception for a specific WorkflowInstance was unhandled.

.
Summary
Occurs when the WorkflowInstance ends in an abnormal way.
.

Can be the result of either a TerminateActivity, calling WorkflowInstance.Terminate() or an unhandled exception.

.

Dim workflowInstance As WorkflowInstance

.
        workflowInstance = workflowRuntime.CreateWorkflow(reader)
.
        workflowInstance.Start()
.

Well that is because the workflow engine adds a cookie named WF_WorkflowInstanceId to the response used to connect the second call to the same workflow. Alright the solution is simple; add the following to the web service before the first call: