예제 #1
0
        /// <summary>
        /// Retrieves the application configuration and begins running the
        /// sample.
        /// </summary>
        private void Run()
        {
            try
            {
                // Prepare and instantiate the platform.
                _helper = new UCMASampleHelper();
                UserEndpointSettings userEndpointSettings = _helper.ReadUserSettings(
                    "PublishPresence Sample User" /*friendly name of the sample's user endpoint*/);

                // Set auto subscription to LocalOwnerPresence.
                userEndpointSettings.AutomaticPresencePublicationEnabled = true;
                _userEndpoint = _helper.CreateUserEndpoint(userEndpointSettings);

                // LocalOwnerPresence is the main class to manage the
                // sample user's presence data.
                _localOwnerPresence = _userEndpoint.LocalOwnerPresence;

                // Wire up handlers to receive presence notifications to self.
                _localOwnerPresence.PresenceNotificationReceived
                    += LocalOwnerPresence_PresenceNotificationReceived;

                // Establish the endpoint.
                _helper.EstablishUserEndpoint(_userEndpoint);

                // Publish presence categories with the new values that
                // are outlined in the sample.
                PublishPresenceCategories(true /* publish presence categories */);
                Console.WriteLine("Note, AggregateState, and ContactCard published.");

                // Wait for user to continue.
                UCMASampleHelper.PauseBeforeContinuing(
                    "Press ENTER to continue and delete the published presence.");

                // Delete presence categories, returning them to the original
                // values before the sample was run.
                PublishPresenceCategories(false /* delete presence categories */);

                // Wait for user to continue.
                UCMASampleHelper.PauseBeforeContinuing("Press ENTER to shutdown and exit.");

                // Un-wire the presence notification event handler.
                _localOwnerPresence.PresenceNotificationReceived
                    -= LocalOwnerPresence_PresenceNotificationReceived;
            }
            finally
            {
                // Shut down platform before exiting the sample.
                _helper.ShutdownPlatform();
            }
        }
예제 #2
0
        private void OnConnect(object sender, EventArgs e)
        {
            try
            {
                if (object.ReferenceEquals(null, _helper))
                {
                    // Prepare and instantiate the platform with friendly name of the sample's user endpoint
                    _helper = new UCMASampleHelper();
                    UserEndpointSettings userEndpointSettings = _helper.ReadUserSettings(((AssemblyTitleAttribute)Attribute.GetCustomAttribute(Assembly.GetExecutingAssembly(), typeof(AssemblyTitleAttribute), false)).Title);

                    // Set auto subscription to LocalOwnerPresence.
                    userEndpointSettings.AutomaticPresencePublicationEnabled = true;

                    // Set the capabilities
                    userEndpointSettings.Presence.PreferredServiceCapabilities.ApplicationSharingSupport = CapabilitySupport.Supported;
                    userEndpointSettings.Presence.PreferredServiceCapabilities.AudioSupport            = CapabilitySupport.Supported;
                    userEndpointSettings.Presence.PreferredServiceCapabilities.InstantMessagingSupport = CapabilitySupport.Supported;
                    userEndpointSettings.Presence.PreferredServiceCapabilities.VideoSupport            = CapabilitySupport.Supported;

                    // Set the status and create endpoint
                    userEndpointSettings.Presence.UserPresenceState = PresenceState.UserAway;
                    _userEndpoint = _helper.CreateUserEndpoint(userEndpointSettings);

                    // LocalOwnerPresence is the main class to manage the
                    // sample user's presence data.
                    _localOwnerPresence = _userEndpoint.LocalOwnerPresence;

                    // Wire up handlers to receive presence notifications to self.
                    _localOwnerPresence.PresenceNotificationReceived
                        += LocalOwnerPresence_PresenceNotificationReceived;

                    // Establish the endpoint.
                    _helper.EstablishUserEndpoint(_userEndpoint);

                    // Set 'Connected' text for the first menu item
                    _trayMenu.MenuItems[0].Text    = "Connected";
                    _trayMenu.MenuItems[0].Checked = true;
                }
            }
            catch (Exception) { throw; }
        }
예제 #3
0
        private void Run()
        {
            // Prepare and instantiate the platform.
            _helper = new UCMASampleHelper();
            UserEndpointSettings userEndpointSettings = _helper.ReadUserSettings(
                "PresenceContainerMembership Sample subscribee" /*endpointFriendlyName*/);

            // Set auto subscription to LocalOwnerPresence
            userEndpointSettings.AutomaticPresencePublicationEnabled = true;
            _subscribee = _helper.CreateUserEndpoint(userEndpointSettings);

            // Establish the endpoint
            _helper.EstablishUserEndpoint(_subscribee);

            _subscriberUri = UCMASampleHelper.PromptUser("Please Enter the subscriber's Uri in the form "
                                                         + "sip:User@Hostuser. Please ensure that the uri is in the same domain as "
                                                         + _subscriberUriKey,
                                                         _subscriberUriKey);

            if (!_subscriberUri.StartsWith(_sipPrefix, StringComparison.OrdinalIgnoreCase))
            {
                _subscriberUri = _sipPrefix + _subscriberUri;
            }

            Console.WriteLine("{0} will block {1}, then unblock him. Please login to Microsoft Lync as {1}.",
                              _subscribee.OwnerUri,
                              _subscriberUri);

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

            // First publish MachineStateOnline using default grammar. UCMA SDK
            // will publish to the correct containers.
            _subscribee.LocalOwnerPresence.BeginPublishPresence(
                new PresenceCategory[] { PresenceState.EndpointOnline, PresenceState.UserAvailable },
                HandleEndPublishPresence,
                null);

            Console.WriteLine("{0} has published 'Available'. ", _subscribee.OwnerUri);
            Console.WriteLine("Using Microsoft Lync, please subscribe to {0} when logged in as {1}. ",
                              _subscribee.OwnerUri,
                              _subscriberUri);
            Console.WriteLine("You should see that {0} is online and Available. ", _subscribee.OwnerUri);

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

            ContainerUpdateOperation operation = new ContainerUpdateOperation(_blockedContainer);

            operation.AddUri(_subscriberUri);
            _subscribee.LocalOwnerPresence.BeginUpdateContainerMembership(
                new ContainerUpdateOperation[] { operation },
                HandleEndUpdateContainerMembership, null);

            Console.WriteLine("{0} has added {1} to container {2} - the blocked container.",
                              _subscribee.OwnerUri,
                              _subscriberUri,
                              _blockedContainer);
            Console.WriteLine("Microsoft Lync should display 'Offline' for user {0} now. ",
                              _subscribee.OwnerUri);

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

            operation = new ContainerUpdateOperation(_blockedContainer);
            operation.DeleteUri(_subscriberUri);
            _subscribee.LocalOwnerPresence.BeginUpdateContainerMembership(
                new ContainerUpdateOperation[] { operation },
                HandleEndUpdateContainerMembership, null);

            Console.WriteLine("{0} has removed {1} from the blocked container. Microsoft Lync should display "
                              + "'online' for user {0} now. ",
                              _subscribee.OwnerUri,
                              _subscriberUri);
            Console.WriteLine(" Sample complete. ");

            UCMASampleHelper.PauseBeforeContinuing("Press ENTER to shutdown and exit.");

            // Shutdown Platform
            _helper.ShutdownPlatform();
        }