This documentation is archived and is not being maintained.

PeerEndPointCollection Class

Represents a container for elements of a PeerEndPoint object. An instance of this type is returned by the Peer class.

System.Object
  System.Collections.ObjectModel.Collection(Of PeerEndPoint)
    System.Net.PeerToPeer.Collaboration.PeerEndPointCollection

Namespace:  System.Net.PeerToPeer.Collaboration
Assembly:  System.Net (in System.Net.dll)

'Declaration
<SerializableAttribute> _
Public Class PeerEndPointCollection _
	Inherits Collection(Of PeerEndPoint) _
	Implements IEquatable(Of PeerEndPointCollection)

The PeerEndPointCollection type exposes the following members.

  NameDescription
Public propertyCountGets the number of elements actually contained in the Collection(Of T). (Inherited from Collection(Of T).)
Public propertyItemGets or sets the element at the specified index. (Inherited from Collection(Of T).)
Protected propertyItemsGets a IList(Of T) wrapper around the Collection(Of T). (Inherited from Collection(Of T).)
Top

  NameDescription
Public methodAddAdds an object to the end of the Collection(Of T). (Inherited from Collection(Of T).)
Public methodClearRemoves all elements from the Collection(Of T). (Inherited from Collection(Of T).)
Protected methodClearItemsRemoves all elements from the Collection(Of T). (Inherited from Collection(Of T).)
Public methodContainsDetermines whether an element is in the Collection(Of T). (Inherited from Collection(Of T).)
Public methodCopyToCopies the entire Collection(Of T) to a compatible one-dimensional Array, starting at the specified index of the target array. (Inherited from Collection(Of T).)
Public methodEquals(Object)Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Public methodEquals(PeerEndPointCollection)Compares the PeerEndPointCollection to the specified object.
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodGetEnumeratorReturns an enumerator that iterates through the Collection(Of T). (Inherited from Collection(Of T).)
Public methodGetHashCodeServes as a hash function for a particular type. (Inherited from Object.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Public methodIndexOfSearches for the specified object and returns the zero-based index of the first occurrence within the entire Collection(Of T). (Inherited from Collection(Of T).)
Public methodInsertInserts an element into the Collection(Of T) at the specified index. (Inherited from Collection(Of T).)
Protected methodInsertItemInserts a new PeerEndPoint element into the PeerEndPointCollection at the specified index or key. (Overrides Collection(Of T).InsertItem(Int32, T).)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodRemoveRemoves the first occurrence of a specific object from the Collection(Of T). (Inherited from Collection(Of T).)
Public methodRemoveAtRemoves the element at the specified index of the Collection(Of T). (Inherited from Collection(Of T).)
Protected methodRemoveItemRemoves the element at the specified index of the Collection(Of T). (Inherited from Collection(Of T).)
Protected methodSetItemReplaces the PeerEndPoint element at the specified index. (Overrides Collection(Of T).SetItem(Int32, T).)
Public methodToStringReturns a String representing the current value for each instance of PeerEndPoint, separated by commas. (Overrides Object.ToString.)
Top

  NameDescription
Explicit interface implemetationPrivate methodICollection.CopyToCopies the elements of the ICollection to an Array, starting at a particular Array index. (Inherited from Collection(Of T).)
Explicit interface implemetationPrivate propertyICollection(Of T).IsReadOnlyGets a value indicating whether the ICollection(Of T) is read-only. (Inherited from Collection(Of T).)
Explicit interface implemetationPrivate propertyICollection.IsSynchronizedGets a value indicating whether access to the ICollection is synchronized (thread safe). (Inherited from Collection(Of T).)
Explicit interface implemetationPrivate propertyICollection.SyncRootGets an object that can be used to synchronize access to the ICollection. (Inherited from Collection(Of T).)
Explicit interface implemetationPrivate methodIEnumerable.GetEnumeratorReturns an enumerator that iterates through a collection. (Inherited from Collection(Of T).)
Explicit interface implemetationPrivate methodIList.AddAdds an item to the IList. (Inherited from Collection(Of T).)
Explicit interface implemetationPrivate methodIList.ContainsDetermines whether the IList contains a specific value. (Inherited from Collection(Of T).)
Explicit interface implemetationPrivate methodIList.IndexOfDetermines the index of a specific item in the IList. (Inherited from Collection(Of T).)
Explicit interface implemetationPrivate methodIList.InsertInserts an item into the IList at the specified index. (Inherited from Collection(Of T).)
Explicit interface implemetationPrivate propertyIList.IsFixedSizeGets a value indicating whether the IList has a fixed size. (Inherited from Collection(Of T).)
Explicit interface implemetationPrivate propertyIList.IsReadOnlyGets a value indicating whether the IList is read-only. (Inherited from Collection(Of T).)
Explicit interface implemetationPrivate propertyIList.ItemGets or sets the element at the specified index. (Inherited from Collection(Of T).)
Explicit interface implemetationPrivate methodIList.RemoveRemoves the first occurrence of a specific object from the IList. (Inherited from Collection(Of T).)
Top


' Displays all contacts and asssociated peer endpoints (PeerEndPoint) in the PeerContactCollection.
Private Shared Sub DisplayContacts(ByVal peerContactsCollection As PeerContactCollection)
    If peerContactsCollection Is Nothing OrElse peerContactsCollection.Count = 0 Then
        Console.WriteLine("No contacts to display. To add a contact select option 0 from the menu.")
    Else
        For Each pc In peerContactsCollection
            Console.WriteLine("The contact is: {0}", pc.DisplayName)
            DisplayEndpoints(pc.PeerEndPoints)
        Next pc
    End If
    Return
End Sub

'------------------------------------------------------------------------------------------------------
'------------------------------------------------------------------------------------------------------
' Displays all peer end points (PeerEndPoint) in the PeerEndPointCollection.

Private Shared Sub DisplayEndpoints(ByVal endpointCollection As PeerEndPointCollection)
    If endpointCollection Is Nothing OrElse endpointCollection.Count = 0 Then
        Console.WriteLine("No peer endpoints in the collection to display.")
    Else
        For Each pep In endpointCollection
            Console.WriteLine("PeerEndPoint is: {0}", pep)
            Console.WriteLine("PeerEndPoint data is:" & vbLf & "  Name: {0}" & vbLf & " EndPoint IP address: {1}" & vbLf & " . Port: {2}" & vbLf, pep.Name, pep.EndPoint.Address, pep.EndPoint.Port)
        Next pep
    End If
    Return
End Sub

'------------------------------------------------------------------------------------------------------
'------------------------------------------------------------------------------------------------------
'List PeerNearMe objects that may be added as contacts.

Private Shared Sub AddContact()
    Dim pnmc As PeerNearMeCollection = Nothing
    Dim peerContacts As PeerContactCollection = Nothing
    Dim peerNameFound As Boolean = False

    Dim application As PeerApplication = Nothing

    Try
        Console.WriteLine("Listing the existing contacts...")
        peerContacts = PeerCollaboration.ContactManager.GetContacts()
    Catch p2pEx As PeerToPeerException
        Console.WriteLine("The Peer Collaboration Infrastructure is not responding to the contact enumeration request: {0}", p2pEx.Message)
    Catch ex As Exception
        Console.WriteLine("An unexpected error occurred while attempting to obtain the contact list: {0}", ex.Message)
    End Try

    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:")
        Dim peerNameToAdd As String = Console.ReadLine()

        application = RegisterCollabApp()

        For Each pnm In pnmc
            Dim res As PeerInvitationResponse = Nothing
            If pnm.Nickname.Contains(peerNameToAdd) Then
                peerNameFound = True
                If Not peerContacts.ToString().Contains(pnm.Nickname) Then
                    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.")
                    For Each pc In peerContacts
                        If pc.Nickname.Equals(pnm.Nickname) Then
                            res = pnm.Invite(application, "Peer Collaboration Sample", application.Data)
                            If res.PeerInvitationResponseType = PeerInvitationResponseType.Accepted Then
                                Console.WriteLine("Invitation to contact succeeded.")
                            Else
                                Console.WriteLine("Invitation to contact {0}.", res.PeerInvitationResponseType)
                            End If
                        End If
                    Next pc

                End If
            End If
        Next pnm

        If Not peerNameFound Then
            Console.WriteLine("No such peer exists near you. Cannot add to contacts.")
            Return
        End If

        peerContacts = PeerCollaboration.ContactManager.GetContacts()

        Console.WriteLine("Listing the contacts again...")
        DisplayContacts(peerContacts)

    Catch ex As Exception
        Console.WriteLine("Error adding a contact: {0}", ex.Message)
    Finally
        application.Dispose()
    End Try
    Return
End Sub


.NET Framework

Supported in: 4, 3.5

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Show: