本文整理汇总了C#中Renci.SshNet.Channels.ChannelSession.Close方法的典型用法代码示例。如果您正苦于以下问题:C# ChannelSession.Close方法的具体用法?C# ChannelSession.Close怎么用?C# ChannelSession.Close使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Renci.SshNet.Channels.ChannelSession
的用法示例。
在下文中一共展示了ChannelSession.Close方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Arrange
private void Arrange()
{
var random = new Random();
_localChannelNumber = (uint)random.Next(0, int.MaxValue);
_localWindowSize = (uint)random.Next(2000, 3000);
_localPacketSize = (uint)random.Next(1000, 2000);
_remoteChannelNumber = (uint)random.Next(0, int.MaxValue);
_remoteWindowSize = (uint)random.Next(0, int.MaxValue);
_remotePacketSize = (uint)random.Next(100, 200);
_sessionSemaphore = new SemaphoreLight(1);
_channelClosedRegister = new List<ChannelEventArgs>();
_channelExceptionRegister = new List<ExceptionEventArgs>();
_sessionMock = new Mock<ISession>(MockBehavior.Strict);
_connectionInfoMock = new Mock<IConnectionInfo>(MockBehavior.Strict);
var sequence = new MockSequence();
_sessionMock.InSequence(sequence).Setup(p => p.ConnectionInfo).Returns(_connectionInfoMock.Object);
_connectionInfoMock.InSequence(sequence).Setup(p => p.RetryAttempts).Returns(1);
_sessionMock.Setup(p => p.SessionSemaphore).Returns(_sessionSemaphore);
_sessionMock.InSequence(sequence)
.Setup(
p =>
p.SendMessage(
It.Is<ChannelOpenMessage>(
m =>
m.LocalChannelNumber == _localChannelNumber &&
m.InitialWindowSize == _localWindowSize && m.MaximumPacketSize == _localPacketSize &&
m.Info is SessionChannelOpenInfo)));
_sessionMock.InSequence(sequence)
.Setup(p => p.WaitOnHandle(It.IsNotNull<WaitHandle>()))
.Callback<WaitHandle>(
w =>
{
_sessionMock.Raise(
s => s.ChannelOpenConfirmationReceived += null,
new MessageEventArgs<ChannelOpenConfirmationMessage>(
new ChannelOpenConfirmationMessage(
_localChannelNumber,
_remoteWindowSize,
_remotePacketSize,
_remoteChannelNumber)));
w.WaitOne();
});
_sessionMock.InSequence(sequence).Setup(p => p.IsConnected).Returns(true);
_sessionMock.InSequence(sequence)
.Setup(p => p.TrySendMessage(It.Is<ChannelEofMessage>(m => m.LocalChannelNumber == _remoteChannelNumber))).Returns(true);
_sessionMock.InSequence(sequence).Setup(p => p.IsConnected).Returns(true);
_sessionMock.InSequence(sequence)
.Setup(p => p.TrySendMessage(It.Is<ChannelCloseMessage>(m => m.LocalChannelNumber == _remoteChannelNumber))).Returns(true);
_sessionMock.InSequence(sequence)
.Setup(p => p.WaitOnHandle(It.IsNotNull<WaitHandle>()))
.Callback<WaitHandle>(
w =>
{
_sessionMock.Raise(
s => s.ChannelCloseReceived += null,
new MessageEventArgs<ChannelCloseMessage>(new ChannelCloseMessage(_localChannelNumber)));
w.WaitOne();
});
_channel = new ChannelSession(_sessionMock.Object, _localChannelNumber, _localWindowSize, _localPacketSize);
_channel.Closed += (sender, args) => _channelClosedRegister.Add(args);
_channel.Exception += (sender, args) => _channelExceptionRegister.Add(args);
_channel.Open();
_channel.Close();
}