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 し、 として PeerContact ローカル 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;
}
このクラスへの参照は クラスによって PeerCollaboration 返されるため、このクラスにはパブリック コンストラクターがありません。
管理に関連付 PeerContact けられているアドレス帳には、ホスト ピアとリモート ピアに関連付けられているアドレス帳が含まれます。 どちらのコンピューターも他のピアと共同作業を行うことができます。ピアがリモート ピアに対してローカルであり、ホスト ピアではない場合は、ホスト ピアの に ContactManager 追加できます。 や などのAddContactDeleteContactクラスに対する特定のContactManager操作は、リモート ピアの Windows アドレス帳で実行されている関連する操作に関連付けられます。
ホスト ピアは、この永続ストレージにアクセスして情報を PeerContact 得ることができます。これは、ピアが参加しようとしているアプリケーションに関連付けることができます。 は PeerApplication 、コンピューター上の永続的な ContactManager ストアのユーザーとして自身を識別できます。
Local |
ローカル ピアを表す PeerContact を取得します。 |
Synchronizing |
このプロパティ値を設定すると、非同期操作の結果として発生したわけではないすべてのイベントが、特定の SynchronizingObject を作成したスレッドでコールバックされるイベント ハンドラーに関連付けられます。 |
Add |
指定した PeerContact をローカル ピアの ContactManager に追加します。 |
Create |
指定された PeerContact オブジェクトの PeerNearMe インスタンスを作成します。 |
Create |
指定された PeerNearMe オブジェクトのコンタクト インスタンスを作成します。 |
Delete |
指定した PeerContact を、ローカル ピアの ContactManager から削除します。 |
Delete |
指定した PeerName に関連付けられている PeerContact をローカル ピアの ContactManager から削除します。 |
Dispose() |
この ContactManager オブジェクトによって使用されているすべてのリソースを解放します。 |
Equals(Object) |
指定されたオブジェクトが現在のオブジェクトと等しいかどうかを判断します。 (継承元 Object) |
Get |
指定された PeerContact の PeerName オブジェクトを返します。 |
Get |
リモート ピアの PeerContactCollection 内のすべての連絡先を格納する ContactManager を返します。 |
Get |
既定のハッシュ関数として機能します。 (継承元 Object) |
Get |
現在のインスタンスの Type を取得します。 (継承元 Object) |
Memberwise |
現在の Object の簡易コピーを作成します。 (継承元 Object) |
To |
現在のオブジェクトを表す文字列を返します。 (継承元 Object) |
Update |
PeerContact に関連付けられているデータを更新します。 |
Application |
PeerApplication 内の PeerContact に関連付けられた ContactManager が変更されたときに発生します。 |
Create |
CreateContact(PeerNearMe) メソッドが完了したときに発生します。 |
Name |
PeerName 内の PeerContact に関連付けられた ContactManager が変更されたときに発生します。 |
Object |
連絡先の登録済みの PeerObject オブジェクト内のオブジェクトが変更されたときに発生します。 |
Presence |
PeerContact 内の ContactManager のプレゼンス ステータスが変更されたときに発生します。 |
Subscription |
サブスクライブされた連絡先の一覧が変更されたときに発生します。 |
製品 | バージョン |
---|---|
.NET Framework | 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET に関するフィードバック
.NET はオープンソース プロジェクトです。 フィードバックを提供するにはリンクを選択します。