Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enable nullable on BaseClient and SftpClient #1339

Merged
merged 2 commits into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 12 additions & 13 deletions src/Renci.SshNet/BaseClient.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
#nullable enable
using System;
using System.Net.Sockets;
using System.Threading;
using System.Threading.Tasks;
Expand All @@ -22,7 +23,7 @@ public abstract class BaseClient : IBaseClient
private readonly IServiceFactory _serviceFactory;
private readonly object _keepAliveLock = new object();
private TimeSpan _keepAliveInterval;
private Timer _keepAliveTimer;
private Timer? _keepAliveTimer;
private ConnectionInfo _connectionInfo;
private bool _isDisposed;

Expand All @@ -32,7 +33,7 @@ public abstract class BaseClient : IBaseClient
/// <value>
/// The current session.
/// </value>
internal ISession Session { get; private set; }
internal ISession? Session { get; private set; }

/// <summary>
/// Gets the factory for creating new services.
Expand Down Expand Up @@ -142,17 +143,17 @@ public TimeSpan KeepAliveInterval
/// <summary>
/// Occurs when an error occurred.
/// </summary>
public event EventHandler<ExceptionEventArgs> ErrorOccurred;
public event EventHandler<ExceptionEventArgs>? ErrorOccurred;

/// <summary>
/// Occurs when host key received.
/// </summary>
public event EventHandler<HostKeyEventArgs> HostKeyReceived;
public event EventHandler<HostKeyEventArgs>? HostKeyReceived;

/// <summary>
/// Occurs when server identification received.
/// </summary>
public event EventHandler<SshIdentificationEventArgs> ServerIdentificationReceived;
public event EventHandler<SshIdentificationEventArgs>? ServerIdentificationReceived;

/// <summary>
/// Initializes a new instance of the <see cref="BaseClient"/> class.
Expand Down Expand Up @@ -193,7 +194,7 @@ private protected BaseClient(ConnectionInfo connectionInfo, bool ownsConnectionI
throw new ArgumentNullException(nameof(serviceFactory));
}

ConnectionInfo = connectionInfo;
_connectionInfo = connectionInfo;
_ownsConnectionInfo = ownsConnectionInfo;
_serviceFactory = serviceFactory;
_keepAliveInterval = SshNet.Session.InfiniteTimeSpan;
Expand Down Expand Up @@ -381,17 +382,17 @@ protected virtual void OnDisconnected()
{
}

private void Session_ErrorOccured(object sender, ExceptionEventArgs e)
private void Session_ErrorOccured(object? sender, ExceptionEventArgs e)
{
ErrorOccurred?.Invoke(this, e);
}

private void Session_HostKeyReceived(object sender, HostKeyEventArgs e)
private void Session_HostKeyReceived(object? sender, HostKeyEventArgs e)
{
HostKeyReceived?.Invoke(this, e);
}

private void Session_ServerIdentificationReceived(object sender, SshIdentificationEventArgs e)
private void Session_ServerIdentificationReceived(object? sender, SshIdentificationEventArgs e)
{
ServerIdentificationReceived?.Invoke(this, e);
}
Expand Down Expand Up @@ -422,14 +423,12 @@ protected virtual void Dispose(bool disposing)

Disconnect();

if (_ownsConnectionInfo && _connectionInfo is not null)
if (_ownsConnectionInfo)
{
if (_connectionInfo is IDisposable connectionInfoDisposable)
{
connectionInfoDisposable.Dispose();
}

_connectionInfo = null;
}

_isDisposed = true;
Expand Down
3 changes: 2 additions & 1 deletion src/Renci.SshNet/IBaseClient.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
#nullable enable
using System;
using System.Net.Sockets;
using System.Threading;
using System.Threading.Tasks;
Expand Down
25 changes: 13 additions & 12 deletions src/Renci.SshNet/ISftpClient.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
#nullable enable
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
Expand Down Expand Up @@ -192,7 +193,7 @@ public interface ISftpClient : IBaseClient
/// <remarks>
/// Method calls made by this method to <paramref name="output" />, may under certain conditions result in exceptions thrown by the stream.
/// </remarks>
IAsyncResult BeginDownloadFile(string path, Stream output, AsyncCallback asyncCallback);
IAsyncResult BeginDownloadFile(string path, Stream output, AsyncCallback? asyncCallback);

/// <summary>
/// Begins an asynchronous file downloading into the stream.
Expand All @@ -211,7 +212,7 @@ public interface ISftpClient : IBaseClient
/// <remarks>
/// Method calls made by this method to <paramref name="output" />, may under certain conditions result in exceptions thrown by the stream.
/// </remarks>
IAsyncResult BeginDownloadFile(string path, Stream output, AsyncCallback asyncCallback, object state, Action<ulong> downloadCallback = null);
IAsyncResult BeginDownloadFile(string path, Stream output, AsyncCallback? asyncCallback, object? state, Action<ulong>? downloadCallback = null);

/// <summary>
/// Begins an asynchronous operation of retrieving list of files in remote directory.
Expand All @@ -224,7 +225,7 @@ public interface ISftpClient : IBaseClient
/// An <see cref="IAsyncResult" /> that references the asynchronous operation.
/// </returns>
/// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
IAsyncResult BeginListDirectory(string path, AsyncCallback asyncCallback, object state, Action<int> listCallback = null);
IAsyncResult BeginListDirectory(string path, AsyncCallback? asyncCallback, object? state, Action<int>? listCallback = null);

/// <summary>
/// Begins the synchronize directories.
Expand All @@ -240,7 +241,7 @@ public interface ISftpClient : IBaseClient
/// <exception cref="ArgumentNullException"><paramref name="sourcePath"/> is <see langword="null"/>.</exception>
/// <exception cref="ArgumentException"><paramref name="destinationPath"/> is <see langword="null"/> or contains only whitespace.</exception>
/// <exception cref="SshException">If a problem occurs while copying the file.</exception>
IAsyncResult BeginSynchronizeDirectories(string sourcePath, string destinationPath, string searchPattern, AsyncCallback asyncCallback, object state);
IAsyncResult BeginSynchronizeDirectories(string sourcePath, string destinationPath, string searchPattern, AsyncCallback? asyncCallback, object? state);

/// <summary>
/// Begins an asynchronous uploading the stream into remote file.
Expand Down Expand Up @@ -289,7 +290,7 @@ public interface ISftpClient : IBaseClient
/// If the remote file already exists, it is overwritten and truncated.
/// </para>
/// </remarks>
IAsyncResult BeginUploadFile(Stream input, string path, AsyncCallback asyncCallback);
IAsyncResult BeginUploadFile(Stream input, string path, AsyncCallback? asyncCallback);

/// <summary>
/// Begins an asynchronous uploading the stream into remote file.
Expand All @@ -316,7 +317,7 @@ public interface ISftpClient : IBaseClient
/// If the remote file already exists, it is overwritten and truncated.
/// </para>
/// </remarks>
IAsyncResult BeginUploadFile(Stream input, string path, AsyncCallback asyncCallback, object state, Action<ulong> uploadCallback = null);
IAsyncResult BeginUploadFile(Stream input, string path, AsyncCallback? asyncCallback, object? state, Action<ulong>? uploadCallback = null);

/// <summary>
/// Begins an asynchronous uploading the stream into remote file.
Expand All @@ -343,7 +344,7 @@ public interface ISftpClient : IBaseClient
/// <see cref="SshException"/>.
/// </para>
/// </remarks>
IAsyncResult BeginUploadFile(Stream input, string path, bool canOverride, AsyncCallback asyncCallback, object state, Action<ulong> uploadCallback = null);
IAsyncResult BeginUploadFile(Stream input, string path, bool canOverride, AsyncCallback? asyncCallback, object? state, Action<ulong>? uploadCallback = null);

/// <summary>
/// Changes remote directory to path.
Expand Down Expand Up @@ -522,7 +523,7 @@ public interface ISftpClient : IBaseClient
/// <remarks>
/// Method calls made by this method to <paramref name="output" />, may under certain conditions result in exceptions thrown by the stream.
/// </remarks>
void DownloadFile(string path, Stream output, Action<ulong> downloadCallback = null);
void DownloadFile(string path, Stream output, Action<ulong>? downloadCallback = null);

/// <summary>
/// Ends an asynchronous file downloading into the stream.
Expand Down Expand Up @@ -700,7 +701,7 @@ public interface ISftpClient : IBaseClient
/// <exception cref="SftpPermissionDeniedException">Permission to list the contents of the directory was denied by the remote host. <para>-or-</para> A SSH command was denied by the server.</exception>
/// <exception cref="SshException">A SSH error where <see cref="Exception.Message" /> is the message from the remote host.</exception>
/// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
IEnumerable<ISftpFile> ListDirectory(string path, Action<int> listCallback = null);
IEnumerable<ISftpFile> ListDirectory(string path, Action<int>? listCallback = null);

/// <summary>
/// Asynchronously enumerates the files in remote directory.
Expand Down Expand Up @@ -1006,7 +1007,7 @@ public interface ISftpClient : IBaseClient
/// <remarks>
/// Method calls made by this method to <paramref name="input" />, may under certain conditions result in exceptions thrown by the stream.
/// </remarks>
void UploadFile(Stream input, string path, Action<ulong> uploadCallback = null);
void UploadFile(Stream input, string path, Action<ulong>? uploadCallback = null);

/// <summary>
/// Uploads stream into remote file.
Expand All @@ -1024,7 +1025,7 @@ public interface ISftpClient : IBaseClient
/// <remarks>
/// Method calls made by this method to <paramref name="input" />, may under certain conditions result in exceptions thrown by the stream.
/// </remarks>
void UploadFile(Stream input, string path, bool canOverride, Action<ulong> uploadCallback = null);
void UploadFile(Stream input, string path, bool canOverride, Action<ulong>? uploadCallback = null);

/// <summary>
/// Writes the specified byte array to the specified file, and closes the file.
Expand Down
Loading