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
구현

예제

다음 예제 코드를 열거 하는 방법을 보여 줍니다는 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;
}

설명

이 클래스에 대 한 참조를 반환한 이후 없는 public 생성자에는 PeerCollaboration 클래스입니다.

와 연결 된 주소록 PeerContact 관리는 원격 피어 호스트 피어와 연결 된 이벤트가 포함 됩니다. 어느 쪽 컴퓨터 든; 다른 동료와 공동 작업 피어 원격 피어의 하지만 하지 호스트 피어에 로컬인 경우에 추가할 수 있습니다는 ContactManager 호스트 피어입니다. 특정 작업을 ContactManager 클래스와 같이 AddContactDeleteContact, 원격 피어의 Windows 주소록에서 수행 하 고 연결 된 작업에 상관 관계를 지정 합니다.

호스트 피어에 대 한이 영구 스토리지에 액세스할 수 있습니다 PeerContact 피어를 참여 하고자 하는 애플리케이션과 연결 될 수 있는 정보입니다. A PeerApplication 자체의 사용자로 식별할 수 있습니다는 ContactManager 컴퓨터에 영구 저장소입니다.

속성

LocalContact

로컬 피어를 나타내는 PeerContact를 가져옵니다.

SynchronizingObject

이 속성 값이 설정되면 비동기 작업의 결과로 발생되지 않는 모든 이벤트에는 특정 SynchronizingObject를 만든 스레드에서 다시 호출된 이벤트 처리기가 연결됩니다.

메서드

AddContact(PeerContact)

지정된 PeerContact를 로컬 피어의 ContactManager에 추가합니다.

CreateContact(PeerNearMe)

지정된 PeerContact 개체에 대해 PeerNearMe 인스턴스를 만듭니다.

CreateContactAsync(PeerNearMe, Object)

지정된 PeerNearMe 개체에 대해 연락처 인스턴스를 만듭니다.

DeleteContact(PeerContact)

로컬 피어의 ContactManager에서 지정된 PeerContact를 제거합니다.

DeleteContact(PeerName)

로컬 피어의 ContactManager에서 지정된 PeerName과 연결된 PeerContact를 제거합니다.

Dispose()

해당 ContactManager 개체에서 사용하는 리소스를 모두 해제합니다.

Equals(Object)

지정된 개체가 현재 개체와 같은지 확인합니다.

(다음에서 상속됨 Object)
GetContact(PeerName)

지정된 PeerContact에 대한 PeerName 개체를 반환합니다.

GetContacts()

원격 피어의 PeerContactCollection에 있는 모든 대화 상대를 포함하는 ContactManager을 반환합니다.

GetHashCode()

기본 해시 함수로 작동합니다.

(다음에서 상속됨 Object)
GetType()

현재 인스턴스의 Type을 가져옵니다.

(다음에서 상속됨 Object)
MemberwiseClone()

현재 Object의 단순 복사본을 만듭니다.

(다음에서 상속됨 Object)
ToString()

현재 개체를 나타내는 문자열을 반환합니다.

(다음에서 상속됨 Object)
UpdateContact(PeerContact)

PeerContact와 연결된 데이터를 업데이트합니다.

이벤트

ApplicationChanged

PeerApplicationPeerContact와 연결된 ContactManager이 변경될 때마다 발생합니다.

CreateContactCompleted

CreateContact(PeerNearMe) 메서드가 완료될 때마다 발생합니다.

NameChanged

PeerNamePeerContact와 연결된 ContactManager이 변경될 때마다 발생합니다.

ObjectChanged

대화 상대의 등록된 PeerObject 개체에 포함된 개체가 변경될 때마다 발생합니다.

PresenceChanged

PeerContact에 포함된 ContactManager의 현재 상태가 변경될 때마다 발생합니다.

SubscriptionListChanged

구독한 대화 상대 목록이 변경되면 발생합니다.

적용 대상

추가 정보