Exemple #1
0
        /// <summary>
        /// Called when a participant is removed from the conversation.
        ///
        /// Removes the participant from the roster listbox.
        /// </summary>
        void conversation_ParticipantRemoved(object sender, ParticipantCollectionChangedEventArgs e)
        {
            //error case, the participant wasn't actually removed
            if (e.StatusCode < 0)
            {
                Console.Out.WriteLine("Participant was not removed: code=" + e.StatusCode);
                return;
            }

            //posts the execution into the UI thread
            this.BeginInvoke(new MethodInvoker(delegate()
            {
                //finds the position of the participant to be removed in the roster listbox
                int removePosition = -1;
                for (int i = 0; i < listBoxRosterContacts.Items.Count; i++)
                {
                    ParticipantItem item = listBoxRosterContacts.Items[i] as ParticipantItem;
                    if (item != null && item.Participant.Equals(e.Participant))
                    {
                        removePosition = i;
                        break;
                    }
                }

                //removes the participant from the roster listbox
                if (removePosition > 0)
                {
                    listBoxRosterContacts.Items.RemoveAt(removePosition);
                }
            }));
        }
Exemple #2
0
        /// <summary>
        /// Removes a participant from the conversation.
        /// </summary>
        private void buttonRemoveRosterContact_Click(object sender, EventArgs e)
        {
            //validates if there's a participant selected
            if (listBoxRosterContacts.SelectedIndex <= 0)
            {
                MessageBox.Show("Please select a participant (other than self).");
                return;
            }

            //get the selected participant for removal
            ParticipantItem item = listBoxRosterContacts.SelectedItem as ParticipantItem;

            //removes the participant from the conversation
            try
            {
                if (item != null)
                {
                    conversation.RemoveParticipant(item.Participant);
                }
            }
            catch (LyncClientException lyncClientException)
            {
                Console.WriteLine(lyncClientException);
            }
            catch (SystemException systemException)
            {
                if (LyncModelExceptionHelper.IsLyncException(systemException))
                {
                    // Log the exception thrown by the Lync Model API.
                    Console.WriteLine("Error: " + systemException);
                }
                else
                {
                    // Rethrow the SystemException which did not come from the Lync Model API.
                    throw;
                }
            }
        }