2

My requirement is I need to create a windows service which retrieves the Lync presence status(Available, Busy, Do not disturb ....) of each user in the Active directory.

I googled and found that below SDKs can retrieve the Lync Presence. Lync Client 2010 SDK, Unified Communications Managed API, Lync Server 2010 SDK, Unified Communications Client API.

Please suggest the best SDK among them to achieve my requirement.

Thanks in Advance.

user369287
  • 692
  • 8
  • 28

2 Answers2

2

There's a good write-up of each SDK and where you would use them here: http://www.codelync.com/an-overview-of-the-lync-apis/

For what you want to achieve, I would recommend using UCMA - the Unified Communications Client API. The way it works it that you give it a list of users you want to monitor status of, and it will then call back on an event each time their presence changes. You get a presence event as soon as you start subscribing, so you could then unsubscribe if you don't want to have ongoing notification.

An example of subscribing to lots of users might be:

  var _remotePresenceView = new RemotePresenceView(_endpoint);
_remotePresenceView.PresenceNotificationReceived += _remotePresenceView_PresenceNotificationReceived;
List<RemotePresentitySubscriptionTarget> subscriptions = new List<RemotePresentitySubscriptionTarget>();

subscriptions.Add(new RemotePresentitySubscriptionTarget("sip:first_user@domain));
subscriptions.Add(new RemotePresentitySubscriptionTarget("sip:second_user@domain));
...
subscriptions.Add(new RemotePresentitySubscriptionTarget("sip:nth_user@domain));

_remotePresenceView.StartSubscribingToPresentities(subscriptions);

There's a couple of tips, tricks and gotchas when using the Remote Presence View: check out MSDN here.

Tom Morgan
  • 2,355
  • 18
  • 29
  • 1
    Tom thanks for the reply. In this link http://social.msdn.microsoft.com/Forums/en-US/ucmanagedsdk/thread/b5329594-944b-4cfd-a517-7242328547d2 it is mentioned that currently UCMA will not support Office365-Lync online... so please advice me what I needs to be done for Lync online. – user369287 May 29 '13 at 07:43
  • I don't think that you currently do anything like for Office365. You might be able to use the client SDK but you'd be limited in the contacts you can get presence for - possibly only those in your contact list. I don't have much experience with O365 I'm afraid. – Tom Morgan May 30 '13 at 15:34
  • Trying to use the Lync Client SDK from the context of a Windows Service is a little problematic... The Lync client is reliant on the desktop manager being active, so you will frequently see the Lync.exe process that you are running via the SDK terminate if the desktop manager goes away, i.e. users log off the OS. It is, so far as I know, the only option for Office 365 until Microsoft gets around to releasing some sort of official API, however. – EricRRichards Sep 21 '15 at 19:09
0

I also tried to find the presence state of the User and come out with the below code to achieve this requirement.

                string _transferUserURI="pass your sipaddress";
                RemotePresenceView _RemotePresence;

                RemotePresenceViewSettings settings = new RemotePresenceViewSettings();
                settings.SubscriptionMode = RemotePresenceViewSubscriptionMode.Default;
                settings.PollingInterval = new TimeSpan(0, 0, 10);
                _RemotePresence = new RemotePresenceView(_appEndpoint, settings);
                _RemotePresence.PresenceNotificationReceived += new EventHandler<RemotePresentitiesNotificationEventArgs>(_RemotePresence_PresenceNotificationReceived);
                //_RemotePresence.SubscriptionStateChanged += new EventHandler<RemoteSubscriptionStateChangedEventArgs>(_RemotePresence_SubscriptionStateChanged);

                RemotePresentitySubscriptionTarget target = new RemotePresentitySubscriptionTarget(_transferUserURI);
                List<RemotePresentitySubscriptionTarget> targets = new List<RemotePresentitySubscriptionTarget>() { target };
                _RemotePresence.StartSubscribingToPresentities(targets);

and _RemotePresence_PresenceNotificationReceived event

       void _RemotePresence_PresenceNotificationReceived(object sender, RemotePresentitiesNotificationEventArgs e)
    {
        try
        {
            // Extract the RemotePresenceView that received the notification.
            RemotePresenceView view = sender as RemotePresenceView;
            // A RemotePresentityNotification will contain all the
            // categories for one user; Notifications can contain notifications
            // for multiple users.


            foreach (RemotePresentityNotification notification in e.Notifications)
            {
                Console.WriteLine("\nView: " + view.ApplicationContext
                    + " Received a Notification for user "
                    + notification.PresentityUri + ".");

                // If a category on notification is null, the category
                // was not present in the notification. This means there were no
                // changes in that category.
                if (notification.AggregatedPresenceState != null)
                {
                    Console.WriteLine("Aggregate State = " + notification.AggregatedPresenceState.Availability + ".");

                    string Availblity = notification.AggregatedPresenceState.Availability.ToString();
                }

                if (notification.PersonalNote != null)
                {
                    Console.WriteLine("PersonalNote: " + notification.PersonalNote.Message + ".");
                }

                if (notification.ContactCard != null)
                {
                    // A ContactCard contains many properties; only display
                    // some.
                    ContactCard contactCard = notification.ContactCard;
                    Console.WriteLine("ContactCard Company: " + contactCard.Company + ".");
                    Console.WriteLine("ContactCard DisplayName: " + contactCard.DisplayName + ".");
                    Console.WriteLine("ContactCard EmailAddress: " + contactCard.EmailAddress + ".");
                }
            }
        }
        catch
        {

        }
    }

I hope this was the answer you are looking otherwise correct me if i was wrong.

Dinesh Haraveer
  • 1,784
  • 3
  • 31
  • 54
  • Thanks for the code. However I am not clear with how you created an App Endpoint. _RemotePresence = new RemotePresenceView(_appEndpoint, settings); – GingerBeer Apr 14 '18 at 03:47