ContactManager クラス
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
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
- 実装
例
次のコード例は、PeerNearMeを列挙し、ローカル ContactManagerに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 クラスに対する特定の操作 (AddContact、DeleteContact など) は、リモート ピアの Windows アドレス帳に対して実行されている関連する操作に関連付けられます。
ホスト ピアは、 PeerContact 情報に対してこの永続的ストレージにアクセスできます。これは、ピアが参加するアプリケーションに関連付けることができます。 PeerApplicationは、コンピューター上のContactManager永続的ストアのユーザーとして自分自身を識別できます。
プロパティ
| 名前 | 説明 |
|---|---|
| LocalContact |
ローカル ピアを表す PeerContact を取得します。 |
| SynchronizingObject |
このプロパティ値を設定すると、非同期操作の結果として発生しないすべてのイベントは、特定の SynchronizingObjectを作成したスレッドで呼び出される関連付けられたイベント ハンドラーを持ちます。 |
メソッド
| 名前 | 説明 |
|---|---|
| AddContact(PeerContact) |
指定した PeerContact をローカル ピアの ContactManager に追加します。 |
| CreateContact(PeerNearMe) |
指定したPeerNearMe オブジェクトのPeerContact インスタンスを作成します。 |
| CreateContactAsync(PeerNearMe, Object) |
指定した PeerNearMe オブジェクトの連絡先インスタンスを作成します。 |
| DeleteContact(PeerContact) |
ローカル ピアのContactManagerから、指定したPeerContactを削除します。 |
| DeleteContact(PeerName) |
ローカル ピアのContactManagerから、指定したPeerNameに関連付けられているPeerContactを削除します。 |
| Dispose() |
ContactManager オブジェクトによって使用されるすべてのリソースを解放します。 |
| Equals(Object) |
指定したオブジェクトが現在のオブジェクトと等しいかどうかを判断します。 (継承元 Object) |
| GetContact(PeerName) |
指定したPeerNameのPeerContact オブジェクトを返します。 |
| GetContacts() |
リモート ピアのContactManager内のすべての連絡先を含むPeerContactCollectionを返します。 |
| GetHashCode() |
既定のハッシュ関数として機能します。 (継承元 Object) |
| GetType() |
現在のインスタンスの Type を取得します。 (継承元 Object) |
| MemberwiseClone() |
現在の Objectの簡易コピーを作成します。 (継承元 Object) |
| ToString() |
現在のオブジェクトを表す文字列を返します。 (継承元 Object) |
| UpdateContact(PeerContact) |
PeerContactに関連付けられているデータを更新します。 |
イベント
| 名前 | 説明 |
|---|---|
| ApplicationChanged |
ContactManager内のPeerContactに関連付けられているPeerApplicationが変更されるたびに発生します。 |
| CreateContactCompleted |
CreateContact(PeerNearMe) メソッドが完了するたびに発生します。 |
| NameChanged |
ContactManagerのPeerContactに関連付けられているPeerNameが変更されるたびに発生します。 |
| ObjectChanged |
連絡先の登録済み PeerObject オブジェクト内のオブジェクトが変更されるたびに発生します。 |
| PresenceChanged |
ContactManager内のPeerContactのプレゼンス状態が変更されるたびに発生します。 |
| SubscriptionListChanged |
サブスクライブしている連絡先の一覧が変更されたときに発生します。 |