Search

Search:

Namespace:

Search Result
.

For activities which fall in category (1) Uninitialize is called immediately after the activity closes. Any primitive activity which does not implement ICompensatableActivity has this behavior. Additionally, any composite activity which has NO children, grandchildren, great grandchildren, etc. which implement ICompensatable will be uninitialized immediately as well. However, if an activity or any of its children or sub children implement ICompensatableActivity then the activity will NOT be Uninitialized until the compensatable activity has either been compensated or has been determined that it cannot ever be compensated (the workflow terminates or completes). For example, if I have the following:

.

Code will uninitialize immediately. MyCompensatableActivity, Sequence, and While will NOT be able to uninitialize until either MyCompensatable activity compensates or the workflow completes and disposes of the compensatable activity.

.
Summary
.

http://msdn.microsoft.com/en-us/library/system.workflow.activities.replicatoractivity.allchildrencomplete.aspx

.

And with this code we are good to go. Running the complete code will show the output below:

.

The complete code in the main module:

.
Summary
.

Triggers the compensation of a completed child Activity that implements the ICompensatableActivity interface.

.
Summary
.

Part of the IPendingWork interface. Called by the WorkBatch after a transaction has completed. The first parameter indicates of the transaction was successful or not.

.

A CompositeActivity manages the execution of its child activities using ActivityExecutionContext class methods and events defined on the Activity class. For example, a child activity is scheduled for execution using the ExecuteActivity of ActivityExecutionContext. A CompositeActivity activity can be notified when a child activity completes its execution by subscribing to the Closed event defined on Activity.

.

A Sequence activity is a composite activity, and can run one or more contained activities. The activities inside a sequence activity will execute one at a time, until the last activity completes. The WhileActivity only permits a single child activity, but if we make the single activity a SequenceActivity, we can drop additional activities inside the sequence activity. All of the children will then run each time the WhileActivity completes an iteration.

.

Imagine we are setting up a workflow that will count employee votes over a period of 30 minutes. We could set the main child activity of the Event Handling Scope activity as a Delay activity, with a 30-minute timeout. We can then place event handling activities in the event branches that listen for Yes and No votes. This activity will continues to listen for the Yes and No events until the Delay activity completes in 30 minutes.

.

The Replicator fires a number of useful events, including Initialized, Completed, ChildInitialized, and ChildCompleted. The ChildInitialized event is a good time to populate the cloned child activity with the data it needs to execute.

.

Let's say we are working on a workflow for a bug tracking system. At some point, a bug might need detailed information, like a screen shot, uploaded to the application. If the workflow needs this additional documentation, the workflow can ask the host to upload the document. The host might upload the documents itself, but more than likely it will notify a user that the bug requires more information. In either case, the workflow will have to wait (perhaps a few seconds, perhaps a few days or longer), for the uploaded document to arrive. The host can let the workflow know when the upload is complete via an event. The following interface defines the communication contract we need to enable this scenario:

.
    event EventHandler<UploadCompletedEventArgs> UploadCompleted;
.

For our IBugService interface, the tool will generate a RequestUploadActivity and an UploadCompletedActivity. The tool generates the activities as source code files that we can include in our project. The activities will have their InterfaceType and EventName or MethodName properties pre-populated, and include properties for all parameters in the communications.

.

The CAG will revaluate its UntilCondition each time a child activity completes. As soon as the condition returns true the CAG will cancel any currently executing activities and close.

.

No product would be complete today if it did not send or receive SOAP envelopes over HTTP. WF includes a number of activities that revolve around web services, both as a consumer and a producer.

.

Visual Studio 2005 allows us to right-click a workflow project and select "Publish As Web Service". This command creates an ASP.NET project, complete with .asmx and web.config files, that will host our workflow as a web service.

.

A state machine consists of a set of states. For instance, a state machine to model the workflow of a software bug might include the states open, assigned, closed, and deferred. The workflow must always be in one of these four states. State machines are completely event driven. Only when the workflow receives an event can the current state transition to a new state. A state machine must have an initial state, and optionally an ending state. When the state machine transitions to the ending state, the workflow is complete.

.

Every state machine workflow needs an initial state. We can set the initial state using the InitialStateName property of the workflow itself (see figure 14). We can optionally set the CompletedStateName to a state that represents completion of the workflow. The state machine in figure 14 has the four State activities for bug tracking: OpenState, AssignedState, DeferredState, and ClosedState.

.

The Tour Is Complete

.

This was part of the WF beta but has since been removed from the product. You can add any required properties in code. To aid in the creation of DependencyProperties there are CodeSnippets containing the complete template.

.

When notified that its timer has expired, a DelayActivity completes its execution.

.

The DelayActivity is guaranteed to complete no sooner than the indicated TimeoutDuration. The delay can take longer because the timer notification might occur some time after the TimeoutDuration is reached. One reason for a longer delay is if the workflow is running under high system stress in a server environment.

.
  • The customer returns some of the goods as unwanted. In the Netherlands this could easily happen because a consumer is permitted by law to return any item within 7 days of the purchase in which case he or she should get a complete refund.
.

A Sequence activity is a composite activity, and can run one or more contained activities. The activities inside a sequence activity will execute one at a time, until the last activity completes. The WhileActivity only permits a single child activity, but if we make the single activity a SequenceActivity, we can drop additional activities inside the sequence activity. All of the children will then run each time the WhileActivity completes an iteration.

.

Imagine we are setting up a workflow that will count employee votes over a period of 30 minutes. We could set the main child activity of the Event Handling Scope activity as a Delay activity, with a 30-minute timeout. We can then place event handling activities in the event branches that listen for Yes and No votes. This activity will continues to listen for the Yes and No events until the Delay activity completes in 30 minutes.

.

The Replicator fires a number of useful events, including Initialized, Completed, ChildInitialized, and ChildCompleted. The ChildInitialized event is a good time to populate the cloned child activity with the data it needs to execute.

.

Let's say we are working on a workflow for a bug tracking system. At some point, a bug might need detailed information, like a screen shot, uploaded to the application. If the workflow needs this additional documentation, the workflow can ask the host to upload the document. The host might upload the documents itself, but more than likely it will notify a user that the bug requires more information. In either case, the workflow will have to wait (perhaps a few seconds, perhaps a few days or longer), for the uploaded document to arrive. The host can let the workflow know when the upload is complete via an event. The following interface defines the communication contract we need to enable this scenario:

.
    event EventHandler<UploadCompletedEventArgs> UploadCompleted;
.

For our IBugService interface, the tool will generate a RequestUploadActivity and an UploadCompletedActivity. The tool generates the activities as source code files that we can include in our project. The activities will have their InterfaceType and EventName or MethodName properties pre-populated, and include properties for all parameters in the communications.

.

The CAG will revaluate its UntilCondition each time a child activity completes. As soon as the condition returns true the CAG will cancel any currently executing activities and close.

.

No product would be complete today if it did not send or receive SOAP envelopes over HTTP. WF includes a number of activities that revolve around web services, both as a consumer and a producer.

.

Visual Studio 2005 allows us to right-click a workflow project and select "Publish As Web Service". This command creates an ASP.NET project, complete with .asmx and web.config files, that will host our workflow as a web service.

.

A state machine consists of a set of states. For instance, a state machine to model the workflow of a software bug might include the states open, assigned, closed, and deferred. The workflow must always be in one of these four states. State machines are completely event driven. Only when the workflow receives an event can the current state transition to a new state. A state machine must have an initial state, and optionally an ending state. When the state machine transitions to the ending state, the workflow is complete.

.

Every state machine workflow needs an initial state. We can set the initial state using the InitialStateName property of the workflow itself (see figure 14). We can optionally set the CompletedStateName to a state that represents completion of the workflow. The state machine in figure 14 has the four State activities for bug tracking: OpenState, AssignedState, DeferredState, and ClosedState.

.

The Tour Is Complete

.

A IfElseActivity can complete without having run any child activity, if no conditions are satisfied.

.
  1. Complete
.

The WorkBatch uses the MustCommit function to determine if a the pending work item needs to be committed. If it returns true it calls the Commit function to do the actual work. Once the work is done the Complete function is called. The first parameter to the Complete function indicates if the transaction was successful or not.

.
Summary
.

The ParallelActivity only finishes when all children are complete.

.
Summary
.
  • Before the WorkflowInstance is completed.
.

If you are developing your own WorkflowActivities make sure you take a good look at the PersistOnClose attribute! If your activity does any work like changing a database its more than likely that you don’t want to have the action executed twice. If the WorkflowRuntime is stopped after your activity has completed without this attribute and is restarted later it will be restarted at the last persisted point, which is before your activity. The result being that your activity is executed again, not quite what you had in mind . The PersistOnClose attribute makes sure that the workflow state is persisted as soon as the activity has completed resulting in a consistent state even after a restart.

.
Summary
.

When using the UntilCondition you need to check the AllChildrenComplete property of the sender so see if all data has been processed.

.

A workflow is considered unlocked when the workflow is not blocked and not completed and not terminated and not suspended and the either the ownerID is null or the ownedUntil UTC datetime has expired.

.
Summary
.
Note
The SendActivity activity is a blocking activity, meaning that workflow execution will be blocked until the activity completes execution.
.

The SequenceActivity class coordinates the running of a set of child activities in an ordered manner, one at a time. The SequenceActivity is completed when the final child activity is finished.

.

The above workflow is a common pattern for replicated user tasks. The CallExternalMethodActivity notifies the user of the task and the HandleExternalEventActivity gets an event when the task is complete. Let's say that we're going to assign 3 tasks for UserA, UserB, and UserC so our replicator will initailize itself with the collection {"UserA", "UserB", "UserC"}. Assuming that the user name is the correlation parameter, our ChildInitialized handler might look like:

.

Partition On Completion is designed for applications that have no downtime and do not want to incur downtime. The partitioning is done on the completion of every workflow instance. The records that are generated from tracking a workflow instance are added to the regular tracking tables until the workflow instance finishes. At that point, the records are moved to partition tables. When partitioning is enabled, a new set of tables is created periodically for tracking data. The tracked data of completed workflow instances moves to these new partitions without disrupting currently running applications.

.

Set the SqlTrackingService PartitionOnCompletion to true to move the tracking data as soon as a workfow instance completes.

.

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

.

The StateMachineWorkflowActivity has properties that are required for the execution of the state machine workflow. Most notably, the StateMachineWorkflowActivity has two properties that are important: InitialState and CompletedState.

.

The CompletedState of the StateMachineWorkflowActivity is a StateActivity activity that is designated as the end state of the StateMachineWorkflowActivity. When a transition is made to the CompletedState, the workflow execution is completed. The CompletedState is not mandatory. This means that you can have a StateMachineWorkflowActivity that is not completed. This does not mean that the state machine workflow is always active in memory. The StateMachineWorkflowActivity might be unloaded as it waits for an event.

.

StateMachineWorkflowActivity activities that never complete are especially useful in processing long running business transactions. Consider a purchase order received by a supplier. The fact that the purchase order was fulfilled does not mean that the purchase order process is over. The goods that are part of the purchase order might be returned or the purchase order might be amended and have additional items added to it after the fulfillment. Sometimes there might be a requirement to keep the purchase order records for an extended period of time for legal or other purposes. The fact that a workflow does not finish just means that the workflow remains in an unloaded state. There may be a case for retiring the workflows, which means that after a set period of time the workflow instance may be forced to shut down.

.

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.

.
        ElseIf replicator.AllChildrenComplete Then
.
  1. The ReplicatorActivity never stops if you don't tell it to. This is the behavior I most dislike with the ReplicatorActivity. Instead of just stopping and continuing with the next activity when all data is processed it just stops . Now this isn't the case when you don't have an UntilCondition, in that case every item is processed and when done it proceeds with the next activity just as you would expect. No with an UntilCondition you are responsible for stopping and to do so the UntilCondition is actually called one more time after the last item has been processed. The thing to check for is the AllChildrenComplete property of the ReplicatorActivity. When this is true all the data has been processed and you are responsible for stopping the ReplicatorActivity. Now this might not be hard but it always is a major point of confusion and, I presume, catches everyone at least the first time. And worse I can see no benefit at all for this behavior as the ReplicatorActivity just stops and the next activity is never scheduled. As far as I am concerned this is a big "bug" in the behavior of the ReplicatorActivity.
.

As you can see there is one additional UntilCondition at the end at which time the AllChildrenComplete property is set to true.

.

Because WindowsWorkflowFoundation is a library, not a standalone platform or service, the developer is completely free to include the WindowsWorkflowFoundation library in process in his own application or web site/service. This can be of great benefit to existing applications where using a separate workflow server, like BizTalk 2006, would be prohibitive. Because of the modular way WindowsWorkflowFoundation is designed, the developer is free to replace standard services like persistence, scheduling or tracking with another implementation if he or she so desires.

.

Now the transaction has completed and is committed but the state of the workflow is still as it was last persisted, ie before the TransactionScopeActivity was executed. Suppose the runtime is restarted, it will detect and reload the workflow and continue from the unloaded point so do the TransactionScopeActivity again.

.

A workflow is created when the instance is completely constructed but before activities are processed. That is, before the workflow start executing. The workflow instance is created by calling WorkflowRuntime.CreateWorkflow().

. .
.
  • WorkflowCompleted
.
Summary