Use .NET code and the Microsoft Lync 2010 SDK to consume contextual data and handle events in a Microsoft Lync 2010 conversation.

Send and Access Contextual Data

Use Conversation object methods and events to send and access contextual data in a Lync 2010 conversation.

Sending Data

Use the BeginSendInitialContext and BeginSendContextData methods to send and update data in existing conversations. For more information, see the topic Send and Update Context in an Existing Conversation .

Accessing Data

On the receiver side, use the InitialContextReceived event to access data. See the following sample code.

  Copy imageCopy Code
public void
OnInitialContextReceived(Microsoft.Lync.Model.Conversation.Conversation
eventSource, Microsoft.Lync.Model.Conversation.ContextEventArgs
eventData)
		{
			try
			{
				string appId = eventData.ApplicationId;
				string appData = eventData.ApplicationData;
				Log(Color.Blue, string.Format(
					"ContextualConversation_OnContextReceived
AppId={0}, AppData={1}",
					appId, appData
					));
		}
			catch (Exception ex)
			{
				Log(ex);
		}
	}

On the sender side, use the InitialContextSent event to access data. See the following sample code.

  Copy imageCopy Code
public void
OnInitialContextSent(Microsoft.Lync.Model.Conversation.Conversation
eventSource, Microsoft.Lync.Model.Conversation.ContextEventArgs
eventData)
		{
			try
			{
				string appId = eventData.ApplicationId;
				string appData = eventData.ApplicationData;
				Log(Color.Blue, string.Format(
					"ContextualConversation_OnContextSent
AppId={0}, AppData={1}",
					appId, appData
					));
				string sourceAppData =
eventSource.GetApplicationData(appId);
		}
			catch (Exception ex)
			{
				Log(ex);
		}
	}

Use the GetApplicationData method on the Conversation object to access the most recent initial context. The most recent initial context is what the user has just sent or received using the BeginSendInitialData or BeginStartConversation methods. GetApplicationData does not return any subsequent context sent or received via BeginSendContextData .

Use LaunchLink to Access Application Data

Each launch link has data embedded in the launch URL. Clicking the link launches the application with the corresponding application data and fires the ConversationContextLinkClicked event. The LaunchLink appears in the conversation history when a user sends or receives a contextual conversation tied to a contextual application whose registration data contains a Path value. Clicking on the link executes the Path+Parameters values. If there is a %AppData% parameter in the Parameters value it will be replaced with the data embedded in the LaunchLink. The click also fires the LinkClicked event which delivers the application data to the application if it is running, If the application is not running the event will be missed. See the following example.

  Copy imageCopy Code
public void OnConversationContextLinkClicked(uc.Conversation
eventSource, uc.ContextEventData eventData)
		{
			try
			{
				Log(Color.Blue,
string.Format("ContextualConversation_OnLAunchLinkClicked
AppId={0}, AppData={1}",
					eventData.ApplicationId,
eventData.ApplicationData
					));
		}
			catch (Exception ex)
			{
				Log(ex);
		}
	}

Handle the ConversationAdded Event

Use the ConversationAdded () () () () event for conversation handling. The ConversationAdded event provides access to Conversation and ConversationWindow objects. Among other topics, see Walkthrough: Start an IM Conversation for example code that shows how to use the ConversationAdded event.

See Also

Other Resources