ContactManager.DeleteContact Methode

Definition

Entfernt ein PeerContact oder PeerName aus dem ContactManager lokalen Peer.

Überlädt

Name Beschreibung
DeleteContact(PeerContact)

Entfernt den angegebenen PeerContact Wert aus dem ContactManager lokalen Peer.

DeleteContact(PeerName)

Entfernt den PeerContact zugehörigen Wert PeerName aus dem ContactManager lokalen Peer.

DeleteContact(PeerContact)

Entfernt den angegebenen PeerContact Wert aus dem ContactManager lokalen Peer.

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)

Parameter

peerContact
PeerContact

The PeerContact to remove from the ContactManager.

Ausnahmen

peerContact ist null.

Beispiele

Im folgenden Codebeispiel wird veranschaulicht, wie sie ein PeerContact Element aus der lokalen Datei ContactManagerlöschen:

//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;
}

Hinweise

Zum Aufrufen dieser Methode ist eine PermissionState von Unrestricted.

Weitere Informationen

Gilt für:

DeleteContact(PeerName)

Entfernt den PeerContact zugehörigen Wert PeerName aus dem ContactManager lokalen Peer.

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)

Parameter

peerName
PeerName

Das PeerName zugeordnete Element, das PeerContact aus dem ContactManagerentfernt werden soll.

Attribute

Ausnahmen

Die PeerContact zugeordnete PeerName Person wurde im Kontakt-Manager nicht gefunden.

peerName ist null.

Dieses Objekt hat Dispose() es zuvor aufgerufen und kann nicht für zukünftige Vorgänge verwendet werden.

Der Vorgang kann nicht abgeschlossen werden DeleteContact .

Beispiele

Im folgenden Codebeispiel wird veranschaulicht, wie sie ein PeerContact Element aus der lokalen Datei ContactManagerlöschen:

//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;
}

Hinweise

Zum Aufrufen dieser Methode ist eine PermissionState von Unrestricted.

Weitere Informationen

Gilt für: