Exercise 1: Exploring the Capabilities of Automation

Task 1 – Beginning the Exercise

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

  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\4\Source\Before.
  5. Open the Lync2010API solution.
  6. In Solution Explorer, right-click the AutomatingLync project and select Set as StartUp Project.
  7. In Solution Explorer, open the App.config file of the AutomatingLync project.
  8. Change the PrimaryLabUserId and SecondaryLabUserId values to your primary and secondary lab accounts.
  9. Select View >> Task List and select Comments from the menu.
  10. Start a remote desktop session with the secondary lab user Id.
  11. Return to the primary lab user’s session.

Task 2 – Starting an Instant Messaging Conversation

In this task, you will get the instance of Automation and start an instant messaging conversation with the secondary lab user.

  1. Double click TODO: 4.1.1.
  2. Add the following code after the TODO: 4.1.1 comment. This gets the Automation instance from the running instance of Lync.

    C#

    _automation = Microsoft.Lync.Model.LyncClient.GetAutomation();
  3. Double click TODO: 4.1.2.
  4. Add the following code after the TODO: 4.1.2 comment. Create a Dictionary of context data to add to the conversation, in this case specifying that the first instant message should be sent immediately to the recipient.

    C#

    var contextData = new Dictionary<AutomationModalitySettings, object>(); contextData.Add(AutomationModalitySettings.FirstInstantMessage, instantMessageText.Text); contextData.Add(AutomationModalitySettings.SendFirstInstantMessageImmediately, true);
  5. Double click TODO: 4.1.3.
  6. Add the following code after the TODO: 4.1.3 comment. This starts an IM conversation by adding a participant, setting the context parameters, and specifying instant messaging mode.

    C#

    _automation.BeginStartConversation( conversationModes: AutomationModalities.InstantMessage, participantUris: participants, contextData: contextData, callback: StartConversationCallback, state: _automation);
  7. Defining an optional callback method allows you to get a handle to the window.
  8. Go to Debug >> Start Without Debugging or use the shortcut key [Ctrl]+[F5] to start the application.
  9. Enter “Hello” into the instant message textbox and click the Send IM button.

  10. Switch to the secondary lab user’s session and receive the message.
  11. Close the application.

Task 3 – Starting an Audio Conversation

In this task, you will start an audio conversation with the secondary lab user.

  1. Navigate to TODO: 4.1.4.
  2. Add the following code after the TODO: 4.1.4 comment. This starts an audio conversation by specifying audio mode.

    C#

    _automation.BeginStartConversation( AutomationModalities.Audio, participants, null, StartConversationCallback, _automation);
  3. Press [Ctrl]+[F5] to start the application.
  4. Click the Start Audio button.
  5. Switch to the secondary lab user’s session and accept the call.

  6. Close the application.

Task 4 – Sharing a Desktop

In this task, you will share your desktop with the secondary lab user.

  1. Navigate to TODO: 4.1.5.
  2. Add the following code after the TODO: 4.1.5 comment. This shares a desktop by setting the context parameters and specifying the app sharing mode.

    C#

    var contextData = new Dictionary<AutomationModalitySettings, object>(); contextData.Add(AutomationModalitySettings.SharedDesktop, true); _automation.BeginStartConversation( AutomationModalities.ApplicationSharing, participants, contextData, StartConversationCallback, _automation);
  3. Press [Ctrl]+[F5] to start the application.
  4. Click the Share Desktop button.
  5. Switch to the secondary lab user’s session and join the desktop sharing conversation.

  6. Close the application.

Task 5 – Transferring a File

In this task, you will transfer a file to the secondary lab user.

  1. Navigate to TODO: 4.1.6.
  2. Add the following code after the TODO: 4.1.6 comment. This transfers a file by setting the context parameters to include the file transfer modality and the file path.

    C#

    var contextData = new Dictionary<AutomationModalitySettings, object>(); contextData.Add(AutomationModalitySettings.FilePathToTransfer, fileTransferPath.Text); contextData.Add(AutomationModalitySettings.FileIsShared, true); _automation.BeginStartConversation( AutomationModalities.FileTransfer, participants, contextData, StartConversationCallback, _automation);
  3. Press [Ctrl]+[F5] to start the application.
  4. Click the Browse button to select a file to transfer.
  5. Select FileTransferSample.txt and click the Open button.

  6. Click the Transfer File button.
  7. Switch to the secondary lab user’s session and download the file.

  8. Close the application.

Task 6 – Docking the Conversation Window

In this task, you will dock and undock the conversation window.

  1. Navigate to TODO: 4.1.7.
  2. Add the following code after the TODO: 4.1.7 comment. This gets the handle to the conversation window.

    C#

    _conversationWindow = ((Automation)ar.AsyncState).EndStartConversation(ar); Dispatcher.Invoke(new Action(() => { if (_canDock) { dockConversationWindow.IsEnabled = true; _conversationWindow.Move(_conversationWindow.Left, _conversationWindow.Top); } else { dockConversationWindow.IsEnabled = false; } }));
  3. Navigate to TODO: 4.1.8.
  4. Add the following code after the TODO: 4.1.8 comment adds event handlers for the conversation window events.

    C#

    _conversationWindow.NeedsSizeChange += new EventHandler<ConversationWindowNeedsSizeChangeEventArgs>(ConversationWindow_NeedsSizeChange); _conversationWindow.NeedsAttention += new EventHandler<ConversationWindowNeedsAttentionEventArgs>(ConversationWindow_NeedsAttention);
  5. Navigate to TODO: 4.1.9.
  6. Add the following code after the TODO: 4.1.9 comment. This docks the window by calling its Dock method and passing the handle to the WindowsFormsHost control that will contain the docked window.

    C#

    _conversationWindow.Dock(windowsFormsHost.Handle);
  7. Navigate to TODO: 4.1.10.
  8. Add the following code after the TODO: 4.1.10 comment. This undocks the window by calling its Undock method.

    _conversationWindow.Undock();
  9. Press [Ctrl]+[F5] to start the application.
  10. Enter “Hello” into the instant message textbox and click the Send IM button.
  11. Click the Dock button.

  12. Verify that the IM conversation window’s chrome is removed and the conversation window is placed in the application window
  13. Drag the application window across the screen to see the IM window stay docked in the application.
  14. Click the Undock button.

  15. Verify that the IM window’s chrome returns and that the window is no longer bound to the application’s position.
  16. Close the application.