< Summary

Information
Class: Renci.SshNet.Channels.ClientChannel
Assembly: Renci.SshNet
File(s): \home\appveyor\projects\ssh-net\src\Renci.SshNet\Channels\ClientChannel.cs
Line coverage
96%
Covered lines: 51
Uncovered lines: 2
Coverable lines: 53
Total lines: 129
Line coverage: 96.2%
Branch coverage
70%
Covered branches: 7
Total branches: 10
Branch coverage: 70%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity Line coverage
.ctor(...)100%1100%
OnOpenConfirmation(...)50%2100%
SendMessage(...)100%1100%
OnOpenFailure(...)50%2100%
OnChannelOpenConfirmation(...)100%2100%
OnChannelOpenFailure(...)100%2100%
Dispose(...)100%1100%
UnsubscribeFromSessionEvents(...)50%271.42%

File(s)

\home\appveyor\projects\ssh-net\src\Renci.SshNet\Channels\ClientChannel.cs

#LineLine coverage
 1using System;
 2using Renci.SshNet.Common;
 3using Renci.SshNet.Messages.Connection;
 4
 5namespace Renci.SshNet.Channels
 6{
 7    internal abstract class ClientChannel : Channel
 8    {
 9        /// <summary>
 10        /// Initializes a new instance of the <see cref="ClientChannel"/> class.
 11        /// </summary>
 12        /// <param name="session">The session.</param>
 13        /// <param name="localChannelNumber">The local channel number.</param>
 14        /// <param name="localWindowSize">Size of the window.</param>
 15        /// <param name="localPacketSize">Size of the packet.</param>
 16        protected ClientChannel(ISession session, uint localChannelNumber, uint localWindowSize, uint localPacketSize)
 197717            : base(session, localChannelNumber, localWindowSize, localPacketSize)
 197718        {
 197719            session.ChannelOpenConfirmationReceived += OnChannelOpenConfirmation;
 197720            session.ChannelOpenFailureReceived += OnChannelOpenFailure;
 197721        }
 22
 23        /// <summary>
 24        /// Occurs when <see cref="ChannelOpenConfirmationMessage"/> is received.
 25        /// </summary>
 26        public event EventHandler<ChannelOpenConfirmedEventArgs> OpenConfirmed;
 27
 28        /// <summary>
 29        /// Occurs when <see cref="ChannelOpenFailureMessage"/> is received.
 30        /// </summary>
 31        public event EventHandler<ChannelOpenFailedEventArgs> OpenFailed;
 32
 33        /// <summary>
 34        /// Called when channel is opened by the server.
 35        /// </summary>
 36        /// <param name="remoteChannelNumber">The remote channel number.</param>
 37        /// <param name="initialWindowSize">Initial size of the window.</param>
 38        /// <param name="maximumPacketSize">Maximum size of the packet.</param>
 39        protected virtual void OnOpenConfirmation(uint remoteChannelNumber, uint initialWindowSize, uint maximumPacketSi
 194140        {
 194141            InitializeRemoteInfo(remoteChannelNumber, initialWindowSize, maximumPacketSize);
 42
 43            // Channel is consider to be open when confirmation message was received
 194144            IsOpen = true;
 45
 194146            OpenConfirmed?.Invoke(this, new ChannelOpenConfirmedEventArgs(remoteChannelNumber, initialWindowSize, maximu
 194147        }
 48
 49        /// <summary>
 50        /// Send message to open a channel.
 51        /// </summary>
 52        /// <param name="message">Message to send.</param>
 53        /// <exception cref="SshConnectionException">The client is not connected.</exception>
 54        /// <exception cref="SshOperationTimeoutException">The operation timed out.</exception>
 55        /// <exception cref="InvalidOperationException">The size of the packet exceeds the maximum size defined by the p
 56        protected void SendMessage(ChannelOpenMessage message)
 203457        {
 203458            Session.SendMessage(message);
 203459        }
 60
 61        /// <summary>
 62        /// Called when channel failed to open.
 63        /// </summary>
 64        /// <param name="reasonCode">The reason code.</param>
 65        /// <param name="description">The description.</param>
 66        /// <param name="language">The language.</param>
 67        protected virtual void OnOpenFailure(uint reasonCode, string description, string language)
 668        {
 669            OpenFailed?.Invoke(this, new ChannelOpenFailedEventArgs(LocalChannelNumber, reasonCode, description, languag
 670        }
 71
 72        private void OnChannelOpenConfirmation(object sender, MessageEventArgs<ChannelOpenConfirmationMessage> e)
 281773        {
 281774            if (e.Message.LocalChannelNumber == LocalChannelNumber)
 194175            {
 76                try
 194177                {
 194178                    OnOpenConfirmation(e.Message.RemoteChannelNumber,
 194179                                       e.Message.InitialWindowSize,
 194180                                       e.Message.MaximumPacketSize);
 193581                }
 682                catch (Exception ex)
 683                {
 684                    OnChannelException(ex);
 685                }
 194186            }
 281787        }
 88
 89        private void OnChannelOpenFailure(object sender, MessageEventArgs<ChannelOpenFailureMessage> e)
 60090        {
 60091            if (e.Message.LocalChannelNumber == LocalChannelNumber)
 9092            {
 93                try
 9094                {
 9095                    OnOpenFailure(e.Message.ReasonCode, e.Message.Description, e.Message.Language);
 8496                }
 697                catch (Exception ex)
 698                {
 699                    OnChannelException(ex);
 6100                }
 90101            }
 600102        }
 103
 104        protected override void Dispose(bool disposing)
 2011105        {
 2011106            UnsubscribeFromSessionEvents(Session);
 107
 2011108            base.Dispose(disposing);
 2011109        }
 110
 111        /// <summary>
 112        /// Unsubscribes the current <see cref="ClientChannel"/> from session events.
 113        /// </summary>
 114        /// <param name="session">The session.</param>
 115        /// <remarks>
 116        /// Does nothing when <paramref name="session"/> is <see langword="null"/>.
 117        /// </remarks>
 118        private void UnsubscribeFromSessionEvents(ISession session)
 2011119        {
 2011120            if (session is null)
 0121            {
 0122                return;
 123            }
 124
 2011125            session.ChannelOpenConfirmationReceived -= OnChannelOpenConfirmation;
 2011126            session.ChannelOpenFailureReceived -= OnChannelOpenFailure;
 2011127        }
 128    }
 129}