/// <summary>Close (or recycle) a session to a host.</summary>
		/// <remarks>Close (or recycle) a session to a host.</remarks>
		/// <param name="session">
		/// a session previously obtained from this factory's
		/// <see cref="GetSession(string, string, string, int, CredentialsProvider, NGit.Util.FS)
		/// 	">GetSession(string, string, string, int, CredentialsProvider, NGit.Util.FS)</see>
		/// method.
		/// </param>
		public virtual void ReleaseSession(Session session)
		{
			if (session.IsConnected())
			{
				session.Disconnect();
			}
		}
Example #2
0
		/// <summary>Initialize SSH session</summary>
		/// <exception cref="NGit.Errors.TransportException">in case of error with opening SSH session
		/// 	</exception>
		protected internal virtual void InitSession()
		{
			if (sock != null)
			{
				return;
			}
			int tms = GetTimeout() > 0 ? GetTimeout() * 1000 : 0;
			string user = uri.GetUser();
			string pass = uri.GetPass();
			string host = uri.GetHost();
			int port = uri.GetPort();
			try
			{
				sock = sch.GetSession(user, pass, host, port, GetCredentialsProvider(), local.FileSystem
					);
				if (!sock.IsConnected())
				{
					sock.Connect(tms);
				}
			}
			catch (JSchException je)
			{
				Exception c = je.InnerException;
				if (c is UnknownHostException)
				{
					throw new TransportException(uri, JGitText.Get().unknownHost);
				}
				if (c is ConnectException)
				{
					throw new TransportException(uri, c.Message);
				}
				throw new TransportException(uri, je.Message, je);
			}
		}