Exercise 1: UCMA 3.0 Workflow SDK Workflow Activities

Task 1 – Open the Visual Studio Solution

In this task, you will open the project and configure it to run with your parameter values.

  1. Navigate to Start >> All Programs >> Microsoft Visual Studio 2010.
  2. Click on the Microsoft Visual Studio 2010 icon to start Visual Studio 2010.
  3. Select File >> Open Project.
  4. Navigate to the folder C:\%UC14TrainingKit%\Labs\7\Source\Before\UCMA_WorkflowActivities.
  5. Open the UCMA_WorkflowActivities solution.
  6. In Solution Explorer, open the App.config file.
  7. Change the value of ApplicationId to the application id of your provisioned UCMA 3.0 application, e.g. urn:application:LabApp10600.
  8. Change the value of ApplicationName to the application name of your provisioned UCMA 3.0 application, e.g. LabApp10600.
  9. Change the value of TrustedContactUri to SIP URI of the contact associated with your provisioned UCMA 3.0 application, e.g. sip:LabContact10600@fabrikam.com.
  10. Change the value of SecondaryLabUserId with the SIP URI of your secondary lab user.

Task 2 – Build the Workflow

In this task, you will learn to use the various workflow activities available in the UCMA 3.0 Workflow SDK.

  1. In the Solution Explorer window, open Workflow1.xoml.
  2. Open and pin the Toolbox.
  3. Expand the Unified Communications Workflow section of the Toolbox.
  4. Drag a SpeechStatement activity onto the workflow design surface and place it as the first activity in communicationsSequenceActivity1.

  5. Open the properties of the new activity and rename it to Welcome.

  6. Right-click the Welcome activity and select Generate Handlers.
  7. Add the following code snippet to the Welcome_TurnStarting event handler. We would like the workflow to greet the caller by name, so we need to dynamically construct the value of MainPrompt at runtime. The TurnStarting event of the SpeechStatementActivity fires when the activity is about to play the prompt.

    C#

    this.Welcome.MainPrompt.AppendText( "Welcome {0}. I can help you manage your tasks", GetUserDisplayName(communicationsSequenceActivity1.CallProvider.Call.RemoteEndpoint.Participant.Uri));
  8. Switch back to the workflow designer.
  9. Highlight the EnterPIN activity and open its properties.
  10. Highlight the ExpectedDtmfInputs property of the EnterPIN activity and click the ellipsis to edit the property.
  11. Enter 1 2 3 4 5 (note the spaces between digits) and click OK. In a later exercise in this lab, you will modify this activity to accept more complex input from the user. For now, this activity will only accept “12345” as valid input.

  12. Set the value of IncompleteTimeout property of the EnterPIN activity to 00:00:20. The IncompleteTimeout property specifies the length of time after the user input that the recognition is complete.
  13. Set the value of the InitialSilenceTimeout property of the EnterPIN activity to 00:00:10. The InitialSilenceTimeout property specifies the length of time before which the user has to start giving input or the recognition fails.
  14. Set the value of the MainPrompt property of the EnterPIN activity to: “Please enter your five-digit PIN”. The MainPrompt is the prompt that is played when the activity starts.
  15. The properties of the EnterPIN activity should now be set as follows:

  16. Double-click the CheckPIN activity. The Code activity is native to Windows Workflow v3.0 and executes the code specified in the associated ExecuteCode handler.

  17. Add the following code snippet to the CheckPIN_ExecuteCode event handler. In a production application, you can execute code to validate the PIN entered by the caller.

    C#

    _validPIN = true;
  18. Double-click the GetTasks activity and add the following code snippet to the GetTasks_ExecuteCode event handler to retrieve the caller’s tasks from an XML file.

    C#

    XDocument xdoc = XDocument.Load("Tasks.xml"); _tasks = (from t in xdoc.Elements("Tasks").Elements("Task") where !t.Element("Status").Equals("Completed") select new Task { Id = Convert.ToInt32(t.Element("Id").Value), AssignedTo = Program.SecondaryLabUserId, Description = t.Element("Description").Value, Status = t.Element("Status").Value }).ToList();
  19. Switch back to the workflow designer.
  20. Drag a SpeechQuestionAnswer activity onto the workflow design surface and place it directly after the GetTasks activity.
  21. Open the properties of the new activity and rename it to ChooseTask.

  22. Set the value of IncompleteTimeout property of the ChooseTask activity to 00:00:20.
  23. Set the value of the InitialSilenceTimeout property of the ChooseTask activity to 00:00:10.
  24. Highlight the ExpectedDtmfInputs property of the ChooseTask activity and click the ellipsis to edit the property.
  25. Enter the numbers 1 through 9 on separate lines and click OK. In a later exercise in this lab, you will modify this activity to set the expected DTMF inputs at runtime based on the tasks retrieved in the GetTasks activity.

  26. The properties of the ChooseTask activity should now be set as follows:

  27. Right-click the ChooseTask activity and select Generate Handlers.
  28. Add the following code snippet to the ChooseTask_TurnStarting event handler. Build the MainPrompt of the ChooseTask activity dynamically after retrieving the caller’s tasks. AppendBreak is used to add a break to a prompt to make it sound more natural. The PromptBreak enum is used to represents breaks of different lengths.

    C#

    this.ChooseTask.MainPrompt.ClearContent(); this.ChooseTask.MainPrompt.AppendText("Please choose one of the following active tasks:"); this.ChooseTask.MainPrompt.AppendBreak(PromptBreak.Medium); foreach (var task in _tasks) { this.ChooseTask.MainPrompt.AppendText("Task {0}: {1}", task.Id, task.Description); this.ChooseTask.MainPrompt.AppendBreak(PromptBreak.Medium); }
  29. Switch back to the workflow designer.
  30. Double-click the SetTask activity and add the following code snippet to the SetTask_ExecuteCode to set the selected task.

    C#

    _selectedTaskId = Convert.ToInt32(this.ChooseTask.RecognitionResult.Text.Replace(" ", String.Empty));
  31. Drag a GetPresence activity onto the workflow design surface and place it directly after the SelectedTask activity.
  32. Open the properties of the new activity and rename it to GetPresence. The warning on the GetPresence activity indicates that the Target property of the activity has not been set. The Targets property represents the list of users for which the activity will query presence. You will later set the Targets property at runtime based on the user that the selected task is assigned to.

  33. Right-click the SelectedTask activity and select View Code.
  34. Add the following code snippet to the end of SelectedTask_TurnStarting event handler. When the caller selects a task, add the assigned user to the Targets collection of the GetPresence activity.

    C#

    this.GetPresence.Targets.Add(new RealTimeAddress(_taskAssignedToUri));
  35. Highlight the ifElseBranchOnline branch of ifElseActivityOnline and open its properties.
  36. Set the Condition Type to Declarative Rule Condition.
  37. Click the ellipsis in the Condition Name property to specify a condition for the If-Else branch.
  38. Highlight the Placeholder condition and press Edit.

    Note:
    In the Before code for this lab, a placeholder condition is set for the ifElseBranchOnline activity in order to allow the lab code to compile without errors.
  39. Replace the placeholder condition with the following code snippet in the rule condition editor and press OK. The condition checks if the presence of the assigned user is Online.

    C#

    this.GetPresence.Results[new RealTimeAddress(this._taskAssignedToUri)].PresenceStatus == PresenceAvailability.Online
  40. After saving the condition, press Rename and rename it to UserIsOnline.

  41. Drag a BlindTransfer activity to the ifElseBranchTransfer branch of ifElseActivityTransfer.
  42. Open the properties of the new activity and rename it to BlindTransfer. The warning on the BlindTransfer activity indicates that the CalledParty of the activity has not yet been set.
  43. Right-click the UserIsOnline activity and select View Code.
  44. Add the following code snippet to the end of UserIsOnline_TurnStarting event handler to set the CalledParty property of the BlindTransfer activity.

    C#

    this.BlindTransfer.CalledParty = new RealTimeAddress(_taskAssignedToUri);
  45. Save your changes.

Task 3 – Test the Workflow

  1. In this task, you will run and test the workflow solution that you completed in the previous task.
  2. Switch to your secondary lab user’s session.
  3. Open Microsoft Lync.
  4. Set the user’s availability to Available.
  5. Switch back to your primary lab user’s session.
  6. Switch to Visual Studio 2010.
  7. Go to Debug >> Run Without Debugging or use the shortcut key [Ctrl]+[F5] to start the application.
  8. Open Microsoft Lync.
  9. Locate the contact associated with your provisioned UCMA 3.0 application, e.g. LabContact10600@fabrikam.com.
  10. Place an audio call to the contact. The attendant answers the call and welcomes the caller by name. The attendant prompts the user to enter their five-digit PIN.
  11. Enter 12345 for the PIN. The attendant retrieves a list of the caller’s active tasks and presents them as choices.
  12. Enter 1 to select task number 1. The attendant confirms the caller’s selection. The workflow checks the presence of the user that the task is assigned to. The attendant notifies the caller that the user is online and asks them if they would like to be transferred to the user.
  13. Enter 1 for Yes. The workflow places a blind transfer of the call.
  14. Switch to your secondary lab user’s session.
  15. Answer the incoming call.
  16. Hang up the call.
  17. Switch to your primary lab user’s session.
  18. Hang up the call.
  19. Switch to the console application and press Enter. The application endpoint is terminated and the collaboration platform is shut down.