// Callback triggered when group is deleted private void EndDeleteGroupCompleted(IAsyncResult ar) { ContactGroupServices services = ar.AsyncState as ContactGroupServices; try { services.EndDeleteGroup(ar); Console.WriteLine("Group {0} was successfully deleted.", _groupName); _waitForGroupDeleted.Set(); } catch (PublishSubscribeException psex) { Console.WriteLine("Group {0} could not be deleted due to exception: {1}", _groupName, psex.ToString()); } catch (InvalidOperationException ioex) { Console.WriteLine("Delete Group failed due to exception: {0}", ioex.ToString()); } catch (OperationFailureException ofex) { Console.WriteLine("Delete Group failed due to exception: {0}", ofex.ToString()); } catch (RealTimeException rtex) { Console.WriteLine("Delete Group failed due to exception: {0}", rtex.ToString()); } finally { // Unsubscribe to target user _remotePresenceView.StartUnsubscribingToPresentities(new string[] { _target.Address.Uri }); } }
/// <summary> /// Unsubscribe from a specific uri. /// </summary> /// <param name="sipUri">Sip uri to unsubscribe from. Cannot be null or empty.</param> private void Unsubscribe(string sipUri) { Debug.Assert(!String.IsNullOrEmpty(sipUri), "Sip uri is null or empty"); SipUriParser uriParser; if (SipUriParser.TryParse(sipUri, out uriParser)) { m_remotePresenceView.StartUnsubscribingToPresentities(new List <string> { sipUri }); } }
/// <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(); }