mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 06:11:10 +00:00
Implements file system path existence check
This commit is contained in:
1 parent
dc47386726
commit
c29d829c91
16 files changed
+452
-125
No files matched your search
+7
@@ -27,6 +27,13 @@ public interface IPathService
|
||||
/// <returns><see langword="true"/> if <paramref name="path"/> is a valid path, <see langword="false"/> otherwise.</returns>
|
||||
bool IsValidPath(string path);
|
||||
|
||||
/// <summary>
|
||||
/// Checks if <paramref name="path"/> exists.
|
||||
/// </summary>
|
||||
/// <param name="path">The path to be checked.</param>
|
||||
/// <returns><see langword="true"/> if <paramref name="path"/> exists, <see langword="false"/> otherwise.</returns>
|
||||
bool Exists(string path);
|
||||
|
||||
/// <summary>
|
||||
/// Tries to combine <paramref name="path"/> with <paramref name="name"/>.
|
||||
/// </summary>
|
||||
|
||||
+13
@@ -51,6 +51,19 @@ public class PathService : IPathService
|
||||
return _platformContext.PathStrategy.IsValidPath(newPathResult.Value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if <paramref name="path"/> exists.
|
||||
/// </summary>
|
||||
/// <param name="path">The path to be checked.</param>
|
||||
/// <returns><see langword="true"/> if <paramref name="path"/> exists, <see langword="false"/> otherwise.</returns>
|
||||
public bool Exists(string path)
|
||||
{
|
||||
ErrorOr<FileSystemPathId> newPathResult = FileSystemPathId.Create(path);
|
||||
if (newPathResult.IsError)
|
||||
return false;
|
||||
return _platformContext.PathStrategy.Exists(newPathResult.Value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tries to combine <paramref name="path"/> with <paramref name="name"/>.
|
||||
/// </summary>
|
||||
|
||||
+7
@@ -23,6 +23,13 @@ public interface IPathStrategy
|
||||
/// <returns><see langword="true"/> if <paramref name="path"/> is a valid path, <see langword="false"/> otherwise.</returns>
|
||||
bool IsValidPath(FileSystemPathId path);
|
||||
|
||||
/// <summary>
|
||||
/// Checks if <paramref name="path"/> exists.
|
||||
/// </summary>
|
||||
/// <param name="path">The path to be checked.</param>
|
||||
/// <returns><see langword="true"/> if <paramref name="path"/> exists, <see langword="false"/> otherwise.</returns>
|
||||
bool Exists(FileSystemPathId path);
|
||||
|
||||
/// <summary>
|
||||
/// Tries to combine <paramref name="path"/> with <paramref name="name"/>.
|
||||
/// </summary>
|
||||
|
||||
+26
@@ -4,6 +4,7 @@ using Lumina.Domain.Common.Errors;
|
||||
using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.ValueObjects;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO.Abstractions;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
#endregion
|
||||
@@ -15,6 +16,10 @@ namespace Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.S
|
||||
/// </summary>
|
||||
public class UnixPathStrategy : IUnixPathStrategy
|
||||
{
|
||||
#region ================================================================== FIELD MEMBERS ================================================================================
|
||||
private readonly IFileSystem _fileSystem;
|
||||
#endregion
|
||||
|
||||
#region ==================================================================== PROPERTIES =================================================================================
|
||||
public char PathSeparator
|
||||
{
|
||||
@@ -22,6 +27,17 @@ public class UnixPathStrategy : IUnixPathStrategy
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region ====================================================================== CTOR =====================================================================================
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="UnixPathStrategy"/> class.
|
||||
/// </summary>
|
||||
/// <param name="fileSystem">Injected service used to interact with the local filesystem.</param>
|
||||
public UnixPathStrategy(IFileSystem fileSystem)
|
||||
{
|
||||
_fileSystem = fileSystem;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region ===================================================================== METHODS ===================================================================================
|
||||
/// <summary>
|
||||
/// Checks if <paramref name="path"/> is a valid path.
|
||||
@@ -41,6 +57,16 @@ public class UnixPathStrategy : IUnixPathStrategy
|
||||
return Regex.IsMatch(path.Path, pathPattern);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if <paramref name="path"/> exists.
|
||||
/// </summary>
|
||||
/// <param name="path">The path to be checked.</param>
|
||||
/// <returns><see langword="true"/> if <paramref name="path"/> exists, <see langword="false"/> otherwise.</returns>
|
||||
public bool Exists(FileSystemPathId path)
|
||||
{
|
||||
return _fileSystem.Path.Exists(path.Path);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tries to combine <paramref name="path"/> with <paramref name="name"/>.
|
||||
/// </summary>
|
||||
|
||||
+26
@@ -6,6 +6,7 @@ using Lumina.Domain.Common.Errors;
|
||||
using System.Text.RegularExpressions;
|
||||
using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.ValueObjects;
|
||||
using System.Linq;
|
||||
using System.IO.Abstractions;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.Strategies.Path;
|
||||
@@ -15,6 +16,10 @@ namespace Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.S
|
||||
/// </summary>
|
||||
public class WindowsPathStrategy : IWindowsPathStrategy
|
||||
{
|
||||
#region ================================================================== FIELD MEMBERS ================================================================================
|
||||
private readonly IFileSystem _fileSystem;
|
||||
#endregion
|
||||
|
||||
#region ==================================================================== PROPERTIES =================================================================================
|
||||
public char PathSeparator
|
||||
{
|
||||
@@ -22,6 +27,17 @@ public class WindowsPathStrategy : IWindowsPathStrategy
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region ====================================================================== CTOR =====================================================================================
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="WindowsPathStrategy"/> class.
|
||||
/// </summary>
|
||||
/// <param name="fileSystem">Injected service used to interact with the local filesystem.</param>
|
||||
public WindowsPathStrategy(IFileSystem fileSystem)
|
||||
{
|
||||
_fileSystem = fileSystem;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region ===================================================================== METHODS ===================================================================================
|
||||
/// <summary>
|
||||
/// Checks if <paramref name="path"/> is a valid path.
|
||||
@@ -40,6 +56,16 @@ public class WindowsPathStrategy : IWindowsPathStrategy
|
||||
return Regex.IsMatch(path.Path, pathPattern);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if <paramref name="path"/> exists.
|
||||
/// </summary>
|
||||
/// <param name="path">The path to be checked.</param>
|
||||
/// <returns><see langword="true"/> if <paramref name="path"/> exists, <see langword="false"/> otherwise.</returns>
|
||||
public bool Exists(FileSystemPathId path)
|
||||
{
|
||||
return _fileSystem.Path.Exists(path.Path);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tries to combine <paramref name="path"/> with <paramref name="name"/>.
|
||||
/// </summary>
|
||||
|
||||
Reference in new issue
Block a user