ContactManager.DeleteContact Méthode

Définition

Supprime un PeerContact ou PeerName à partir de l’homologue ContactManager local.

Surcharges

Nom Description
DeleteContact(PeerContact)

Supprime la valeur spécifiée PeerContact de l’homologue ContactManager local.

DeleteContact(PeerName)

Supprime l’associé PeerContact à l’homologue ContactManager local spécifiéPeerName.

DeleteContact(PeerContact)

Supprime la valeur spécifiée PeerContact de l’homologue ContactManager local.

public:
 void DeleteContact(System::Net::PeerToPeer::Collaboration::PeerContact ^ peerContact);
public void DeleteContact(System.Net.PeerToPeer.Collaboration.PeerContact peerContact);
member this.DeleteContact : System.Net.PeerToPeer.Collaboration.PeerContact -> unit
Public Sub DeleteContact (peerContact As PeerContact)

Paramètres

peerContact
PeerContact

À PeerContact supprimer du ContactManager.

Exceptions

peerContact a la valeur null.

Exemples

L’exemple de code suivant montre comment supprimer un d’un PeerContact local ContactManager:

//Enumerating the contacts and letting the user choose which one to delete.
public static void DeleteContact()
{
    PeerContactCollection pcc = null;
    string contactToDelete = "";

    try
    {
        pcc = EnumContacts();
        if (pcc == null ||
            pcc.Count == 0)
        {
            Console.WriteLine("Contact list is empty -- no such contact exists.");
            return;
        }
        Console.Write("Please enter the nickname of the contact you wish to delete: ");
        contactToDelete = Console.ReadLine();

        foreach (PeerContact pc in pcc)
        {
            if (pc.Nickname.Equals(contactToDelete))
            {
                PeerCollaboration.ContactManager.DeleteContact(pc);
                Console.WriteLine("Contact {0} successfully deleted!", contactToDelete);
                return;
            }
        }
        Console.WriteLine("Contact {0} could not be found in the contact collection.", contactToDelete);
    }
    catch (ArgumentNullException argNullEx)
    {
        Console.WriteLine("The supplied contact is null: {0}", argNullEx.Message);
    }
    catch (ArgumentException argEx)
    {
        Console.WriteLine("The supplied contact \"{0}\" could not be found in the Contact Manager: {1}",
            contactToDelete, argEx.Message);
    }
    catch (PeerToPeerException p2pEx)
    {
        Console.WriteLine("The Peer Collaboration Infrastructure could not delete \"{0}\": {1}",
            contactToDelete, p2pEx.Message);
    }
    catch (Exception ex)
    {
        Console.WriteLine("Unexpected exception when trying to delete a contact : {0}", ex);
    }
    return;
}

Remarques

L’appel de cette méthode nécessite un PermissionState de Unrestricted.

Voir aussi

S’applique à

DeleteContact(PeerName)

Supprime l’associé PeerContact à l’homologue ContactManager local spécifiéPeerName.

public:
 void DeleteContact(System::Net::PeerToPeer::PeerName ^ peerName);
[System.Security.SecurityCritical]
public void DeleteContact(System.Net.PeerToPeer.PeerName peerName);
[<System.Security.SecurityCritical>]
member this.DeleteContact : System.Net.PeerToPeer.PeerName -> unit
Public Sub DeleteContact (peerName As PeerName)

Paramètres

peerName
PeerName

Associé PeerName à la PeerContact suppression du ContactManager.

Attributs

Exceptions

Impossible de trouver l’associé PeerContactPeerName au gestionnaire de contacts.

peerName a la valeur null.

Cet objet a déjà été Dispose() appelé et ne peut pas être utilisé pour les opérations futures.

Impossible d’effectuer DeleteContact l’opération.

Exemples

L’exemple de code suivant montre comment supprimer un d’un PeerContact local ContactManager:

//Enumerating the contacts and letting the user choose which one to delete.
public static void DeleteContact()
{
    PeerContactCollection pcc = null;
    string contactToDelete = "";

    try
    {
        pcc = EnumContacts();
        if (pcc == null ||
            pcc.Count == 0)
        {
            Console.WriteLine("Contact list is empty -- no such contact exists.");
            return;
        }
        Console.Write("Please enter the nickname of the contact you wish to delete: ");
        contactToDelete = Console.ReadLine();

        foreach (PeerContact pc in pcc)
        {
            if (pc.Nickname.Equals(contactToDelete))
            {
                PeerCollaboration.ContactManager.DeleteContact(pc);
                Console.WriteLine("Contact {0} successfully deleted!", contactToDelete);
                return;
            }
        }
        Console.WriteLine("Contact {0} could not be found in the contact collection.", contactToDelete);
    }
    catch (ArgumentNullException argNullEx)
    {
        Console.WriteLine("The supplied contact is null: {0}", argNullEx.Message);
    }
    catch (ArgumentException argEx)
    {
        Console.WriteLine("The supplied contact \"{0}\" could not be found in the Contact Manager: {1}",
            contactToDelete, argEx.Message);
    }
    catch (PeerToPeerException p2pEx)
    {
        Console.WriteLine("The Peer Collaboration Infrastructure could not delete \"{0}\": {1}",
            contactToDelete, p2pEx.Message);
    }
    catch (Exception ex)
    {
        Console.WriteLine("Unexpected exception when trying to delete a contact : {0}", ex);
    }
    return;
}

Remarques

L’appel de cette méthode nécessite un PermissionState de Unrestricted.

Voir aussi

S’applique à