我想编写一个应用程序来检查lync 2013用户列表的可用性。所以有一种方法可以让lync用我的应用程序交换这些信息。
我想与在特定时间在线的用户进行通信。由于该列表将有数百个用户,因此我很难手动检查哪个用户在线。因此我想开发一个外部应用程序这对我来说。
答案 0 :(得分: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 + ".");
}
}
}