Skip to content

Instantly share code, notes, and snippets.

@dannylloyd
Created August 19, 2013 18:43
Show Gist options
  • Select an option

  • Save dannylloyd/6272575 to your computer and use it in GitHub Desktop.

Select an option

Save dannylloyd/6272575 to your computer and use it in GitHub Desktop.
Get Lync Presence
Imports Microsoft.Lync.Model
Imports System.Threading
Public Class PresenceChecker
Private _contact As Contact
Dim waithandle As AutoResetEvent = New Threading.AutoResetEvent(False)
Dim state As ContactAvailability
Public Function GetUsersPresence(user As String) As ContactAvailability
' Microsoft Lync Client is not even available
Dim client = LyncClient.GetClient()
Dim contactManager = client.ContactManager.CreateSubscription()
Dim contactInformationList As New List(Of ContactInformationType)
contactInformationList.Add(ContactInformationType.Availability)
'contactManager.AddContact(client.ContactManager.GetContactByUri("email@email.com"))
contactManager = LyncClient.GetClient().ContactManager.CreateSubscription()
Dim contact = client.ContactManager.GetContactByUri("drlloyd@uams.edu")
_contact = contact
contactManager.AddContact(contact)
contactManager.Subscribe(ContactSubscriptionRefreshRate.High, contactInformationList)
AddHandler contact.ContactInformationChanged, AddressOf contactInformationChanged
waithandle.WaitOne()
' in case of signing out or re-signing, self contact is already released
If client.State = ClientState.SigningOut OrElse client.State = ClientState.SignedOut OrElse client.State = ClientState.SigningIn Then
Return ContactAvailability.Offline
End If
Dim self As Contact = client.Self.Contact
Return DirectCast(self.GetContactInformation(ContactInformationType.Availability), ContactAvailability)
End Function
Private Function contactInformationChanged(sender As Object, e As ContactInformationChangedEventArgs) As ContactAvailability
If e.ChangedContactInformation.Contains(Microsoft.Lync.Model.ContactInformationType.Availability) Then
waithandle.Set()
state = _contact.GetContactInformation(ContactInformationType.Availability)
End If
Return Nothing
End Function
End Class
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment