Skip to content

Commit

Permalink
Code Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
Mauro Cardillo committed Sep 2, 2023
1 parent 4ba7b95 commit 01ef153
Show file tree
Hide file tree
Showing 10 changed files with 23 additions and 23 deletions.
2 changes: 1 addition & 1 deletion src/FileSystem.Adapters.Ftp/src/FtpAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
2 changes: 1 addition & 1 deletion src/FileSystem.Adapters.Memory/src/MemoryAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
}

Expand Down
4 changes: 2 additions & 2 deletions src/FileSystem.Adapters.Sftp/src/SftpAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down Expand Up @@ -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);
Expand Down
15 changes: 14 additions & 1 deletion src/FileSystem/src/Adapters/Adapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<IFile> GetFileAsync(string path, CancellationToken cancellationToken = default);
public abstract Task<IDirectory> GetDirectoryAsync(string path, CancellationToken cancellationToken = default);
Expand Down
2 changes: 1 addition & 1 deletion src/FileSystem/src/Adapters/LocalAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public LocalAdapter(string prefix, string rootPath) : base(prefix, rootPath)
{
}

public override void Dispose()
public override void DisposeAdapter(bool disposing)
{
}

Expand Down
7 changes: 1 addition & 6 deletions src/FileSystem/src/Exceptions/ConnectionException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.";
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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.";
}
}
}
2 changes: 1 addition & 1 deletion src/FileSystem/src/Models/FileModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down
2 changes: 1 addition & 1 deletion src/FileSystem/src/Models/IFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
}
}
3 changes: 0 additions & 3 deletions tests/FileSystem.Tests/FileSystem/FileSystemTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 01ef153

Please sign in to comment.