本文整理汇总了C#中BusAttachment.LeaveSession方法的典型用法代码示例。如果您正苦于以下问题:C# BusAttachment.LeaveSession方法的具体用法?C# BusAttachment.LeaveSession怎么用?C# BusAttachment.LeaveSession使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BusAttachment
的用法示例。
在下文中一共展示了BusAttachment.LeaveSession方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: JoinSessionAsyncTest
public void JoinSessionAsyncTest()
{
BusAttachment service = new BusAttachment("service", true, 4);
ServiceSessionPortListener spl = new ServiceSessionPortListener(service);
service.Start();
service.ConnectAsync(connectSpec).AsTask().Wait();
service.RequestName("org.alljoyn.testing.service", (byte)RequestNameType.DBUS_NAME_DO_NOT_QUEUE);
SessionOpts opts = new SessionOpts(TrafficType.TRAFFIC_MESSAGES, false, ProximityType.PROXIMITY_ANY, TransportMaskType.TRANSPORT_ANY);
service.BindSessionPort(77, new ushort[1], opts, spl.spl);
service.AdvertiseName("org.alljoyn.testing.service", TransportMaskType.TRANSPORT_ANY);
BusAttachment client = new BusAttachment("client", true, 4);
BusListener cbl = new BusListener(client);
ClientSessionListener csl = new ClientSessionListener(client);
cbl.FoundAdvertisedName += new BusListenerFoundAdvertisedNameHandler(
(string name, TransportMaskType transport, string namePrefix) =>
{
if (namePrefix == "org.alljoyn.testing.service")
{
clientFoundService.Set();
}
});
client.RegisterBusListener(cbl);
client.Start();
client.ConnectAsync(connectSpec).AsTask().Wait();
client.FindAdvertisedName("org.alljoyn.testing.service");
clientFoundService.WaitOne();
SessionOpts[] optsOut = new SessionOpts[1];
Task<JoinSessionResult> joinTask = client.JoinSessionAsync("org.alljoyn.testing.service", (ushort)77, csl.sl, opts, optsOut, null).AsTask<JoinSessionResult>();
joinTask.Wait();
//The wait of 10ms ensures that the acceptSessionJoiner and sessionJoined callbacks are completed onthe service side.
Task.Delay(10).Wait();
if (QStatus.ER_OK == joinTask.Result.Status)
{
Assert.IsTrue(spl.AcceptSessionJoinerCalled && spl.SessionJoinedCalled);
Assert.AreEqual(joinTask.Result.SessionId, spl.SessionId);
Assert.AreEqual(joinTask.Result.Opts.IsMultipoint, optsOut[0].IsMultipoint);
Assert.AreEqual(joinTask.Result.Opts.Proximity, optsOut[0].Proximity);
Assert.AreEqual(joinTask.Result.Opts.Traffic, optsOut[0].Traffic);
Assert.AreEqual(joinTask.Result.Opts.TransportMask, optsOut[0].TransportMask);
Assert.AreEqual(joinTask.Result.Opts.IsMultipoint, opts.IsMultipoint);
Assert.AreEqual(joinTask.Result.Opts.Proximity, opts.Proximity);
Assert.AreEqual(joinTask.Result.Opts.Traffic, opts.Traffic);
Assert.AreEqual(joinTask.Result.Opts.TransportMask, opts.TransportMask);
}
else
{
Assert.IsFalse(true);
}
service.LeaveSession(spl.SessionId);
sessionLost.WaitOne();
}