Пример #1
0
        /// <summary>
        /// Constructor of a presence watcher supporting persistent, polling and on-demand subscriptions 
        /// to presence categories published by specified remote presentities. on-demand subscription is 
        /// also known as presence query. The code here also handles self-presence.
        /// </summary>
        /// <param name="endpoint"></param>
        public PresenceWatcher(LocalEndpoint endpoint)
        {
            _remotePresenceServices = endpoint.PresenceServices;

            // RemotePresenceView for persitent subscription:
            RemotePresenceViewSettings rpvs = new RemotePresenceViewSettings();
            rpvs.SubscriptionMode = RemotePresenceViewSubscriptionMode.Persistent;
            
            _persistentPresenceView = new RemotePresenceView(endpoint, rpvs);
            _persistentPresenceView.PresenceNotificationReceived += new EventHandler<RemotePresentitiesNotificationEventArgs>(PersistentPresenceReceivedEventHandler);
            
            _persistentPresenceView.SubscriptionStateChanged += new EventHandler<RemoteSubscriptionStateChangedEventArgs>(PersistentSubscriptionStateChangedEventHandler);
            
            // RemotePresenceView for polling subscription
            rpvs = new RemotePresenceViewSettings();
            rpvs.SubscriptionMode = RemotePresenceViewSubscriptionMode.Polling;
            rpvs.PollingInterval = new TimeSpan(0, 5, 0);  // every 5 minutes
            _pollingPresenceView = new RemotePresenceView(endpoint, rpvs);

            _pollingPresenceView.SetPresenceSubscriptionCategoriesForPolling(new string[] { "contactCard", "state", "note", "noteHistory" });
            
            _pollingPresenceView.PresenceNotificationReceived += new EventHandler<RemotePresentitiesNotificationEventArgs>(PollingPresenceReceivedEventHandler);

            _pollingPresenceView.SubscriptionStateChanged += new EventHandler<RemoteSubscriptionStateChangedEventArgs>(PollingSubscriptionStateChangedEventHandler);

        }
 public static Task <IEnumerable <RemotePresentityNotification> > PresenceQueryAsync(
     this LocalEndpointPresenceServices presenceServices, IEnumerable <string> targets, string[] categories,
     EventHandler <RemotePresentitiesNotificationEventArgs> queryResultHandler)
 {
     return(Task <IEnumerable <RemotePresentityNotification> > .Factory.FromAsync(
                presenceServices.BeginPresenceQuery,
                presenceServices.EndPresenceQuery,
                targets, categories,
                queryResultHandler, null));
 }
 public static Task RefreshRemotePresenceViews(this
                                               LocalEndpointPresenceServices presenceServices)
 {
     return(Task.Factory.FromAsync(presenceServices.BeginRefreshRemotePresenceViews,
                                   presenceServices.EndRefreshRemotePresenceViews, null));
 }