Introduction to the Microsoft Lync 2010 Managed API - Working ...

basicgratisΜηχανική

5 Νοε 2013 (πριν από 3 χρόνια και 11 μήνες)

286 εμφανίσεις





Hands
-
On Lab

Introduction to
the Microsoft
Lync 2010

Managed
API



Lab version:



1
.
0

Last updated:


11/6/2013










CONTENTS

OVERVIEW

................................
................................
................................
................................
...................

3

System Requirements

3

EXERCISE 1: EXPLORIN
G THE CAPABILITIES O
F AUTOMATION

................................
.......................

4

Task 1


Beginning the Exercise

................................
................................
................................
............

4

Task 2


Starting an Instant Messaging Conversation

................................
................................
..........

4

Task 3


Starting an Audio Conversation

................................
................................
..............................

5

Task 4


Sharing a Desktop

................................
................................
................................
...................

6

Task 5


Transferring a File

................................
................................
................................
...................

7

Task 6


Docking the Conversation Window

................................
................................
........................

8

SUMMARY

................................
................................
................................
................................
..................

10





Overview

Lab Time:

45 Minutes

Lab Folder:

C:
\
%
Office365TrainingKit
%
\
Labs
\
9
.3
\
Source
\
Before

The
After

folder contains the completed lab exercises.

Lab Overview:

The
Microsoft
Lync 2010

Managed
API
is a rich and full
-
featured client API
that combines
the automation capabilities of the Office Communicator Automation API with the flexibility and
functionality of th
e UCC API. The Lync 2010
Managed
API
provides
the
Automation
class
to enable
you
to launch
conversations, add contacts
,

and
automate Lync within your

applications.

The
Lync 2010
Managed
API also
provides a rich object model that developers can use to build thei
r own
communications
-
enabled applications

without the

Lync 2010

UI
.

In this lab solution,
you will use the
Lync 2010
Managed
API
to do the
following:



S
tart an instant messaging conversation



S
tart an audio conversation



S
tart a desktop sharing conversation



S
tart a file transfer conversation



D
ock and undock a conversation window



P
repare your application to sign in to
Lync

2
010




S
et up event handlers for
Lync

events



S
et up event handlers for Contact and Group events



P
ublish and retrieve presence items

System Requirements

You must have the following items to complete this lab:



Microsoft Visual Studio 2010



Microsoft
Lync 2010



Microsoft Lync 2010 SDK



Two accounts (referred to as the primary and secondary lab users in this document),
provisioned for
Lync
Online

that are able to successfully sign in to
Lync 2010.



Exercise 1:
Exploring the Capabilities of
Automation

Task 1


B
eginning 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:
\
%
Office365TrainingKit
%
\
Labs
\
9
.3
\
Source
\
Before
.

5.

Open the
Lync2010
API

solution
.

6.

In Solution Explorer, right
-
click the
Automating
Lync

project and select
Set as

StartUp
Project
.

7.

In Solution Explorer, open the

A
pp.config

file

of the
Automating
Lync

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 cl
ick
TODO:
9.3
.1
.

2.

Add the following code after the
TODO:
9.3
.1

comment
. This

g
et
s

the
Automation

instance
from the running instance of
Ly
nc.

C#

_automation = Microsoft.
Lync
.Model.
Lync
Client.GetAutomation();

3.

Double click
TODO:
9.3
.2
.

4.

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.

C#

v
ar contextData = new Dictionary<A
utomationModalitySettings, object>();


contextData.Add(AutomationModalitySettings.FirstInstantMessage,
instantMessageText.Text);


contextData.Add(AutomationModalitySettings.SendFirstInstantMessageImmediately,
true);

5.

Double click
TODO:
9.3
.3
.

6.

Add the following code after the
TODO:
9.3
.3

comment
. This

s
tart
s

an IM conversation by
adding a participant, setting the context parameters, and specifying instant messaging mode.

C#

_automation.BeginStartConversation(


conversationModes: AutomationMod
alities.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:
9.3
.4
.

2.

Add the following code after the
TODO:
9.3
.4

comment
. This

s
tart
s

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:
9.3
.5
.

2.

Add the following co
de after the
TODO:
9.3
.5

comment
. This

s
hare
s

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 secondar
y lab user.

1.

Navigate to
TODO:
9.3
.6
.

2.

Add the following code after the
TODO:
9.3
.6

comment
. This

t
ransfer
s

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.Fil
eTransfer,


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:
9.3
.7
.

2.

Add the following code after the
TODO:
9.3
.7

comment
. This

g
et
s

the handle to the
conversation
window
.

C#

_conversationWindow = ((Automation)ar.AsyncState).EndStartConversation(ar);


Dispatcher.Invoke(new Action(() =>

{


if (_canDock)


{


doc
kConversationWindow.IsEnabled = true;


_conversationWindow.Move(_conversationWindow.Left,
_conversationWindow.Top);


}


else


{


dockConversationWindow.IsEnabled = false;


}

}));

3.

Navigate to
TODO:
9.3
.8
.

4.

Add the following code aft
er the
TODO:
9.3
.8

comment adds event handlers for the
conversation window events.

C#

_conversationWindow.NeedsSizeChange +=


new
EventHandler<ConversationWindowNeedsSizeChangeEventArgs>(ConversationWindow_Ne
edsSizeChange);


_conversationWindow.NeedsAttention +=


new
EventHandler<ConversationWindowNeedsAttentionEventArgs>(ConversationWindow_Nee
dsAttention);

5.

Navigate to
TODO:
9.3
.
9
.

6.

Add the following code after the
TODO:
9.3
.9

comment
. This

d
ock
s

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:
9.3
.
10
.

8.

Add the following code after the
TODO:
9.3
.10

comment
. This

u
ndock
s

the
window by
calling its
Undock

method.

C#

_
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.



Summary

In this lab, you used the
Microsoft
Lync 2010

Managed
API
to build simp
le applications that leverage
Automation and the

Lync 2010

object model. You saw how easy it is to start conversations in different
modalities (IM, Audio, Desktop S
haring, File Transfer) using
Automation.