Exemplo n.º 1
0
        /// <summary>
        /// Subscribe to a specific uri.
        /// </summary>
        /// <param name="sipUri">Sip uri to subscribe to. Cannot be null or empty.</param>
        private void Subscribe(string sipUri)
        {
            Debug.Assert(!String.IsNullOrEmpty(sipUri), "Sip uri is null or empty");
            SipUriParser uriParser;

            if (SipUriParser.TryParse(sipUri, out uriParser))
            {
                var subscriptionTargets = new List <RemotePresentitySubscriptionTarget>();
                subscriptionTargets.Add(new RemotePresentitySubscriptionTarget(uriParser.ToString()));
                // Immediately fires NotificationReceived with current presence of targets
                m_remotePresenceView.StartSubscribingToPresentities(subscriptionTargets);
            }
        }
        // Handler for the NotificationsReceived event on the ContactGroupServices class.
        private void ContactGroupServices_NotificationReceived(object sender,
                                                               ContactsGroups.ContactGroupNotificationEventArgs e)
        {
            List <RemotePresentitySubscriptionTarget> targets = new List <RemotePresentitySubscriptionTarget>();

            foreach (NotificationItem <ContactsGroups.Contact> contactNotification in e.Contacts)
            {
                if (contactNotification.Operation == PublishOperation.Add)
                {
                    foreach (int id in contactNotification.Item.GroupIds)
                    {
                        if (id == (int)_groupID)
                        {
                            targets.Add(new RemotePresentitySubscriptionTarget(contactNotification.Item.Uri));
                        }
                    }
                }
            }
            _remotePresenceView.StartSubscribingToPresentities(targets);
        }
Exemplo n.º 3
0
 private void SubscribeToRemotePresentities()
 {
     try
     {
         Collection <RemotePresentitySubscriptionTarget> remotePresentities = new Collection <RemotePresentitySubscriptionTarget>();
         lock (this.SyncRoot)
         {
             foreach (string uri in m_contacts.Keys)
             {
                 remotePresentities.Add(new RemotePresentitySubscriptionTarget(uri));
             }
         }
         if (remotePresentities.Count > 0)
         {
             m_remotePresenceView.StartSubscribingToPresentities(remotePresentities);
         }
     }
     catch (InvalidOperationException ioe)
     {
         this.Logger.Log(Logger.LogLevel.Error, ioe);
     }
 }
Exemplo n.º 4
0
        private void StartupPresenceView(AsyncTask task, object state)
        {
            task.DoFinalStep(
                delegate()
            {
                CallbackRequest callbackRequest = (CallbackRequest)state;
                var viewSettings = new RemotePresenceViewSettings();
                viewSettings.SubscriptionMode = RemotePresenceViewSubscriptionMode.Persistent;
                var presenceView = new RemotePresenceView(callbackRequest.CutomerEndpoint, viewSettings);
                presenceView.ApplicationContext = callbackRequest;

                var target = new RemotePresentitySubscriptionTarget(callbackRequest.TargetUri);

                presenceView.PresenceNotificationReceived += this.PresenceView_NotificationReceived;
                presenceView.SubscriptionStateChanged     += this.PresenceView_SubscriptionStateChanged;

                callbackRequest.PresenceView = presenceView;

                presenceView.StartSubscribingToPresentities(
                    new RemotePresentitySubscriptionTarget[] { target });
            });
        }
Exemplo n.º 5
0
            /// <summary>
            /// Starts subscribing to the Presence of agents upon successful registration of the endpoint
            /// </summary>
            private void OnEstablishComplete(IAsyncResult result)
            {
                try
                {
                    _matchMaker._endpoint.EndEstablish(result);

                    //create a SubscriptionTarget for each agent
                    RemotePresentitySubscriptionTarget[] contacts = new RemotePresentitySubscriptionTarget[_matchMaker._configuration.Agents.Count];
                    for (int i = 0; i < _matchMaker.Configuration.Agents.Count; i++)
                    {
                        contacts[i] = new RemotePresentitySubscriptionTarget(_matchMaker._configuration.Agents[i].SignInAddress);
                    }


                    RemotePresenceView MatchMakerPresence = new RemotePresenceView(_matchMaker._endpoint);

                    //Initiate the persistent batch subscription to the list of agents
                    //Only interested in subscribing to the Agents Availability. We should not expect more than one category instance
                    //per Remote Presentity notification change. Always register the event handler before starting the subscription.
                    MatchMakerPresence.PresenceNotificationReceived += _matchMaker.HandleAgentAvailabilityChanged;


                    MatchMakerPresence.StartSubscribingToPresentities(contacts);

                    try
                    {
                        _matchMaker._mohServer = new AcdMusicOnHoldServer(_matchMaker, _matchMaker.Configuration.MusicOnHoldFilePath, _matchMaker._logger);

                        _matchMaker._mohServer.BeginStartUp(ar =>
                        {
                            AcdMusicOnHoldServer mohServer = ar.AsyncState as AcdMusicOnHoldServer;

                            mohServer.EndStartUp(ar);

                            lock (_matchMaker._syncRoot)
                            {
                                _matchMaker.UpdateState(MatchMakerState.Started);
                            }

                            this.SetAsCompleted(null, false);
                        },
                                                            _matchMaker._mohServer);
                    }
                    catch (RealTimeException ex)
                    {
                        _matchMaker._logger.Log("AcdAgentMatchMaker failed to subscribe to the Presence of its Agents", ex);
                        _matchMaker.BeginShutdown((asyncResult) =>
                        {
                            _matchMaker.EndShutdown(asyncResult);
                            this.SetAsCompleted(ex, false);
                        },
                                                  ex);
                    }
                }
                catch (RealTimeException ex)
                {
                    _matchMaker._logger.Log("AcdAgentMatchMaker failed to subscribe to the Presence of its Agents; verify your agent configuration.", ex);
                    this.SetAsCompleted(ex, false);
                    _matchMaker.BeginShutdown((asyncResult) =>
                    {
                        _matchMaker.EndShutdown(asyncResult);
                        this.SetAsCompleted(ex, false);
                    },
                                              ex);
                }
            }
Exemplo n.º 6
0
        /// <summary>
        /// Retrieves the application configuration and runs the sample.
        /// </summary>
        private void Run()
        {
            // Prepare and instantiate the platform.
            _helper       = new UCMASampleHelper();
            _userEndpoint = _helper.CreateEstablishedUserEndpoint(
                "SubscribePresence Sample User" /*endpointFriendlyName*/);

            // Get the URI of the remote user whose presence to subscribe to.
            _remoteUserUri = "sip:" + UCMASampleHelper.PromptUser(
                "Please enter the URI, in the format user@host, of the user whose Presence to subscribe to "
                + "=> ", "RemoteUserURI");

            // RemotePresenceView is the class to be used to subscribe to
            // another entity's presence.
            _remotePresenceView = new RemotePresenceView(_userEndpoint);

            // Wire up event handlers to receive the incoming notifications of
            // the remote user being subscribed to.
            _remotePresenceView.SubscriptionStateChanged += new EventHandler <
                RemoteSubscriptionStateChangedEventArgs>(
                RemotePresence_SubscriptionStateNotificationReceived);
            _remotePresenceView.PresenceNotificationReceived += new EventHandler <
                RemotePresentitiesNotificationEventArgs>(RemotePresence_PresenceNotificationReceived);

            try
            {
                // Subscribe to target user.
                _target = new RemotePresentitySubscriptionTarget(_remoteUserUri);
                _remotePresenceView.StartSubscribingToPresentities(
                    new RemotePresentitySubscriptionTarget[] { _target });

                // Subscribe to ContactGroupServices.
                // This is done so that the user can add/delete groups and
                // add/delete contacts, among other operations.
                _userEndpoint.ContactGroupServices.NotificationReceived += new EventHandler
                                                                           <Microsoft.Rtc.Collaboration.ContactsGroups.ContactGroupNotificationEventArgs>(
                    ContactGroupServices_NotificationReceived);
                _userEndpoint.ContactGroupServices.SubscriptionStateChange += new EventHandler
                                                                              <PresenceSubscriptionStateChangedEventArgs>(ContactGroupServices_SubscriptionStateChange);
                _userEndpoint.ContactGroupServices.BeginSubscribe(EndSubscribeCompleted,
                                                                  _userEndpoint.ContactGroupServices);

                // Wait for subscription to ContactsGroups to be completed.
                _waitForSubscribedToContactsGroupsCompleted.WaitOne();
                Console.WriteLine("Subscription to ContactsGroups completed.");

                // Create a new group.
                _userEndpoint.ContactGroupServices.BeginAddGroup(_groupName,
                                                                 null /* group data */,
                                                                 EndAddGroupCompleted,
                                                                 _userEndpoint.ContactGroupServices);

                // Wait for group to be created.
                _waitForGroupIdSet.WaitOne();

                // Add the remote user to the newly created group.
                ContactsGroups.ContactAddOptions addOptions
                    = new Microsoft.Rtc.Collaboration.ContactsGroups.ContactAddOptions();
                addOptions.GroupIds.Add(_groupId);
                _userEndpoint.ContactGroupServices.BeginAddContact(_remoteUserUri,
                                                                   addOptions,
                                                                   EndAddContactCompleted,
                                                                   _userEndpoint.ContactGroupServices);

                UCMASampleHelper.PauseBeforeContinuing("You are now subscribed to the presence of the remote "
                                                       + "user. \nPlease toggle the user state of the remote user to get the appropriate "
                                                       + "notifications. \nPress ENTER to delete the contact, delete the group, and unsubscribe"
                                                       + "to the presence of the remote user.");

                // Remove contact from group, and delete group.
                _userEndpoint.ContactGroupServices.BeginDeleteContact(_remoteUserUri,
                                                                      EndDeleteContactCompleted,
                                                                      _userEndpoint.ContactGroupServices);
            }
            catch (ArgumentException ex)
            {
                Console.WriteLine("Could not subscribe to the presence of the remote user: "******"\n\n********************");
            Console.WriteLine("Press ENTER to shutdown and exit.");
            Console.WriteLine("********************\n\n");
            Console.ReadLine();


            // Shutdown Platform
            _helper.ShutdownPlatform();
        }
Exemplo n.º 7
0
        /// <summary>
        /// Retrieves the application configuration and begins running the
        /// sample.
        /// </summary>
        private void Run()
        {
            // Prepare and instantiate the platform and an endpoint.
            _helper       = new UCMASampleHelper();
            _userEndpoint = _helper.CreateEstablishedUserEndpoint(
                "SubscribePresenceView Sample User" /*endpointFriendlyName*/);

            // Get the Uri of the remote user to subscribe to.
            _remoteUserUri = "sip:" +
                             UCMASampleHelper.PromptUser(
                "Please enter the URI, in the format User@Host, of the user to subscribe to => ",
                "RemoteUserURI");

            Console.WriteLine("\nChanging PresenceSubscriptionCategory Filter to only include ContactCard " +
                              "and PresenceState");
            // Set category filter. This is a global filter for all persistent
            // subscriptions and can only be changed before any subscriptions
            // are active.
            // BUGBUG: error CS0618: 'Microsoft.Rtc.Collaboration.LocalEndpoint.RemotePresence' is obsolete: 'This property will be removed from future Versions. Please see RemotePresenceView and PresenceServices instead.'
            // _userEndpoint.RemotePresence.PresenceSubscriptionCategories =
            //    new string[] { PresenceCategoryNames.ContactCard, PresenceCategoryNames.State };

            // RemotePresencView objects can be used to group subscriptions.
            // When a RemotePresenceView is created, it is created with the
            // specified RemotePresenceViewSettings and associated with the
            // specified LocalEndpoint. The views can then be accessed via the
            // LocalEndpoint setting: RemotePresenceViews.

            // RemotePresenceView.ApplicationContext can be used to pass or
            // store information related to the view (seen below).

            // Create a RemotePresenceView with a persistent subscription mode.
            // This type of view can represent a contact list, for example.
            // Note: The Default SubscriptionMode will start a subscription as
            // Persistent and downgrade to Polling if an error occurs.
            var persistentSettings = new RemotePresenceViewSettings();

            persistentSettings.SubscriptionMode = RemotePresenceViewSubscriptionMode.Default;
            _persistentView = new RemotePresenceView(_userEndpoint, persistentSettings);
            _persistentView.ApplicationContext = "Persistent View";

            // Wire up event handlers for the view
            this.WireUpHandlersForView(_persistentView);

            // Create a RemotePresenceView with a polling subscription mode
            // This type of view can represent a list of people
            // on the To: line of an e-mail, for example.
            var pollingSettings = new RemotePresenceViewSettings();

            pollingSettings.SubscriptionMode = RemotePresenceViewSubscriptionMode.Polling;
            // The line below is not necessary; PollingInterval has a default
            // (and minimum) value of 5 minutes.
            pollingSettings.PollingInterval = TimeSpan.FromMinutes(5);
            _pollingView = new RemotePresenceView(_userEndpoint, pollingSettings);
            _pollingView.ApplicationContext = "Polling View";

            // Wire up event handlers for the view
            this.WireUpHandlersForView(_pollingView);

            Console.WriteLine("\nChanging Polling View's category filter to only include Note.");
            _pollingView.SetPresenceSubscriptionCategoriesForPolling(
                new string[] { PresenceCategoryNames.Note });

            try
            {
                // This constructor does very basic validation on the uri
                _target = new RemotePresentitySubscriptionTarget(_remoteUserUri);
            }
            catch (ArgumentException argumentException)
            {
                // ArgumentException will be thrown if the parameter used to
                // create the RemotePresentitySubscriptionTarget is an
                // invalid sip Uri.

                // TODO (Left to the reader): Error handling code to either
                // retry creating the target with corrected parameters, log
                // the error for debugging or gracefully exit the program.
                Console.WriteLine(argumentException.ToString());
                throw;
            }

            Console.WriteLine("\nInitiating subscriptions for both Views to user: "******"succeed", but the StateChanged notifications will indicate the
            // subscription went to a Terminated state.
            _persistentView.StartSubscribingToPresentities(new RemotePresentitySubscriptionTarget[] { _target });
            _pollingView.StartSubscribingToPresentities(new RemotePresentitySubscriptionTarget[] { _target });

            // There is no callback for the StartSubscribingToPresentities
            // operation because subscriptions to multiple targets can
            // complete at different times. Completion or failure of the
            // subscription can be monitored through the
            // SubscriptionStateChanged event handler,
            // RemotePresenceView_NotificationReceived.

            UCMASampleHelper.PauseBeforeContinuing("Press ENTER to unsubscribe.");

            Console.WriteLine("\nBoth Views are terminating any subscriptions to user: "******"Press ENTER to shutdown and exit.");

            // Shutdown Platform
            _helper.ShutdownPlatform();
        }