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传递给
application
的对象PeerApplication上的 属性为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 此状态。