PeerCollaboration.RegisterApplication Metoda

Definice

Zaregistruje zadanou PeerApplication pro relaci spolupráce s volajícím peerem.

public:
 static void RegisterApplication(System::Net::PeerToPeer::Collaboration::PeerApplication ^ application, System::Net::PeerToPeer::Collaboration::PeerApplicationRegistrationType type);
[System.Security.SecurityCritical]
public static void RegisterApplication (System.Net.PeerToPeer.Collaboration.PeerApplication application, System.Net.PeerToPeer.Collaboration.PeerApplicationRegistrationType type);
[<System.Security.SecurityCritical>]
static member RegisterApplication : System.Net.PeerToPeer.Collaboration.PeerApplication * System.Net.PeerToPeer.Collaboration.PeerApplicationRegistrationType -> unit
Public Shared Sub RegisterApplication (application As PeerApplication, type As PeerApplicationRegistrationType)

Parametry

application
PeerApplication

Pro PeerApplication který se má zaregistrovat volající partnerský uzel v rámci přidruženého oboru (globální, místní a odkaz-místní).

type
PeerApplicationRegistrationType

Typ registrace, která se má provést. Aplikace může být zaregistrovaná jenom pro volající partnerský uzel nebo pro všechny partnerské vztahy používající počítač.

Atributy

Výjimky

  • Vlastnost Path objektu předaného PeerApplication do application je null.

  • Zadaná instance partnerské aplikace má stejnou globálně jedinečnou Id jako aplikace, která je už zaregistrovaná. Před registrací nové aplikace pomocí zadaného identifikátoru musí být registrace stávající registrace zrušena.

Parametry application a type nemohou být null. Musí být zadány oba parametry.

Parametr type není ve výčtu nastaven na známou PeerApplicationRegistrationType hodnotu.

Operaci RegisterApplication(PeerApplication, PeerApplicationRegistrationType) nelze dokončit, dokud se volající k infrastruktuře neodhlásí.

Příklady

Následující příklad kódu ukazuje, jak zaregistrovat aplikaci v infrastruktuře pro spolupráci:

// Registering Notepad.exe as a collab application with a fixed GUID.
// Note: If you're using the application to send invitations,
// the same application with the same GUID must be registered on the remote peer machine.
private static PeerApplication RegisterCollabApp()
{
    PeerApplication application = null;
    string pathToApp = "%SystemRoot%\\notepad.exe";
    Guid appGuid = new Guid(0xAAAAAAAA, 0xFADE, 0xDEAF, 0xBE, 0xEF, 0xFF, 0xEE, 0xDD, 0xCC, 0xBB, 0xAE);

    application = new PeerApplication();
    application.Id = appGuid;
    application.Path = pathToApp;
    application.Description = "Peer Collaboration Sample -- notepad.exe";
    application.PeerScope = PeerScope.All;
    application.CommandLineArgs = "n";
    application.Data = ASCIIEncoding.ASCII.GetBytes("Test");

    Console.WriteLine("Attempting to register the application \"notepad.exe\"...");
    try
    {

        PeerApplicationCollection pac = PeerCollaboration.GetLocalRegisteredApplications(PeerApplicationRegistrationType.AllUsers);
        if (pac.Contains(application))
        {
            Console.WriteLine("The application is already registered on the peer.");
        }
        else
        {
            PeerCollaboration.RegisterApplication(application, PeerApplicationRegistrationType.AllUsers);
            Console.WriteLine("Application registration succeeded!");
        }
    }
    catch (ArgumentException argEx)
    {
        Console.WriteLine("The application was previously registered with the Peer Collaboration Infrastructure: {0}.", argEx.Message);
    }
    catch (PeerToPeerException p2pEx)
    {
        Console.WriteLine("The application failed to register with the Peer Collaboration Infrastructure: {0}", p2pEx.Message);
    }
    catch (Exception ex)
    {
        Console.WriteLine("An unexpected exception occurred when trying to register the application: {0}.", ex.Message);
    }
    return application;
}

Poznámky

Volající partner se před voláním této metody musí přihlásit k infrastruktuře partnerské spolupráce pomocí SignIn metody.

Přístup k této metodě vyžaduje .PermissionStateUnrestricted Tento stav se vytvoří při Peer zahájení relace spolupráce.

Platí pro