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.
- Navigate to Start >> All Programs >> Microsoft Visual Studio 2010.
- Click on the Microsoft Visual Studio 2010 icon to start Visual Studio 2010.
- Select File >> Open Project.
- Navigate to the folder C:\%Office365TrainingKit%\Labs\9.3\Source\Before.
- Open the Lync2010API solution.
- In Solution Explorer, right-click the AutomatingLync project and select Set as StartUp Project.
- In Solution Explorer, open the App.config file of the AutomatingLync project.
- Change the PrimaryLabUserId and SecondaryLabUserId values to your primary and secondary lab accounts.
- Select View >> Task List and select Comments from the menu.
- Start a remote desktop session with the secondary lab user Id.
- 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.
- Double click TODO: 9.3.1.
- Add the following code after the TODO: 9.3.1 comment. This gets the Automation instance from the running instance of Lync.
_automation = Microsoft.Lync.Model.LyncClient.GetAutomation();
- Double click TODO: 9.3.2.
- Add the following code after the TODO: 9.3.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.
var contextData = new Dictionary<AutomationModalitySettings, object>(); contextData.Add(AutomationModalitySettings.FirstInstantMessage, instantMessageText.Text); contextData.Add(AutomationModalitySettings.SendFirstInstantMessageImmediately, true);
- Double click TODO: 9.3.3.
- Add the following code after the TODO: 9.3.3 comment. This starts an IM conversation by adding a participant, setting the context parameters, and specifying instant messaging mode.
_automation.BeginStartConversation( conversationModes: AutomationModalities.InstantMessage, participantUris: participants, contextData: contextData, callback: StartConversationCallback, state: _automation);
- Defining an optional callback method allows you to get a handle to the window.
- Go to Debug >> Start Without Debugging or use the shortcut key [Ctrl]+[F5] to start the application.
Enter “Hello” into the instant message textbox and click the Send IM button.
- Switch to the secondary lab user’s session and receive the message.
- Close the application.
Task 3 – Starting an Audio Conversation
In this task, you will start an audio conversation with the secondary lab user.
- Navigate to TODO: 9.3.4.
- Add the following code after the TODO: 9.3.4 comment. This starts an audio conversation by specifying audio mode.
_automation.BeginStartConversation( AutomationModalities.Audio, participants, null, StartConversationCallback, _automation);
- Press [Ctrl]+[F5] to start the application.
- Click the Start Audio button.
Switch to the secondary lab user’s session and accept the call.
- Close the application.
Task 4 – Sharing a Desktop
In this task, you will share your desktop with the secondary lab user.
- Navigate to TODO: 9.3.5.
- Add the following code after the TODO: 9.3.5 comment. This shares a desktop by setting the context parameters and specifying the app sharing mode.
var contextData = new Dictionary<AutomationModalitySettings, object>(); contextData.Add(AutomationModalitySettings.SharedDesktop, true); _automation.BeginStartConversation( AutomationModalities.ApplicationSharing, participants, contextData, StartConversationCallback, _automation);
- Press [Ctrl]+[F5] to start the application.
- Click the Share Desktop button.
Switch to the secondary lab user’s session and join the desktop sharing conversation.
- Close the application.
Task 5 – Transferring a File
In this task, you will transfer a file to the secondary lab user.
- Navigate to TODO: 9.3.6.
- Add the following code after the TODO: 9.3.6 comment. This transfers a file by setting the context parameters to include the file transfer modality and the file path.
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);
- Press [Ctrl]+[F5] to start the application.
- Click the Browse button to select a file to transfer.
Select FileTransferSample.txt and click the Open button.
- Click the Transfer File button.
Switch to the secondary lab user’s session and download the file.
- Close the application.
Task 6 – Docking the Conversation Window
In this task, you will dock and undock the conversation window.
- Navigate to TODO: 9.3.7.
- Add the following code after the TODO: 9.3.7 comment. This gets the handle to the conversation window.
_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; } }));
- Navigate to TODO: 9.3.8.
- Add the following code after the TODO: 9.3.8 comment adds event handlers for the conversation window events.
_conversationWindow.NeedsSizeChange += new EventHandler<ConversationWindowNeedsSizeChangeEventArgs>(ConversationWindow_NeedsSizeChange); _conversationWindow.NeedsAttention += new EventHandler<ConversationWindowNeedsAttentionEventArgs>(ConversationWindow_NeedsAttention);
- Navigate to TODO: 9.3.9.
- Add the following code after the TODO: 9.3.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.
_conversationWindow.Dock(windowsFormsHost.Handle);
- Navigate to TODO: 9.3.10.
- Add the following code after the TODO: 9.3.10 comment. This undocks the window by calling its Undock method.
_conversationWindow.Undock();
- Press [Ctrl]+[F5] to start the application.
- Enter “Hello” into the instant message textbox and click the Send IM button.
Click the Dock button.
- Verify that the IM conversation window’s chrome is removed and the conversation window is placed in the application window
- Drag the application window across the screen to see the IM window stay docked in the application.
Click the Undock button.
- Verify that the IM window’s chrome returns and that the window is no longer bound to the application’s position.
- Close the application.