ContactManager Classe
Définition
Important
Certaines informations portent sur la préversion du produit qui est susceptible d’être en grande partie modifiée avant sa publication. Microsoft exclut toute garantie, expresse ou implicite, concernant les informations fournies ici.
Représente une collection d’objets PeerContact qui persistent dans un carnet d’adresses Windows.
public ref class ContactManager sealed : IDisposable
public sealed class ContactManager : IDisposable
type ContactManager = class
interface IDisposable
Public NotInheritable Class ContactManager
Implements IDisposable
- Héritage
-
ContactManager
- Implémente
Exemples
L’exemple de code suivant illustre comment énumérer un PeerNearMe et l’ajouter en tant que PeerContact code local ContactManager:
// Displays all contacts and asssociated peer endpoints (PeerEndPoint) in the PeerContactCollection.
private static void DisplayContacts(PeerContactCollection peerContactsCollection)
{
if (peerContactsCollection == null ||
peerContactsCollection.Count == 0)
{
Console.WriteLine("No contacts to display. To add a contact select option 0 from the menu.");
}
else
{
foreach (PeerContact pc in peerContactsCollection)
{
Console.WriteLine("The contact is: {0}", pc.DisplayName);
DisplayEndpoints(pc.PeerEndPoints);
}
}
return;
}
//------------------------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------------------------
// Displays all peer end points (PeerEndPoint) in the PeerEndPointCollection.
private static void DisplayEndpoints(PeerEndPointCollection endpointCollection)
{
if (endpointCollection == null || endpointCollection.Count == 0)
{
Console.WriteLine("No peer endpoints in the collection to display.");
}
else
{
foreach (PeerEndPoint pep in endpointCollection)
{
Console.WriteLine("PeerEndPoint is: {0}", pep);
Console.WriteLine("PeerEndPoint data is:\n Name: {0}\n EndPoint IP address: {1}\n . Port: {2}\n",
pep.Name,
pep.EndPoint.Address,
pep.EndPoint.Port);
}
}
return;
}
//------------------------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------------------------
//List PeerNearMe objects that may be added as contacts.
private static void AddContact()
{
PeerNearMeCollection pnmc = null;
PeerContactCollection peerContacts = null;
bool peerNameFound = false;
PeerApplication application = null;
try
{
Console.WriteLine("Listing the existing contacts...");
peerContacts = PeerCollaboration.ContactManager.GetContacts();
}
catch (PeerToPeerException p2pEx)
{
Console.WriteLine("The Peer Collaboration Infrastructure is not responding to the contact enumeration request: {0}", p2pEx.Message);
}
catch (Exception ex)
{
Console.WriteLine("An unexpected error occurred while attempting to obtain the contact list: {0}", ex.Message);
}
DisplayContacts(peerContacts);
try
{
//Adds one of the PeerNearMe objects as a contact.
pnmc = GetPeersNearMe();
Console.WriteLine("Please enter the nickname of the peer you wish to add as a contact:");
string peerNameToAdd = Console.ReadLine();
application = RegisterCollabApp();
foreach (PeerNearMe pnm in pnmc)
{
PeerInvitationResponse res = null;
if (pnm.Nickname.Contains(peerNameToAdd))
{
peerNameFound = true;
if (!peerContacts.ToString().Contains(pnm.Nickname))
{
Console.WriteLine("Adding peer {0} to the contact list.", pnm.Nickname);
pnm.AddToContactManager();
}
else
{
Console.WriteLine("This peer already exists in your contact list.");
Console.WriteLine("Sending invitation using the Contact structure instead of the PeerNearMe.");
foreach (PeerContact pc in peerContacts)
{
if (pc.Nickname.Equals(pnm.Nickname))
{
res = pnm.Invite(application, "Peer Collaboration Sample", application.Data);
if (res.PeerInvitationResponseType == PeerInvitationResponseType.Accepted)
{
Console.WriteLine("Invitation to contact succeeded.");
}
else
{
Console.WriteLine("Invitation to contact {0}.", res.PeerInvitationResponseType);
}
}
}
}
}
}
if (!peerNameFound)
{
Console.WriteLine("No such peer exists near you. Cannot add to contacts.");
return;
}
peerContacts = PeerCollaboration.ContactManager.GetContacts();
Console.WriteLine("Listing the contacts again...");
DisplayContacts(peerContacts);
}
catch (Exception ex)
{
Console.WriteLine("Error adding a contact: {0}", ex.Message);
}
finally
{
application.Dispose();
}
return;
}
Remarques
Cette classe n’a aucun constructeur public, car une référence à celle-ci est retournée par la PeerCollaboration classe.
Les carnets d’adresses associés à PeerContact la gestion incluent ceux associés à l’homologue hôte et à un homologue distant. L’un ou l’autre ordinateur peut collaborer avec d’autres homologues ; lorsqu’un homologue est local vers l’homologue distant, mais pas l’homologue hôte, il peut être ajouté à l’homologue ContactManager hôte. Certaines opérations sur la classe ContactManager, telles que AddContact et DeleteContact, correspondent aux opérations associées effectuées sur le carnet d’adresses Windows de l’homologue distant.
L’homologue hôte a accès à ce stockage persistant pour PeerContact obtenir des informations, qui peuvent être associées aux applications dans lesquelles un homologue a l’intention de participer. Un PeerApplication peut s’identifier en tant qu’utilisateur d’un ContactManager magasin persistant sur un ordinateur.
Propriétés
| Nom | Description |
|---|---|
| LocalContact |
Obtient le PeerContact représentant de l’homologue local. |
| SynchronizingObject |
Lorsque cette valeur de propriété est définie, tous les événements qui ne sont pas déclenchés suite à une opération asynchrone auront les gestionnaires d’événements associés appelés sur le thread qui a créé l’élément spécifique SynchronizingObject. |
Méthodes
| Nom | Description |
|---|---|
| AddContact(PeerContact) |
Ajoute le paramètre spécifié PeerContact à l’homologue ContactManager local. |
| CreateContact(PeerNearMe) |
Crée une PeerContact instance pour l’objet spécifié PeerNearMe . |
| CreateContactAsync(PeerNearMe, Object) |
Crée une instance de contact pour l’objet spécifié PeerNearMe . |
| 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. |
| Dispose() |
Libère toutes les ressources utilisées par l’objet ContactManager . |
| Equals(Object) |
Détermine si l’objet spécifié est égal à l’objet actuel. (Hérité de Object) |
| GetContact(PeerName) |
Retourne l’objet PeerContact pour le fichier spécifié PeerName. |
| GetContacts() |
Retourne un PeerContactCollection qui contient tous les contacts au sein de l’homologue ContactManager distant. |
| GetHashCode() |
Sert de fonction de hachage par défaut. (Hérité de Object) |
| GetType() |
Obtient la Type de l’instance actuelle. (Hérité de Object) |
| MemberwiseClone() |
Crée une copie superficielle du Objectactuel. (Hérité de Object) |
| ToString() |
Retourne une chaîne qui représente l’objet actuel. (Hérité de Object) |
| UpdateContact(PeerContact) |
Met à jour les données associées au PeerContact. |
Événements
| Nom | Description |
|---|---|
| ApplicationChanged |
Déclenché chaque fois qu’un PeerApplication associé à un PeerContact dans le fichier ContactManager a changé. |
| CreateContactCompleted |
Déclenché chaque fois qu’une CreateContact(PeerNearMe) méthode est terminée. |
| NameChanged |
Déclenché chaque fois que l’associé PeerName à un PeerContact dans le fichier ContactManager a changé. |
| ObjectChanged |
Déclenché chaque fois qu’un objet dans les objets inscrits PeerObject d’un contact a changé. |
| PresenceChanged |
Déclenché chaque fois que l’état de présence d’un PeerContact dans le fichier ContactManager a changé. |
| SubscriptionListChanged |
Déclenché lorsque la liste des contacts abonnés change. |