PeerCollaboration.RegisterApplication(PeerApplication, PeerApplicationRegistrationType) PeerCollaboration.RegisterApplication(PeerApplication, PeerApplicationRegistrationType) PeerCollaboration.RegisterApplication(PeerApplication, PeerApplicationRegistrationType) PeerCollaboration.RegisterApplication(PeerApplication, PeerApplicationRegistrationType) Method

定義

針對與發出呼叫的對等進行共同作業工作階段註冊指定的 PeerApplicationRegisters the specified PeerApplication for a collaboration session with the calling peer.

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);
static member RegisterApplication : System.Net.PeerToPeer.Collaboration.PeerApplication * System.Net.PeerToPeer.Collaboration.PeerApplicationRegistrationType -> unit
Public Shared Sub RegisterApplication (application As PeerApplication, type As PeerApplicationRegistrationType)

參數

application
PeerApplication PeerApplication PeerApplication PeerApplication

要在相關聯的範圍 (全域、區域或連結區域) 內註冊發出呼叫之對等的 PeerApplicationThe PeerApplication for which to register the calling peer within the associated scope (global, local, and link-local).

type
PeerApplicationRegistrationType PeerApplicationRegistrationType PeerApplicationRegistrationType PeerApplicationRegistrationType

要執行的註冊類型。The type of registration to perform. 可以只針對發出呼叫的對等註冊應用程式,也可以針對使用該電腦的所有對等註冊應用程式。The application may be registered for just the calling peer or for all peers using the machine.

例外狀況

- PeerApplication 物件上傳遞到 applicationPath 屬性為 null.- The Path property on the PeerApplication object passed to application is null.

- 提供的對等應用程式執行個體具有與已註冊之應用程式相同的全域唯一 Id- The peer application instance provided has the same globally unique Id as an application which is already registered. 必須取消註冊現有的註冊,才能使用提供的識別項來註冊新的應用程式。The existing registration must be unregistered before a new application can be registered with the provided identifier.

applicationtype 參數不可以是 nullThe application and type parameters cannot be null. 兩個參數都必須指定。Both parameters must be specified.

Type 參數未設定為 PeerApplicationRegistrationType 列舉中的已知值。The type parameter is not set to a known value in the PeerApplicationRegistrationType enumeration.

呼叫者必須先登入基礎結構,RegisterApplication(PeerApplication, PeerApplicationRegistrationType) 作業才能完成。The RegisterApplication(PeerApplication, PeerApplicationRegistrationType) operation cannot be completed until the caller has signed-in to the infrastructure.

範例

下列程式碼範例說明如何註冊應用程式與共同作業基礎結構:The following code example illustrates how to register an application with the Collaboration infrastructure:

// 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;
}

備註

呼叫的對等,才可登入對等共同作業基礎結構與SignIn方法之前呼叫這個方法。The calling peer is required to sign in to the peer collaboration infrastructure with the SignIn method prior to calling this method.

存取此方法需要PermissionStateUnrestrictedAccess to this method requires a PermissionState of Unrestricted. 此狀態時,會建立Peer共同作業工作階段開始。This state is created when the Peer collaboration session begins.

適用於