diff --git a/src/FileSystem.Adapters.Ftp/src/FtpAdapter.cs b/src/FileSystem.Adapters.Ftp/src/FtpAdapter.cs index eb22139..a0afc31 100644 --- a/src/FileSystem.Adapters.Ftp/src/FtpAdapter.cs +++ b/src/FileSystem.Adapters.Ftp/src/FtpAdapter.cs @@ -25,7 +25,7 @@ public FtpAdapter(string prefix, string rootPath, FtpClient client) : base(prefi this.client = client; } - public override void Dispose() + public override void DisposeAdapter(bool disposing) { client.Dispose(); } diff --git a/src/FileSystem.Adapters.Memory/src/MemoryAdapter.cs b/src/FileSystem.Adapters.Memory/src/MemoryAdapter.cs index fae117d..924ce45 100644 --- a/src/FileSystem.Adapters.Memory/src/MemoryAdapter.cs +++ b/src/FileSystem.Adapters.Memory/src/MemoryAdapter.cs @@ -23,7 +23,7 @@ public MemoryAdapter(string prefix, string rootPath) : base(prefix, rootPath) _directories.Add(System.IO.Path.Combine(rootPath), new MemoryDirectory() { FullName = rootPath, Name = GetLastPathPart(rootPath), Root = "" }); } - public override void Dispose() + public override void DisposeAdapter(bool disposing) { } diff --git a/src/FileSystem.Adapters.Sftp/src/SftpAdapter.cs b/src/FileSystem.Adapters.Sftp/src/SftpAdapter.cs index 450ebdd..13acc4e 100644 --- a/src/FileSystem.Adapters.Sftp/src/SftpAdapter.cs +++ b/src/FileSystem.Adapters.Sftp/src/SftpAdapter.cs @@ -25,7 +25,7 @@ public SftpAdapter(string prefix, string rootPath, SftpClient client) : base(pre this.client = client; } - public override void Dispose() + public override void DisposeAdapter(bool disposing) { client.Dispose(); } @@ -387,7 +387,7 @@ private static Exception Exception(Exception exception) private string PathSftp(string path) { - if (path.StartsWith("/")) + if (path.Substring(0, 1) == "/") { if (path.Length > 1) return path.Substring(1); diff --git a/src/FileSystem/src/Adapters/Adapter.cs b/src/FileSystem/src/Adapters/Adapter.cs index f474d42..2c160e3 100644 --- a/src/FileSystem/src/Adapters/Adapter.cs +++ b/src/FileSystem/src/Adapters/Adapter.cs @@ -119,7 +119,20 @@ public string ReadTextFile(string path) public async Task AppendFileAsync(string path, string contents, CancellationToken cancellationToken = default) => await AppendFileAsync(path, Encoding.UTF8.GetBytes(contents), cancellationToken); - public abstract void Dispose(); + public void Dispose() + { + Dispose(true); + GC.SuppressFinalize(this); + } + + protected virtual void Dispose(bool disposing) + { + // Cleanup + DisposeAdapter(disposing); + } + + public abstract void DisposeAdapter(bool disposing); + public abstract void Connect(); public abstract Task GetFileAsync(string path, CancellationToken cancellationToken = default); public abstract Task GetDirectoryAsync(string path, CancellationToken cancellationToken = default); diff --git a/src/FileSystem/src/Adapters/LocalAdapter.cs b/src/FileSystem/src/Adapters/LocalAdapter.cs index fb0ea57..a52ea00 100644 --- a/src/FileSystem/src/Adapters/LocalAdapter.cs +++ b/src/FileSystem/src/Adapters/LocalAdapter.cs @@ -18,7 +18,7 @@ public LocalAdapter(string prefix, string rootPath) : base(prefix, rootPath) { } - public override void Dispose() + public override void DisposeAdapter(bool disposing) { } diff --git a/src/FileSystem/src/Exceptions/ConnectionException.cs b/src/FileSystem/src/Exceptions/ConnectionException.cs index 78ff80b..e5d768a 100644 --- a/src/FileSystem/src/Exceptions/ConnectionException.cs +++ b/src/FileSystem/src/Exceptions/ConnectionException.cs @@ -4,13 +4,8 @@ namespace Maurosoft.FileSystem.Exceptions { public class ConnectionException : FileSystemException { - public ConnectionException(Exception innerException) : base(GetMessage(), innerException) + public ConnectionException(Exception innerException) : base("A connection exception occured. See the inner exception for more details.", innerException) { } - - private static string GetMessage() - { - return "A connection exception occured. See the inner exception for more details."; - } } } \ No newline at end of file diff --git a/src/FileSystem/src/Exceptions/NoAdaptersRegisteredException.cs b/src/FileSystem/src/Exceptions/NoAdaptersRegisteredException.cs index 161b0ba..f512377 100644 --- a/src/FileSystem/src/Exceptions/NoAdaptersRegisteredException.cs +++ b/src/FileSystem/src/Exceptions/NoAdaptersRegisteredException.cs @@ -2,13 +2,8 @@ namespace Maurosoft.FileSystem.Exceptions { public class NoAdaptersRegisteredException : FileSystemException { - public NoAdaptersRegisteredException() : base(GetMessage()) + public NoAdaptersRegisteredException() : base("No adapters registered with the file system.") { } - - private static string GetMessage() - { - return "No adapters registered with the file system."; - } } } \ No newline at end of file diff --git a/src/FileSystem/src/Models/FileModel.cs b/src/FileSystem/src/Models/FileModel.cs index 627f7bc..80ceb02 100644 --- a/src/FileSystem/src/Models/FileModel.cs +++ b/src/FileSystem/src/Models/FileModel.cs @@ -5,7 +5,7 @@ namespace Maurosoft.FileSystem.Models public class FileModel : Model, IFile { public long? Length { get; set; } - public byte[] Content { get; set; } + public byte[]? Content { get; set; } public FileModel() { diff --git a/src/FileSystem/src/Models/IFile.cs b/src/FileSystem/src/Models/IFile.cs index d159303..65b7972 100644 --- a/src/FileSystem/src/Models/IFile.cs +++ b/src/FileSystem/src/Models/IFile.cs @@ -9,6 +9,6 @@ public interface IFile public long? Length { get; set; } public DateTime? LastModifiedDateTime { get; set; } public DateTime? CreatedDateTime { get; set; } - public byte[] Content { get; set; } + public byte[]? Content { get; set; } } } \ No newline at end of file diff --git a/tests/FileSystem.Tests/FileSystem/FileSystemTest.cs b/tests/FileSystem.Tests/FileSystem/FileSystemTest.cs index b703ebb..9ef5d14 100644 --- a/tests/FileSystem.Tests/FileSystem/FileSystemTest.cs +++ b/tests/FileSystem.Tests/FileSystem/FileSystemTest.cs @@ -2,9 +2,7 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; using Maurosoft.FileSystem.Adapters; using Maurosoft.FileSystem.Exceptions; -using Serilog; using Maurosoft.FileSystem.Adapters.Memory; -using System.Text; using System; using System.Linq; @@ -62,7 +60,6 @@ public void FileSystem_Adapters_Add_Should_Return_Adapter() public void FileSystem_GetAdapter_NoRegistred_Should_ThrowException_NoAdaptersRegisteredException() { //Arrange - var localAdapter1 = new LocalAdapter("prefix-1", "/"); var fileSystem = new Maurosoft.FileSystem.FileSystem(); //Act && Assert