Code Activity In Visual Studio application, when user adds the code activity, an event handler is associated with it. The ExecuteCode event is used for the purpose. User needs to write the code. The following code is an event handler for the ExecuteCode for displaying a message on screen. Code: private void codeActivity1_ExecuteCode(object sender, EventArgs e) { Console.WriteLine(“Welcome User”); } IfElse Activity The activity is similar to the If Else statement of the programming language. The If Else activity contains one or more branch activities. Every branch activity has a conditional property. Only the last branch does not contain any condition property. The If Else activity evaluates from left to right. The branch with true condition property will execute. If no branches satisfy the condition, no branch is executed. Additional branches can be added by right clicking the branch and selecting the Add Branch option. The Delete option is used for the branch removal. The following image shows the If Else activity. The rule condition editor in the Properties window and add an expression. Consider the code to demonstrate the condition defined in the file. Code: private void OrderData(object sender, ConditionalEventArgs e ) { e.Result = price > 20000; } The event for evaluating the code condition is mentioned below. The value returned can be true or false. WhileActivity The WhileActivity can be either declarative or code condition. The activity is in process till the condition is true. The condition is checked before each iteration. Sequence Activity The sequence activity is a composite activity that contains more than one child activities. The activities placed in the sequence are executed one by one, till the last activity is completed. A single child is added in the while activity. If the single activity is added in the sequence activity, user can drop more activities in the sequence activity. Suspend Activity The Suspend Activity creates a halt in the workflow. The activity is useful when the workflow checks an error. The activity contains an error property of string data type. The WorkflowSuspended event is used for subscribe the workflow runtime. The host resumes the workflow execution using the Resume method. Terminate Activity The Terminate activity halts the execution of the workflow. In this activity, the host cannot resume the terminated workflow. The activity is useful when the workflow reaches the point where it cannot proceed. It has an Error property of string type. The host subscribes the runtime’s WorkflowTerminated event and check the error. The event handler receives the argument of type WorkflowTerminatedEventArgs. The runtime wraps the error message in the exception. Throw Activity The Throw activity is same as the throw statement in C# and VB. The throw activity makes the exception as explicit. If the exception is not handled, the workflow catches the exception and raises the WorkflowTerminated event. The Fault property references to the exception thrown. The FaultType property describes the exception type the activity throws. InvokeWorkflow Activity The activity asynchronously executes another workflow. User cannot access the output parameters from the other workflow as the execution is asynchronous. User can set the TargetWorkflow property for referencing the workflow type. User can select the workflow types from the referred assembly. The InvokeWorkflow activity is useful when workflows have independent execution. The Invoking event handler is useful for initializing parameters. Parallel Activity User can execute multiple activities using the parallel activity. Although the activity allows multiple processing, only one thread is executed at a time in the workflow. User can separate branches inside activity for independent execution. In the Parallel activity, the workflow will process the event and wait for other events. The activity is not completed till all branches have completed processing. Delay Activity The Delay Activity initializes the timer and waits for the timer expiration. The activity is useful for returning the control to the engine and helps other activities to execution. The TimeoutDuration property is TimeSpan representing the time to wait. User can initialize the property in the designer window or through code. The event handler for the InitializeTimeoutDuration is as shown below: Code: private void delay1_InitializeTimeoutDuration(object sender, EventArgs e) { DelayActivity d1 = sender as DelayActivity; if ( delay != null ) { delay.TimeoutDuration = new TimeSpan(0,0,10); } } Listen Activity The Listen activity contains multiple branches. In the activity, the branches are EventDriven activities. Consider there are three branches having an individual task. If one of three activities is to be executed, branch with the corresponding event will be executed. The execution of other branches is cancelled. Synchronization Scope Activity The activity can serialize the access to the resources across several workflow instances. The SynchronizationScope checks that only a single instance reads and writes to the field. The SynchronizationHandle contains the handle that workflow will use before execution. It is released once the work is completed. It is a string object and the collection of strings is maintained. Local Communication Events When user needs to communicate with the other activity, the built in activities are used. For execution of the communication the contract is of .NET interface type is defined. The methods and events used for invoking the local service are defined. Consider an example of uploading an application to the service. The host can upload the application and notify the user for more information. In such situation, the workflow needs to wait for some time. The host can notify the workflow the completion of the upload through an event. Code: [ExternalDataExchange] interface IDataService { bool Request ( Guid id, string name ); event EventHandler<UploadCompletedEventArgs> UploadCompleted; } The activities like CallExternalMethodActivity and HandleExternalEventActivity are used for interacting with the interface. CallExternalMethodActivity The activity adds a method on the local service. User needs to set up the properties of the activity. The InterfaceType property is set and helps the methods to be available to the service. The MethodName property is useful for setting the method to call. The ExternalDataExchangeService is added to the workflow at the runtime. The service is added for implementing the interface. The StudService class implements the IStudService interface. Code: WorkflowRuntime workflow1 = new WorkflowRuntime(); ExternalDataExchangeService dt1 = new ExternalDataExhangeService(); workflow1.AddService(dt1); StudService stud = new StudService(); dt1.AddService(stud); The activity contains MethodInvoking event. The event fires before the activity is called. The following code demonstrates the event. Code: private void CallExternalMethodActivity1_MethodInvoking( object sender, EventArgs e) { id= this.WrokflowInstanceId; userName=”Nick”; } HandleExternalEventActivity The activity contains InterfaceType property that must be set. The following figure shows the EventName property. The HandleExternalEvent is the blocking activity. The activity is incomplete till the event arrives the local service. The Roles property of the activity binds the WorkflowRoleCollection object. The runtime can perform role based authorization. It compares the role membership of the identity. Transaction and Compensation Transactions contain ACID properties. The Transaction class is available in the System.Transactions namespace. It can manage transactions across different types of durable stores. TransactionScopeActivity The activity starts a transaction and lists activity it contains into the transaction. The TransactionOptions property controls the timeout and the isolation level. The following figure shows the transactionscope activity. If there are no errors, it will automatically commit the transaction. If the exception occurs inside the scope, the activity is aborted and the work is roll back. Compensatable Sequence Activity The activity is similar to the Sequence activity containing the compensation handler. User can view the handler by right clicking the activity and selecting View Compensation Handler. User can add the activities to compensate for activities for the normal execution of sequence. Web Services The messages are sent and received using the HTTP protocol. The workflow contains number of activities used for client and server. InvokeWebService Activity The activity can call the external web service. When user drops the activity in the workflow, the Add Web Reference activity will appear. User can configure the activity using the method name, binding the parameters to properties and fields in the window. It consists the invoking and Invoked event handlers to be fired before the service call. WebServiceOutput Activity The activity pairs with the WebServiceInput activity. User cannot use the activity without configuring the WebServiceInput activity. The InputActivityName property pairs the activity with the input. The ReturnValue property is the response to the web service. State Activities The state machine contains the set of states. The states included in the state machine model are open, assigned, closed, and deferred. The workflow must be present in one of the four states. The machines are event driven. The machine is in the initial state and is in ending state when the workflow is completed. StateActivity It is used to represent one of the states in the machine. User can place the states anywhere in the design view. The state machine workflow is in initial state. The InitialStateName property is used for setting the initial state. The CompleteStateName is useful for completion of the workflow. StateInitialization Activity The activity is a sequence activity containing child activities. When the state machine transitions to a state, the children in the initialization activity will execute. There is only one initialization activity for a state. EventDriven Activity The activity is a sequence activity containing children in it. The activity is executed when the event arrives. The state activity contains more than one EventDriven activity. The event driven activity in OpenState is used to configure the event handler for the event. The ExternalDataExchange attribute is used for the interface communication.