PeerCollaboration.RegisterApplication 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
註冊指定的 PeerApplication 人與呼叫的對等端進行協作會話。
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)
參數
- application
- PeerApplication
在 PeerApplication 相關範圍(全域、本地及連結本地)中註冊呼叫對端的
應該進行的註冊類型。 應用程式可僅註冊給呼叫的對等端,或為所有使用該機器的對等端註冊。
- 屬性
例外狀況
傳遞給 Path 的物件上的PeerApplication
application性質為null。所提供的對等應用程式實例與已註冊的應用程式具有相同的全域唯一 Id 性。 必須先將現有註冊取消註冊,才能以所提供識別碼註冊新申請。
且application參數type不可能是null。 這兩個參數都必須指定。
型別參數在列舉中並未設定為已知值 PeerApplicationRegistrationType 。
RegisterApplication(PeerApplication, PeerApplicationRegistrationType)在呼叫者登入基礎設施後,操作無法完成。
範例
以下程式碼範例說明如何在協作基礎設施中註冊應用程式:
// 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 方法登入對等協作基礎設施,才能呼叫此方法。
存取此方法需要 一個 PermissionState 。Unrestricted 此狀態是在協作會話開始時 Peer 建立的。