PeerNameRegistration.Start Método

Definición

Registra el PeerName en el Cloud. Si no se especifica ningún EndPointCollection, se usa la selección automática de direcciones con el valor de puerto especificado por la propiedad Port.

public:
 void Start();
[System.Security.SecurityCritical]
public void Start ();
[<System.Security.SecurityCritical>]
member this.Start : unit -> unit
Public Sub Start ()
Atributos

Excepciones

La propiedad PeerName está establecida en null.

Este objeto había llamado a Dispose() en él previamente.

  • El PeerName especificado ya se ha registrado. El método Update() debe utilizarse para actualizar un registro.

  • El elemento del mismo nivel remoto no posee el Authority para el PeerName especificado.

  • Ni PeerName ni Data se han especificado; al menos uno debe proporcionarse.

  • Los elementos de datos o el mensaje no son válidos. O bien, UseAutoEndPointSelection no está establecida y ningún blob de datos o IPEndPoint está especificado.

Ejemplos

En el ejemplo de código siguiente se crea y PeerName se registra junto con los metadatos especificados.

// Creates a PeerName and registers it along with the metadata specified
// The parameters used to register the name are static types that are set
// from user input (command-line or user dialog).
// These parameters include the following:
//   static String peerName
//   static PeerNameType peerNameType
//   static int portNumber
//   static String comment
//   static Cloud cloudName

public static void CreateAndPublishPeerName()
{
    try{
        // Creates a the PeerName to register using the classifier and type provided
        PeerName peerName = new PeerName(peerNameClassifier, peerNameType);

        // Create a registration object which represents the registration
        // of the PeerName in a Cloud
        PeerNameRegistration peerNameRegistration = new PeerNameRegistration();
        peerNameRegistration.PeerName = peerName;
        peerNameRegistration.Port = portNumber;
        peerNameRegistration.Comment = comment;
        peerNameRegistration.Cloud = cloudName;
        // Since the peerNameRegistration.EndPointCollection is not specified,
        // all (IPv4&IPv6) addresses assigned to the local host will
        // automatically be associated with the peerNameRegistration instance.
        // This behavior can be control using peerNameRegistration.UseAutoEndPointSelection

        //Note: Additional information may be specified on the PeerNameRegistration
        // object, which is not shown in this example.

        // Starting the registration means the name is published for
        // other peers to resolve
        peerNameRegistration.Start();
        Console.WriteLine("Registration of Peer Name: {0} complete.", peerName.ToString(), cloudName);
        Console.WriteLine();

        Console.WriteLine("Press any key to stop the registration and close the program");
        Console.ReadKey();

        // Stopping the registration means the name is no longer published
        peerNameRegistration.Stop();
    } catch(Exception e){
        Console.WriteLine("Error creating and registering the PeerName: {0} \n", e.Message);
        Console.WriteLine(e.StackTrace);
    }
}

Comentarios

El método registra el nombre del mismo nivel especificado en la PeerName propiedad con todas las direcciones de origen y el Port especificado en el constructor. Este método usa el puerto predeterminado solo cuando no se especifica ningún punto de conexión.

Si la Cloud propiedad es null, este método registra el nombre del mismo nivel especificado en la PeerName propiedad mediante el Available campo , que inicializa los valores predeterminados para , NameScopey ScopeId.

Una vez iniciado un PeerNameRegistration objeto, se usa el Stop método para detenerlo.

Para actualizar un registro, se debe usar el Update método .

Se aplica a