Share via


Refreshing Active Subscriptions

In Microsoft Unified Communications Managed API (UCMA) 3.0, refreshing remote presence subscriptions is performed using an LocalEndpointPresenceServices object that can be obtained from an established (or connected) LocalEndpoint object.

Refreshing remote presence subscription is an asynchronous process. It applies to all the current subscriptions represented by the active RemotePresenceView objects. To refresh remote presence subscriptions, call BeginRefreshRemotePresenceViews/EndRefreshRemotePresenceViews methods. If the request is successful, the current values of the subscribed category instances, as specified in each active subscription view, will be returned as the PresenceNotificationReceived events and are handled by the same event handlers of the respective subscription.

The following code example shows how to refresh all active remote subscriptions.

        #region Refresh all remote presence views
        public void RefreshRemoteSubscription()
        {
            _remotePresenceServices.BeginRefreshRemotePresenceViews(CallbackOnBeginRefreshReturned, _remotePresenceServices);
        }

        private void CallbackOnBeginRefreshReturned(IAsyncResult result)
        {
            try
            {
                LocalEndpointPresenceServices localEndpointPresenceServices = result.AsyncState as LocalEndpointPresenceServices;
                if (localEndpointPresenceServices == _remotePresenceServices)
                {
                    _remotePresenceServices.EndRefreshRemotePresenceViews(result);
                    if (OnRefreshPresenceViewsCompleted != null)
                        RaiseEvent(OnRefreshPresenceViewsCompleted, this,
                            new AsyncOpStatusEventArgs(AsyncOpStatus.OK, null));
                }
            }
            catch (Exception ex)
            {
                if (OnRefreshPresenceViewsCompleted != null)
                    RaiseEvent(OnRefreshPresenceViewsCompleted, this, 
                        new AsyncOpStatusEventArgs(AsyncOpStatus.Error, ex));
            }
        }
        #endregion Refresh all remote presence views

In this example, the results are returned in both PersistentPresenceReceivedEventHandler and PollingPresenceReceivedEventHandler. For an implementation of these event handlers, see Handling Events to Receive Presence Publications.