This walkthrough demonstrates how to set extensibility window 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 Registering Contextual Conversation Packages .
Prerequisites
For a list of prerequisites, see Walkthrough: Start an Instant Message Conversation . In addition, install Internet Information Services on both 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 places the application on the appropriate client computers. The context application must be installed and registered on each sending and receiving client computer. For details, in the topic Walkthrough: Perform Install Registration for an Extensibility Application , see the section Creating a Sample Context Application.
Register the Application
Use registry entries to register the context application with Microsoft Lync 2010. The context application must be registered on each sending and receiving client computer. For details, in the topic Walkthrough: Perform Install Registration for an Extensibility Application , see the section Adding Registry Entries. The GUID you add to the registry for this walkthrough must match the value you specify in the code described in the following section.
Create the Messaging Application
The following procedure describes creating a sample application to launch an instant messaging conversation with the sample context application running in the Microsoft Lync 2010 extensibility pane.
To create the registration application
-
In the Visual Studio development system, create a new application. The application can be any type of managed code application. In this procedure you create a Microsoft Windows Forms application.
-
Add a project reference to Microsoft.Lync.Model. The default location is %ProgramFiles%\Microsoft Lync\SDK\Assemblies\WPF.
-
In Form1.cs add the following using statements.
Copy Code using Microsoft.Lync.Model; using Microsoft.Lync.Model.Extensibility;
-
Add the following declarations to the Form class.
Copy Code ApplicationRegistration myApplicationRegistration; ConversationWindow cWindow;
-
Add the following code to the Form1 constructor following the InitializeComponent method.
Copy 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 started. conversationContextData.Add(AutomationModalitySettings.SendFirstInstantMessageImmediately, true); // Provide Conversation context: Set the Application ID of the registered application providing 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);
-
Add the following three methods to the Form1 class.
Copy Code //Perform run-time registration 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 properties of the conversation extensibility window. //Ensure that the internalURL parameter is valid on your computer. myApplicationRegistration.SetExtensibilityWindowProperties( "http://localhost/Test/sample2.html" , "http://msn.com" , ConversationWindowExtensionSize.Medium); // Register the application. this.myApplicationRegistration.AddRegistration(); } //Notify the Automation object and ConversationWindow //that the conversation is started. private void BeginConversationCallBack(IAsyncResult ar) { if (ar.IsCompleted == true) { Automation _automation = ar.AsyncState as Automation; cWindow = _automation.EndStartConversation(ar); IAsyncResult OpenExtensibilityResult = cWindow.BeginOpenExtensibility("{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(); }
-
Build and run the application.
-
In the conversation window on the sending and receiving clients, see the extensibility pane appear containing the context application.