1

我想编写一个应用程序来检查 lync 2013 用户列表的可用性。所以有没有一种方法可以让 lync 与我的应用程序交换这些信息。

我想与在特定时间在线的用户进行交流。由于该列表将有数百个用户,因此我很难手动检查哪个用户在线。因此我想开发一个外部应用程序来执行此操作我。

4

1 回答 1

1

通过订阅 Lync 用户状态,您应该能够通过 UCMA 做到这一点。参考下面的示例代码:

// Set Persistent view in class constructor
var persistentSettings = new RemotePresenceViewSettings();
persistentSettings.SubscriptionMode = RemotePresenceViewSubscriptionMode.Persistent;                
this.PersistentPresenceView = new RemotePresenceView(this.AppEndpoint, persistentSettings);

// Listen to SubscriptionStateChanged  and PresenceNotificationReceived  events
this.PersistentPresenceView.SubscriptionStateChanged += this.RemotePresenceView_SubscriptionStateChanged;
this.PersistentPresenceView.PresenceNotificationReceived += this.RemotePresenceView_NotificationReceived;

// Call below public method to subscribe to user Lync Presence
public void SubscribeToPresences(List<string> emailAddressList)
{
    var subscriptionTargets = new List<RemotePresentitySubscriptionTarget>();
    var subscribedPresentities = this.PersistentPresenceView.GetPresentities();

    if (emailAddressList != null && emailAddressList.Count > 0)
    {
        foreach (var email in emailAddressList)
        {
            try
            {
                var target = new RemotePresentitySubscriptionTarget("sip:"+email);
                if (!subscribedPresentities.Contains(presence.EmailAddress))
                {
                    subscriptionTargets.Add(target);
                }
            }
            catch (ArgumentException argumentException)
            {                                
                // ToDO: Handle exception
            }
            catch (RealTimeException realTimeException)
            {                             
                // ToDO: Handle exception
            }

        }
    }
}

// Subscription changed event
private void RemotePresenceView_SubscriptionStateChanged(object sender, RemoteSubscriptionStateChangedEventArgs e)
{  
    foreach (KeyValuePair<RealTimeAddress, RemotePresentityStateChange> stateChanged in e.SubscriptionStateChanges)
    {
        if (view != null)
        {
            Console.WriteLine("\nView: " + view.ApplicationContext
                              + "; Subscription State for user: "
                              + stateChanged.Key /* uri of subscription target */
                              + " has changed from: " + stateChanged.Value.PreviousState
                              + " to: " + stateChanged.Value.State + ".");
        }
    }
}

// Notification received event
private void RemotePresenceView_NotificationReceived(object sender, RemotePresentitiesNotificationEventArgs e)
{
    foreach (RemotePresentityNotification notification in e.Notifications)
    {
        //// 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("Email Address: " + notification.PresentityUri.Split(':')[1]+ " Aggregate State = " + notification.AggregatedPresenceState.Availability + ".");
        }
    }
}
于 2015-04-13T16:26:14.427 回答