Sdílet prostřednictvím


Walkthrough: Perform Run-Time Registration for an Extensibility Application (Lync 2010 SDK)

This topic shows how to set Microsoft Lync 2010 Conversation Window Extension properties, use a Run-Time Registration object to register an application, and then start an IM conversation. For more information about Run-Time Registration, see Register Contextual Conversation Packages in Lync 2010.

Prerequisites

For a list of prerequisites, see Walkthrough: Start an Instant Message Conversation (Lync 2010 SDK). In addition, you must install Internet Information Services (IIS) on the sending and receiving client computers.

Create a Sample Context Application

Create and install a simple HTML page to represent a context application packaged in a conversation. In a production environment, substitute an application install procedure that installs the application on the appropriate client computers. The context application must be installed and registered on each sending and receiving client computer. For more information, in Walkthrough: Perform Install Registration for an Extensibility Application (Lync 2010 SDK), see “Creating a Sample Context Application.”

Register the Application

Use registry entries to register the context application together with Lync 2010. The context application must be registered on each sending and receiving client computer. For more information, in Walkthrough: Perform Install Registration for an Extensibility Application (Lync 2010 SDK), see “Adding Registry Entries.” The GUID that you add to the registry for this walkthrough must match the value that you specify in the code that appears in the next section.

Creating the Messaging Application

The following procedure shows how to create a sample application that is used to start an instant messaging conversation with the sample context application that runs in the Lync 2010 Conversation Window Extension.

To create the registration application

  1. In the Microsoft Visual Studio development system, create a new application. The application can be any kind of managed code application. In this procedure, you create a Microsoft Windows Forms application.

  2. Add a project reference to Microsoft.Lync.Model. The default location is %ProgramFiles%\Microsoft Lync\SDK\Assemblies\WPF.

  3. In Form1.cs, add the following using statements.

    using Microsoft.Lync.Model;
    using Microsoft.Lync.Model.Extensibility;
    
  4. Add the following declarations to the Form class.

    ApplicationRegistration myApplicationRegistration;
    ConversationWindow cWindow;
    
  5. In the Form1 constructor that follows the InitializeComponent method, add the following code.

    // Call this method to perform Run-Time 
    // Registration using the ApplicationRegistration class.
    PerformRunTimeRegistration();
    
    // Conversation participant list. Initial value set in constructor.
    // Update the sample URL here with a valid value.
    List<string> ConversationParticipantList = new List<string>();
    ConversationParticipantList.Add("sip:elise@contoso.com");
    
    // Declare instance of Dictionary to pass the conversation context data.
    Dictionary<AutomationModalitySettings, object> conversationContextData = new Dictionary<AutomationModalitySettings, object>();
    
    // Provide Conversation context: First IM Message.
    conversationContextData.Add(AutomationModalitySettings.FirstInstantMessage, "Contoso Application Context");
    
    // Provide Conversation context: Send first IM message immediately after conversation starts.
    conversationContextData.Add(AutomationModalitySettings.SendFirstInstantMessageImmediately, true);
    
    // Provide Conversation context: Set the Application ID of the registered application that provides context.
    conversationContextData.Add(AutomationModalitySettings.ApplicationId, "{90B996A3-2BDB-48FB-BF74-2FE14D1BA6F4}");
    
    // Provide Conversation context: Set application data. 
    conversationContextData.Add(AutomationModalitySettings.ApplicationData, "1234");
    
    // Register the application.
    this.myApplicationRegistration.AddRegistration();
    
    // Create an Automation object.
    Automation myUIAuto = LyncClient.GetAutomation();
    
    // Start the conversation.
    IAsyncResult beginconversation = myUIAuto.BeginStartConversation(
    AutomationModalities.InstantMessage
    , ConversationParticipantList
    , conversationContextData
    , BeginConversationCallBack
    , myUIAuto);
    
    
  6. In the Form1 class, add the following code.

    // Perform Run-Time Registration by using the ApplicationRegistration class.
    void PerformRunTimeRegistration()
    {
      // Ensure that this GUID matches the registry value entered in the previous section.
      string guid = "{90B996A3-2BDB-48FB-BF74-2FE14D1BA6F4}";
      string appname = "Contoso Test Application";
      myApplicationRegistration = LyncClient.GetClient().CreateApplicationRegistration(guid, appname);
    
      // Set the Conversation Window Extension properties.
      // Ensure that the internalURL parameter is valid on your computer.
      myApplicationRegistration.SetExtensibilityWindowProperties(
        "https://localhost/Test/sample2.html"
        , "https://msn.com"
        , ConversationWindowExtensionSize.Medium);
    
      // Register the application.
      this.myApplicationRegistration.AddRegistration();
    }
    
    // Notify the Automation object and ConversationWindow
    // that the conversation started.
    private void BeginConversationCallBack(IAsyncResult ar)
    {
      if (ar.IsCompleted == true)
      {
        Automation _automation = ar.AsyncState as Automation;
        cWindow = _automation.EndStartConversation(ar);
        IAsyncResult OpenExtensibilityResult = cWindow.BeginOpenExtensibilityWindow("{90B996A3-2BDB-48FB-BF74-2FE14D1BA6F4}",null,null);
        cWindow.EndOpenExtensibility(OpenExtensibilityResult);
      }
    }
    
    // End the conversation.
    private void EndConversation_Click(object sender, EventArgs e)
    {
      try
      {
        // Unregister Run-Time Registration for application context.
        myApplicationRegistration.RemoveRegistration();
        this.cWindow.Close();
      }
      catch (Exception) { }
      this.Close();
    }
    
  7. Build and run the application.

  8. In the conversation window on the sending and receiving clients, the Conversation Window Extension appears with the context application inside it.

See Also

Other Resources

Lync Extensibility API Contextual Conversations (Lync 2010 SDK)