ContactManager クラス

定義

Windows アドレス帳に保持された PeerContact オブジェクトのコレクションを表します。

public ref class ContactManager sealed : IDisposable
public sealed class ContactManager : IDisposable
type ContactManager = class
    interface IDisposable
Public NotInheritable Class ContactManager
Implements IDisposable
継承
ContactManager
実装

次のコード例は、a を列挙PeerNearMeしてローカルContactManagerに a としてPeerContact追加する方法を示しています。

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

注釈

このクラスへの参照はクラスによって PeerCollaboration 返されるため、パブリック コンストラクターはありません。

管理に関連付 PeerContact けられているアドレス帳には、ホスト ピアとリモート ピアに関連付けられているアドレス帳が含まれます。 いずれかのコンピューターが他のピアと共同作業を行う場合があります。ピアがリモート ピアに対してローカルであるが、ホスト ピアではない場合は、そのピアを ContactManager ホスト ピアに追加できます。 クラスに対する特定のContactManager操作 (and DeleteContactなどAddContact) は、リモート ピアの Windows アドレス帳で実行されている関連する操作に関連付けられます。

ホスト ピアは、ピアが参加しようとしているアプリケーションに関連付けることができる情報を PeerContact 得るために、この永続ストレージにアクセスできます。 A PeerApplication は、コンピューター上の永続的な ContactManager ストアのユーザーとして自分自身を識別できます。

プロパティ

LocalContact

ローカル ピアを表す PeerContact を取得します。

SynchronizingObject

このプロパティ値を設定すると、非同期操作の結果として発生したわけではないすべてのイベントが、特定の SynchronizingObject を作成したスレッドでコールバックされるイベント ハンドラーに関連付けられます。

メソッド

AddContact(PeerContact)

指定した PeerContact をローカル ピアの ContactManager に追加します。

CreateContact(PeerNearMe)

指定された PeerContact オブジェクトの PeerNearMe インスタンスを作成します。

CreateContactAsync(PeerNearMe, Object)

指定された PeerNearMe オブジェクトのコンタクト インスタンスを作成します。

DeleteContact(PeerContact)

指定した PeerContact を、ローカル ピアの ContactManager から削除します。

DeleteContact(PeerName)

指定した PeerName に関連付けられている PeerContact をローカル ピアの ContactManager から削除します。

Dispose()

この ContactManager オブジェクトによって使用されているすべてのリソースを解放します。

Equals(Object)

指定されたオブジェクトが現在のオブジェクトと等しいかどうかを判断します。

(継承元 Object)
GetContact(PeerName)

指定された PeerContactPeerName オブジェクトを返します。

GetContacts()

リモート ピアの PeerContactCollection 内のすべての連絡先を格納する ContactManager を返します。

GetHashCode()

既定のハッシュ関数として機能します。

(継承元 Object)
GetType()

現在のインスタンスの Type を取得します。

(継承元 Object)
MemberwiseClone()

現在の Object の簡易コピーを作成します。

(継承元 Object)
ToString()

現在のオブジェクトを表す文字列を返します。

(継承元 Object)
UpdateContact(PeerContact)

PeerContact に関連付けられているデータを更新します。

events

ApplicationChanged

PeerApplication 内の PeerContact に関連付けられた ContactManager が変更されたときに発生します。

CreateContactCompleted

CreateContact(PeerNearMe) メソッドが完了したときに発生します。

NameChanged

PeerName 内の PeerContact に関連付けられた ContactManager が変更されたときに発生します。

ObjectChanged

連絡先の登録済みの PeerObject オブジェクト内のオブジェクトが変更されたときに発生します。

PresenceChanged

PeerContact 内の ContactManager のプレゼンス ステータスが変更されたときに発生します。

SubscriptionListChanged

サブスクライブされた連絡先の一覧が変更されたときに発生します。

適用対象

こちらもご覧ください