using System;
using System.Collections.Generic;
using System.Linq;
using System.Collections.ObjectModel;
namespace Renci.SshNet
{
///
/// Provides connection information when private key authentication method is used
///
///
///
///
public class PrivateKeyConnectionInfo : ConnectionInfo, IDisposable
{
///
/// Gets the key files used for authentication.
///
public ICollection KeyFiles { get; private set; }
///
/// Initializes a new instance of the class.
///
/// Connection host.
/// Connection username.
/// Connection key files.
///
///
///
///
public PrivateKeyConnectionInfo(string host, string username, params PrivateKeyFile[] keyFiles)
: this(host, DefaultPort, username, ProxyTypes.None, string.Empty, 0, string.Empty, string.Empty, keyFiles)
{
}
///
/// Initializes a new instance of the class.
///
/// Connection host.
/// Connection port.
/// Connection username.
/// Connection key files.
public PrivateKeyConnectionInfo(string host, int port, string username, params PrivateKeyFile[] keyFiles)
: this(host, port, username, ProxyTypes.None, string.Empty, 0, string.Empty, string.Empty, keyFiles)
{
}
///
/// Initializes a new instance of the class.
///
/// Connection host.
/// The port.
/// Connection username.
/// Type of the proxy.
/// The proxy host.
/// The proxy port.
/// The key files.
public PrivateKeyConnectionInfo(string host, int port, string username, ProxyTypes proxyType, string proxyHost, int proxyPort, params PrivateKeyFile[] keyFiles)
: this(host, port, username, proxyType, proxyHost, proxyPort, string.Empty, string.Empty, keyFiles)
{
}
///
/// Initializes a new instance of the class.
///
/// Connection host.
/// The port.
/// Connection username.
/// Type of the proxy.
/// The proxy host.
/// The proxy port.
/// The proxy username.
/// The key files.
public PrivateKeyConnectionInfo(string host, int port, string username, ProxyTypes proxyType, string proxyHost, int proxyPort, string proxyUsername, params PrivateKeyFile[] keyFiles)
: this(host, port, username, proxyType, proxyHost, proxyPort, proxyUsername, string.Empty, keyFiles)
{
}
///
/// Initializes a new instance of the class.
///
/// Connection host.
/// Connection username.
/// Type of the proxy.
/// The proxy host.
/// The proxy port.
/// The key files.
public PrivateKeyConnectionInfo(string host, string username, ProxyTypes proxyType, string proxyHost, int proxyPort, params PrivateKeyFile[] keyFiles)
: this(host, DefaultPort, username, proxyType, proxyHost, proxyPort, string.Empty, string.Empty, keyFiles)
{
}
///
/// Initializes a new instance of the class.
///
/// Connection host.
/// Connection username.
/// Type of the proxy.
/// The proxy host.
/// The proxy port.
/// The proxy username.
/// The key files.
public PrivateKeyConnectionInfo(string host, string username, ProxyTypes proxyType, string proxyHost, int proxyPort, string proxyUsername, params PrivateKeyFile[] keyFiles)
: this(host, DefaultPort, username, proxyType, proxyHost, proxyPort, proxyUsername, string.Empty, keyFiles)
{
}
///
/// Initializes a new instance of the class.
///
/// Connection host.
/// Connection username.
/// Type of the proxy.
/// The proxy host.
/// The proxy port.
/// The proxy username.
/// The proxy password.
/// The key files.
public PrivateKeyConnectionInfo(string host, string username, ProxyTypes proxyType, string proxyHost, int proxyPort, string proxyUsername, string proxyPassword, params PrivateKeyFile[] keyFiles)
: this(host, DefaultPort, username, proxyType, proxyHost, proxyPort, proxyUsername, proxyPassword, keyFiles)
{
}
///
/// Initializes a new instance of the class.
///
/// Connection host.
/// The port.
/// Connection username.
/// Type of the proxy.
/// The proxy host.
/// The proxy port.
/// The proxy username.
/// The proxy password.
/// The key files.
public PrivateKeyConnectionInfo(string host, int port, string username, ProxyTypes proxyType, string proxyHost, int proxyPort, string proxyUsername, string proxyPassword, params PrivateKeyFile[] keyFiles)
: base(host, port, username, proxyType, proxyHost, proxyPort, proxyUsername, proxyPassword, new PrivateKeyAuthenticationMethod(username, keyFiles))
{
KeyFiles = new Collection(keyFiles);
}
#region IDisposable Members
private bool _isDisposed;
///
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
///
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
///
/// Releases unmanaged and - optionally - managed resources
///
/// true to release both managed and unmanaged resources; false to release only unmanaged resources.
protected virtual void Dispose(bool disposing)
{
if (_isDisposed)
return;
if (disposing)
{
// Dispose managed resources.
if (AuthenticationMethods != null)
{
foreach (var authenticationMethods in AuthenticationMethods.OfType())
{
authenticationMethods.Dispose();
}
}
_isDisposed = true;
}
}
///
/// Releases unmanaged resources and performs other cleanup operations before the
/// is reclaimed by garbage collection.
///
~PrivateKeyConnectionInfo()
{
// Do not re-create Dispose clean-up code here.
// Calling Dispose(false) is optimal in terms of
// readability and maintainability.
Dispose(false);
}
#endregion
}
}