Running UCMA Code in a Windows Workflow Application: Adding UCMA Components (Part 3 of 4)

Summary:   Combine the capabilities of Microsoft Unified Communications Managed API (UCMA) and Windows Workflow Foundation. Part 3 describes how to add a UCMA project to a Windows Workflow application.

Applies to:   Microsoft Unified Communications Managed API (UCMA) 3.0 Core SDK | Windows Workflow Foundation

Published:   October 2011 | Provided by:   John Clarkson, Microsoft | About the Author

Contents

Download code  Download code

Watch video  See video

This is the third in a series of four articles about how to add a UCMA component to a workflow.

Creating the UCMA Code Project

Part 3 describes how to add a UCMA project to a Windows Workflow application. Part 4 provides a code listing for the completed application.

To Add the Console Application

  1. In Microsoft Visual Studio 10 development system, on the menu bar choose File, Add, New Project. In the installed templates list, choose Visual C#, Windows. In the .NET Framework version list, ensure that .NET Framework 3.5 is selected. In the Windows list, choose Console Application. In the Name box, type ConsoleAppDotNET35 and then click OK.

  2. In Solution Explorer, right-click ConsoleAppDotNET35 and then choose Add, Existing Item. Browse to the folder containing the UCMA 3.0 SDK. At the path SDK\Core\Sample Applications\QuickStarts\Common, select UCMASampleHelper.cs and then click Add. This file contains code that performs Lync platform startup and creates endpoints.

  3. Right-click ConsoleAppDotNET35 and then choose Add Reference. On the NET tab, choose System.Configuration and then click OK. This library contains the code needed to read the App.config file.

  4. Right-click ConsoleAppDotNET35 and then choose Add Reference. On the Browse tab, in the folder containing the UCMA 3.0 SDK, find the SDK\Core\Bin folder. Choose Microsoft.Rtc.Collaboration.dll and then click OK. This library contains UCMA 3.0 Core SDK namespaces.

Note

For more information about the App.config contents, see Part 4.

To Modify the Startup Project’s Config File

  1. In Solution Explorer, right-click WorkflowConsoleApplication1 and then choose Set as Startup Project.

  2. Open App.config and modify the Startup element as shown in the following example.

    <startup useLegacyV2RuntimeActivationPolicy="true">
      <supportedRuntime version="v4.0" />
    </startup>
    
  3. Add keys identifying the following items in the project’s Lync server domain:

    • Lync server FQDN (for example: sales1.contoso.com)

    • Microsoft Lync 2010 user name (for example: john)

    • Lync 2010 user domain (for example: contoso.com)

    • Lync 2010 user URI (for example: john@contoso.com)

  4. In the ConsoleAppDotNET35 project, open the UCMASampleHelper.cs file. Near the top of the UCMASampleHelper class, find the declarations for the following properties and set their values to match the keys added to the App.config file in the previous step.

    • _serverFQDNPrompt

    • _userNamePrompt

    • _userDomainPrompt

    • _userURIPrompt

To Add UCMA Code to ConsoleAppDotNET35

  1. In the ConsoleAppDotNET35 project, replace the content of Program.cs with the code contained in the code listing in Part 4.

  2. Build the solution. This adds ConsoleAppDotNET35 to the Toolbox so it can be used in the following procedure.

Adding Code Activities

Code activites are used in this project to call the UcmaIM() method in the ConsoleAppDotNET35 project.

To Create the Code Activities

  1. In Visual Studio 10, on the menu bar choose File, Add, New Project. In the installed templates list, choose Visual C#, Workflow. In the .NET Framework version list, ensure that .NET Framework 4.0 is selected. In the Workflow list, choose Activity Library, and then click OK.

  2. In Solution Explorer, delete the Activity1.xaml file in the ActivityLibrary1 project.

  3. Right-click ActivityLibrary1 and then choose Add Reference. On the Projects tab, select ConsoleAppDotNET35 and then click OK.

  4. Right-click ActivityLibrary1 and then choose Add, New Item. In the installed templates list, choose Workflow. In the Workflow list choose Code Activity. In the Name box type UcmaHello and then click OK.

  5. Replace the content of UcmaHello.cs with the following code.

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Activities;
    using ConsoleAppDotNET35;
    
    namespace ActivityLibrary1
    {
        public sealed class UcmaHello : CodeActivity
        {
            private UCProgram ucma;
    
            // Define an activity input argument of type string
            public InArgument<string> Text { get; set; }
    
            // If your activity returns a value, derive from CodeActivity<TResult>
            // and return the value from the Execute method.
            protected override void Execute(CodeActivityContext context)
            {
                ucma = new UCProgram();
                ucma.UcmaIM(1);
            }
        }
    }
    
  6. Create a second Code activity named UcmaGoodbye. Replace the code in this new activity with the code that is used in the UcmaHello activity. Make two changes to the code, as shown in the following example.

    1. Change the class name to UcmaGoodbye.

    2. Set the parameter for the UcmaIM() method to 2 rather than 1.

    public sealed class UcmaGoodbye : CodeActivity
    ...
    ucma.UcmaIM(2);
    
  7. Build the solution. This adds the Code activities to the Toolbox so they can be used in the following procedure.

To Add the Code Activities to the Workflow

  1. In Solution Explorer, right-click Workflow1.xaml and then choose View Designer.

  2. In the Design pane, delete the WriteLine activities from the Then and Else sections of the If activity.

  3. Drag a UcmaHello activity from the ActivityLibrary1 section of the Toolbox and drop it in the Then section of the If activity.

  4. Drag a UcmaGoodbye activity from the ActivityLibrary1 section of the Toolbox and drop it in the Else section of the If activity. See the following illustration for comparison.

  5. Build and run the workflow. Responding with a 1 executes the UcmaHello Code activity and results in an IM with the text “hello”. Responding with a 2 executes the UcmaGoodbye Code activity and results in an IM with the text “goodbye”.

    Figure 1. Completed workflow application with UCMA project

    Completed application

Conclusion

Part 3 describes how to add a UCMA project to a Windows Workflow application. Part 4 includes the application configuration, code, and helper class.

Additional Resources

For more information, see the following resources:

About the Author

John Clarkson is a programming writer with the Microsoft Lync product team.