/// <summary> /// Determines whether an Agent is available or not based on a Presence State change /// notification. /// </summary> /// <param name="notification">presence state change notification associated with an agent</param> private bool IsAgentAvailable(RemotePresentityNotification notification) { bool isAgentAvailable = false; long availability = notification.AggregatedPresenceState.AvailabilityValue; _logger.Log("Presence Changed: " + notification.PresentityUri + ": " + availability.ToString()); //return true only if the availability is return(isAgentAvailable = (availability > (long)PresenceAvailability.Online && availability < (long)PresenceAvailability.Busy)); }
/// <summary> /// Helper method to convery notification to presence. /// </summary> /// <param name="notification">Notification</param> /// <returns>Presence subscription</returns> private PresenceInformation ConvertNotificationToPresence(RemotePresentityNotification notification) { //after the first notification for a contact, you only get the categories that changed next time //so after the first notification if presence changes, you only get presence; if name changes you only get contact card long availability = PresenceInformation.NoChangeInAvailability; string status = PresenceInformation.NoChange; string contactName = PresenceInformation.NoChange; string activityStatus = PresenceInformation.NoChange; var presence = notification.AggregatedPresenceState; if (presence != null) { //Get availability. availability = presence.AvailabilityValue; status = AvailabilityToStatusConverter.Convert(availability); //Get activity status. PresenceActivity activity = presence.Activity; if (activity != null && activity.CustomTokens != null && activity.CustomTokens.Count > 0) { //For now just take the first token. activityStatus = activity.CustomTokens[0].Value ?? PresenceInformation.NoChange; } } var contactCard = notification.ContactCard; if (contactCard != null) { contactName = contactCard.DisplayName; } return(new PresenceInformation { Availability = availability, ContactName = contactName, SipUri = notification.PresentityUri, Status = status, ActivityStatus = activityStatus }); }