Step 2: Handling Main Menu Choices

This is the second of three topics describing the steps to create the Author an IM Agent for Information Access walkthrough application. This sequence of topics demonstrates how the instant messaging (IM) capabilities of communications workflow activities are used to create an IM agent for basic information access. The procedures for creating the walkthrough application build sequentially. Completing the procedures in sequence is important.

The decision-making logic for the IfElseActivity class evaluates each branch from left to right. The first branch evaluated as true is followed. The path through the final branch, the last one on the right, is chosen if the true/false logic on the branches to the left fail. As a result, the last IfElseActivity branch does not need code to complete a true/false check. The last branch is chosen only if the true/false check on all other branches fails.

In the following procedure three if/else branches are added to the workflow. The first two branches require simple event handler code to evaluate the recognized text from the InstantMessagingQuestionAnswerActivity activity. The third branch does not need code to evaluate the recognition because it is chosen only if the first two branches evaluate as false.

To add an ifElse activity to handle the main menu choice

  1. In the Microsoft Visual Studio development system Toolbox, expand Windows Workflow to display workflow activities.

  2. Drag and drop an IfElse activity onto the design surface between qaMainMenu and disconnectCallActivity1.

  3. Rename ifElseActivity1 to ifElseMain. Rename the branch on the left as ifElseBranchGovernment, and the branch on the right as ifElseBranchCorporate.

  4. On the red exclamation mark at the top of ifElseBranchGovernment, click the arrow, and then click Property 'Condition' is not set.

  5. In the Properties window for ifElseBranchGovernment, set the Condition property to Code Condition, and then expand the Condition property.

  6. Type conditionGovernment as a name for the condition.

  7. To set the property, click the design surface adjacent to the Properties window.

  8. In the event handler, add a statement to set the Result property to true or false based on the answer to qaMainMenu:

    e.Result = (this.qaMainMenu.RecognitionResult.Text == "government");
  9. Right-click the design surface inside ifElseMain and then click Add Branch. Rename the new branch ifElseBranchAcademic.

  10. Because a third branch is added, the second IfElse branch now requires code to complete a true/false check. As shown in step 4 through step 7, on ifElseBranchCorporate, add a conditionCorporate code condition. In the following example, the corporate code condition is specified.

    e.Result = (this.qaMainMenu.RecognitionResult.Text == "corporate");

As shown in the next procedure, add three InstantMessagingStatementActivity activities to test the existing workflow.

To add prompts confirming the menu choices

  1. In the Toolbox, expand Unified Communications Workflow to display workflow activities, and then drag and drop a InstantMessagingStatement activity onto ifElseBranchGovernment where Drop Activities Here appears.

  2. Rename instantMessagingStatementActivity1 to promptGovernment, and set the MainPrompt property to Looking for an IM contact in our government department.

  3. Following the instructions in step 1 and step 2, add an InstantMessagingStatement activity to ifElseBranchCorporate. Rename instantMessagingStatementActivity1 to promptCorporate. Set the MainPrompt property to Looking for an IM contact in our corporate department.

  4. Following the instructions in step 1 and step 2, add an InstantMessagingStatement activity to ifElseBranchAcademic. Rename instantMessagingStatementActivity1 to promptAcademic. Set the MainPrompt property to Looking for an IM contact in our academic department. Verify that your workflow activities are arranged as shown in the following illustration.

  5. As shown in the following procedure, debug your application by answering alternately with the following words and verify that the appropriate IM text appears in the reply:

    • Government

    • Corporate

    • Academic


To build and debug the application

  1. Create a debugging environment. For information about creating a debugging environment, see Provision and Deploy a UCMA Workflow Application.

  2. Debug the application. For information about debugging applications, see Walkthrough: Debugging a Communications Workflow Application.