mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 17:11:10 +00:00
Replaces ErrorOr library with a custom implementation.
This commit is contained in:
1 parent
8fe90a4dde
commit
3b772d68ca
436 files changed
+4234
-3922
No files matched your search
+3
-3
@@ -1,6 +1,6 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
|
||||
using Lumina.Domain.Common.ValueObjects.Metadata;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
@@ -102,9 +102,9 @@ public class AudioMetadata : BaseMetadata
|
||||
/// <param name="genres">The genres of the audio.</param>
|
||||
/// <param name="tags">The tags associated with the audio.</param>
|
||||
/// <returns>
|
||||
/// An <see cref="ErrorOr{TValue}"/> containing either a successfully created <see cref="AudioMetadata"/>, or an error message.
|
||||
/// An <see cref="Result{TValue}"/> containing either a successfully created <see cref="AudioMetadata"/>, or an error message.
|
||||
/// </returns>
|
||||
public static ErrorOr<AudioMetadata> Create(
|
||||
public static Result<AudioMetadata> Create(
|
||||
string title,
|
||||
Optional<string> originalTitle,
|
||||
int durationInSeconds,
|
||||
|
||||
+17
-17
@@ -1,6 +1,6 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
|
||||
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.ValueObjects;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.FileSystem;
|
||||
using System;
|
||||
@@ -54,9 +54,9 @@ public sealed class Directory : FileSystemItem
|
||||
/// <param name="dateModified">The date and time the directory was last modified. Can be optional if unknown.</param>
|
||||
/// <param name="status">The status of the file system item.</param>
|
||||
/// <returns>
|
||||
/// An <see cref="ErrorOr{TValue}"/> containing either a successfully created <see cref="Directory"/>, or an error message.
|
||||
/// An <see cref="Result{TValue}"/> containing either a successfully created <see cref="Directory"/>, or an error message.
|
||||
/// </returns>
|
||||
public static ErrorOr<Directory> Create(
|
||||
public static Result<Directory> Create(
|
||||
string path,
|
||||
string name,
|
||||
Optional<DateTime> dateCreated,
|
||||
@@ -64,16 +64,16 @@ public sealed class Directory : FileSystemItem
|
||||
FileSystemItemStatus status = FileSystemItemStatus.Accessible)
|
||||
{
|
||||
// TODO: enforce invariants
|
||||
ErrorOr<FileSystemPathId> createPathResult = FileSystemPathId.Create(path);
|
||||
if (createPathResult.IsError)
|
||||
Result<FileSystemPathId> createPathResult = FileSystemPathId.Create(path);
|
||||
if (createPathResult.IsFailure)
|
||||
return createPathResult.Errors;
|
||||
Directory newDirectory = new(
|
||||
createPathResult.Value,
|
||||
name,
|
||||
dateCreated,
|
||||
dateModified);
|
||||
ErrorOr<Updated> setStatusResult = newDirectory.SetStatus(status);
|
||||
if (setStatusResult.IsError)
|
||||
Result<Updated> setStatusResult = newDirectory.SetStatus(status);
|
||||
if (setStatusResult.IsFailure)
|
||||
return setStatusResult.Errors;
|
||||
return newDirectory;
|
||||
}
|
||||
@@ -86,9 +86,9 @@ public sealed class Directory : FileSystemItem
|
||||
/// <param name="dateModified">The date and time the directory was last modified. Can be optional if unknown.</param>
|
||||
/// <param name="status">The status of the file system item.</param>
|
||||
/// <returns>
|
||||
/// An <see cref="ErrorOr{TValue}"/> containing either a successfully created <see cref="Directory"/>, or an error message.
|
||||
/// An <see cref="Result{TValue}"/> containing either a successfully created <see cref="Directory"/>, or an error message.
|
||||
/// </returns>
|
||||
public static ErrorOr<Directory> Create(
|
||||
public static Result<Directory> Create(
|
||||
FileSystemPathId id,
|
||||
string name,
|
||||
Optional<DateTime> dateCreated,
|
||||
@@ -101,8 +101,8 @@ public sealed class Directory : FileSystemItem
|
||||
name,
|
||||
dateCreated,
|
||||
dateModified);
|
||||
ErrorOr<Updated> setStatusResult = newDirectory.SetStatus(status);
|
||||
if (setStatusResult.IsError)
|
||||
Result<Updated> setStatusResult = newDirectory.SetStatus(status);
|
||||
if (setStatusResult.IsFailure)
|
||||
return setStatusResult.Errors;
|
||||
return newDirectory;
|
||||
}
|
||||
@@ -111,8 +111,8 @@ public sealed class Directory : FileSystemItem
|
||||
/// Updates the last modified date of the file system item.
|
||||
/// </summary>
|
||||
/// <param name="date">The new date and time of last modification.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
public ErrorOr<Updated> UpdateLastModified(DateTime date)
|
||||
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
public Result<Updated> UpdateLastModified(DateTime date)
|
||||
{
|
||||
DateModified = date;
|
||||
return Result.Updated;
|
||||
@@ -122,8 +122,8 @@ public sealed class Directory : FileSystemItem
|
||||
/// Adds a file system item to the directory.
|
||||
/// </summary>
|
||||
/// <param name="item">The file system item to add.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
public ErrorOr<Updated> AddItem(FileSystemItem item)
|
||||
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
public Result<Updated> AddItem(FileSystemItem item)
|
||||
{
|
||||
_items.Add(item);
|
||||
return Result.Updated;
|
||||
@@ -133,8 +133,8 @@ public sealed class Directory : FileSystemItem
|
||||
/// Removes a file system item from the directory.
|
||||
/// </summary>
|
||||
/// <param name="item">The file system item to remove.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
public ErrorOr<Updated> RemoveItem(FileSystemItem item)
|
||||
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
public Result<Updated> RemoveItem(FileSystemItem item)
|
||||
{
|
||||
_items.Remove(item);
|
||||
return Result.Updated;
|
||||
|
||||
+18
-18
@@ -1,9 +1,9 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
|
||||
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.ValueObjects;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.FileSystem;
|
||||
using Lumina.Domain.SharedKernel.Common.Errors;
|
||||
using Lumina.Domain.Common.Errors;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
@@ -55,9 +55,9 @@ public sealed class File : FileSystemItem
|
||||
/// <param name="size">The size of the file in bytes.</param>
|
||||
/// <param name="status">The status of the file system item.</param>
|
||||
/// <returns>
|
||||
/// An <see cref="ErrorOr{TValue}"/> containing either a successfully created <see cref="File"/>, or an error message.
|
||||
/// An <see cref="Result{TValue}"/> containing either a successfully created <see cref="File"/>, or an error message.
|
||||
/// </returns>
|
||||
public static ErrorOr<File> Create(
|
||||
public static Result<File> Create(
|
||||
string path,
|
||||
string name,
|
||||
Optional<DateTime> dateCreated,
|
||||
@@ -66,8 +66,8 @@ public sealed class File : FileSystemItem
|
||||
FileSystemItemStatus status = FileSystemItemStatus.Accessible)
|
||||
{
|
||||
// TODO: enforce invariants
|
||||
ErrorOr<FileSystemPathId> createPathResult = FileSystemPathId.Create(path);
|
||||
if (createPathResult.IsError)
|
||||
Result<FileSystemPathId> createPathResult = FileSystemPathId.Create(path);
|
||||
if (createPathResult.IsFailure)
|
||||
return createPathResult.Errors;
|
||||
File newFile = new(
|
||||
createPathResult.Value,
|
||||
@@ -75,8 +75,8 @@ public sealed class File : FileSystemItem
|
||||
dateCreated,
|
||||
dateModified,
|
||||
size);
|
||||
ErrorOr<Updated> setStatusResult = newFile.SetStatus(status);
|
||||
if (setStatusResult.IsError)
|
||||
Result<Updated> setStatusResult = newFile.SetStatus(status);
|
||||
if (setStatusResult.IsFailure)
|
||||
return setStatusResult.Errors;
|
||||
return newFile;
|
||||
}
|
||||
@@ -91,9 +91,9 @@ public sealed class File : FileSystemItem
|
||||
/// <param name="size">The size of the file in bytes.</param>
|
||||
/// <param name="status">The status of the file system item.</param>
|
||||
/// <returns>
|
||||
/// An <see cref="ErrorOr{TValue}"/> containing either a successfully created <see cref="File"/>, or an error message.
|
||||
/// An <see cref="Result{TValue}"/> containing either a successfully created <see cref="File"/>, or an error message.
|
||||
/// </returns>
|
||||
public static ErrorOr<File> Create(
|
||||
public static Result<File> Create(
|
||||
FileSystemPathId id,
|
||||
string name,
|
||||
Optional<DateTime> dateCreated,
|
||||
@@ -108,8 +108,8 @@ public sealed class File : FileSystemItem
|
||||
dateCreated,
|
||||
dateModified,
|
||||
size);
|
||||
ErrorOr<Updated> setStatusResult = newFile.SetStatus(status);
|
||||
if (setStatusResult.IsError)
|
||||
Result<Updated> setStatusResult = newFile.SetStatus(status);
|
||||
if (setStatusResult.IsFailure)
|
||||
return setStatusResult.Errors;
|
||||
return newFile;
|
||||
}
|
||||
@@ -118,8 +118,8 @@ public sealed class File : FileSystemItem
|
||||
/// Updates the last modified date of the file system item.
|
||||
/// </summary>
|
||||
/// <param name="date">The new date and time of last modification.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
public ErrorOr<Updated> UpdateLastModified(DateTime date)
|
||||
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
public Result<Updated> UpdateLastModified(DateTime date)
|
||||
{
|
||||
DateModified = date;
|
||||
return Result.Updated;
|
||||
@@ -129,8 +129,8 @@ public sealed class File : FileSystemItem
|
||||
/// Updates the size of the file.
|
||||
/// </summary>
|
||||
/// <param name="newSize">The new size, in bytes.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
public ErrorOr<Updated> UpdateSize(long newSize)
|
||||
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
public Result<Updated> UpdateSize(long newSize)
|
||||
{
|
||||
Size = newSize;
|
||||
return Result.Updated;
|
||||
@@ -140,8 +140,8 @@ public sealed class File : FileSystemItem
|
||||
/// Renames the file system item to the specified new name.
|
||||
/// </summary>
|
||||
/// <param name="newName">The new name for the file system item.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
public ErrorOr<Updated> Rename(string newName)
|
||||
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
public Result<Updated> Rename(string newName)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(newName))
|
||||
return Errors.FileSystemManagement.NameCannotBeEmpty;
|
||||
|
||||
+7
-7
@@ -1,5 +1,5 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.FileSystem;
|
||||
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate;
|
||||
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.ValueObjects;
|
||||
@@ -37,16 +37,16 @@ public sealed class UnixRootItem : FileSystemItem
|
||||
/// </summary>
|
||||
/// <param name="status">The status of the file system root item.</param>
|
||||
/// <returns>
|
||||
/// An <see cref="ErrorOr{TValue}"/> containing either a successfully created <see cref="UnixRootItem"/>, or an error message.
|
||||
/// An <see cref="Result{TValue}"/> containing either a successfully created <see cref="UnixRootItem"/>, or an error message.
|
||||
/// </returns>
|
||||
public static ErrorOr<UnixRootItem> Create(FileSystemItemStatus status = FileSystemItemStatus.Accessible)
|
||||
public static Result<UnixRootItem> Create(FileSystemItemStatus status = FileSystemItemStatus.Accessible)
|
||||
{
|
||||
ErrorOr<FileSystemPathId> createPathResult = FileSystemPathId.Create(PATH);
|
||||
if (createPathResult.IsError)
|
||||
Result<FileSystemPathId> createPathResult = FileSystemPathId.Create(PATH);
|
||||
if (createPathResult.IsFailure)
|
||||
return createPathResult.Errors;
|
||||
UnixRootItem newRoot = new(createPathResult.Value, PATH);
|
||||
ErrorOr<Updated> setStatusResult = newRoot.SetStatus(status);
|
||||
if (setStatusResult.IsError)
|
||||
Result<Updated> setStatusResult = newRoot.SetStatus(status);
|
||||
if (setStatusResult.IsFailure)
|
||||
return setStatusResult.Errors;
|
||||
return newRoot;
|
||||
}
|
||||
|
||||
+11
-11
@@ -1,5 +1,5 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.FileSystem;
|
||||
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate;
|
||||
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.ValueObjects;
|
||||
@@ -38,22 +38,22 @@ public sealed class WindowsRootItem : FileSystemItem
|
||||
/// <param name="name">The name of the file system root item.</param>
|
||||
/// <param name="status">The status of the file system root item.</param>
|
||||
/// <returns>
|
||||
/// An <see cref="ErrorOr{TValue}"/> containing either a successfully created <see cref="WindowsRootItem"/>, or an error message.
|
||||
/// An <see cref="Result{TValue}"/> containing either a successfully created <see cref="WindowsRootItem"/>, or an error message.
|
||||
/// </returns>
|
||||
public static ErrorOr<WindowsRootItem> Create(
|
||||
public static Result<WindowsRootItem> Create(
|
||||
string path,
|
||||
string name,
|
||||
FileSystemItemStatus status = FileSystemItemStatus.Accessible)
|
||||
{
|
||||
// TODO: enforce invariants
|
||||
ErrorOr<FileSystemPathId> createPathResult = FileSystemPathId.Create(path);
|
||||
if (createPathResult.IsError)
|
||||
Result<FileSystemPathId> createPathResult = FileSystemPathId.Create(path);
|
||||
if (createPathResult.IsFailure)
|
||||
return createPathResult.Errors;
|
||||
WindowsRootItem newRoot = new(
|
||||
createPathResult.Value,
|
||||
name);
|
||||
ErrorOr<Updated> setStatusResult = newRoot.SetStatus(status);
|
||||
if (setStatusResult.IsError)
|
||||
Result<Updated> setStatusResult = newRoot.SetStatus(status);
|
||||
if (setStatusResult.IsFailure)
|
||||
return setStatusResult.Errors;
|
||||
return newRoot;
|
||||
}
|
||||
@@ -65,9 +65,9 @@ public sealed class WindowsRootItem : FileSystemItem
|
||||
/// <param name="name">The name of the file system root item.</param>
|
||||
/// <param name="status">The status of the file system root item.</param>
|
||||
/// <returns>
|
||||
/// An <see cref="ErrorOr{TValue}"/> containing either a successfully created <see cref="WindowsRootItem"/>, or an error message.
|
||||
/// An <see cref="Result{TValue}"/> containing either a successfully created <see cref="WindowsRootItem"/>, or an error message.
|
||||
/// </returns>
|
||||
public static ErrorOr<WindowsRootItem> Create(
|
||||
public static Result<WindowsRootItem> Create(
|
||||
FileSystemPathId id,
|
||||
string name,
|
||||
FileSystemItemStatus status = FileSystemItemStatus.Accessible)
|
||||
@@ -76,8 +76,8 @@ public sealed class WindowsRootItem : FileSystemItem
|
||||
WindowsRootItem newFile = new(
|
||||
id,
|
||||
name);
|
||||
ErrorOr<Updated> setStatusResult = newFile.SetStatus(status);
|
||||
if (setStatusResult.IsError)
|
||||
Result<Updated> setStatusResult = newFile.SetStatus(status);
|
||||
if (setStatusResult.IsFailure)
|
||||
return setStatusResult.Errors;
|
||||
return newFile;
|
||||
}
|
||||
|
||||
+8
-8
@@ -1,9 +1,9 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.FileSystem;
|
||||
using Lumina.Domain.SharedKernel.Common.Errors;
|
||||
using Lumina.Domain.Common.Models.Core;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.FileSystem;
|
||||
using Lumina.Domain.Common.Errors;
|
||||
using Lumina.Domain.Common.Models.Core;
|
||||
|
||||
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.ValueObjects;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
@@ -52,8 +52,8 @@ public abstract class FileSystemItem : AggregateRoot<FileSystemPathId>
|
||||
/// Sets the status of the filesystem item.
|
||||
/// </summary>
|
||||
/// <param name="status">The status to be set.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
public ErrorOr<Updated> SetStatus(FileSystemItemStatus status)
|
||||
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
public Result<Updated> SetStatus(FileSystemItemStatus status)
|
||||
{
|
||||
Status = status;
|
||||
return Result.Updated;
|
||||
@@ -63,8 +63,8 @@ public abstract class FileSystemItem : AggregateRoot<FileSystemPathId>
|
||||
/// Sets the parent of the filesystem item.
|
||||
/// </summary>
|
||||
/// <param name="parent">The file system item to be set as parent.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
public ErrorOr<Updated> SetParent(FileSystemItem parent)
|
||||
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
public Result<Updated> SetParent(FileSystemItem parent)
|
||||
{
|
||||
if (parent is not null)
|
||||
Parent = parent;
|
||||
|
||||
+36
-36
@@ -1,8 +1,8 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.FileSystem;
|
||||
using Lumina.Domain.SharedKernel.Common.Errors;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.FileSystem;
|
||||
using Lumina.Domain.Common.Errors;
|
||||
|
||||
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Services;
|
||||
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.ValueObjects;
|
||||
using System;
|
||||
@@ -38,19 +38,19 @@ internal class DirectoryProviderService : IDirectoryProviderService
|
||||
/// </summary>
|
||||
/// <param name="path">The path from which to retrieve the subdirectory paths.</param>
|
||||
/// <param name="includeHiddenElements">Whether to include hidden subdirectories or not.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either a collection of directory paths or an error.</returns>
|
||||
public ErrorOr<IEnumerable<FileSystemPathId>> GetSubdirectoryPaths(FileSystemPathId path, bool includeHiddenElements)
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either a collection of directory paths or an error.</returns>
|
||||
public Result<IEnumerable<FileSystemPathId>> GetSubdirectoryPaths(FileSystemPathId path, bool includeHiddenElements)
|
||||
{
|
||||
// check if the user has access permissions to the provided path
|
||||
if (!_fileSystemPermissionsService.CanAccessPath(path, FileAccessMode.ListDirectory, false))
|
||||
return Errors.Permission.UnauthorizedAccess;
|
||||
return ErrorOrFactory.From(_fileSystem.Directory.GetDirectories(path.Path)
|
||||
return Result.From(_fileSystem.Directory.GetDirectories(path.Path)
|
||||
.Where(path => includeHiddenElements || (GetAttributes(path) & FileAttributes.Hidden) != FileAttributes.Hidden)
|
||||
.OrderBy(path => path)
|
||||
.Select(path => path.EndsWith(_fileSystem.Path.DirectorySeparatorChar) ? path : path + _fileSystem.Path.DirectorySeparatorChar)
|
||||
.Select(path => FileSystemPathId.Create(path))
|
||||
.Where(errorOrPathId => !errorOrPathId.IsError)
|
||||
.Select(errorOrPathId => errorOrPathId.Value)
|
||||
.Where(pathIdResult => !pathIdResult.IsFailure)
|
||||
.Select(pathIdResult => pathIdResult.Value)
|
||||
.AsEnumerable());
|
||||
}
|
||||
|
||||
@@ -76,8 +76,8 @@ internal class DirectoryProviderService : IDirectoryProviderService
|
||||
/// Checks if a directory with the specified path exists.
|
||||
/// </summary>
|
||||
/// <param name="path">The path of the directory whose existance is checked.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either the result of checking the existance of a directory, or an error.</returns>
|
||||
public ErrorOr<bool> DirectoryExists(FileSystemPathId path)
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either the result of checking the existance of a directory, or an error.</returns>
|
||||
public Result<bool> DirectoryExists(FileSystemPathId path)
|
||||
{
|
||||
return _fileSystem.Directory.Exists(path.Path);
|
||||
}
|
||||
@@ -87,8 +87,8 @@ internal class DirectoryProviderService : IDirectoryProviderService
|
||||
/// </summary>
|
||||
/// <param name="path">The path to extract the file name from.</param>
|
||||
/// <returns>The name of the file without the path, or the last segment of the path if no file name is found.</returns>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either a file name or an error.</returns>
|
||||
public ErrorOr<string> GetFileName(FileSystemPathId path)
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either a file name or an error.</returns>
|
||||
public Result<string> GetFileName(FileSystemPathId path)
|
||||
{
|
||||
string inputPath = path.Path.EndsWith(_fileSystem.Path.DirectorySeparatorChar) ? path.Path[..^1] : path.Path;
|
||||
return _fileSystem.Path.GetFileName(inputPath);
|
||||
@@ -98,8 +98,8 @@ internal class DirectoryProviderService : IDirectoryProviderService
|
||||
/// Gets the last write time of a specific path.
|
||||
/// </summary>
|
||||
/// <param name="path">The path to retrieve the last write time for.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either the optional last write time of <paramref name="path"/> if available, or an error.</returns>
|
||||
public ErrorOr<Optional<DateTime>> GetLastWriteTime(FileSystemPathId path)
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either the optional last write time of <paramref name="path"/> if available, or an error.</returns>
|
||||
public Result<Optional<DateTime>> GetLastWriteTime(FileSystemPathId path)
|
||||
{
|
||||
// check if the user has access permissions to the provided path
|
||||
if (!_fileSystemPermissionsService.CanAccessPath(path, FileAccessMode.ReadProperties, false))
|
||||
@@ -111,8 +111,8 @@ internal class DirectoryProviderService : IDirectoryProviderService
|
||||
/// Gets the creation time of a specific path.
|
||||
/// </summary>
|
||||
/// <param name="path">The path to retrieve the creation time for.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing the optional creation time of <paramref name="path"/> if available, or an error.</returns>
|
||||
public ErrorOr<Optional<DateTime>> GetCreationTime(FileSystemPathId path)
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing the optional creation time of <paramref name="path"/> if available, or an error.</returns>
|
||||
public Result<Optional<DateTime>> GetCreationTime(FileSystemPathId path)
|
||||
{
|
||||
// check if the user has access permissions to the provided path
|
||||
if (!_fileSystemPermissionsService.CanAccessPath(path, FileAccessMode.ReadProperties, false))
|
||||
@@ -125,8 +125,8 @@ internal class DirectoryProviderService : IDirectoryProviderService
|
||||
/// </summary>
|
||||
/// <param name="path">The path where the directory will be created..</param>
|
||||
/// <param name="name">The name of the directory that will be created.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either the path of a created directory, or an error.</returns>
|
||||
public ErrorOr<FileSystemPathId> CreateDirectory(FileSystemPathId path, string name)
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either the path of a created directory, or an error.</returns>
|
||||
public Result<FileSystemPathId> CreateDirectory(FileSystemPathId path, string name)
|
||||
{
|
||||
// to create a directory, its parent directory must be writable
|
||||
if (!_fileSystemPermissionsService.CanAccessPath(path, FileAccessMode.Write, false))
|
||||
@@ -142,8 +142,8 @@ internal class DirectoryProviderService : IDirectoryProviderService
|
||||
/// <param name="sourcePath">Identifier for the path where the directory to be copied is located.</param>
|
||||
/// <param name="destinationPath">Identifier for the path where the directory will be copied.</param>
|
||||
/// <param name="overrideExisting">Whether to override existing directories, or not.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either the copied directory, or an error.</returns>
|
||||
public ErrorOr<FileSystemPathId> CopyDirectory(FileSystemPathId sourcePath, FileSystemPathId destinationPath, bool overrideExisting)
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either the copied directory, or an error.</returns>
|
||||
public Result<FileSystemPathId> CopyDirectory(FileSystemPathId sourcePath, FileSystemPathId destinationPath, bool overrideExisting)
|
||||
{
|
||||
// check if the source directory exists
|
||||
if (!_fileSystem.Directory.Exists(sourcePath.Path))
|
||||
@@ -165,15 +165,15 @@ internal class DirectoryProviderService : IDirectoryProviderService
|
||||
// copy all subdirectories
|
||||
foreach (IDirectoryInfo subDirInfo in sourceDirInfo.GetDirectories())
|
||||
{
|
||||
ErrorOr<FileSystemPathId> newSourcePathResult = FileSystemPathId.Create(subDirInfo.FullName);
|
||||
if (newSourcePathResult.IsError)
|
||||
Result<FileSystemPathId> newSourcePathResult = FileSystemPathId.Create(subDirInfo.FullName);
|
||||
if (newSourcePathResult.IsFailure)
|
||||
return newSourcePathResult.Errors;
|
||||
ErrorOr<FileSystemPathId> newDestinationPathResult = FileSystemPathId.Create(_fileSystem.Path.Combine(destPath, subDirInfo.Name));
|
||||
if (newDestinationPathResult.IsError)
|
||||
Result<FileSystemPathId> newDestinationPathResult = FileSystemPathId.Create(_fileSystem.Path.Combine(destPath, subDirInfo.Name));
|
||||
if (newDestinationPathResult.IsFailure)
|
||||
return newDestinationPathResult.Errors;
|
||||
// recursive call
|
||||
ErrorOr<FileSystemPathId> copySubDirResult = CopyDirectory(newSourcePathResult.Value, newDestinationPathResult.Value, overrideExisting);
|
||||
if (copySubDirResult.IsError)
|
||||
Result<FileSystemPathId> copySubDirResult = CopyDirectory(newSourcePathResult.Value, newDestinationPathResult.Value, overrideExisting);
|
||||
if (copySubDirResult.IsFailure)
|
||||
return copySubDirResult.Errors;
|
||||
}
|
||||
return FileSystemPathId.Create(destPath);
|
||||
@@ -205,8 +205,8 @@ internal class DirectoryProviderService : IDirectoryProviderService
|
||||
/// <param name="sourcePath">Identifier for the path where the directory to be moved is located.</param>
|
||||
/// <param name="destinationPath">Identifier for the path where the directory will be moved.</param>
|
||||
/// <param name="overrideExisting">Whether to override existing directories, or not.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either a moved directory, or an error.</returns>
|
||||
public ErrorOr<FileSystemPathId> MoveDirectory(FileSystemPathId sourcePath, FileSystemPathId destinationPath, bool overrideExisting)
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either a moved directory, or an error.</returns>
|
||||
public Result<FileSystemPathId> MoveDirectory(FileSystemPathId sourcePath, FileSystemPathId destinationPath, bool overrideExisting)
|
||||
{
|
||||
// check if the source directory exists
|
||||
if (!_fileSystem.Directory.Exists(sourcePath.Path))
|
||||
@@ -273,21 +273,21 @@ internal class DirectoryProviderService : IDirectoryProviderService
|
||||
/// </summary>
|
||||
/// <param name="path">The path of the directory to be renamed.</param>
|
||||
/// <param name="name">The new name of the directory.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either the absolute path of the renamed directory, or an error.</returns>
|
||||
public ErrorOr<FileSystemPathId> RenameDirectory(FileSystemPathId path, string name)
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either the absolute path of the renamed directory, or an error.</returns>
|
||||
public Result<FileSystemPathId> RenameDirectory(FileSystemPathId path, string name)
|
||||
{
|
||||
// to rename a directory, its parent directory must be writable
|
||||
string? parentDirectory = _fileSystem.Directory.GetParent(path.Path)?.FullName;
|
||||
if (!string.IsNullOrEmpty(parentDirectory))
|
||||
{
|
||||
ErrorOr<FileSystemPathId> parendDirectoryResult = FileSystemPathId.Create(parentDirectory);
|
||||
if (parendDirectoryResult.IsError)
|
||||
Result<FileSystemPathId> parendDirectoryResult = FileSystemPathId.Create(parentDirectory);
|
||||
if (parendDirectoryResult.IsFailure)
|
||||
return parendDirectoryResult.Errors;
|
||||
string? newDirectory = _fileSystem.Path.Combine(parentDirectory, name);
|
||||
if (!string.IsNullOrEmpty(newDirectory))
|
||||
{
|
||||
ErrorOr<FileSystemPathId> newDirectoryPathResult = FileSystemPathId.Create(newDirectory);
|
||||
if (newDirectoryPathResult.IsError)
|
||||
Result<FileSystemPathId> newDirectoryPathResult = FileSystemPathId.Create(newDirectory);
|
||||
if (newDirectoryPathResult.IsFailure)
|
||||
return newDirectoryPathResult.Errors;
|
||||
if (!_fileSystemPermissionsService.CanAccessPath(parendDirectoryResult.Value, FileAccessMode.Write, false))
|
||||
return Errors.Permission.UnauthorizedAccess;
|
||||
@@ -308,8 +308,8 @@ internal class DirectoryProviderService : IDirectoryProviderService
|
||||
/// Deletes a directory at the specified path.
|
||||
/// </summary>
|
||||
/// <param name="path">The path of the directory to be deleted.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either the result of deleting a directory, or an error.</returns>
|
||||
public ErrorOr<Deleted> DeleteDirectory(FileSystemPathId path)
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either the result of deleting a directory, or an error.</returns>
|
||||
public Result<Deleted> DeleteDirectory(FileSystemPathId path)
|
||||
{
|
||||
// check if the user has access permissions to the provided path
|
||||
if (!_fileSystemPermissionsService.CanAccessPath(path, FileAccessMode.Delete, false))
|
||||
|
||||
+97
-97
@@ -1,8 +1,8 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.FileSystem;
|
||||
using Lumina.Domain.SharedKernel.Common.Errors;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.FileSystem;
|
||||
using Lumina.Domain.Common.Errors;
|
||||
|
||||
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Strategies.Environment;
|
||||
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Strategies.Platform;
|
||||
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.ValueObjects;
|
||||
@@ -37,11 +37,11 @@ public class DirectoryService : IDirectoryService
|
||||
/// </summary>
|
||||
/// <param name="path">String representation of the file path.</param>
|
||||
/// <param name="includeHiddenElements">Whether to include hidden subdirectories or not.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either a collection of subdirectories or an error.</returns>
|
||||
public ErrorOr<IEnumerable<Directory>> GetSubdirectories(string path, bool includeHiddenElements)
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either a collection of subdirectories or an error.</returns>
|
||||
public Result<IEnumerable<Directory>> GetSubdirectories(string path, bool includeHiddenElements)
|
||||
{
|
||||
ErrorOr<FileSystemPathId> fileSystemPathIdResult = FileSystemPathId.Create(path);
|
||||
if (fileSystemPathIdResult.IsError)
|
||||
Result<FileSystemPathId> fileSystemPathIdResult = FileSystemPathId.Create(path);
|
||||
if (fileSystemPathIdResult.IsFailure)
|
||||
return fileSystemPathIdResult.Errors;
|
||||
return GetSubdirectories(fileSystemPathIdResult.Value, includeHiddenElements);
|
||||
}
|
||||
@@ -51,8 +51,8 @@ public class DirectoryService : IDirectoryService
|
||||
/// </summary>
|
||||
/// <param name="directory">Directory object to retrieve subdirectories for.</param>
|
||||
/// <param name="includeHiddenElements">Whether to include hidden subdirectories or not.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either a collection of subdirectories or an error.</returns>
|
||||
public ErrorOr<IEnumerable<Directory>> GetSubdirectories(Directory directory, bool includeHiddenElements)
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either a collection of subdirectories or an error.</returns>
|
||||
public Result<IEnumerable<Directory>> GetSubdirectories(Directory directory, bool includeHiddenElements)
|
||||
{
|
||||
return GetSubdirectories(directory.Id, includeHiddenElements);
|
||||
}
|
||||
@@ -62,38 +62,38 @@ public class DirectoryService : IDirectoryService
|
||||
/// </summary>
|
||||
/// <param name="path">Identifier for the file path.</param>
|
||||
/// <param name="includeHiddenElements">Whether to include hidden subdirectories or not.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either a collection of subdirectories or an error.</returns>
|
||||
public ErrorOr<IEnumerable<Directory>> GetSubdirectories(FileSystemPathId path, bool includeHiddenElements)
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either a collection of subdirectories or an error.</returns>
|
||||
public Result<IEnumerable<Directory>> GetSubdirectories(FileSystemPathId path, bool includeHiddenElements)
|
||||
{
|
||||
// retrieve the list of subdirectories
|
||||
ErrorOr<IEnumerable<FileSystemPathId>> subdirectoryPathsResult = _environmentContext.DirectoryProviderService.GetSubdirectoryPaths(path, includeHiddenElements);
|
||||
if (subdirectoryPathsResult.IsError)
|
||||
Result<IEnumerable<FileSystemPathId>> subdirectoryPathsResult = _environmentContext.DirectoryProviderService.GetSubdirectoryPaths(path, includeHiddenElements);
|
||||
if (subdirectoryPathsResult.IsFailure)
|
||||
return subdirectoryPathsResult.Errors;
|
||||
List<Directory> result = [];
|
||||
foreach (FileSystemPathId subPath in subdirectoryPathsResult.Value)
|
||||
{
|
||||
// extract directory details
|
||||
ErrorOr<string> dirNameResult = _environmentContext.DirectoryProviderService.GetFileName(subPath);
|
||||
ErrorOr<Optional<DateTime>> dateModifiedResult = _environmentContext.DirectoryProviderService.GetLastWriteTime(subPath);
|
||||
ErrorOr<Optional<DateTime>> dateCreatedResult = _environmentContext.DirectoryProviderService.GetCreationTime(subPath);
|
||||
Result<string> dirNameResult = _environmentContext.DirectoryProviderService.GetFileName(subPath);
|
||||
Result<Optional<DateTime>> dateModifiedResult = _environmentContext.DirectoryProviderService.GetLastWriteTime(subPath);
|
||||
Result<Optional<DateTime>> dateCreatedResult = _environmentContext.DirectoryProviderService.GetCreationTime(subPath);
|
||||
|
||||
// if any error occurred, mark directory as Inaccessible
|
||||
if (dirNameResult.IsError || dateModifiedResult.IsError || dateCreatedResult.IsError)
|
||||
if (dirNameResult.IsFailure || dateModifiedResult.IsFailure || dateCreatedResult.IsFailure)
|
||||
{
|
||||
ErrorOr<Directory> errorDirResult = Directory.Create(subPath, !dirNameResult.IsError ? dirNameResult.Value : null!,
|
||||
!dateCreatedResult.IsError ? dateCreatedResult.Value : Optional<DateTime>.None(),
|
||||
!dateModifiedResult.IsError ? dateModifiedResult.Value : Optional<DateTime>.None());
|
||||
if (errorDirResult.IsError)
|
||||
Result<Directory> errorDirResult = Directory.Create(subPath, !dirNameResult.IsFailure ? dirNameResult.Value : null!,
|
||||
!dateCreatedResult.IsFailure ? dateCreatedResult.Value : Optional<DateTime>.None(),
|
||||
!dateModifiedResult.IsFailure ? dateModifiedResult.Value : Optional<DateTime>.None());
|
||||
if (errorDirResult.IsFailure)
|
||||
return errorDirResult.Errors;
|
||||
ErrorOr<Updated> setStatusResult = errorDirResult.Value.SetStatus(FileSystemItemStatus.Inaccessible);
|
||||
if (setStatusResult.IsError)
|
||||
Result<Updated> setStatusResult = errorDirResult.Value.SetStatus(FileSystemItemStatus.Inaccessible);
|
||||
if (setStatusResult.IsFailure)
|
||||
return setStatusResult.Errors;
|
||||
result.Add(errorDirResult.Value);
|
||||
}
|
||||
else
|
||||
{
|
||||
ErrorOr<Directory> subDirectoryResult = Directory.Create(subPath, dirNameResult.Value, dateCreatedResult.Value, dateModifiedResult.Value);
|
||||
if (subDirectoryResult.IsError)
|
||||
Result<Directory> subDirectoryResult = Directory.Create(subPath, dirNameResult.Value, dateCreatedResult.Value, dateModifiedResult.Value);
|
||||
if (subDirectoryResult.IsFailure)
|
||||
return subDirectoryResult.Errors;
|
||||
result.Add(subDirectoryResult.Value);
|
||||
}
|
||||
@@ -106,11 +106,11 @@ public class DirectoryService : IDirectoryService
|
||||
/// </summary>
|
||||
/// <param name="path">String representation of the path where the directory will be created.</param>
|
||||
/// <param name="name">The name of the directory that will be created.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either the result of creating a directory, or an error.</returns>
|
||||
public ErrorOr<Directory> CreateDirectory(string path, string name)
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either the result of creating a directory, or an error.</returns>
|
||||
public Result<Directory> CreateDirectory(string path, string name)
|
||||
{
|
||||
ErrorOr<FileSystemPathId> fileSystemPathIdResult = FileSystemPathId.Create(path);
|
||||
if (fileSystemPathIdResult.IsError)
|
||||
Result<FileSystemPathId> fileSystemPathIdResult = FileSystemPathId.Create(path);
|
||||
if (fileSystemPathIdResult.IsFailure)
|
||||
return fileSystemPathIdResult.Errors;
|
||||
return CreateDirectory(fileSystemPathIdResult.Value, name);
|
||||
}
|
||||
@@ -120,37 +120,37 @@ public class DirectoryService : IDirectoryService
|
||||
/// </summary>
|
||||
/// <param name="path">Identifier for the path where the directory will be created.</param>
|
||||
/// <param name="name">The name of the directory that will be created.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either the result of creating a directory, or an error.</returns>
|
||||
public ErrorOr<Directory> CreateDirectory(FileSystemPathId path, string name)
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either the result of creating a directory, or an error.</returns>
|
||||
public Result<Directory> CreateDirectory(FileSystemPathId path, string name)
|
||||
{
|
||||
// first, check if the directory about to be created does not already exist
|
||||
ErrorOr<FileSystemPathId> combinedPath = _platformContext.PathStrategy.CombinePath(path, name);
|
||||
if (combinedPath.IsError)
|
||||
Result<FileSystemPathId> combinedPath = _platformContext.PathStrategy.CombinePath(path, name);
|
||||
if (combinedPath.IsFailure)
|
||||
return combinedPath.Errors;
|
||||
ErrorOr<bool> directoryExists = _environmentContext.DirectoryProviderService.DirectoryExists(combinedPath.Value);
|
||||
if (directoryExists.IsError)
|
||||
Result<bool> directoryExists = _environmentContext.DirectoryProviderService.DirectoryExists(combinedPath.Value);
|
||||
if (directoryExists.IsFailure)
|
||||
return directoryExists.Errors;
|
||||
else if (directoryExists.Value == true)
|
||||
return Errors.FileSystemManagement.DirectoryAlreadyExists;
|
||||
else
|
||||
{
|
||||
// create the new directory
|
||||
ErrorOr<FileSystemPathId> newDirectoryPathResult = _environmentContext.DirectoryProviderService.CreateDirectory(path, name);
|
||||
if (newDirectoryPathResult.IsError)
|
||||
Result<FileSystemPathId> newDirectoryPathResult = _environmentContext.DirectoryProviderService.CreateDirectory(path, name);
|
||||
if (newDirectoryPathResult.IsFailure)
|
||||
return newDirectoryPathResult.Errors;
|
||||
ErrorOr<string> dirNameResult = _environmentContext.DirectoryProviderService.GetFileName(newDirectoryPathResult.Value);
|
||||
ErrorOr<Optional<DateTime>> dateModifiedResult = _environmentContext.DirectoryProviderService.GetLastWriteTime(newDirectoryPathResult.Value);
|
||||
ErrorOr<Optional<DateTime>> dateCreatedResult = _environmentContext.DirectoryProviderService.GetCreationTime(newDirectoryPathResult.Value);
|
||||
Result<string> dirNameResult = _environmentContext.DirectoryProviderService.GetFileName(newDirectoryPathResult.Value);
|
||||
Result<Optional<DateTime>> dateModifiedResult = _environmentContext.DirectoryProviderService.GetLastWriteTime(newDirectoryPathResult.Value);
|
||||
Result<Optional<DateTime>> dateCreatedResult = _environmentContext.DirectoryProviderService.GetCreationTime(newDirectoryPathResult.Value);
|
||||
// if any error occurred, mark directory as Inaccessible
|
||||
if (dirNameResult.IsError || dateModifiedResult.IsError || dateCreatedResult.IsError)
|
||||
if (dirNameResult.IsFailure || dateModifiedResult.IsFailure || dateCreatedResult.IsFailure)
|
||||
{
|
||||
ErrorOr<Directory> errorDirResult = Directory.Create(newDirectoryPathResult.Value, !dirNameResult.IsError ? dirNameResult.Value : null!,
|
||||
!dateCreatedResult.IsError ? dateCreatedResult.Value : Optional<DateTime>.None(),
|
||||
!dateModifiedResult.IsError ? dateModifiedResult.Value : Optional<DateTime>.None());
|
||||
if (errorDirResult.IsError)
|
||||
Result<Directory> errorDirResult = Directory.Create(newDirectoryPathResult.Value, !dirNameResult.IsFailure ? dirNameResult.Value : null!,
|
||||
!dateCreatedResult.IsFailure ? dateCreatedResult.Value : Optional<DateTime>.None(),
|
||||
!dateModifiedResult.IsFailure ? dateModifiedResult.Value : Optional<DateTime>.None());
|
||||
if (errorDirResult.IsFailure)
|
||||
return errorDirResult.Errors;
|
||||
ErrorOr<Updated> setStatusResult = errorDirResult.Value.SetStatus(FileSystemItemStatus.Inaccessible);
|
||||
if (setStatusResult.IsError)
|
||||
Result<Updated> setStatusResult = errorDirResult.Value.SetStatus(FileSystemItemStatus.Inaccessible);
|
||||
if (setStatusResult.IsFailure)
|
||||
return setStatusResult.Errors;
|
||||
return errorDirResult;
|
||||
}
|
||||
@@ -165,19 +165,19 @@ public class DirectoryService : IDirectoryService
|
||||
/// <param name="sourcePath">String representation of the path where the directory to be copied is located.</param>
|
||||
/// <param name="destinationPath">String representation of the path where the directory will be copied.</param>
|
||||
/// <param name="overrideExisting">Whether to override existing directories, or not.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either a copied directory, or an error.</returns>
|
||||
public ErrorOr<Directory> CopyDirectory(string sourcePath, string destinationPath, bool? overrideExisting)
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either a copied directory, or an error.</returns>
|
||||
public Result<Directory> CopyDirectory(string sourcePath, string destinationPath, bool? overrideExisting)
|
||||
{
|
||||
// make sure the paths are in the expected format
|
||||
if (!sourcePath.EndsWith(_platformContext.PathStrategy.PathSeparator))
|
||||
sourcePath += _platformContext.PathStrategy.PathSeparator;
|
||||
if (!destinationPath.EndsWith(_platformContext.PathStrategy.PathSeparator))
|
||||
destinationPath += _platformContext.PathStrategy.PathSeparator;
|
||||
ErrorOr<FileSystemPathId> fileSystemSourcePathIdResult = FileSystemPathId.Create(sourcePath);
|
||||
if (fileSystemSourcePathIdResult.IsError)
|
||||
Result<FileSystemPathId> fileSystemSourcePathIdResult = FileSystemPathId.Create(sourcePath);
|
||||
if (fileSystemSourcePathIdResult.IsFailure)
|
||||
return fileSystemSourcePathIdResult.Errors;
|
||||
ErrorOr<FileSystemPathId> fileSystemDestinationPathIdResult = FileSystemPathId.Create(destinationPath);
|
||||
if (fileSystemDestinationPathIdResult.IsError)
|
||||
Result<FileSystemPathId> fileSystemDestinationPathIdResult = FileSystemPathId.Create(destinationPath);
|
||||
if (fileSystemDestinationPathIdResult.IsFailure)
|
||||
return fileSystemDestinationPathIdResult.Errors;
|
||||
return CopyDirectory(fileSystemSourcePathIdResult.Value, fileSystemDestinationPathIdResult.Value, overrideExisting ?? false);
|
||||
}
|
||||
@@ -188,18 +188,18 @@ public class DirectoryService : IDirectoryService
|
||||
/// <param name="sourcePath">Identifier for the path where the directory to be copied is located.</param>
|
||||
/// <param name="destinationPath">Identifier for the path where the directory will be copied.</param>
|
||||
/// <param name="overrideExisting">Whether to override existing directories, or not.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either the copied directory, or an error.</returns>
|
||||
public ErrorOr<Directory> CopyDirectory(FileSystemPathId sourcePath, FileSystemPathId destinationPath, bool overrideExisting)
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either the copied directory, or an error.</returns>
|
||||
public Result<Directory> CopyDirectory(FileSystemPathId sourcePath, FileSystemPathId destinationPath, bool overrideExisting)
|
||||
{
|
||||
ErrorOr<bool> directoryExists = _environmentContext.DirectoryProviderService.DirectoryExists(sourcePath);
|
||||
if (directoryExists.IsError)
|
||||
Result<bool> directoryExists = _environmentContext.DirectoryProviderService.DirectoryExists(sourcePath);
|
||||
if (directoryExists.IsFailure)
|
||||
return directoryExists.Errors;
|
||||
else if (directoryExists.Value == false)
|
||||
return Errors.FileSystemManagement.DirectoryNotFound;
|
||||
else
|
||||
{
|
||||
// copy the directory
|
||||
ErrorOr<FileSystemPathId> newDirectory = _environmentContext.DirectoryProviderService.CopyDirectory(sourcePath, destinationPath, overrideExisting);
|
||||
Result<FileSystemPathId> newDirectory = _environmentContext.DirectoryProviderService.CopyDirectory(sourcePath, destinationPath, overrideExisting);
|
||||
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
@@ -211,19 +211,19 @@ public class DirectoryService : IDirectoryService
|
||||
/// <param name="sourcePath">String representation of the path where the directory to be moved is located.</param>
|
||||
/// <param name="destinationPath">String representation of the path where the directory will be moved.</param>
|
||||
/// <param name="overrideExisting">Whether to override existing directories, or not.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either a moved directory, or an error.</returns>
|
||||
public ErrorOr<Directory> MoveDirectory(string sourcePath, string destinationPath, bool? overrideExisting)
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either a moved directory, or an error.</returns>
|
||||
public Result<Directory> MoveDirectory(string sourcePath, string destinationPath, bool? overrideExisting)
|
||||
{
|
||||
// make sure the paths are in the expected format
|
||||
if (!sourcePath.EndsWith(_platformContext.PathStrategy.PathSeparator))
|
||||
sourcePath += _platformContext.PathStrategy.PathSeparator;
|
||||
if (!destinationPath.EndsWith(_platformContext.PathStrategy.PathSeparator))
|
||||
destinationPath += _platformContext.PathStrategy.PathSeparator;
|
||||
ErrorOr<FileSystemPathId> fileSystemSourcePathIdResult = FileSystemPathId.Create(sourcePath);
|
||||
if (fileSystemSourcePathIdResult.IsError)
|
||||
Result<FileSystemPathId> fileSystemSourcePathIdResult = FileSystemPathId.Create(sourcePath);
|
||||
if (fileSystemSourcePathIdResult.IsFailure)
|
||||
return fileSystemSourcePathIdResult.Errors;
|
||||
ErrorOr<FileSystemPathId> fileSystemDestinationPathIdResult = FileSystemPathId.Create(destinationPath);
|
||||
if (fileSystemDestinationPathIdResult.IsError)
|
||||
Result<FileSystemPathId> fileSystemDestinationPathIdResult = FileSystemPathId.Create(destinationPath);
|
||||
if (fileSystemDestinationPathIdResult.IsFailure)
|
||||
return fileSystemDestinationPathIdResult.Errors;
|
||||
return MoveDirectory(fileSystemSourcePathIdResult.Value, fileSystemDestinationPathIdResult.Value, overrideExisting ?? false);
|
||||
}
|
||||
@@ -234,18 +234,18 @@ public class DirectoryService : IDirectoryService
|
||||
/// <param name="sourcePath">Identifier for the path where the directory to be moved is located.</param>
|
||||
/// <param name="destinationPath">Identifier for the path where the directory will be moved.</param>
|
||||
/// <param name="overrideExisting">Whether to override existing directories, or not.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either the moved directory, or an error.</returns>
|
||||
public ErrorOr<Directory> MoveDirectory(FileSystemPathId sourcePath, FileSystemPathId destinationPath, bool overrideExisting)
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either the moved directory, or an error.</returns>
|
||||
public Result<Directory> MoveDirectory(FileSystemPathId sourcePath, FileSystemPathId destinationPath, bool overrideExisting)
|
||||
{
|
||||
ErrorOr<bool> directoryExists = _environmentContext.DirectoryProviderService.DirectoryExists(sourcePath);
|
||||
if (directoryExists.IsError)
|
||||
Result<bool> directoryExists = _environmentContext.DirectoryProviderService.DirectoryExists(sourcePath);
|
||||
if (directoryExists.IsFailure)
|
||||
return directoryExists.Errors;
|
||||
else if (directoryExists.Value == false)
|
||||
return Errors.FileSystemManagement.DirectoryNotFound;
|
||||
else
|
||||
{
|
||||
// move the directory
|
||||
ErrorOr<FileSystemPathId> newDirectory = _environmentContext.DirectoryProviderService.MoveDirectory(sourcePath, destinationPath, overrideExisting);
|
||||
Result<FileSystemPathId> newDirectory = _environmentContext.DirectoryProviderService.MoveDirectory(sourcePath, destinationPath, overrideExisting);
|
||||
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
@@ -256,11 +256,11 @@ public class DirectoryService : IDirectoryService
|
||||
/// </summary>
|
||||
/// <param name="path">String representation of the directory path.</param>
|
||||
/// <param name="name">The new name of the directory.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either the renamed directory, or an error.</returns>
|
||||
public ErrorOr<Directory> RenameDirectory(string path, string name)
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either the renamed directory, or an error.</returns>
|
||||
public Result<Directory> RenameDirectory(string path, string name)
|
||||
{
|
||||
ErrorOr<FileSystemPathId> fileSystemPathIdResult = FileSystemPathId.Create(path);
|
||||
if (fileSystemPathIdResult.IsError)
|
||||
Result<FileSystemPathId> fileSystemPathIdResult = FileSystemPathId.Create(path);
|
||||
if (fileSystemPathIdResult.IsFailure)
|
||||
return fileSystemPathIdResult.Errors;
|
||||
return RenameDirectory(fileSystemPathIdResult.Value, name);
|
||||
}
|
||||
@@ -270,37 +270,37 @@ public class DirectoryService : IDirectoryService
|
||||
/// </summary>
|
||||
/// <param name="path">Identifier for the directory path.</param>
|
||||
/// <param name="name">The new name of the directory.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either the renamed directory, or an error.</returns>
|
||||
public ErrorOr<Directory> RenameDirectory(FileSystemPathId path, string name)
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either the renamed directory, or an error.</returns>
|
||||
public Result<Directory> RenameDirectory(FileSystemPathId path, string name)
|
||||
{
|
||||
// first, check if the directory about to be created does not already exist
|
||||
ErrorOr<FileSystemPathId> combinedPath = _platformContext.PathStrategy.CombinePath(path, name);
|
||||
if (combinedPath.IsError)
|
||||
Result<FileSystemPathId> combinedPath = _platformContext.PathStrategy.CombinePath(path, name);
|
||||
if (combinedPath.IsFailure)
|
||||
return combinedPath.Errors;
|
||||
ErrorOr<bool> directoryExists = _environmentContext.DirectoryProviderService.DirectoryExists(combinedPath.Value);
|
||||
if (directoryExists.IsError)
|
||||
Result<bool> directoryExists = _environmentContext.DirectoryProviderService.DirectoryExists(combinedPath.Value);
|
||||
if (directoryExists.IsFailure)
|
||||
return directoryExists.Errors;
|
||||
else if (directoryExists.Value == true)
|
||||
return Errors.FileSystemManagement.DirectoryAlreadyExists;
|
||||
else
|
||||
{
|
||||
// rename the directory
|
||||
ErrorOr<FileSystemPathId> newDirectoryPathResult = _environmentContext.DirectoryProviderService.RenameDirectory(path, name);
|
||||
if (newDirectoryPathResult.IsError)
|
||||
Result<FileSystemPathId> newDirectoryPathResult = _environmentContext.DirectoryProviderService.RenameDirectory(path, name);
|
||||
if (newDirectoryPathResult.IsFailure)
|
||||
return newDirectoryPathResult.Errors;
|
||||
ErrorOr<string> dirNameResult = _environmentContext.DirectoryProviderService.GetFileName(newDirectoryPathResult.Value);
|
||||
ErrorOr<Optional<DateTime>> dateModifiedResult = _environmentContext.DirectoryProviderService.GetLastWriteTime(newDirectoryPathResult.Value);
|
||||
ErrorOr<Optional<DateTime>> dateCreatedResult = _environmentContext.DirectoryProviderService.GetCreationTime(newDirectoryPathResult.Value);
|
||||
Result<string> dirNameResult = _environmentContext.DirectoryProviderService.GetFileName(newDirectoryPathResult.Value);
|
||||
Result<Optional<DateTime>> dateModifiedResult = _environmentContext.DirectoryProviderService.GetLastWriteTime(newDirectoryPathResult.Value);
|
||||
Result<Optional<DateTime>> dateCreatedResult = _environmentContext.DirectoryProviderService.GetCreationTime(newDirectoryPathResult.Value);
|
||||
// if any error occurred, mark directory as Inaccessible
|
||||
if (dirNameResult.IsError || dateModifiedResult.IsError || dateCreatedResult.IsError)
|
||||
if (dirNameResult.IsFailure || dateModifiedResult.IsFailure || dateCreatedResult.IsFailure)
|
||||
{
|
||||
ErrorOr<Directory> errorDirResult = Directory.Create(newDirectoryPathResult.Value, !dirNameResult.IsError ? dirNameResult.Value : null!,
|
||||
!dateCreatedResult.IsError ? dateCreatedResult.Value : Optional<DateTime>.None(),
|
||||
!dateModifiedResult.IsError ? dateModifiedResult.Value : Optional<DateTime>.None());
|
||||
if (errorDirResult.IsError)
|
||||
Result<Directory> errorDirResult = Directory.Create(newDirectoryPathResult.Value, !dirNameResult.IsFailure ? dirNameResult.Value : null!,
|
||||
!dateCreatedResult.IsFailure ? dateCreatedResult.Value : Optional<DateTime>.None(),
|
||||
!dateModifiedResult.IsFailure ? dateModifiedResult.Value : Optional<DateTime>.None());
|
||||
if (errorDirResult.IsFailure)
|
||||
return errorDirResult.Errors;
|
||||
ErrorOr<Updated> setStatusResult = errorDirResult.Value.SetStatus(FileSystemItemStatus.Inaccessible);
|
||||
if (setStatusResult.IsError)
|
||||
Result<Updated> setStatusResult = errorDirResult.Value.SetStatus(FileSystemItemStatus.Inaccessible);
|
||||
if (setStatusResult.IsFailure)
|
||||
return setStatusResult.Errors;
|
||||
return errorDirResult;
|
||||
}
|
||||
@@ -313,11 +313,11 @@ public class DirectoryService : IDirectoryService
|
||||
/// Delete a directory for the specified string path.
|
||||
/// </summary>
|
||||
/// <param name="path">String representation of the directory path.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either the result of deleting a directory, or an error.</returns>
|
||||
public ErrorOr<Deleted> DeleteDirectory(string path)
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either the result of deleting a directory, or an error.</returns>
|
||||
public Result<Deleted> DeleteDirectory(string path)
|
||||
{
|
||||
ErrorOr<FileSystemPathId> fileSystemPathIdResult = FileSystemPathId.Create(path);
|
||||
if (fileSystemPathIdResult.IsError)
|
||||
Result<FileSystemPathId> fileSystemPathIdResult = FileSystemPathId.Create(path);
|
||||
if (fileSystemPathIdResult.IsFailure)
|
||||
return fileSystemPathIdResult.Errors;
|
||||
return DeleteDirectory(fileSystemPathIdResult.Value);
|
||||
}
|
||||
@@ -326,8 +326,8 @@ public class DirectoryService : IDirectoryService
|
||||
/// Delete a directory for the specified path.
|
||||
/// </summary>
|
||||
/// <param name="path">Identifier for the directory path.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either the result of deleting a directory, or an error.</returns>
|
||||
public ErrorOr<Deleted> DeleteDirectory(FileSystemPathId path)
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either the result of deleting a directory, or an error.</returns>
|
||||
public Result<Deleted> DeleteDirectory(FileSystemPathId path)
|
||||
{
|
||||
return _environmentContext.DirectoryProviderService.DeleteDirectory(path);
|
||||
}
|
||||
|
||||
+11
-11
@@ -1,5 +1,5 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.FileSystem;
|
||||
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate;
|
||||
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Services;
|
||||
@@ -33,32 +33,32 @@ public class DriveService : IDriveService
|
||||
/// <summary>
|
||||
/// Retrieves the list of drives.
|
||||
/// </summary>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either a collection of drives or an error.</returns>
|
||||
public ErrorOr<IEnumerable<FileSystemItem>> GetDrives()
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either a collection of drives or an error.</returns>
|
||||
public Result<IEnumerable<FileSystemItem>> GetDrives()
|
||||
{
|
||||
if (_platformContext.Platform == PlatformType.Unix)
|
||||
{
|
||||
ErrorOr<UnixRootItem> unixRootResult = UnixRootItem.Create(FileSystemItemStatus.Accessible);
|
||||
if (unixRootResult.IsError)
|
||||
Result<UnixRootItem> unixRootResult = UnixRootItem.Create(FileSystemItemStatus.Accessible);
|
||||
if (unixRootResult.IsFailure)
|
||||
return unixRootResult.Errors;
|
||||
return new List<FileSystemItem>() { unixRootResult.Value };
|
||||
}
|
||||
else
|
||||
return ErrorOrFactory.From(_fileSystem.DriveInfo.GetDrives()
|
||||
return Result.From(_fileSystem.DriveInfo.GetDrives()
|
||||
.OrderBy(driveInfo => driveInfo.Name)
|
||||
.Where(driveInfo => driveInfo.IsReady)
|
||||
.Select(driveInfo =>
|
||||
{
|
||||
ErrorOr<FileSystemItem> root;
|
||||
ErrorOr<WindowsRootItem> windowsRootResult = WindowsRootItem.Create(driveInfo.Name, driveInfo.Name);
|
||||
if (windowsRootResult.IsError)
|
||||
Result<FileSystemItem> root;
|
||||
Result<WindowsRootItem> windowsRootResult = WindowsRootItem.Create(driveInfo.Name, driveInfo.Name);
|
||||
if (windowsRootResult.IsFailure)
|
||||
return windowsRootResult.Errors;
|
||||
else
|
||||
root = windowsRootResult.Value;
|
||||
return root;
|
||||
})
|
||||
.Where(errorOrDrive => !errorOrDrive.IsError)
|
||||
.Select(errorOrDrive => errorOrDrive.Value)
|
||||
.Where(driveResult => !driveResult.IsFailure)
|
||||
.Select(driveResult => driveResult.Value)
|
||||
.AsEnumerable());
|
||||
}
|
||||
}
|
||||
+32
-32
@@ -1,8 +1,8 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.FileSystem;
|
||||
using Lumina.Domain.SharedKernel.Common.Errors;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.FileSystem;
|
||||
using Lumina.Domain.Common.Errors;
|
||||
|
||||
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.ValueObjects;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -37,18 +37,18 @@ internal class FileProviderService : IFileProviderService
|
||||
/// </summary>
|
||||
/// <param name="path">The path for which to retrieve the list of files.</param>
|
||||
/// <param name="includeHiddenElements">Whether to include hidden files or not.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either a collection of file paths or an error.</returns>
|
||||
public ErrorOr<IEnumerable<FileSystemPathId>> GetFilePaths(FileSystemPathId path, bool includeHiddenElements)
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either a collection of file paths or an error.</returns>
|
||||
public Result<IEnumerable<FileSystemPathId>> GetFilePaths(FileSystemPathId path, bool includeHiddenElements)
|
||||
{
|
||||
// check if the user has access permissions to the provided path
|
||||
if (!_fileSystemPermissionsService.CanAccessPath(path, FileAccessMode.ListDirectory))
|
||||
return Errors.Permission.UnauthorizedAccess;
|
||||
return ErrorOrFactory.From(_fileSystem.Directory.GetFiles(path.Path)
|
||||
return Result.From(_fileSystem.Directory.GetFiles(path.Path)
|
||||
.Where(path => includeHiddenElements || (GetAttributes(path) & FileAttributes.Hidden) != FileAttributes.Hidden)
|
||||
.OrderBy(path => path)
|
||||
.Select(path => FileSystemPathId.Create(path))
|
||||
.Where(errorOrPathId => !errorOrPathId.IsError)
|
||||
.Select(errorOrPathId => errorOrPathId.Value)
|
||||
.Where(pathIdResult => !pathIdResult.IsFailure)
|
||||
.Select(pathIdResult => pathIdResult.Value)
|
||||
.AsEnumerable());
|
||||
}
|
||||
|
||||
@@ -74,8 +74,8 @@ internal class FileProviderService : IFileProviderService
|
||||
/// Checks if a file with the specified path exists.
|
||||
/// </summary>
|
||||
/// <param name="path">The path of the file whose existance is checked.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either the result of checking the existance of a file, or an error.</returns>
|
||||
public ErrorOr<bool> FileExists(FileSystemPathId path)
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either the result of checking the existance of a file, or an error.</returns>
|
||||
public Result<bool> FileExists(FileSystemPathId path)
|
||||
{
|
||||
return _fileSystem.File.Exists(path.Path);
|
||||
}
|
||||
@@ -84,8 +84,8 @@ internal class FileProviderService : IFileProviderService
|
||||
/// Retrieves the file name from the specified path.
|
||||
/// </summary>
|
||||
/// <param name="path">The path to extract the file name from.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either the name of the file without the path, or the last segment of the path if no file name is found, or an error.</returns>
|
||||
public ErrorOr<string> GetFileName(FileSystemPathId path)
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either the name of the file without the path, or the last segment of the path if no file name is found, or an error.</returns>
|
||||
public Result<string> GetFileName(FileSystemPathId path)
|
||||
{
|
||||
return _fileSystem.Path.GetFileName(path.Path);
|
||||
}
|
||||
@@ -94,8 +94,8 @@ internal class FileProviderService : IFileProviderService
|
||||
/// Retrieves the contents of a file at the specified path.
|
||||
/// </summary>
|
||||
/// <param name="path">The path for which to retrieve the file contents.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either the contents of a file at the specified path, or an error.</returns>
|
||||
public ErrorOr<byte[]> GetFileAsync(FileSystemPathId path)
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either the contents of a file at the specified path, or an error.</returns>
|
||||
public Result<byte[]> GetFileAsync(FileSystemPathId path)
|
||||
{
|
||||
// check if the user has access permissions to the provided path
|
||||
if (!_fileSystemPermissionsService.CanAccessPath(path, FileAccessMode.ReadContents))
|
||||
@@ -107,8 +107,8 @@ internal class FileProviderService : IFileProviderService
|
||||
/// Gets the last write time of a file at the specified path.
|
||||
/// </summary>
|
||||
/// <param name="path">The path of the file to retrieve the last write time for.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either the optional last write time of <paramref name="path"/> if available, or an error.</returns>
|
||||
public ErrorOr<Optional<DateTime>> GetLastWriteTime(FileSystemPathId path)
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either the optional last write time of <paramref name="path"/> if available, or an error.</returns>
|
||||
public Result<Optional<DateTime>> GetLastWriteTime(FileSystemPathId path)
|
||||
{
|
||||
// check if the user has access permissions to the provided path
|
||||
if (!_fileSystemPermissionsService.CanAccessPath(path, FileAccessMode.ReadProperties))
|
||||
@@ -120,8 +120,8 @@ internal class FileProviderService : IFileProviderService
|
||||
/// Gets the creation time of a file at the specified path.
|
||||
/// </summary>
|
||||
/// <param name="path">The path of the file to retrieve the creation time for.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either the optional creation time of <paramref name="path"/> if available, or an error.</returns>
|
||||
public ErrorOr<Optional<DateTime>> GetCreationTime(FileSystemPathId path)
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either the optional creation time of <paramref name="path"/> if available, or an error.</returns>
|
||||
public Result<Optional<DateTime>> GetCreationTime(FileSystemPathId path)
|
||||
{
|
||||
// check if the user has access permissions to the provided path
|
||||
if (!_fileSystemPermissionsService.CanAccessPath(path, FileAccessMode.ReadProperties))
|
||||
@@ -133,8 +133,8 @@ internal class FileProviderService : IFileProviderService
|
||||
/// Gets the size of a file at the specified path.
|
||||
/// </summary>
|
||||
/// <param name="path">The path of the file to retrieve the size for.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either the size of <paramref name="path"/> or an error.</returns>
|
||||
public ErrorOr<long?> GetSize(FileSystemPathId path)
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either the size of <paramref name="path"/> or an error.</returns>
|
||||
public Result<long?> GetSize(FileSystemPathId path)
|
||||
{
|
||||
// check if the user has access permissions to the provided path
|
||||
if (!_fileSystemPermissionsService.CanAccessPath(path, FileAccessMode.ReadProperties))
|
||||
@@ -148,8 +148,8 @@ internal class FileProviderService : IFileProviderService
|
||||
/// <param name="sourceFilePath">Identifier for the path where the file to be copied is located.</param>
|
||||
/// <param name="destinationDirectoryPath">Identifier for the path of the directory where the file will be copied.</param>
|
||||
/// <param name="overrideExisting">Whether to override existing files, or not.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either the copied file, or an error.</returns>
|
||||
public ErrorOr<FileSystemPathId> CopyFile(FileSystemPathId sourceFilePath, FileSystemPathId destinationDirectoryPath, bool overrideExisting)
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either the copied file, or an error.</returns>
|
||||
public Result<FileSystemPathId> CopyFile(FileSystemPathId sourceFilePath, FileSystemPathId destinationDirectoryPath, bool overrideExisting)
|
||||
{
|
||||
// check if the source file exists
|
||||
if (!_fileSystem.File.Exists(sourceFilePath.Path))
|
||||
@@ -201,8 +201,8 @@ internal class FileProviderService : IFileProviderService
|
||||
/// <param name="sourceFilePath">Identifier for the path where the file to be moved is located.</param>
|
||||
/// <param name="destinationDirectoryPath">Identifier for the path of the directory where the file will be moved.</param>
|
||||
/// <param name="overrideExisting">Whether to override existing files, or not.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either a moved file, or an error.</returns>
|
||||
public ErrorOr<FileSystemPathId> MoveFile(FileSystemPathId sourceFilePath, FileSystemPathId destinationDirectoryPath, bool overrideExisting)
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either a moved file, or an error.</returns>
|
||||
public Result<FileSystemPathId> MoveFile(FileSystemPathId sourceFilePath, FileSystemPathId destinationDirectoryPath, bool overrideExisting)
|
||||
{
|
||||
// check if the source file exists
|
||||
if (!_fileSystem.File.Exists(sourceFilePath.Path))
|
||||
@@ -232,20 +232,20 @@ internal class FileProviderService : IFileProviderService
|
||||
/// </summary>
|
||||
/// <param name="path">The path of the file to be renamed.</param>
|
||||
/// <param name="name">The new name of the file.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either the absolute path of the renamed file, or an error.</returns>
|
||||
public ErrorOr<FileSystemPathId> RenameFile(FileSystemPathId path, string name)
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either the absolute path of the renamed file, or an error.</returns>
|
||||
public Result<FileSystemPathId> RenameFile(FileSystemPathId path, string name)
|
||||
{
|
||||
string? parentDirectory = _fileSystem.FileInfo.New(path.Path)?.DirectoryName;
|
||||
if (!string.IsNullOrEmpty(parentDirectory))
|
||||
{
|
||||
ErrorOr<FileSystemPathId> parendDirectoryResult = FileSystemPathId.Create(parentDirectory);
|
||||
if (parendDirectoryResult.IsError)
|
||||
Result<FileSystemPathId> parendDirectoryResult = FileSystemPathId.Create(parentDirectory);
|
||||
if (parendDirectoryResult.IsFailure)
|
||||
return parendDirectoryResult.Errors;
|
||||
string? newFile = _fileSystem.Path.Combine(parendDirectoryResult.Value.Path, name);
|
||||
if (!string.IsNullOrEmpty(newFile))
|
||||
{
|
||||
ErrorOr<FileSystemPathId> newFilePathResult = FileSystemPathId.Create(newFile);
|
||||
if (newFilePathResult.IsError)
|
||||
Result<FileSystemPathId> newFilePathResult = FileSystemPathId.Create(newFile);
|
||||
if (newFilePathResult.IsFailure)
|
||||
return newFilePathResult.Errors;
|
||||
// check if the user has access permissions to the provided path
|
||||
if (!_fileSystemPermissionsService.CanAccessPath(path, FileAccessMode.Execute))
|
||||
@@ -266,8 +266,8 @@ internal class FileProviderService : IFileProviderService
|
||||
/// Deletes a file at the specified path.
|
||||
/// </summary>
|
||||
/// <param name="path">The path of the file to be deleted.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either the result of deleting a file, or an error.</returns>
|
||||
public ErrorOr<Deleted> DeleteFile(FileSystemPathId path)
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either the result of deleting a file, or an error.</returns>
|
||||
public Result<Deleted> DeleteFile(FileSystemPathId path)
|
||||
{
|
||||
// check if the user has access permissions to the provided path
|
||||
if (!_fileSystemPermissionsService.CanAccessPath(path, FileAccessMode.Delete))
|
||||
|
||||
+102
-103
@@ -1,12 +1,11 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.FileSystem;
|
||||
using Lumina.Domain.SharedKernel.Common.Errors;
|
||||
using Lumina.Domain.Common.Errors;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Entities;
|
||||
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Strategies.Environment;
|
||||
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Strategies.Platform;
|
||||
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.ValueObjects;
|
||||
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Entities;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.FileSystem;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
#endregion
|
||||
@@ -37,11 +36,11 @@ public class FileService : IFileService
|
||||
/// </summary>
|
||||
/// <param name="path">String representation of the file path.</param>
|
||||
/// <param name="includeHiddenElements">Whether to include hidden files or not.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either a collection of files or an error.</returns>
|
||||
public ErrorOr<IEnumerable<File>> GetFiles(string path, bool includeHiddenElements)
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either a collection of files or an error.</returns>
|
||||
public Result<IEnumerable<File>> GetFiles(string path, bool includeHiddenElements)
|
||||
{
|
||||
ErrorOr<FileSystemPathId> fileSystemPathIdResult = FileSystemPathId.Create(path);
|
||||
if (fileSystemPathIdResult.IsError)
|
||||
Result<FileSystemPathId> fileSystemPathIdResult = FileSystemPathId.Create(path);
|
||||
if (fileSystemPathIdResult.IsFailure)
|
||||
return fileSystemPathIdResult.Errors;
|
||||
return GetFiles(fileSystemPathIdResult.Value, includeHiddenElements);
|
||||
}
|
||||
@@ -51,8 +50,8 @@ public class FileService : IFileService
|
||||
/// </summary>
|
||||
/// <param name="file">The file object.</param>
|
||||
/// <param name="includeHiddenElements">Whether to include hidden files or not.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either a collection of files or an error.</returns>
|
||||
public ErrorOr<IEnumerable<File>> GetFiles(File file, bool includeHiddenElements)
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either a collection of files or an error.</returns>
|
||||
public Result<IEnumerable<File>> GetFiles(File file, bool includeHiddenElements)
|
||||
{
|
||||
return GetFiles(file.Id, includeHiddenElements);
|
||||
}
|
||||
@@ -62,40 +61,40 @@ public class FileService : IFileService
|
||||
/// </summary>
|
||||
/// <param name="path">Identifier for the file path.</param>
|
||||
/// <param name="includeHiddenElements">Whether to include hidden files or not.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either a collection of files or an error.</returns>
|
||||
public ErrorOr<IEnumerable<File>> GetFiles(FileSystemPathId path, bool includeHiddenElements)
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either a collection of files or an error.</returns>
|
||||
public Result<IEnumerable<File>> GetFiles(FileSystemPathId path, bool includeHiddenElements)
|
||||
{
|
||||
// retrieve the list of files
|
||||
ErrorOr<IEnumerable<FileSystemPathId>> filePathsResult = _environmentContext.FileProviderService.GetFilePaths(path, includeHiddenElements);
|
||||
if (filePathsResult.IsError)
|
||||
Result<IEnumerable<FileSystemPathId>> filePathsResult = _environmentContext.FileProviderService.GetFilePaths(path, includeHiddenElements);
|
||||
if (filePathsResult.IsFailure)
|
||||
return filePathsResult.Errors;
|
||||
List<File> result = [];
|
||||
IEnumerable<FileSystemPathId> filePaths = filePathsResult.Value;
|
||||
foreach (FileSystemPathId filePath in filePaths)
|
||||
{
|
||||
// extract file details and add to the result list
|
||||
ErrorOr<string> fileNameResult = _environmentContext.FileProviderService.GetFileName(filePath);
|
||||
ErrorOr<Optional<DateTime>> dateModifiedResult = _environmentContext.FileProviderService.GetLastWriteTime(filePath);
|
||||
ErrorOr<Optional<DateTime>> dateCreatedResult = _environmentContext.FileProviderService.GetCreationTime(filePath);
|
||||
ErrorOr<long?> sizeResult = _environmentContext.FileProviderService.GetSize(filePath);
|
||||
Result<string> fileNameResult = _environmentContext.FileProviderService.GetFileName(filePath);
|
||||
Result<Optional<DateTime>> dateModifiedResult = _environmentContext.FileProviderService.GetLastWriteTime(filePath);
|
||||
Result<Optional<DateTime>> dateCreatedResult = _environmentContext.FileProviderService.GetCreationTime(filePath);
|
||||
Result<long?> sizeResult = _environmentContext.FileProviderService.GetSize(filePath);
|
||||
long size = sizeResult.Value ?? 0;
|
||||
// if any of the details returned an error, set inaccessible status
|
||||
if (fileNameResult.IsError || dateModifiedResult.IsError || dateCreatedResult.IsError)
|
||||
if (fileNameResult.IsFailure || dateModifiedResult.IsFailure || dateCreatedResult.IsFailure)
|
||||
{
|
||||
ErrorOr<File> errorFileResult = File.Create(filePath, !fileNameResult.IsError ? fileNameResult.Value : null!,
|
||||
!dateCreatedResult.IsError ? dateCreatedResult.Value : Optional<DateTime>.None(),
|
||||
!dateModifiedResult.IsError ? dateModifiedResult.Value : Optional<DateTime>.None(), size);
|
||||
if (errorFileResult.IsError)
|
||||
Result<File> errorFileResult = File.Create(filePath, !fileNameResult.IsFailure ? fileNameResult.Value : null!,
|
||||
!dateCreatedResult.IsFailure ? dateCreatedResult.Value : Optional<DateTime>.None(),
|
||||
!dateModifiedResult.IsFailure ? dateModifiedResult.Value : Optional<DateTime>.None(), size);
|
||||
if (errorFileResult.IsFailure)
|
||||
return errorFileResult.Errors;
|
||||
ErrorOr<Updated> setStatusResult = errorFileResult.Value.SetStatus(FileSystemItemStatus.Inaccessible);
|
||||
if (setStatusResult.IsError)
|
||||
Result<Updated> setStatusResult = errorFileResult.Value.SetStatus(FileSystemItemStatus.Inaccessible);
|
||||
if (setStatusResult.IsFailure)
|
||||
return setStatusResult.Errors;
|
||||
result.Add(errorFileResult.Value);
|
||||
}
|
||||
else
|
||||
{
|
||||
ErrorOr<File> fileResult = File.Create(filePath, fileNameResult.Value, dateCreatedResult.Value, dateModifiedResult.Value, size);
|
||||
if (fileResult.IsError)
|
||||
Result<File> fileResult = File.Create(filePath, fileNameResult.Value, dateCreatedResult.Value, dateModifiedResult.Value, size);
|
||||
if (fileResult.IsFailure)
|
||||
return fileResult.Errors;
|
||||
result.Add(fileResult.Value);
|
||||
}
|
||||
@@ -109,19 +108,19 @@ public class FileService : IFileService
|
||||
/// <param name="sourceFilePath">String representation of the path where the file to be copied is located.</param>
|
||||
/// <param name="destinationDirectoryPath">String representation of the path of the directory where the file will be copied.</param>
|
||||
/// <param name="overrideExisting">Whether to override existing files, or not.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either a copied file, or an error.</returns>
|
||||
public ErrorOr<File> CopyFile(string sourceFilePath, string destinationDirectoryPath, bool? overrideExisting)
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either a copied file, or an error.</returns>
|
||||
public Result<File> CopyFile(string sourceFilePath, string destinationDirectoryPath, bool? overrideExisting)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(destinationDirectoryPath))
|
||||
return Errors.FileSystemManagement.InvalidPath;
|
||||
// make sure the paths are in the expected format
|
||||
if (!destinationDirectoryPath.EndsWith(_platformContext.PathStrategy.PathSeparator))
|
||||
destinationDirectoryPath += _platformContext.PathStrategy.PathSeparator;
|
||||
ErrorOr<FileSystemPathId> fileSystemSourcePathIdResult = FileSystemPathId.Create(sourceFilePath);
|
||||
if (fileSystemSourcePathIdResult.IsError)
|
||||
Result<FileSystemPathId> fileSystemSourcePathIdResult = FileSystemPathId.Create(sourceFilePath);
|
||||
if (fileSystemSourcePathIdResult.IsFailure)
|
||||
return fileSystemSourcePathIdResult.Errors;
|
||||
ErrorOr<FileSystemPathId> fileSystemDestinationPathIdResult = FileSystemPathId.Create(destinationDirectoryPath);
|
||||
if (fileSystemDestinationPathIdResult.IsError)
|
||||
Result<FileSystemPathId> fileSystemDestinationPathIdResult = FileSystemPathId.Create(destinationDirectoryPath);
|
||||
if (fileSystemDestinationPathIdResult.IsFailure)
|
||||
return fileSystemDestinationPathIdResult.Errors;
|
||||
return CopyFile(fileSystemSourcePathIdResult.Value, fileSystemDestinationPathIdResult.Value, overrideExisting ?? false);
|
||||
}
|
||||
@@ -132,35 +131,35 @@ public class FileService : IFileService
|
||||
/// <param name="sourceFilePath">Identifier for the path where the file to be copied is located.</param>
|
||||
/// <param name="destinationDirectoryPath">Identifier for the path of the directory where the file will be copied.</param>
|
||||
/// <param name="overrideExisting">Whether to override existing files, or not.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either the copied file, or an error.</returns>
|
||||
public ErrorOr<File> CopyFile(FileSystemPathId sourceFilePath, FileSystemPathId destinationDirectoryPath, bool overrideExisting)
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either the copied file, or an error.</returns>
|
||||
public Result<File> CopyFile(FileSystemPathId sourceFilePath, FileSystemPathId destinationDirectoryPath, bool overrideExisting)
|
||||
{
|
||||
ErrorOr<bool> fileExists = _environmentContext.FileProviderService.FileExists(sourceFilePath);
|
||||
if (fileExists.IsError)
|
||||
Result<bool> fileExists = _environmentContext.FileProviderService.FileExists(sourceFilePath);
|
||||
if (fileExists.IsFailure)
|
||||
return fileExists.Errors;
|
||||
else if (fileExists.Value == false)
|
||||
return Errors.FileSystemManagement.FileNotFound;
|
||||
else
|
||||
{
|
||||
// copy the file
|
||||
ErrorOr<FileSystemPathId> copyFileResult = _environmentContext.FileProviderService.CopyFile(sourceFilePath, destinationDirectoryPath, overrideExisting);
|
||||
if (copyFileResult.IsError)
|
||||
Result<FileSystemPathId> copyFileResult = _environmentContext.FileProviderService.CopyFile(sourceFilePath, destinationDirectoryPath, overrideExisting);
|
||||
if (copyFileResult.IsFailure)
|
||||
return copyFileResult.Errors;
|
||||
ErrorOr<string> fileNameResult = _environmentContext.FileProviderService.GetFileName(copyFileResult.Value);
|
||||
ErrorOr<Optional<DateTime>> dateModifiedResult = _environmentContext.FileProviderService.GetLastWriteTime(copyFileResult.Value);
|
||||
ErrorOr<Optional<DateTime>> dateCreatedResult = _environmentContext.FileProviderService.GetCreationTime(copyFileResult.Value);
|
||||
ErrorOr<long?> sizeResult = _environmentContext.FileProviderService.GetSize(copyFileResult.Value);
|
||||
Result<string> fileNameResult = _environmentContext.FileProviderService.GetFileName(copyFileResult.Value);
|
||||
Result<Optional<DateTime>> dateModifiedResult = _environmentContext.FileProviderService.GetLastWriteTime(copyFileResult.Value);
|
||||
Result<Optional<DateTime>> dateCreatedResult = _environmentContext.FileProviderService.GetCreationTime(copyFileResult.Value);
|
||||
Result<long?> sizeResult = _environmentContext.FileProviderService.GetSize(copyFileResult.Value);
|
||||
long size = sizeResult.Value ?? 0;
|
||||
// if any of the details returned an error, set inaccessible status
|
||||
if (fileNameResult.IsError || dateModifiedResult.IsError || dateCreatedResult.IsError)
|
||||
if (fileNameResult.IsFailure || dateModifiedResult.IsFailure || dateCreatedResult.IsFailure)
|
||||
{
|
||||
ErrorOr<File> errorFileResult = File.Create(copyFileResult.Value, !fileNameResult.IsError ? fileNameResult.Value : null!,
|
||||
!dateCreatedResult.IsError ? dateCreatedResult.Value : Optional<DateTime>.None(),
|
||||
!dateModifiedResult.IsError ? dateModifiedResult.Value : Optional<DateTime>.None(), size);
|
||||
if (errorFileResult.IsError)
|
||||
Result<File> errorFileResult = File.Create(copyFileResult.Value, !fileNameResult.IsFailure ? fileNameResult.Value : null!,
|
||||
!dateCreatedResult.IsFailure ? dateCreatedResult.Value : Optional<DateTime>.None(),
|
||||
!dateModifiedResult.IsFailure ? dateModifiedResult.Value : Optional<DateTime>.None(), size);
|
||||
if (errorFileResult.IsFailure)
|
||||
return errorFileResult.Errors;
|
||||
ErrorOr<Updated> setStatusResult = errorFileResult.Value.SetStatus(FileSystemItemStatus.Inaccessible);
|
||||
if (setStatusResult.IsError)
|
||||
Result<Updated> setStatusResult = errorFileResult.Value.SetStatus(FileSystemItemStatus.Inaccessible);
|
||||
if (setStatusResult.IsFailure)
|
||||
return setStatusResult.Errors;
|
||||
return errorFileResult;
|
||||
}
|
||||
@@ -175,19 +174,19 @@ public class FileService : IFileService
|
||||
/// <param name="sourceFilePath">String representation of the path where the file to be moved is located.</param>
|
||||
/// <param name="destinationDirectoryPath">String representation of the path of the directory where the file will be moved.</param>
|
||||
/// <param name="overrideExisting">Whether to override existing files, or not.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either a moved file, or an error.</returns>
|
||||
public ErrorOr<File> MoveFile(string sourceFilePath, string destinationDirectoryPath, bool? overrideExisting)
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either a moved file, or an error.</returns>
|
||||
public Result<File> MoveFile(string sourceFilePath, string destinationDirectoryPath, bool? overrideExisting)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(destinationDirectoryPath))
|
||||
return Errors.FileSystemManagement.InvalidPath;
|
||||
// make sure the paths are in the expected format
|
||||
if (!destinationDirectoryPath.EndsWith(_platformContext.PathStrategy.PathSeparator))
|
||||
destinationDirectoryPath += _platformContext.PathStrategy.PathSeparator;
|
||||
ErrorOr<FileSystemPathId> fileSystemSourcePathIdResult = FileSystemPathId.Create(sourceFilePath);
|
||||
if (fileSystemSourcePathIdResult.IsError)
|
||||
Result<FileSystemPathId> fileSystemSourcePathIdResult = FileSystemPathId.Create(sourceFilePath);
|
||||
if (fileSystemSourcePathIdResult.IsFailure)
|
||||
return fileSystemSourcePathIdResult.Errors;
|
||||
ErrorOr<FileSystemPathId> fileSystemDestinationPathIdResult = FileSystemPathId.Create(destinationDirectoryPath);
|
||||
if (fileSystemDestinationPathIdResult.IsError)
|
||||
Result<FileSystemPathId> fileSystemDestinationPathIdResult = FileSystemPathId.Create(destinationDirectoryPath);
|
||||
if (fileSystemDestinationPathIdResult.IsFailure)
|
||||
return fileSystemDestinationPathIdResult.Errors;
|
||||
return MoveFile(fileSystemSourcePathIdResult.Value, fileSystemDestinationPathIdResult.Value, overrideExisting ?? false);
|
||||
}
|
||||
@@ -198,35 +197,35 @@ public class FileService : IFileService
|
||||
/// <param name="sourceFilePath">Identifier for the path where the file to be moved is located.</param>
|
||||
/// <param name="destinationDirectoryPath">Identifier for the path of the directory where the file will be moved.</param>
|
||||
/// <param name="overrideExisting">Whether to override existing files, or not.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either the moved file, or an error.</returns>
|
||||
public ErrorOr<File> MoveFile(FileSystemPathId sourceFilePath, FileSystemPathId destinationDirectoryPath, bool overrideExisting)
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either the moved file, or an error.</returns>
|
||||
public Result<File> MoveFile(FileSystemPathId sourceFilePath, FileSystemPathId destinationDirectoryPath, bool overrideExisting)
|
||||
{
|
||||
ErrorOr<bool> fileExists = _environmentContext.FileProviderService.FileExists(sourceFilePath);
|
||||
if (fileExists.IsError)
|
||||
Result<bool> fileExists = _environmentContext.FileProviderService.FileExists(sourceFilePath);
|
||||
if (fileExists.IsFailure)
|
||||
return fileExists.Errors;
|
||||
else if (fileExists.Value == false)
|
||||
return Errors.FileSystemManagement.FileNotFound;
|
||||
else
|
||||
{
|
||||
// move the file
|
||||
ErrorOr<FileSystemPathId> moveFileResult = _environmentContext.FileProviderService.MoveFile(sourceFilePath, destinationDirectoryPath, overrideExisting);
|
||||
if (moveFileResult.IsError)
|
||||
Result<FileSystemPathId> moveFileResult = _environmentContext.FileProviderService.MoveFile(sourceFilePath, destinationDirectoryPath, overrideExisting);
|
||||
if (moveFileResult.IsFailure)
|
||||
return moveFileResult.Errors;
|
||||
ErrorOr<string> fileNameResult = _environmentContext.FileProviderService.GetFileName(moveFileResult.Value);
|
||||
ErrorOr<Optional<DateTime>> dateModifiedResult = _environmentContext.FileProviderService.GetLastWriteTime(moveFileResult.Value);
|
||||
ErrorOr<Optional<DateTime>> dateCreatedResult = _environmentContext.FileProviderService.GetCreationTime(moveFileResult.Value);
|
||||
ErrorOr<long?> sizeResult = _environmentContext.FileProviderService.GetSize(moveFileResult.Value);
|
||||
Result<string> fileNameResult = _environmentContext.FileProviderService.GetFileName(moveFileResult.Value);
|
||||
Result<Optional<DateTime>> dateModifiedResult = _environmentContext.FileProviderService.GetLastWriteTime(moveFileResult.Value);
|
||||
Result<Optional<DateTime>> dateCreatedResult = _environmentContext.FileProviderService.GetCreationTime(moveFileResult.Value);
|
||||
Result<long?> sizeResult = _environmentContext.FileProviderService.GetSize(moveFileResult.Value);
|
||||
long size = sizeResult.Value ?? 0;
|
||||
// if any of the details returned an error, set inaccessible status
|
||||
if (fileNameResult.IsError || dateModifiedResult.IsError || dateCreatedResult.IsError)
|
||||
if (fileNameResult.IsFailure || dateModifiedResult.IsFailure || dateCreatedResult.IsFailure)
|
||||
{
|
||||
ErrorOr<File> errorFileResult = File.Create(moveFileResult.Value, !fileNameResult.IsError ? fileNameResult.Value : null!,
|
||||
!dateCreatedResult.IsError ? dateCreatedResult.Value : Optional<DateTime>.None(),
|
||||
!dateModifiedResult.IsError ? dateModifiedResult.Value : Optional<DateTime>.None(), size);
|
||||
if (errorFileResult.IsError)
|
||||
Result<File> errorFileResult = File.Create(moveFileResult.Value, !fileNameResult.IsFailure ? fileNameResult.Value : null!,
|
||||
!dateCreatedResult.IsFailure ? dateCreatedResult.Value : Optional<DateTime>.None(),
|
||||
!dateModifiedResult.IsFailure ? dateModifiedResult.Value : Optional<DateTime>.None(), size);
|
||||
if (errorFileResult.IsFailure)
|
||||
return errorFileResult.Errors;
|
||||
ErrorOr<Updated> setStatusResult = errorFileResult.Value.SetStatus(FileSystemItemStatus.Inaccessible);
|
||||
if (setStatusResult.IsError)
|
||||
Result<Updated> setStatusResult = errorFileResult.Value.SetStatus(FileSystemItemStatus.Inaccessible);
|
||||
if (setStatusResult.IsFailure)
|
||||
return setStatusResult.Errors;
|
||||
return errorFileResult;
|
||||
}
|
||||
@@ -240,11 +239,11 @@ public class FileService : IFileService
|
||||
/// </summary>
|
||||
/// <param name="path">String representation of the file path.</param>
|
||||
/// <param name="name">The new name of the file.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either the renamed file, or an error.</returns>
|
||||
public ErrorOr<File> RenameFile(string path, string name)
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either the renamed file, or an error.</returns>
|
||||
public Result<File> RenameFile(string path, string name)
|
||||
{
|
||||
ErrorOr<FileSystemPathId> fileSystemPathIdResult = FileSystemPathId.Create(path);
|
||||
if (fileSystemPathIdResult.IsError)
|
||||
Result<FileSystemPathId> fileSystemPathIdResult = FileSystemPathId.Create(path);
|
||||
if (fileSystemPathIdResult.IsFailure)
|
||||
return fileSystemPathIdResult.Errors;
|
||||
return RenameFile(fileSystemPathIdResult.Value, name);
|
||||
}
|
||||
@@ -254,39 +253,39 @@ public class FileService : IFileService
|
||||
/// </summary>
|
||||
/// <param name="path">Identifier for the file path.</param>
|
||||
/// <param name="name">The new name of the file.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either the renamed file, or an error.</returns>
|
||||
public ErrorOr<File> RenameFile(FileSystemPathId path, string name)
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either the renamed file, or an error.</returns>
|
||||
public Result<File> RenameFile(FileSystemPathId path, string name)
|
||||
{
|
||||
// first, check if the directory about to be created does not already exist
|
||||
ErrorOr<FileSystemPathId> combinedPath = _platformContext.PathStrategy.CombinePath(path, name);
|
||||
if (combinedPath.IsError)
|
||||
Result<FileSystemPathId> combinedPath = _platformContext.PathStrategy.CombinePath(path, name);
|
||||
if (combinedPath.IsFailure)
|
||||
return combinedPath.Errors;
|
||||
ErrorOr<bool> fileExists = _environmentContext.FileProviderService.FileExists(combinedPath.Value);
|
||||
if (fileExists.IsError)
|
||||
Result<bool> fileExists = _environmentContext.FileProviderService.FileExists(combinedPath.Value);
|
||||
if (fileExists.IsFailure)
|
||||
return fileExists.Errors;
|
||||
else if (fileExists.Value == true)
|
||||
return Errors.FileSystemManagement.FileAlreadyExists;
|
||||
else
|
||||
{
|
||||
// rename the file
|
||||
ErrorOr<FileSystemPathId> newFilePathResult = _environmentContext.FileProviderService.RenameFile(path, name);
|
||||
if (newFilePathResult.IsError)
|
||||
Result<FileSystemPathId> newFilePathResult = _environmentContext.FileProviderService.RenameFile(path, name);
|
||||
if (newFilePathResult.IsFailure)
|
||||
return newFilePathResult.Errors;
|
||||
ErrorOr<string> fileNameResult = _environmentContext.FileProviderService.GetFileName(newFilePathResult.Value);
|
||||
ErrorOr<Optional<DateTime>> dateModifiedResult = _environmentContext.FileProviderService.GetLastWriteTime(newFilePathResult.Value);
|
||||
ErrorOr<Optional<DateTime>> dateCreatedResult = _environmentContext.FileProviderService.GetCreationTime(newFilePathResult.Value);
|
||||
ErrorOr<long?> sizeResult = _environmentContext.FileProviderService.GetSize(newFilePathResult.Value);
|
||||
Result<string> fileNameResult = _environmentContext.FileProviderService.GetFileName(newFilePathResult.Value);
|
||||
Result<Optional<DateTime>> dateModifiedResult = _environmentContext.FileProviderService.GetLastWriteTime(newFilePathResult.Value);
|
||||
Result<Optional<DateTime>> dateCreatedResult = _environmentContext.FileProviderService.GetCreationTime(newFilePathResult.Value);
|
||||
Result<long?> sizeResult = _environmentContext.FileProviderService.GetSize(newFilePathResult.Value);
|
||||
long size = sizeResult.Value ?? 0;
|
||||
// if any of the details returned an error, set inaccessible status
|
||||
if (fileNameResult.IsError || dateModifiedResult.IsError || dateCreatedResult.IsError)
|
||||
if (fileNameResult.IsFailure || dateModifiedResult.IsFailure || dateCreatedResult.IsFailure)
|
||||
{
|
||||
ErrorOr<File> errorFileResult = File.Create(newFilePathResult.Value, !fileNameResult.IsError ? fileNameResult.Value : null!,
|
||||
!dateCreatedResult.IsError ? dateCreatedResult.Value : Optional<DateTime>.None(),
|
||||
!dateModifiedResult.IsError ? dateModifiedResult.Value : Optional<DateTime>.None(), size);
|
||||
if (errorFileResult.IsError)
|
||||
Result<File> errorFileResult = File.Create(newFilePathResult.Value, !fileNameResult.IsFailure ? fileNameResult.Value : null!,
|
||||
!dateCreatedResult.IsFailure ? dateCreatedResult.Value : Optional<DateTime>.None(),
|
||||
!dateModifiedResult.IsFailure ? dateModifiedResult.Value : Optional<DateTime>.None(), size);
|
||||
if (errorFileResult.IsFailure)
|
||||
return errorFileResult.Errors;
|
||||
ErrorOr<Updated> setStatusResult = errorFileResult.Value.SetStatus(FileSystemItemStatus.Inaccessible);
|
||||
if (setStatusResult.IsError)
|
||||
Result<Updated> setStatusResult = errorFileResult.Value.SetStatus(FileSystemItemStatus.Inaccessible);
|
||||
if (setStatusResult.IsFailure)
|
||||
return setStatusResult.Errors;
|
||||
return errorFileResult;
|
||||
}
|
||||
@@ -299,11 +298,11 @@ public class FileService : IFileService
|
||||
/// Delete a file for the specified string path.
|
||||
/// </summary>
|
||||
/// <param name="path">String representation of the file path.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either the result of deleting a file, or an error.</returns>
|
||||
public ErrorOr<Deleted> DeleteFile(string path)
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either the result of deleting a file, or an error.</returns>
|
||||
public Result<Deleted> DeleteFile(string path)
|
||||
{
|
||||
ErrorOr<FileSystemPathId> fileSystemPathIdResult = FileSystemPathId.Create(path);
|
||||
if (fileSystemPathIdResult.IsError)
|
||||
Result<FileSystemPathId> fileSystemPathIdResult = FileSystemPathId.Create(path);
|
||||
if (fileSystemPathIdResult.IsFailure)
|
||||
return fileSystemPathIdResult.Errors;
|
||||
return DeleteFile(fileSystemPathIdResult.Value);
|
||||
}
|
||||
@@ -312,13 +311,13 @@ public class FileService : IFileService
|
||||
/// Delete a file for the specified string path.
|
||||
/// </summary>
|
||||
/// <param name="path">Identifier for the file path.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either the result of deleting a file, or an error.</returns>
|
||||
public ErrorOr<Deleted> DeleteFile(FileSystemPathId path)
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either the result of deleting a file, or an error.</returns>
|
||||
public Result<Deleted> DeleteFile(FileSystemPathId path)
|
||||
{
|
||||
return _environmentContext.FileProviderService.DeleteFile(path);
|
||||
}
|
||||
|
||||
public ErrorOr<bool> ReadFile(FileSystemPathId path)
|
||||
public Result<bool> ReadFile(FileSystemPathId path)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
+14
-14
@@ -1,6 +1,6 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Domain.SharedKernel.Common.Errors;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Common.Errors;
|
||||
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Strategies.Environment;
|
||||
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.ValueObjects;
|
||||
#endregion
|
||||
@@ -30,32 +30,32 @@ internal class FileSystemStructureSeedService : IFileSystemStructureSeedService
|
||||
/// Sets up the default file system directories needed by the application.
|
||||
/// </summary>
|
||||
/// <param name="rootPath">The base path where the directories will be created relative to.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
public ErrorOr<Created> SetDefaultDirectories(string rootPath)
|
||||
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
public Result<Created> SetDefaultDirectories(string rootPath)
|
||||
{
|
||||
// make sure the root path exists
|
||||
ErrorOr<FileSystemPathId> rootPathIdResult = FileSystemPathId.Create(rootPath);
|
||||
if (rootPathIdResult.IsError)
|
||||
Result<FileSystemPathId> rootPathIdResult = FileSystemPathId.Create(rootPath);
|
||||
if (rootPathIdResult.IsFailure)
|
||||
return rootPathIdResult.Errors;
|
||||
|
||||
// create the libraries directory
|
||||
ErrorOr<string> librariesPathResult = _pathService.CombinePath(rootPath, "libraries");
|
||||
if (librariesPathResult.IsError)
|
||||
Result<string> librariesPathResult = _pathService.CombinePath(rootPath, "libraries");
|
||||
if (librariesPathResult.IsFailure)
|
||||
return librariesPathResult.Errors;
|
||||
|
||||
ErrorOr<FileSystemPathId> libraryPathIdResult = FileSystemPathId.Create(librariesPathResult.Value);
|
||||
if (libraryPathIdResult.IsError)
|
||||
Result<FileSystemPathId> libraryPathIdResult = FileSystemPathId.Create(librariesPathResult.Value);
|
||||
if (libraryPathIdResult.IsFailure)
|
||||
return libraryPathIdResult.Errors;
|
||||
|
||||
ErrorOr<bool> librariesDirectoryExistsResult = _environmentContext.DirectoryProviderService.DirectoryExists(libraryPathIdResult.Value);
|
||||
if (librariesDirectoryExistsResult.IsError)
|
||||
Result<bool> librariesDirectoryExistsResult = _environmentContext.DirectoryProviderService.DirectoryExists(libraryPathIdResult.Value);
|
||||
if (librariesDirectoryExistsResult.IsFailure)
|
||||
return librariesDirectoryExistsResult.Errors;
|
||||
|
||||
// only create it if it doesn't already exist
|
||||
if (!librariesDirectoryExistsResult.Value)
|
||||
{
|
||||
ErrorOr<FileSystemPathId> createDirectoryResult = _environmentContext.DirectoryProviderService.CreateDirectory(rootPathIdResult.Value, "libraries");
|
||||
if (createDirectoryResult.IsError)
|
||||
Result<FileSystemPathId> createDirectoryResult = _environmentContext.DirectoryProviderService.CreateDirectory(rootPathIdResult.Value, "libraries");
|
||||
if (createDirectoryResult.IsFailure)
|
||||
return createDirectoryResult.Errors;
|
||||
}
|
||||
return Result.Created;
|
||||
|
||||
+6
-6
@@ -1,8 +1,8 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.FileSystem;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.PhotoLibrary;
|
||||
using Lumina.Domain.SharedKernel.Common.Errors;
|
||||
using Lumina.Domain.Common.Errors;
|
||||
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.ValueObjects;
|
||||
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Entities;
|
||||
using System;
|
||||
@@ -40,8 +40,8 @@ public class FileTypeService : IFileTypeService
|
||||
/// </summary>
|
||||
/// <param name="file">The file to determine if it is an image or not.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing the type of image or an error.</returns>
|
||||
public async Task<ErrorOr<ImageType>> GetImageTypeAsync(File file, CancellationToken cancellationToken)
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing the type of image or an error.</returns>
|
||||
public async Task<Result<ImageType>> GetImageTypeAsync(File file, CancellationToken cancellationToken)
|
||||
{
|
||||
return await GetImageTypeAsync(file.Id, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
@@ -51,8 +51,8 @@ public class FileTypeService : IFileTypeService
|
||||
/// </summary>
|
||||
/// <param name="path">The path of the file to determine if it is an image or not.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing the type of image or an error.</returns>
|
||||
public async Task<ErrorOr<ImageType>> GetImageTypeAsync(FileSystemPathId path, CancellationToken cancellationToken)
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing the type of image or an error.</returns>
|
||||
public async Task<Result<ImageType>> GetImageTypeAsync(FileSystemPathId path, CancellationToken cancellationToken)
|
||||
{
|
||||
// check if the user has access permissions to the provided path
|
||||
if (!_fileSystemPermissionsService.CanAccessPath(path, FileAccessMode.ReadContents))
|
||||
|
||||
+21
-21
@@ -1,6 +1,6 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
|
||||
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.ValueObjects;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -18,45 +18,45 @@ public interface IDirectoryProviderService
|
||||
/// </summary>
|
||||
/// <param name="path">The path from which to retrieve the subdirectory paths.</param>
|
||||
/// <param name="includeHiddenElements">Whether to include hidden subdirectories or not.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either a collection of directory paths or an error.</returns>
|
||||
ErrorOr<IEnumerable<FileSystemPathId>> GetSubdirectoryPaths(FileSystemPathId path, bool includeHiddenElements);
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either a collection of directory paths or an error.</returns>
|
||||
Result<IEnumerable<FileSystemPathId>> GetSubdirectoryPaths(FileSystemPathId path, bool includeHiddenElements);
|
||||
|
||||
/// <summary>
|
||||
/// Checks if a directory with the specified path exists.
|
||||
/// </summary>
|
||||
/// <param name="path">The path of the directory whose existance is checked.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either the result of checking the existance of a directory, or an error.</returns>
|
||||
ErrorOr<bool> DirectoryExists(FileSystemPathId path);
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either the result of checking the existance of a directory, or an error.</returns>
|
||||
Result<bool> DirectoryExists(FileSystemPathId path);
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves the file name from the specified path.
|
||||
/// </summary>
|
||||
/// <param name="path">The path to extract the file name from.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either a file name or an error.</returns>
|
||||
ErrorOr<string> GetFileName(FileSystemPathId path);
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either a file name or an error.</returns>
|
||||
Result<string> GetFileName(FileSystemPathId path);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the last write time of a specific path.
|
||||
/// </summary>
|
||||
/// <param name="path">The path to retrieve the last write time for.</param>
|
||||
/// <returns>The last write time for the specified path, or null if unavailable.</returns>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either the optional last write time of <paramref name="path"/> if available, or an error.</returns>
|
||||
ErrorOr<Optional<DateTime>> GetLastWriteTime(FileSystemPathId path);
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either the optional last write time of <paramref name="path"/> if available, or an error.</returns>
|
||||
Result<Optional<DateTime>> GetLastWriteTime(FileSystemPathId path);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the creation time of a specific path.
|
||||
/// </summary>
|
||||
/// <param name="path">The path to retrieve the creation time for.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing the optional creation time of <paramref name="path"/> if available, or an error.</returns>
|
||||
ErrorOr<Optional<DateTime>> GetCreationTime(FileSystemPathId path);
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing the optional creation time of <paramref name="path"/> if available, or an error.</returns>
|
||||
Result<Optional<DateTime>> GetCreationTime(FileSystemPathId path);
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new directory with the specified name, at the specified path.
|
||||
/// </summary>
|
||||
/// <param name="path">The path where the directory will be created.</param>
|
||||
/// <param name="name">The name of the directory that will be created.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either the path of a created directory, or an error.</returns>
|
||||
ErrorOr<FileSystemPathId> CreateDirectory(FileSystemPathId path, string name);
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either the path of a created directory, or an error.</returns>
|
||||
Result<FileSystemPathId> CreateDirectory(FileSystemPathId path, string name);
|
||||
|
||||
/// <summary>
|
||||
/// Copies a directory located at <paramref name="sourcePath"/> to <paramref name="destinationPath"/>.
|
||||
@@ -64,8 +64,8 @@ public interface IDirectoryProviderService
|
||||
/// <param name="sourcePath">Identifier for the path where the directory to be copied is located.</param>
|
||||
/// <param name="destinationPath">Identifier for the path where the directory will be copied.</param>
|
||||
/// <param name="overrideExisting">Whether to override existing directories, or not.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either the copied directory, or an error.</returns>
|
||||
ErrorOr<FileSystemPathId> CopyDirectory(FileSystemPathId sourcePath, FileSystemPathId destinationPath, bool overrideExisting);
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either the copied directory, or an error.</returns>
|
||||
Result<FileSystemPathId> CopyDirectory(FileSystemPathId sourcePath, FileSystemPathId destinationPath, bool overrideExisting);
|
||||
|
||||
/// <summary>
|
||||
/// Moves a directory located at <paramref name="sourcePath"/> to <paramref name="destinationPath"/>.
|
||||
@@ -73,21 +73,21 @@ public interface IDirectoryProviderService
|
||||
/// <param name="sourcePath">Identifier for the path where the directory to be moved is located.</param>
|
||||
/// <param name="destinationPath">Identifier for the path where the directory will be moved.</param>
|
||||
/// <param name="overrideExisting">Whether to override existing directories, or not.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either a moved directory, or an error.</returns>
|
||||
ErrorOr<FileSystemPathId> MoveDirectory(FileSystemPathId sourcePath, FileSystemPathId destinationPath, bool overrideExisting);
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either a moved directory, or an error.</returns>
|
||||
Result<FileSystemPathId> MoveDirectory(FileSystemPathId sourcePath, FileSystemPathId destinationPath, bool overrideExisting);
|
||||
|
||||
/// <summary>
|
||||
/// Renames a directory at the specified path.
|
||||
/// </summary>
|
||||
/// <param name="path">The path of the directory to be renamed.</param>
|
||||
/// <param name="name">The new name of the directory.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either the absolute path of the renamed directory, or an error.</returns>
|
||||
ErrorOr<FileSystemPathId> RenameDirectory(FileSystemPathId path, string name);
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either the absolute path of the renamed directory, or an error.</returns>
|
||||
Result<FileSystemPathId> RenameDirectory(FileSystemPathId path, string name);
|
||||
|
||||
/// <summary>
|
||||
/// Deletes a directory at the specified path.
|
||||
/// </summary>
|
||||
/// <param name="path">The path of the directory to be deleted.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either the result of deleting a directory, or an error.</returns>
|
||||
ErrorOr<Deleted> DeleteDirectory(FileSystemPathId path);
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either the result of deleting a directory, or an error.</returns>
|
||||
Result<Deleted> DeleteDirectory(FileSystemPathId path);
|
||||
}
|
||||
+17
-17
@@ -1,5 +1,5 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.ValueObjects;
|
||||
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Entities;
|
||||
using System.Collections.Generic;
|
||||
@@ -17,32 +17,32 @@ public interface IDirectoryService
|
||||
/// </summary>
|
||||
/// <param name="path">String representation of the file path.</param>
|
||||
/// <param name="includeHiddenElements">Whether to include hidden subdirectories or not.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either a collection of subdirectories or an error.</returns>
|
||||
ErrorOr<IEnumerable<Directory>> GetSubdirectories(string path, bool includeHiddenElements);
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either a collection of subdirectories or an error.</returns>
|
||||
Result<IEnumerable<Directory>> GetSubdirectories(string path, bool includeHiddenElements);
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves subdirectories for the given directory.
|
||||
/// </summary>
|
||||
/// <param name="directory">Directory object to retrieve subdirectories for.</param>
|
||||
/// <param name="includeHiddenElements">Whether to include hidden subdirectories or not.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either a collection of subdirectories or an error.</returns>
|
||||
ErrorOr<IEnumerable<Directory>> GetSubdirectories(Directory directory, bool includeHiddenElements);
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either a collection of subdirectories or an error.</returns>
|
||||
Result<IEnumerable<Directory>> GetSubdirectories(Directory directory, bool includeHiddenElements);
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves subdirectories for the specified file system path.
|
||||
/// </summary>
|
||||
/// <param name="path">Identifier for the file path.</param>
|
||||
/// <param name="includeHiddenElements">Whether to include hidden subdirectories or not.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either a collection of subdirectories or an error.</returns>
|
||||
ErrorOr<IEnumerable<Directory>> GetSubdirectories(FileSystemPathId path, bool includeHiddenElements);
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either a collection of subdirectories or an error.</returns>
|
||||
Result<IEnumerable<Directory>> GetSubdirectories(FileSystemPathId path, bool includeHiddenElements);
|
||||
|
||||
/// <summary>
|
||||
/// Creates a directory with the specified <paramref name="name"/>, at the specified <paramref name="path"/>.
|
||||
/// </summary>
|
||||
/// <param name="path">String representation of the path where the directory will be created.</param>
|
||||
/// <param name="name">The name of the directory that will be created.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either a created directory, or an error.</returns>
|
||||
ErrorOr<Directory> CreateDirectory(string path, string name);
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either a created directory, or an error.</returns>
|
||||
Result<Directory> CreateDirectory(string path, string name);
|
||||
|
||||
/// <summary>
|
||||
/// Copies a directory located at <paramref name="sourcePath"/> to <paramref name="destinationPath"/>.
|
||||
@@ -50,8 +50,8 @@ public interface IDirectoryService
|
||||
/// <param name="sourcePath">String representation of the path where the directory to be copied is located.</param>
|
||||
/// <param name="destinationPath">String representation of the path where the directory will be copied.</param>
|
||||
/// <param name="overrideExisting">Whether to override existing directories, or not.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either a copied directory, or an error.</returns>
|
||||
ErrorOr<Directory> CopyDirectory(string sourcePath, string destinationPath, bool? overrideExisting);
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either a copied directory, or an error.</returns>
|
||||
Result<Directory> CopyDirectory(string sourcePath, string destinationPath, bool? overrideExisting);
|
||||
|
||||
/// <summary>
|
||||
/// Moves a directory located at <paramref name="sourcePath"/> to <paramref name="destinationPath"/>.
|
||||
@@ -59,21 +59,21 @@ public interface IDirectoryService
|
||||
/// <param name="sourcePath">String representation of the path where the directory to be moved is located.</param>
|
||||
/// <param name="destinationPath">String representation of the path where the directory will be moved.</param>
|
||||
/// <param name="overrideExisting">Whether to override existing directories, or not.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either a moved directory, or an error.</returns>
|
||||
ErrorOr<Directory> MoveDirectory(string sourcePath, string destinationPath, bool? overrideExisting);
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either a moved directory, or an error.</returns>
|
||||
Result<Directory> MoveDirectory(string sourcePath, string destinationPath, bool? overrideExisting);
|
||||
|
||||
/// <summary>
|
||||
/// Renames a directory with the specified <paramref name="name"/>, at the specified <paramref name="path"/>.
|
||||
/// </summary>
|
||||
/// <param name="path">String representation of the path of the directory that will be renamed.</param>
|
||||
/// <param name="name">The new name of the directory.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either a renamed directory, or an error.</returns>
|
||||
ErrorOr<Directory> RenameDirectory(string path, string name);
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either a renamed directory, or an error.</returns>
|
||||
Result<Directory> RenameDirectory(string path, string name);
|
||||
|
||||
/// <summary>
|
||||
/// Delete a directory for the specified string path.
|
||||
/// </summary>
|
||||
/// <param name="path">String representation of the directory path.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either the result of deleting a directory, or an error.</returns>
|
||||
ErrorOr<Deleted> DeleteDirectory(string path);
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either the result of deleting a directory, or an error.</returns>
|
||||
Result<Deleted> DeleteDirectory(string path);
|
||||
}
|
||||
+3
-3
@@ -1,5 +1,5 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate;
|
||||
using System.Collections.Generic;
|
||||
#endregion
|
||||
@@ -14,6 +14,6 @@ public interface IDriveService
|
||||
/// <summary>
|
||||
/// Retrieves the list of drives.
|
||||
/// </summary>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either a collection of drives or an error.</returns>
|
||||
ErrorOr<IEnumerable<FileSystemItem>> GetDrives();
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either a collection of drives or an error.</returns>
|
||||
Result<IEnumerable<FileSystemItem>> GetDrives();
|
||||
}
|
||||
+23
-23
@@ -1,6 +1,6 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
|
||||
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.ValueObjects;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -18,50 +18,50 @@ public interface IFileProviderService
|
||||
/// </summary>
|
||||
/// <param name="path">The path for which to retrieve the list of files.</param>
|
||||
/// <param name="includeHiddenElements">Whether to include hidden files or not.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either a collection of file paths, or an error.</returns>
|
||||
ErrorOr<IEnumerable<FileSystemPathId>> GetFilePaths(FileSystemPathId path, bool includeHiddenElements);
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either a collection of file paths, or an error.</returns>
|
||||
Result<IEnumerable<FileSystemPathId>> GetFilePaths(FileSystemPathId path, bool includeHiddenElements);
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves the contents of a file at the specified path.
|
||||
/// </summary>
|
||||
/// <param name="path">The path for which to retrieve the file contents.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either the contents of a file at the specified path, or an error.</returns>
|
||||
ErrorOr<byte[]> GetFileAsync(FileSystemPathId path);
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either the contents of a file at the specified path, or an error.</returns>
|
||||
Result<byte[]> GetFileAsync(FileSystemPathId path);
|
||||
|
||||
/// <summary>
|
||||
/// Checks if a file with the specified path exists.
|
||||
/// </summary>
|
||||
/// <param name="path">The path of the file whose existance is checked.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either the result of checking the existance of a file, or an error.</returns>
|
||||
ErrorOr<bool> FileExists(FileSystemPathId path);
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either the result of checking the existance of a file, or an error.</returns>
|
||||
Result<bool> FileExists(FileSystemPathId path);
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves the file name from the specified path.
|
||||
/// </summary>
|
||||
/// <param name="path">The path to extract the file name from.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either the name of the file without the path, or the last segment of the path if no file name is found, or an error.</returns>
|
||||
ErrorOr<string> GetFileName(FileSystemPathId path);
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either the name of the file without the path, or the last segment of the path if no file name is found, or an error.</returns>
|
||||
Result<string> GetFileName(FileSystemPathId path);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the last write time of a file at the specified path.
|
||||
/// </summary>
|
||||
/// <param name="path">The path of the file to retrieve the last write time for.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either the optional last write time of <paramref name="path"/> if available, or an error.</returns>
|
||||
ErrorOr<Optional<DateTime>> GetLastWriteTime(FileSystemPathId path);
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either the optional last write time of <paramref name="path"/> if available, or an error.</returns>
|
||||
Result<Optional<DateTime>> GetLastWriteTime(FileSystemPathId path);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the creation time of a file at the specified path.
|
||||
/// </summary>
|
||||
/// <param name="path">The path of the file to retrieve the creation time for.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either the otional creation time of <paramref name="path"/> if available, or an error.</returns>
|
||||
ErrorOr<Optional<DateTime>> GetCreationTime(FileSystemPathId path);
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either the otional creation time of <paramref name="path"/> if available, or an error.</returns>
|
||||
Result<Optional<DateTime>> GetCreationTime(FileSystemPathId path);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the size of a file at the specified path.
|
||||
/// </summary>
|
||||
/// <param name="path">The path of the file to retrieve the size for.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either the size of <paramref name="path"/> or an error.</returns>
|
||||
ErrorOr<long?> GetSize(FileSystemPathId path);
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either the size of <paramref name="path"/> or an error.</returns>
|
||||
Result<long?> GetSize(FileSystemPathId path);
|
||||
|
||||
/// <summary>
|
||||
/// Copies a file located at <paramref name="sourceFilePath"/> to <paramref name="destinationDirectoryPath"/>.
|
||||
@@ -69,8 +69,8 @@ public interface IFileProviderService
|
||||
/// <param name="sourceFilePath">Identifier for the path where the file to be copied is located.</param>
|
||||
/// <param name="destinationDirectoryPath">Identifier for the path of the directory where the file will be copied.</param>
|
||||
/// <param name="overrideExisting">Whether to override existing files, or not.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either the copied file, or an error.</returns>
|
||||
ErrorOr<FileSystemPathId> CopyFile(FileSystemPathId sourceFilePath, FileSystemPathId destinationDirectoryPath, bool overrideExisting);
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either the copied file, or an error.</returns>
|
||||
Result<FileSystemPathId> CopyFile(FileSystemPathId sourceFilePath, FileSystemPathId destinationDirectoryPath, bool overrideExisting);
|
||||
|
||||
/// <summary>
|
||||
/// Moves a file located at <paramref name="sourceFilePath"/> to <paramref name="destinationDirectoryPath"/>.
|
||||
@@ -78,21 +78,21 @@ public interface IFileProviderService
|
||||
/// <param name="sourceFilePath">Identifier for the path where the file to be moved is located.</param>
|
||||
/// <param name="destinationDirectoryPath">Identifier for the path of the directory where the file will be moved.</param>
|
||||
/// <param name="overrideExisting">Whether to override existing files, or not.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either a moved file, or an error.</returns>
|
||||
ErrorOr<FileSystemPathId> MoveFile(FileSystemPathId sourceFilePath, FileSystemPathId destinationDirectoryPath, bool overrideExisting);
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either a moved file, or an error.</returns>
|
||||
Result<FileSystemPathId> MoveFile(FileSystemPathId sourceFilePath, FileSystemPathId destinationDirectoryPath, bool overrideExisting);
|
||||
|
||||
/// <summary>
|
||||
/// Renames a file at the specified path.
|
||||
/// </summary>
|
||||
/// <param name="path">The path of the file to be renamed.</param>
|
||||
/// <param name="name">The new name of the file.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either the absolute path of the renamed file, or an error.</returns>
|
||||
ErrorOr<FileSystemPathId> RenameFile(FileSystemPathId path, string name);
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either the absolute path of the renamed file, or an error.</returns>
|
||||
Result<FileSystemPathId> RenameFile(FileSystemPathId path, string name);
|
||||
|
||||
/// <summary>
|
||||
/// Deletes a file at the specified path.
|
||||
/// </summary>
|
||||
/// <param name="path">The path of the file to be deleted.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either the result of deleting a file, or an error.</returns>
|
||||
ErrorOr<Deleted> DeleteFile(FileSystemPathId path);
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either the result of deleting a file, or an error.</returns>
|
||||
Result<Deleted> DeleteFile(FileSystemPathId path);
|
||||
}
|
||||
+15
-15
@@ -1,5 +1,5 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.ValueObjects;
|
||||
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Entities;
|
||||
using System.Collections.Generic;
|
||||
@@ -17,24 +17,24 @@ public interface IFileService
|
||||
/// </summary>
|
||||
/// <param name="path">String representation of the file path.</param>
|
||||
/// <param name="includeHiddenElements">Whether to include hidden files or not.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either a collection of files or an error.</returns>
|
||||
ErrorOr<IEnumerable<File>> GetFiles(string path, bool includeHiddenElements);
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either a collection of files or an error.</returns>
|
||||
Result<IEnumerable<File>> GetFiles(string path, bool includeHiddenElements);
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves files associated with a given file.
|
||||
/// </summary>
|
||||
/// <param name="file">The file object.</param>
|
||||
/// <param name="includeHiddenElements">Whether to include hidden files or not.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either a collection of files or an error.</returns>
|
||||
ErrorOr<IEnumerable<File>> GetFiles(File file, bool includeHiddenElements);
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either a collection of files or an error.</returns>
|
||||
Result<IEnumerable<File>> GetFiles(File file, bool includeHiddenElements);
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves files for a specified file path ID.
|
||||
/// </summary>
|
||||
/// <param name="path">Identifier for the file path.</param>
|
||||
/// <param name="includeHiddenElements">Whether to include hidden files or not.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either a collection of files or an error.</returns>
|
||||
ErrorOr<IEnumerable<File>> GetFiles(FileSystemPathId path, bool includeHiddenElements);
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either a collection of files or an error.</returns>
|
||||
Result<IEnumerable<File>> GetFiles(FileSystemPathId path, bool includeHiddenElements);
|
||||
|
||||
/// <summary>
|
||||
/// Copies a file located at <paramref name="sourcePath"/> to <paramref name="destinationPath"/>.
|
||||
@@ -42,8 +42,8 @@ public interface IFileService
|
||||
/// <param name="sourcePath">String representation of the path where the file to be copied is located.</param>
|
||||
/// <param name="destinationPath">String representation of the path where the file will be copied.</param>
|
||||
/// <param name="overrideExisting">Whether to override existing files, or not.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either a copied file, or an error.</returns>
|
||||
ErrorOr<File> CopyFile(string sourcePath, string destinationPath, bool? overrideExisting);
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either a copied file, or an error.</returns>
|
||||
Result<File> CopyFile(string sourcePath, string destinationPath, bool? overrideExisting);
|
||||
|
||||
/// <summary>
|
||||
/// Moves a file located at <paramref name="sourcePath"/> to <paramref name="destinationPath"/>.
|
||||
@@ -51,21 +51,21 @@ public interface IFileService
|
||||
/// <param name="sourcePath">String representation of the path where the file to be moved is located.</param>
|
||||
/// <param name="destinationPath">String representation of the path where the file will be moved.</param>
|
||||
/// <param name="overrideExisting">Whether to override existing files, or not.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either a moved file, or an error.</returns>
|
||||
ErrorOr<File> MoveFile(string sourcePath, string destinationPath, bool? overrideExisting);
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either a moved file, or an error.</returns>
|
||||
Result<File> MoveFile(string sourcePath, string destinationPath, bool? overrideExisting);
|
||||
|
||||
/// <summary>
|
||||
/// Renames a file with the specified <paramref name="name"/>, at the specified <paramref name="path"/>.
|
||||
/// </summary>
|
||||
/// <param name="path">String representation of the path of the file that will be renamed.</param>
|
||||
/// <param name="name">The new name of the file.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either a renamed file, or an error.</returns>
|
||||
ErrorOr<File> RenameFile(string path, string name);
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either a renamed file, or an error.</returns>
|
||||
Result<File> RenameFile(string path, string name);
|
||||
|
||||
/// <summary>
|
||||
/// Delete a file for the specified string path.
|
||||
/// </summary>
|
||||
/// <param name="path">String representation of the file path.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either the result of deleting a file, or an error.</returns>
|
||||
ErrorOr<Deleted> DeleteFile(string path);
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either the result of deleting a file, or an error.</returns>
|
||||
Result<Deleted> DeleteFile(string path);
|
||||
}
|
||||
+3
-3
@@ -1,5 +1,5 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Services;
|
||||
@@ -13,6 +13,6 @@ public interface IFileSystemStructureSeedService
|
||||
/// Sets up the default file system directories needed by the application.
|
||||
/// </summary>
|
||||
/// <param name="rootPath">The base path where the directories will be created relative to.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
ErrorOr<Created> SetDefaultDirectories(string rootPath);
|
||||
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
Result<Created> SetDefaultDirectories(string rootPath);
|
||||
}
|
||||
+5
-5
@@ -1,5 +1,5 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.PhotoLibrary;
|
||||
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.ValueObjects;
|
||||
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Entities;
|
||||
@@ -19,14 +19,14 @@ public interface IFileTypeService
|
||||
/// </summary>
|
||||
/// <param name="file">The file to determine if it is an image or not.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing the type of image or an error.</returns>
|
||||
Task<ErrorOr<ImageType>> GetImageTypeAsync(File file, CancellationToken cancellationToken);
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing the type of image or an error.</returns>
|
||||
Task<Result<ImageType>> GetImageTypeAsync(File file, CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Determines if a file identified by <paramref name="path"/> is of type image or not, and returns its type.
|
||||
/// </summary>
|
||||
/// <param name="path">The path of the file to determine if it is an image or not.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing the type of image or an error.</returns>
|
||||
Task<ErrorOr<ImageType>> GetImageTypeAsync(FileSystemPathId path, CancellationToken cancellationToken);
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing the type of image or an error.</returns>
|
||||
Task<Result<ImageType>> GetImageTypeAsync(FileSystemPathId path, CancellationToken cancellationToken);
|
||||
}
|
||||
+9
-9
@@ -1,5 +1,5 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.ValueObjects;
|
||||
using System.Collections.Generic;
|
||||
#endregion
|
||||
@@ -36,22 +36,22 @@ public interface IPathService
|
||||
/// </summary>
|
||||
/// <param name="path">The path to be combined.</param>
|
||||
/// <param name="path">The name to be combined with the path.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing the combined path, or an error.</returns>
|
||||
ErrorOr<string> CombinePath(string path, string name);
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing the combined path, or an error.</returns>
|
||||
Result<string> CombinePath(string path, string name);
|
||||
|
||||
/// <summary>
|
||||
/// Parses <paramref name="path"/> into path segments.
|
||||
/// </summary>
|
||||
/// <param name="path">The path to be parsed.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing the path segments, or an error.</returns>
|
||||
ErrorOr<IEnumerable<PathSegment>> ParsePath(string path);
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing the path segments, or an error.</returns>
|
||||
Result<IEnumerable<PathSegment>> ParsePath(string path);
|
||||
|
||||
/// <summary>
|
||||
/// Goes up one level from <paramref name="path"/>, and returns the path segments.
|
||||
/// </summary>
|
||||
/// <param name="path">The path from which to navigate up one level.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing the path segments of the path up one level from <paramref name="path"/>, or an error.</returns>
|
||||
ErrorOr<IEnumerable<PathSegment>> GoUpOneLevel(string path);
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing the path segments of the path up one level from <paramref name="path"/>, or an error.</returns>
|
||||
Result<IEnumerable<PathSegment>> GoUpOneLevel(string path);
|
||||
|
||||
/// <summary>
|
||||
/// Returns a collection of characters that are invalid for paths.
|
||||
@@ -63,6 +63,6 @@ public interface IPathService
|
||||
/// Returns the root portion of the given path.
|
||||
/// </summary>
|
||||
/// <param name="path">The path for which to get the root.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing the root of <paramref name="path"/>, or an error.</returns>
|
||||
ErrorOr<PathSegment> GetPathRoot(string path);
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing the root of <paramref name="path"/>, or an error.</returns>
|
||||
Result<PathSegment> GetPathRoot(string path);
|
||||
}
|
||||
+5
-5
@@ -1,5 +1,5 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.ValueObjects;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
@@ -18,8 +18,8 @@ public interface IThumbnailService
|
||||
/// <param name="path">String representation of the file path.</param>
|
||||
/// <param name="quality">The quality of the thumbnail to get.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either a collection of bytes representing the thumbnail of the file at the specified path or an error.</returns>
|
||||
Task<ErrorOr<Thumbnail>> GetThumbnailAsync(string path, int quality, CancellationToken cancellationToken);
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either a collection of bytes representing the thumbnail of the file at the specified path or an error.</returns>
|
||||
Task<Result<Thumbnail>> GetThumbnailAsync(string path, int quality, CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the thumbnail of a file at the specified path.
|
||||
@@ -27,6 +27,6 @@ public interface IThumbnailService
|
||||
/// <param name="path">The path object.</param>
|
||||
/// <param name="quality">The quality of the thumbnail to get.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either a collection of bytes representing the thumbnail of the file at the specified path or an error.</returns>
|
||||
Task<ErrorOr<Thumbnail>> GetThumbnailAsync(FileSystemPathId path, int quality, CancellationToken cancellationToken);
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either a collection of bytes representing the thumbnail of the file at the specified path or an error.</returns>
|
||||
Task<Result<Thumbnail>> GetThumbnailAsync(FileSystemPathId path, int quality, CancellationToken cancellationToken);
|
||||
}
|
||||
+24
-24
@@ -1,6 +1,6 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Domain.SharedKernel.Common.Errors;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Common.Errors;
|
||||
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Strategies.Platform;
|
||||
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.ValueObjects;
|
||||
using System.Collections.Generic;
|
||||
@@ -36,8 +36,8 @@ public class PathService : IPathService
|
||||
/// <returns><see langword="true"/> if <paramref name="path"/> is a valid path, <see langword="false"/> otherwise.</returns>
|
||||
public bool IsValidPath(string path)
|
||||
{
|
||||
ErrorOr<FileSystemPathId> newPathResult = FileSystemPathId.Create(path);
|
||||
if (newPathResult.IsError)
|
||||
Result<FileSystemPathId> newPathResult = FileSystemPathId.Create(path);
|
||||
if (newPathResult.IsFailure)
|
||||
return false;
|
||||
return _platformContext.PathStrategy.IsValidPath(newPathResult.Value);
|
||||
}
|
||||
@@ -50,8 +50,8 @@ public class PathService : IPathService
|
||||
/// <returns><see langword="true"/> if <paramref name="path"/> exists, <see langword="false"/> otherwise.</returns>
|
||||
public bool Exists(string path, bool includeHiddenElements = true)
|
||||
{
|
||||
ErrorOr<FileSystemPathId> newPathResult = FileSystemPathId.Create(path);
|
||||
if (newPathResult.IsError)
|
||||
Result<FileSystemPathId> newPathResult = FileSystemPathId.Create(path);
|
||||
if (newPathResult.IsFailure)
|
||||
return false;
|
||||
return _platformContext.PathStrategy.Exists(newPathResult.Value, includeHiddenElements);
|
||||
}
|
||||
@@ -61,16 +61,16 @@ public class PathService : IPathService
|
||||
/// </summary>
|
||||
/// <param name="path">The path to be combined.</param>
|
||||
/// <param name="path">The name to be combined with the path.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing the combined path, or an error.</returns>
|
||||
public ErrorOr<string> CombinePath(string path, string name)
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing the combined path, or an error.</returns>
|
||||
public Result<string> CombinePath(string path, string name)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(path) || string.IsNullOrWhiteSpace(name))
|
||||
return Errors.FileSystemManagement.InvalidPath;
|
||||
ErrorOr<FileSystemPathId> newPathResult = FileSystemPathId.Create(path);
|
||||
if (newPathResult.IsError)
|
||||
Result<FileSystemPathId> newPathResult = FileSystemPathId.Create(path);
|
||||
if (newPathResult.IsFailure)
|
||||
return newPathResult.Errors;
|
||||
ErrorOr<FileSystemPathId> combinedPathResult = _platformContext.PathStrategy.CombinePath(newPathResult.Value, name);
|
||||
if (combinedPathResult.IsError)
|
||||
Result<FileSystemPathId> combinedPathResult = _platformContext.PathStrategy.CombinePath(newPathResult.Value, name);
|
||||
if (combinedPathResult.IsFailure)
|
||||
return combinedPathResult.Errors;
|
||||
return combinedPathResult.Value.Path;
|
||||
}
|
||||
@@ -79,11 +79,11 @@ public class PathService : IPathService
|
||||
/// Parses <paramref name="path"/> into path segments.
|
||||
/// </summary>
|
||||
/// <param name="path">The path to be parsed.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing the path segments, or an error.</returns>
|
||||
public ErrorOr<IEnumerable<PathSegment>> ParsePath(string path)
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing the path segments, or an error.</returns>
|
||||
public Result<IEnumerable<PathSegment>> ParsePath(string path)
|
||||
{
|
||||
ErrorOr<FileSystemPathId> newPathResult = FileSystemPathId.Create(path);
|
||||
if (newPathResult.IsError)
|
||||
Result<FileSystemPathId> newPathResult = FileSystemPathId.Create(path);
|
||||
if (newPathResult.IsFailure)
|
||||
return newPathResult.Errors;
|
||||
return _platformContext.PathStrategy.ParsePath(newPathResult.Value);
|
||||
}
|
||||
@@ -92,11 +92,11 @@ public class PathService : IPathService
|
||||
/// Goes up one level from <paramref name="path"/>, and returns the path segments.
|
||||
/// </summary>
|
||||
/// <param name="path">The path from which to navigate up one level.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing the path segments of the path up one level from <paramref name="path"/>, or an error.</returns>
|
||||
public ErrorOr<IEnumerable<PathSegment>> GoUpOneLevel(string path)
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing the path segments of the path up one level from <paramref name="path"/>, or an error.</returns>
|
||||
public Result<IEnumerable<PathSegment>> GoUpOneLevel(string path)
|
||||
{
|
||||
ErrorOr<FileSystemPathId> newPathResult = FileSystemPathId.Create(path);
|
||||
if (newPathResult.IsError)
|
||||
Result<FileSystemPathId> newPathResult = FileSystemPathId.Create(path);
|
||||
if (newPathResult.IsFailure)
|
||||
return newPathResult.Errors;
|
||||
return _platformContext.PathStrategy.GoUpOneLevel(newPathResult.Value);
|
||||
}
|
||||
@@ -114,11 +114,11 @@ public class PathService : IPathService
|
||||
/// Returns the root portion of the given path.
|
||||
/// </summary>
|
||||
/// <param name="path">The path for which to get the root.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing the root of <paramref name="path"/>, or an error.</returns>
|
||||
public ErrorOr<PathSegment> GetPathRoot(string path)
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing the root of <paramref name="path"/>, or an error.</returns>
|
||||
public Result<PathSegment> GetPathRoot(string path)
|
||||
{
|
||||
ErrorOr<FileSystemPathId> newPathResult = FileSystemPathId.Create(path);
|
||||
if (newPathResult.IsError)
|
||||
Result<FileSystemPathId> newPathResult = FileSystemPathId.Create(path);
|
||||
if (newPathResult.IsFailure)
|
||||
return newPathResult.Errors;
|
||||
return _platformContext.PathStrategy.GetPathRoot(newPathResult.Value);
|
||||
}
|
||||
|
||||
+12
-12
@@ -1,7 +1,7 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.PhotoLibrary;
|
||||
using Lumina.Domain.SharedKernel.Common.Errors;
|
||||
using Lumina.Domain.Common.Errors;
|
||||
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Strategies.Environment;
|
||||
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.ValueObjects;
|
||||
using SixLabors.ImageSharp;
|
||||
@@ -38,11 +38,11 @@ public class ThumbnailService : IThumbnailService
|
||||
/// <param name="path">String representation of the file path.</param>
|
||||
/// <param name="quality">The quality of the thumbnail to get.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either a collection of bytes representing the thumbnail of the file at the specified path or an error.</returns>
|
||||
public async Task<ErrorOr<Thumbnail>> GetThumbnailAsync(string path, int quality, CancellationToken cancellationToken)
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either a collection of bytes representing the thumbnail of the file at the specified path or an error.</returns>
|
||||
public async Task<Result<Thumbnail>> GetThumbnailAsync(string path, int quality, CancellationToken cancellationToken)
|
||||
{
|
||||
ErrorOr<FileSystemPathId> fileSystemPathIdResult = FileSystemPathId.Create(path);
|
||||
if (fileSystemPathIdResult.IsError)
|
||||
Result<FileSystemPathId> fileSystemPathIdResult = FileSystemPathId.Create(path);
|
||||
if (fileSystemPathIdResult.IsFailure)
|
||||
return fileSystemPathIdResult.Errors;
|
||||
return await GetThumbnailAsync(fileSystemPathIdResult.Value, quality, cancellationToken);
|
||||
}
|
||||
@@ -53,18 +53,18 @@ public class ThumbnailService : IThumbnailService
|
||||
/// <param name="path">The path of the file for which to get the thumbnail.</param>
|
||||
/// <param name="quality">The quality of the thumbnail to get.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either a collection of bytes representing the thumbnail of the file at the specified path or an error.</returns>
|
||||
public async Task<ErrorOr<Thumbnail>> GetThumbnailAsync(FileSystemPathId path, int quality, CancellationToken cancellationToken)
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either a collection of bytes representing the thumbnail of the file at the specified path or an error.</returns>
|
||||
public async Task<Result<Thumbnail>> GetThumbnailAsync(FileSystemPathId path, int quality, CancellationToken cancellationToken)
|
||||
{
|
||||
// first, get the type of the image file
|
||||
ErrorOr<ImageType> imageTypeResult = await _environmentContext.FileTypeService.GetImageTypeAsync(path, cancellationToken);
|
||||
if (imageTypeResult.IsError)
|
||||
Result<ImageType> imageTypeResult = await _environmentContext.FileTypeService.GetImageTypeAsync(path, cancellationToken);
|
||||
if (imageTypeResult.IsFailure)
|
||||
return imageTypeResult.Errors;
|
||||
if (imageTypeResult.Value != ImageType.None)
|
||||
{
|
||||
// then, get its bytes
|
||||
ErrorOr<byte[]> resultFileContents = _environmentContext.FileProviderService.GetFileAsync(path);
|
||||
if (resultFileContents.IsError)
|
||||
Result<byte[]> resultFileContents = _environmentContext.FileProviderService.GetFileAsync(path);
|
||||
if (resultFileContents.IsFailure)
|
||||
return resultFileContents.Errors;
|
||||
byte[] fileContents = resultFileContents.Value;
|
||||
// finally, resize or adjust quality based on image type
|
||||
|
||||
+9
-9
@@ -1,5 +1,5 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.ValueObjects;
|
||||
using System.Collections.Generic;
|
||||
#endregion
|
||||
@@ -33,22 +33,22 @@ public interface IPathStrategy
|
||||
/// </summary>
|
||||
/// <param name="path">The path to be combined.</param>
|
||||
/// <param name="path">The name to be combined with the path.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing the combined path, or an error.</returns>
|
||||
ErrorOr<FileSystemPathId> CombinePath(FileSystemPathId path, string name);
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing the combined path, or an error.</returns>
|
||||
Result<FileSystemPathId> CombinePath(FileSystemPathId path, string name);
|
||||
|
||||
/// <summary>
|
||||
/// Parses <paramref name="path"/> into path segments.
|
||||
/// </summary>
|
||||
/// <param name="path">The path to be parsed.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing the path segments, or an error.</returns>
|
||||
ErrorOr<IEnumerable<PathSegment>> ParsePath(FileSystemPathId path);
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing the path segments, or an error.</returns>
|
||||
Result<IEnumerable<PathSegment>> ParsePath(FileSystemPathId path);
|
||||
|
||||
/// <summary>
|
||||
/// Goes up one level from <paramref name="path"/>, and returns the path segments.
|
||||
/// </summary>
|
||||
/// <param name="path">The path from which to navigate up one level.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing the path segments of the path up one level from <paramref name="path"/>, or an error.</returns>
|
||||
ErrorOr<IEnumerable<PathSegment>> GoUpOneLevel(FileSystemPathId path);
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing the path segments of the path up one level from <paramref name="path"/>, or an error.</returns>
|
||||
Result<IEnumerable<PathSegment>> GoUpOneLevel(FileSystemPathId path);
|
||||
|
||||
/// <summary>
|
||||
/// Returns a collection of characters that are invalid for paths.
|
||||
@@ -60,6 +60,6 @@ public interface IPathStrategy
|
||||
/// Returns the root portion of the given path.
|
||||
/// </summary>
|
||||
/// <param name="path">The path for which to get the root.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing the root of <paramref name="path"/>, or an error.</returns>
|
||||
ErrorOr<PathSegment> GetPathRoot(FileSystemPathId path);
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing the root of <paramref name="path"/>, or an error.</returns>
|
||||
Result<PathSegment> GetPathRoot(FileSystemPathId path);
|
||||
}
|
||||
+16
-16
@@ -1,6 +1,6 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Domain.SharedKernel.Common.Errors;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Common.Errors;
|
||||
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.ValueObjects;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -79,8 +79,8 @@ public class UnixPathStrategy : IUnixPathStrategy
|
||||
/// </summary>
|
||||
/// <param name="path">The path to be combined.</param>
|
||||
/// <param name="name">The name to be combined with the path.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing the combined path, or an error.</returns>
|
||||
public ErrorOr<FileSystemPathId> CombinePath(FileSystemPathId path, string name)
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing the combined path, or an error.</returns>
|
||||
public Result<FileSystemPathId> CombinePath(FileSystemPathId path, string name)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(name))
|
||||
return Errors.FileSystemManagement.NameCannotBeEmpty;
|
||||
@@ -96,15 +96,15 @@ public class UnixPathStrategy : IUnixPathStrategy
|
||||
/// Parses <paramref name="path"/> into path segments.
|
||||
/// </summary>
|
||||
/// <param name="path">The path to be parsed.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing the path segments, or an error.</returns>
|
||||
public ErrorOr<IEnumerable<PathSegment>> ParsePath(FileSystemPathId path)
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing the path segments, or an error.</returns>
|
||||
public Result<IEnumerable<PathSegment>> ParsePath(FileSystemPathId path)
|
||||
{
|
||||
// if path starts with anything other than '/', it's considered relative and invalid for this parser
|
||||
if (!path.Path.StartsWith(PathSeparator))
|
||||
return Errors.FileSystemManagement.InvalidPath;
|
||||
// get the path segments
|
||||
List<string> splitSegments = [.. path.Path.Split(new[] { PathSeparator }, StringSplitOptions.RemoveEmptyEntries)];
|
||||
IEnumerable<ErrorOr<PathSegment>> segmentsResults = splitSegments.Select((segment, index) =>
|
||||
IEnumerable<Result<PathSegment>> segmentsResults = splitSegments.Select((segment, index) =>
|
||||
{
|
||||
bool isDirectory;
|
||||
if (segment.Contains('.'))
|
||||
@@ -113,18 +113,18 @@ public class UnixPathStrategy : IUnixPathStrategy
|
||||
isDirectory = true;
|
||||
return PathSegment.Create(segment, isDirectory, isDrive: false);
|
||||
}).Prepend(PathSegment.Create(PathSeparator.ToString(), isDirectory: false, isDrive: true)); // UNIX paths have '/' as "root drive"
|
||||
foreach (ErrorOr<PathSegment> segment in segmentsResults)
|
||||
if (segment.IsError)
|
||||
foreach (Result<PathSegment> segment in segmentsResults)
|
||||
if (segment.IsFailure)
|
||||
return segment.Errors;
|
||||
return ErrorOrFactory.From(segmentsResults.Select(segmentResult => segmentResult.Value));
|
||||
return Result.From(segmentsResults.Select(segmentResult => segmentResult.Value));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Goes up one level from <paramref name="path"/>, and returns the path segments.
|
||||
/// </summary>
|
||||
/// <param name="path">The path from which to navigate up one level.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing the path segments of the path up one level from <paramref name="path"/>, or an error.</returns>
|
||||
public ErrorOr<IEnumerable<PathSegment>> GoUpOneLevel(FileSystemPathId path)
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing the path segments of the path up one level from <paramref name="path"/>, or an error.</returns>
|
||||
public Result<IEnumerable<PathSegment>> GoUpOneLevel(FileSystemPathId path)
|
||||
{
|
||||
// validation: ensure the path is not null or empty
|
||||
if (!IsValidPath(path))
|
||||
@@ -139,8 +139,8 @@ public class UnixPathStrategy : IUnixPathStrategy
|
||||
if (lastIndex < 0)
|
||||
return Errors.FileSystemManagement.CannotNavigateUp;
|
||||
// return the path up to the last slash, or, if there's only the root slash, return that one instead
|
||||
ErrorOr<FileSystemPathId> newPathResult = FileSystemPathId.Create(lastIndex > 0 ? tempPath[..lastIndex] : tempPath[..1]);
|
||||
if (newPathResult.IsError)
|
||||
Result<FileSystemPathId> newPathResult = FileSystemPathId.Create(lastIndex > 0 ? tempPath[..lastIndex] : tempPath[..1]);
|
||||
if (newPathResult.IsFailure)
|
||||
return newPathResult.Errors;
|
||||
return ParsePath(newPathResult.Value);
|
||||
}
|
||||
@@ -158,8 +158,8 @@ public class UnixPathStrategy : IUnixPathStrategy
|
||||
/// Returns the root portion of the given path.
|
||||
/// </summary>
|
||||
/// <param name="path">The path for which to get the root.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing the root of <paramref name="path"/>, or an error.</returns>
|
||||
public ErrorOr<PathSegment> GetPathRoot(FileSystemPathId path)
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing the root of <paramref name="path"/>, or an error.</returns>
|
||||
public Result<PathSegment> GetPathRoot(FileSystemPathId path)
|
||||
{
|
||||
if (!IsValidPath(path))
|
||||
return Errors.FileSystemManagement.InvalidPath;
|
||||
|
||||
+18
-18
@@ -1,6 +1,6 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Domain.SharedKernel.Common.Errors;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Common.Errors;
|
||||
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.ValueObjects;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -78,8 +78,8 @@ public class WindowsPathStrategy : IWindowsPathStrategy
|
||||
/// </summary>
|
||||
/// <param name="path">The path to be combined.</param>
|
||||
/// <param name="name">The name to be combined with the path.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing the combined path, or an error.</returns>
|
||||
public ErrorOr<FileSystemPathId> CombinePath(FileSystemPathId path, string name)
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing the combined path, or an error.</returns>
|
||||
public Result<FileSystemPathId> CombinePath(FileSystemPathId path, string name)
|
||||
{
|
||||
if (name == null)
|
||||
return Errors.FileSystemManagement.NameCannotBeEmpty;
|
||||
@@ -95,18 +95,18 @@ public class WindowsPathStrategy : IWindowsPathStrategy
|
||||
/// Parses <paramref name="path"/> into path segments.
|
||||
/// </summary>
|
||||
/// <param name="path">The path to be parsed.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing the path segments, or an error.</returns>
|
||||
public ErrorOr<IEnumerable<PathSegment>> ParsePath(FileSystemPathId path)
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing the path segments, or an error.</returns>
|
||||
public Result<IEnumerable<PathSegment>> ParsePath(FileSystemPathId path)
|
||||
{
|
||||
// Windows paths usually start with a drive letter and colon, e.g., "C:", or "\\" (UNC paths)
|
||||
if (!(path.Path.StartsWith(@"\\") || (path.Path.Length >= 3 && char.IsLetter(path.Path[0]) && path.Path[1] == ':' && path.Path[2] == PathSeparator)))
|
||||
return Errors.FileSystemManagement.InvalidPath;
|
||||
IEnumerable<ErrorOr<PathSegment>> getPathSegmentsResults = GetPathSegments();
|
||||
foreach (ErrorOr<PathSegment> getPathSegmentsResult in getPathSegmentsResults)
|
||||
if (getPathSegmentsResult.IsError)
|
||||
IEnumerable<Result<PathSegment>> getPathSegmentsResults = GetPathSegments();
|
||||
foreach (Result<PathSegment> getPathSegmentsResult in getPathSegmentsResults)
|
||||
if (getPathSegmentsResult.IsFailure)
|
||||
return getPathSegmentsResult.Errors;
|
||||
return ErrorOrFactory.From(getPathSegmentsResults.Select(getPathSegmentsResult => getPathSegmentsResult.Value));
|
||||
IEnumerable<ErrorOr<PathSegment>> GetPathSegments()
|
||||
return Result.From(getPathSegmentsResults.Select(getPathSegmentsResult => getPathSegmentsResult.Value));
|
||||
IEnumerable<Result<PathSegment>> GetPathSegments()
|
||||
{
|
||||
if (path.Path.StartsWith(@"\\"))
|
||||
{
|
||||
@@ -135,7 +135,7 @@ public class WindowsPathStrategy : IWindowsPathStrategy
|
||||
}
|
||||
}
|
||||
}
|
||||
ErrorOr<PathSegment> CreatePathSegment(string segment, int index, int totalSegments)
|
||||
Result<PathSegment> CreatePathSegment(string segment, int index, int totalSegments)
|
||||
{
|
||||
bool isDirectory = segment.Contains('.')
|
||||
? index != totalSegments - 1 || path.Path.EndsWith(PathSeparator)
|
||||
@@ -148,8 +148,8 @@ public class WindowsPathStrategy : IWindowsPathStrategy
|
||||
/// Goes up one level from <paramref name="path"/>, and returns the path segments.
|
||||
/// </summary>
|
||||
/// <param name="path">The path from which to navigate up one level.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing the path segments of the path up one level from <paramref name="path"/>, or an error.</returns>
|
||||
public ErrorOr<IEnumerable<PathSegment>> GoUpOneLevel(FileSystemPathId path)
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing the path segments of the path up one level from <paramref name="path"/>, or an error.</returns>
|
||||
public Result<IEnumerable<PathSegment>> GoUpOneLevel(FileSystemPathId path)
|
||||
{
|
||||
// validation: ensure the path is not null or empty
|
||||
if (!IsValidPath(path))
|
||||
@@ -174,8 +174,8 @@ public class WindowsPathStrategy : IWindowsPathStrategy
|
||||
if (lastIndex <= 2)
|
||||
return ParsePath(FileSystemPathId.Create(tempPath[..3]).Value);
|
||||
// return the path up to the last backslash
|
||||
ErrorOr<FileSystemPathId> newPathResult = FileSystemPathId.Create(tempPath[..lastIndex]);
|
||||
if (newPathResult.IsError)
|
||||
Result<FileSystemPathId> newPathResult = FileSystemPathId.Create(tempPath[..lastIndex]);
|
||||
if (newPathResult.IsFailure)
|
||||
return newPathResult.Errors;
|
||||
|
||||
return ParsePath(newPathResult.Value);
|
||||
@@ -194,8 +194,8 @@ public class WindowsPathStrategy : IWindowsPathStrategy
|
||||
/// Returns the root portion of the given path.
|
||||
/// </summary>
|
||||
/// <param name="path">The path for which to get the root.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing the root of <paramref name="path"/>, or an error.</returns>
|
||||
public ErrorOr<PathSegment> GetPathRoot(FileSystemPathId path)
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing the root of <paramref name="path"/>, or an error.</returns>
|
||||
public Result<PathSegment> GetPathRoot(FileSystemPathId path)
|
||||
{
|
||||
if (!IsValidPath(path))
|
||||
return Errors.FileSystemManagement.InvalidPath;
|
||||
|
||||
+4
-4
@@ -1,6 +1,6 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Domain.SharedKernel.Common.Errors;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Common.Errors;
|
||||
using Lumina.Domain.Common.Models.Core;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
@@ -39,9 +39,9 @@ public sealed class FileSystemPathId : ValueObject
|
||||
/// </summary>
|
||||
/// <param name="path">The path of the file system item.</param>
|
||||
/// <returns>
|
||||
/// An <see cref="ErrorOr{TValue}"/> containing either a successfully created <see cref="FileSystemPathId"/> or an error message.
|
||||
/// An <see cref="Result{TValue}"/> containing either a successfully created <see cref="FileSystemPathId"/> or an error message.
|
||||
/// </returns>
|
||||
public static ErrorOr<FileSystemPathId> Create(string path)
|
||||
public static Result<FileSystemPathId> Create(string path)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(path))
|
||||
return Errors.FileSystemManagement.InvalidPath;
|
||||
|
||||
+4
-4
@@ -1,6 +1,6 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Domain.SharedKernel.Common.Errors;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Common.Errors;
|
||||
using Lumina.Domain.Common.Models.Core;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
@@ -49,9 +49,9 @@ public class PathSegment : ValueObject
|
||||
/// <param name="isDirectory">Value indicating if the current path segment is a file system directory or not.</param>
|
||||
/// <param name="isDrive">Value indicating if the current path segment is a file system drive or not.</param>
|
||||
/// <returns>
|
||||
/// An <see cref="ErrorOr{TValue}"/> containing either a successfully created <see cref="PathSegment"/> or an error message.
|
||||
/// An <see cref="Result{TValue}"/> containing either a successfully created <see cref="PathSegment"/> or an error message.
|
||||
/// </returns>
|
||||
public static ErrorOr<PathSegment> Create(string name, bool isDirectory, bool isDrive)
|
||||
public static Result<PathSegment> Create(string name, bool isDirectory, bool isDrive)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(name))
|
||||
return Errors.FileSystemManagement.NameCannotBeEmpty;
|
||||
|
||||
+5
-5
@@ -1,8 +1,8 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Domain.SharedKernel.Common.Errors;
|
||||
using Lumina.Domain.Common.Models.Core;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Common.Errors;
|
||||
using Lumina.Domain.Common.Models.Core;
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
@@ -98,9 +98,9 @@ public class StreamInfo : ValueObject
|
||||
/// <param name="sampleRate">The sample rate of the stream (for audio).</param>
|
||||
/// <param name="channels">The number of channels (for audio).</param>
|
||||
/// <returns>
|
||||
/// An <see cref="ErrorOr{TValue}"/> containing either a successfully created <see cref="StreamInfo"/>, or an error message.
|
||||
/// An <see cref="Result{TValue}"/> containing either a successfully created <see cref="StreamInfo"/>, or an error message.
|
||||
/// </returns>
|
||||
public static ErrorOr<StreamInfo> Create(
|
||||
public static Result<StreamInfo> Create(
|
||||
string streamId,
|
||||
string mimeType,
|
||||
int bitrate,
|
||||
|
||||
+11
-11
@@ -1,5 +1,5 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
||||
using Lumina.Domain.Common.Models.Core;
|
||||
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.ValueObjects;
|
||||
@@ -143,9 +143,9 @@ public class Library : AggregateRoot<LibraryId>
|
||||
/// <param name="shouldSkipUnchangedDirectoriesDuringScan">Whether this media library should skip the directories whose contents have not changed since the last scan, during the scan, or not.</param>
|
||||
/// <param name="scanIds">The list of objects representing the unique identifier of scans of the media library.</param>
|
||||
/// <returns>
|
||||
/// An <see cref="ErrorOr{TValue}"/> containing either a successfully created <see cref="Library"/>, or an error message.
|
||||
/// An <see cref="Result{TValue}"/> containing either a successfully created <see cref="Library"/>, or an error message.
|
||||
/// </returns>
|
||||
public static ErrorOr<Library> Create(
|
||||
public static Result<Library> Create(
|
||||
UserId userId,
|
||||
string title,
|
||||
LibraryType libraryType,
|
||||
@@ -162,8 +162,8 @@ public class Library : AggregateRoot<LibraryId>
|
||||
// go through all the file system paths that make up the media library and create domain objects from them
|
||||
foreach (string contentLocation in contentLocations)
|
||||
{
|
||||
ErrorOr<FileSystemPathId> contentLocationResult = FileSystemPathId.Create(contentLocation);
|
||||
if (contentLocationResult.IsError)
|
||||
Result<FileSystemPathId> contentLocationResult = FileSystemPathId.Create(contentLocation);
|
||||
if (contentLocationResult.IsFailure)
|
||||
return contentLocationResult.Errors;
|
||||
tempContentLocations.Add(contentLocationResult.Value);
|
||||
}
|
||||
@@ -199,9 +199,9 @@ public class Library : AggregateRoot<LibraryId>
|
||||
/// <param name="shouldSkipUnchangedDirectoriesDuringScan">Whether this media library should skip the directories whose contents have not changed since the last scan, during the scan, or not.</param>
|
||||
/// <param name="scanIds">The list of objects representing the unique identifier of scans of the media library.</param>
|
||||
/// <returns>
|
||||
/// An <see cref="ErrorOr{TValue}"/> containing either a successfully created <see cref="Library"/>, or an error message.
|
||||
/// An <see cref="Result{TValue}"/> containing either a successfully created <see cref="Library"/>, or an error message.
|
||||
/// </returns>
|
||||
public static ErrorOr<Library> Create(
|
||||
public static Result<Library> Create(
|
||||
LibraryId id,
|
||||
UserId userId,
|
||||
string title,
|
||||
@@ -219,8 +219,8 @@ public class Library : AggregateRoot<LibraryId>
|
||||
// go through all the file system paths that make up the media library and create domain objects from them
|
||||
foreach (string contentLocation in contentLocations)
|
||||
{
|
||||
ErrorOr<FileSystemPathId> contentLocationResult = FileSystemPathId.Create(contentLocation);
|
||||
if (contentLocationResult.IsError)
|
||||
Result<FileSystemPathId> contentLocationResult = FileSystemPathId.Create(contentLocation);
|
||||
if (contentLocationResult.IsFailure)
|
||||
return contentLocationResult.Errors;
|
||||
tempContentLocations.Add(contentLocationResult.Value);
|
||||
}
|
||||
@@ -260,8 +260,8 @@ public class Library : AggregateRoot<LibraryId>
|
||||
/// <summary>
|
||||
/// Marks the current library as deleted.
|
||||
/// </summary>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
public ErrorOr<Deleted> Delete()
|
||||
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
public Result<Deleted> Delete()
|
||||
{
|
||||
// clear all existing events since they become irrelevant when the entity is deleted, and they dont need to be processed
|
||||
_domainEvents.Clear();
|
||||
|
||||
+16
-16
@@ -1,7 +1,7 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
||||
using Lumina.Domain.SharedKernel.Common.Errors;
|
||||
using Lumina.Domain.Common.Errors;
|
||||
using Lumina.Domain.Common.Models.Core;
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryAggregate.ValueObjects;
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.Events;
|
||||
@@ -61,9 +61,9 @@ public class LibraryScan : AggregateRoot<ScanId>
|
||||
/// <param name="userId">The object representing the unique identifier of the user initiating the media library scan.</param>
|
||||
/// <param name="pastScans">The list of past media library scans the library identified by <paramref name="libraryId"/> had.</param>
|
||||
/// <returns>
|
||||
/// An <see cref="ErrorOr{TValue}"/> containing either a successfully created <see cref="LibraryScan"/>, or an error message.
|
||||
/// An <see cref="Result{TValue}"/> containing either a successfully created <see cref="LibraryScan"/>, or an error message.
|
||||
/// </returns>
|
||||
public static ErrorOr<LibraryScan> Create(LibraryId libraryId, UserId userId, List<LibraryScan> pastScans)
|
||||
public static Result<LibraryScan> Create(LibraryId libraryId, UserId userId, List<LibraryScan> pastScans)
|
||||
{
|
||||
return new LibraryScan(ScanId.CreateUnique(), libraryId, userId, LibraryScanJobStatus.Pending, pastScans);
|
||||
}
|
||||
@@ -77,9 +77,9 @@ public class LibraryScan : AggregateRoot<ScanId>
|
||||
/// <param name="status">The status of the media library scan.</param>
|
||||
/// <param name="pastScans">The list of past media library scans the library identified by <paramref name="libraryId"/> had.</param>
|
||||
/// <returns>
|
||||
/// An <see cref="ErrorOr{TValue}"/> containing either a successfully created <see cref="LibraryScan"/>, or an error message.
|
||||
/// An <see cref="Result{TValue}"/> containing either a successfully created <see cref="LibraryScan"/>, or an error message.
|
||||
/// </returns>
|
||||
public static ErrorOr<LibraryScan> Create(ScanId id, LibraryId libraryId, UserId userId, LibraryScanJobStatus status, List<LibraryScan> pastScans)
|
||||
public static Result<LibraryScan> Create(ScanId id, LibraryId libraryId, UserId userId, LibraryScanJobStatus status, List<LibraryScan> pastScans)
|
||||
{
|
||||
return new LibraryScan(id, libraryId, userId, status, pastScans);
|
||||
}
|
||||
@@ -87,8 +87,8 @@ public class LibraryScan : AggregateRoot<ScanId>
|
||||
/// <summary>
|
||||
/// Queues a media library scan.
|
||||
/// </summary>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
public ErrorOr<Success> QueueScan()
|
||||
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
public Result<Success> QueueScan()
|
||||
{
|
||||
// there must be no active scan for this library in the past 30 days
|
||||
if (_pastScans.Any(libraryScan => libraryScan.Status == LibraryScanJobStatus.Running || libraryScan.Status == LibraryScanJobStatus.Pending))
|
||||
@@ -102,8 +102,8 @@ public class LibraryScan : AggregateRoot<ScanId>
|
||||
/// <summary>
|
||||
/// Starts the media library scan.
|
||||
/// </summary>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
public ErrorOr<Success> StartScan()
|
||||
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
public Result<Success> StartScan()
|
||||
{
|
||||
if (Status == LibraryScanJobStatus.Pending)
|
||||
Status = LibraryScanJobStatus.Running;
|
||||
@@ -122,8 +122,8 @@ public class LibraryScan : AggregateRoot<ScanId>
|
||||
/// <summary>
|
||||
/// Finishes the media library scan.
|
||||
/// </summary>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
public ErrorOr<Success> FinishScan()
|
||||
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
public Result<Success> FinishScan()
|
||||
{
|
||||
if (Status == LibraryScanJobStatus.Running)
|
||||
Status = LibraryScanJobStatus.Completed;
|
||||
@@ -136,8 +136,8 @@ public class LibraryScan : AggregateRoot<ScanId>
|
||||
/// <summary>
|
||||
/// Cancels the media library scan.
|
||||
/// </summary>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
public ErrorOr<Success> CancelScan()
|
||||
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
public Result<Success> CancelScan()
|
||||
{
|
||||
if (Status == LibraryScanJobStatus.Running)
|
||||
Status = LibraryScanJobStatus.Canceled;
|
||||
@@ -152,8 +152,8 @@ public class LibraryScan : AggregateRoot<ScanId>
|
||||
/// <summary>
|
||||
/// Marks the media library scan as failed.
|
||||
/// </summary>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
public ErrorOr<Success> FailScan()
|
||||
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
public Result<Success> FailScan()
|
||||
{
|
||||
if (Status == LibraryScanJobStatus.Running)
|
||||
Status = LibraryScanJobStatus.Failed;
|
||||
|
||||
+5
-5
@@ -1,5 +1,5 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
@@ -19,13 +19,13 @@ public interface IMediaLibraryScanningService
|
||||
/// <param name="libraryType">The type of the media library to be scanned.</param>
|
||||
/// <param name="downloadMetadataFromWeb">Whether the library permits downloading data from the web, or not.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
Task<ErrorOr<Success>> StartScanAsync(LibraryScan scan, LibraryType libraryType, bool downloadMetadataFromWeb, CancellationToken cancellationToken);
|
||||
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
Task<Result<Success>> StartScanAsync(LibraryScan scan, LibraryType libraryType, bool downloadMetadataFromWeb, CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Cancels <paramref name="scan"/>.
|
||||
/// </summary>
|
||||
/// <param name="scan">The scan to cancel.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
ErrorOr<Success> CancelScan(LibraryScan scan);
|
||||
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
Result<Success> CancelScan(LibraryScan scan);
|
||||
}
|
||||
+7
-7
@@ -1,5 +1,5 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
||||
using Lumina.Domain.Common.Events;
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.Services.Cancellation;
|
||||
@@ -57,12 +57,12 @@ internal class MediaLibraryScanningService : IMediaLibraryScanningService
|
||||
/// <param name="libraryType">The type of the media library to be scanned.</param>
|
||||
/// <param name="downloadMetadataFromWeb">Whether the library permits downloading data from the web, or not.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
public async Task<ErrorOr<Success>> StartScanAsync(LibraryScan scan, LibraryType libraryType, bool downloadMetadataFromWeb, CancellationToken cancellationToken)
|
||||
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
public async Task<Result<Success>> StartScanAsync(LibraryScan scan, LibraryType libraryType, bool downloadMetadataFromWeb, CancellationToken cancellationToken)
|
||||
{
|
||||
// mark the scan itself as started
|
||||
ErrorOr<Success> startScanResult = scan.StartScan();
|
||||
if (startScanResult.IsError)
|
||||
Result<Success> startScanResult = scan.StartScan();
|
||||
if (startScanResult.IsFailure)
|
||||
return startScanResult.Errors;
|
||||
|
||||
foreach (IDomainEvent domainEvent in scan.GetDomainEvents())
|
||||
@@ -103,8 +103,8 @@ internal class MediaLibraryScanningService : IMediaLibraryScanningService
|
||||
/// Cancels <paramref name="scan"/>.
|
||||
/// </summary>
|
||||
/// <param name="scan">The media library scan to cancel.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
public ErrorOr<Success> CancelScan(LibraryScan scan)
|
||||
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
public Result<Success> CancelScan(LibraryScan scan)
|
||||
{
|
||||
// trigger the process that cancels the jobs of the scan
|
||||
_mediaLibrariesScanCancellationTracker.CancelScan(MediaLibraryScanCompositeId.Create(scan.Id, scan.UserId));
|
||||
|
||||
+11
-11
@@ -1,5 +1,5 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryAggregate.ValueObjects;
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.ValueObjects;
|
||||
#endregion
|
||||
@@ -17,16 +17,16 @@ public interface IMediaLibrariesScanProgressTracker
|
||||
/// <param name="libraryId">The object representing the unique identifier of the media library being scanned.</param>
|
||||
/// <param name="mediaLibraryScanCompositeId">Model for tracking media library scans.</param>
|
||||
/// <param name="totalJobs">The total number of jobs that this media library scan contains.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
ErrorOr<Created> InitializeScanProgress(LibraryId libraryId, MediaLibraryScanCompositeId mediaLibraryScanCompositeId, int totalJobs);
|
||||
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
Result<Created> InitializeScanProgress(LibraryId libraryId, MediaLibraryScanCompositeId mediaLibraryScanCompositeId, int totalJobs);
|
||||
|
||||
/// <summary>
|
||||
/// Updates the progress tracking of the media library scan by incrementing the number of completed scan jobs.
|
||||
/// </summary>
|
||||
/// <param name="libraryId">The object representing the unique identifier of the media library being scanned.</param>
|
||||
/// <param name="mediaLibraryScanCompositeId">Model for tracking media library scans.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
ErrorOr<Updated> UpdateScanProgress(LibraryId libraryId, MediaLibraryScanCompositeId mediaLibraryScanCompositeId);
|
||||
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
Result<Updated> UpdateScanProgress(LibraryId libraryId, MediaLibraryScanCompositeId mediaLibraryScanCompositeId);
|
||||
|
||||
/// <summary>
|
||||
/// Updates the progress tracking of the media library scan by incrementing the number of completed items of a scan job.
|
||||
@@ -34,24 +34,24 @@ public interface IMediaLibrariesScanProgressTracker
|
||||
/// <param name="libraryId">The object representing the unique identifier of the media library being scanned.</param>
|
||||
/// <param name="mediaLibraryScanCompositeId">Model for tracking media library scans.</param>
|
||||
/// <param name="progress">The object representing the progress of the media library scan job.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
ErrorOr<Updated> UpdateScanJobProgress(LibraryId libraryId, MediaLibraryScanCompositeId mediaLibraryScanCompositeId, MediaLibraryScanJobProgress progress);
|
||||
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
Result<Updated> UpdateScanJobProgress(LibraryId libraryId, MediaLibraryScanCompositeId mediaLibraryScanCompositeId, MediaLibraryScanJobProgress progress);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the progress of a media library scan.
|
||||
/// </summary>
|
||||
/// <param name="mediaLibraryScanCompositeId">Model for tracking media library scans.</param>
|
||||
/// <returns>
|
||||
/// An <see cref="ErrorOr{TValue}"/> containing either a <see cref="MediaLibraryScanProgress"/>, or an error message.
|
||||
/// An <see cref="Result{TValue}"/> containing either a <see cref="MediaLibraryScanProgress"/>, or an error message.
|
||||
/// </returns>
|
||||
ErrorOr<MediaLibraryScanProgress> GetScanProgress(MediaLibraryScanCompositeId mediaLibraryScanCompositeId);
|
||||
Result<MediaLibraryScanProgress> GetScanProgress(MediaLibraryScanCompositeId mediaLibraryScanCompositeId);
|
||||
|
||||
/// <summary>
|
||||
/// Removes the progress of a media library scan.
|
||||
/// </summary>
|
||||
/// <param name="mediaLibraryScanCompositeId">Model for tracking media library scans.</param>
|
||||
/// <returns>
|
||||
/// An <see cref="ErrorOr{TValue}"/> containing either a <see cref="MediaLibraryScanProgress"/>, or an error message.
|
||||
/// An <see cref="Result{TValue}"/> containing either a <see cref="MediaLibraryScanProgress"/>, or an error message.
|
||||
/// </returns>
|
||||
ErrorOr<MediaLibraryScanProgress> RemoveScanProgress(MediaLibraryScanCompositeId mediaLibraryScanCompositeId);
|
||||
Result<MediaLibraryScanProgress> RemoveScanProgress(MediaLibraryScanCompositeId mediaLibraryScanCompositeId);
|
||||
}
|
||||
+20
-21
@@ -1,10 +1,9 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
||||
using Lumina.Domain.SharedKernel.Common.Errors;
|
||||
using Lumina.Domain.Common.Errors;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryAggregate.ValueObjects;
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.ValueObjects;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
||||
using System.Collections.Concurrent;
|
||||
#endregion
|
||||
|
||||
@@ -23,14 +22,14 @@ internal class MediaLibrariesScanProgressTracker : IMediaLibrariesScanProgressTr
|
||||
/// <param name="libraryId">The object representing the unique identifier of the media library being scanned.</param>
|
||||
/// <param name="mediaLibraryScanCompositeId">Model for tracking media library scans.</param>
|
||||
/// <param name="totalJobs">The total number of jobs that this media library scan contains.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
public ErrorOr<Created> InitializeScanProgress(LibraryId libraryId, MediaLibraryScanCompositeId mediaLibraryScanCompositeId, int totalJobs)
|
||||
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
public Result<Created> InitializeScanProgress(LibraryId libraryId, MediaLibraryScanCompositeId mediaLibraryScanCompositeId, int totalJobs)
|
||||
{
|
||||
ErrorOr<MediaLibraryScanJobProgress> createLibraryScanJobProgressResult = MediaLibraryScanJobProgress.Create(0, 0, "Initializing");
|
||||
if (createLibraryScanJobProgressResult.IsError)
|
||||
Result<MediaLibraryScanJobProgress> createLibraryScanJobProgressResult = MediaLibraryScanJobProgress.Create(0, 0, "Initializing");
|
||||
if (createLibraryScanJobProgressResult.IsFailure)
|
||||
return createLibraryScanJobProgressResult.Errors;
|
||||
|
||||
ErrorOr<MediaLibraryScanProgress> createScanProgressResult = MediaLibraryScanProgress.Create(
|
||||
Result<MediaLibraryScanProgress> createScanProgressResult = MediaLibraryScanProgress.Create(
|
||||
mediaLibraryScanCompositeId.ScanId,
|
||||
mediaLibraryScanCompositeId.UserId,
|
||||
libraryId,
|
||||
@@ -39,7 +38,7 @@ internal class MediaLibrariesScanProgressTracker : IMediaLibrariesScanProgressTr
|
||||
LibraryScanJobStatus.Pending,
|
||||
Optional<MediaLibraryScanJobProgress>.Some(createLibraryScanJobProgressResult.Value)
|
||||
);
|
||||
if (createScanProgressResult.IsError)
|
||||
if (createScanProgressResult.IsFailure)
|
||||
return createScanProgressResult.Errors;
|
||||
|
||||
_scanProgresses[mediaLibraryScanCompositeId] = createScanProgressResult.Value;
|
||||
@@ -52,12 +51,12 @@ internal class MediaLibrariesScanProgressTracker : IMediaLibrariesScanProgressTr
|
||||
/// </summary>
|
||||
/// <param name="libraryId">The object representing the unique identifier of the media library being scanned.</param>
|
||||
/// <param name="mediaLibraryScanCompositeId">Model for tracking media library scans.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
public ErrorOr<Updated> UpdateScanProgress(LibraryId libraryId, MediaLibraryScanCompositeId mediaLibraryScanCompositeId)
|
||||
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
public Result<Updated> UpdateScanProgress(LibraryId libraryId, MediaLibraryScanCompositeId mediaLibraryScanCompositeId)
|
||||
{
|
||||
if (_scanProgresses.TryGetValue(mediaLibraryScanCompositeId, out MediaLibraryScanProgress? progress))
|
||||
{
|
||||
ErrorOr<MediaLibraryScanProgress> createScanProgressResult = MediaLibraryScanProgress.Create(
|
||||
Result<MediaLibraryScanProgress> createScanProgressResult = MediaLibraryScanProgress.Create(
|
||||
mediaLibraryScanCompositeId.ScanId,
|
||||
mediaLibraryScanCompositeId.UserId,
|
||||
libraryId,
|
||||
@@ -66,7 +65,7 @@ internal class MediaLibrariesScanProgressTracker : IMediaLibrariesScanProgressTr
|
||||
progress.CompletedJobs + 1 == progress.TotalJobs ? LibraryScanJobStatus.Completed : LibraryScanJobStatus.Running,
|
||||
progress.CurrentJobProgress
|
||||
);
|
||||
if (createScanProgressResult.IsError)
|
||||
if (createScanProgressResult.IsFailure)
|
||||
return createScanProgressResult.Errors;
|
||||
|
||||
_scanProgresses[mediaLibraryScanCompositeId] = createScanProgressResult.Value;
|
||||
@@ -80,12 +79,12 @@ internal class MediaLibrariesScanProgressTracker : IMediaLibrariesScanProgressTr
|
||||
/// <param name="libraryId">The object representing the unique identifier of the media library being scanned.</param>
|
||||
/// <param name="mediaLibraryScanCompositeId">Model for tracking media library scans.</param>
|
||||
/// <param name="progress">The object representing the progress of the media library scan job.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
public ErrorOr<Updated> UpdateScanJobProgress(LibraryId libraryId, MediaLibraryScanCompositeId mediaLibraryScanCompositeId, MediaLibraryScanJobProgress progress)
|
||||
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
public Result<Updated> UpdateScanJobProgress(LibraryId libraryId, MediaLibraryScanCompositeId mediaLibraryScanCompositeId, MediaLibraryScanJobProgress progress)
|
||||
{
|
||||
if (_scanProgresses.TryGetValue(mediaLibraryScanCompositeId, out MediaLibraryScanProgress? scanProgress))
|
||||
{
|
||||
ErrorOr<MediaLibraryScanProgress> createScanProgressResult = MediaLibraryScanProgress.Create(
|
||||
Result<MediaLibraryScanProgress> createScanProgressResult = MediaLibraryScanProgress.Create(
|
||||
mediaLibraryScanCompositeId.ScanId,
|
||||
mediaLibraryScanCompositeId.UserId,
|
||||
libraryId,
|
||||
@@ -94,7 +93,7 @@ internal class MediaLibrariesScanProgressTracker : IMediaLibrariesScanProgressTr
|
||||
scanProgress.Status,
|
||||
Optional<MediaLibraryScanJobProgress>.Some(progress)
|
||||
);
|
||||
if (createScanProgressResult.IsError)
|
||||
if (createScanProgressResult.IsFailure)
|
||||
return createScanProgressResult.Errors;
|
||||
|
||||
_scanProgresses[mediaLibraryScanCompositeId] = createScanProgressResult.Value;
|
||||
@@ -108,9 +107,9 @@ internal class MediaLibrariesScanProgressTracker : IMediaLibrariesScanProgressTr
|
||||
/// </summary>
|
||||
/// <param name="mediaLibraryScanCompositeId">Model for tracking media library scans.</param>
|
||||
/// <returns>
|
||||
/// An <see cref="ErrorOr{TValue}"/> containing either a <see cref="MediaLibraryScanProgress"/>, or an error message.
|
||||
/// An <see cref="Result{TValue}"/> containing either a <see cref="MediaLibraryScanProgress"/>, or an error message.
|
||||
/// </returns>
|
||||
public ErrorOr<MediaLibraryScanProgress> GetScanProgress(MediaLibraryScanCompositeId mediaLibraryScanCompositeId)
|
||||
public Result<MediaLibraryScanProgress> GetScanProgress(MediaLibraryScanCompositeId mediaLibraryScanCompositeId)
|
||||
{
|
||||
if (_scanProgresses.TryGetValue(mediaLibraryScanCompositeId, out MediaLibraryScanProgress? progress))
|
||||
return progress;
|
||||
@@ -122,9 +121,9 @@ internal class MediaLibrariesScanProgressTracker : IMediaLibrariesScanProgressTr
|
||||
/// </summary>
|
||||
/// <param name="mediaLibraryScanCompositeId">Model for tracking media library scans.</param>
|
||||
/// <returns>
|
||||
/// An <see cref="ErrorOr{TValue}"/> containing either a <see cref="MediaLibraryScanProgress"/>, or an error message.
|
||||
/// An <see cref="Result{TValue}"/> containing either a <see cref="MediaLibraryScanProgress"/>, or an error message.
|
||||
/// </returns>
|
||||
public ErrorOr<MediaLibraryScanProgress> RemoveScanProgress(MediaLibraryScanCompositeId mediaLibraryScanCompositeId)
|
||||
public Result<MediaLibraryScanProgress> RemoveScanProgress(MediaLibraryScanCompositeId mediaLibraryScanCompositeId)
|
||||
{
|
||||
if (_scanProgresses.TryRemove(mediaLibraryScanCompositeId, out MediaLibraryScanProgress? progress))
|
||||
return progress;
|
||||
|
||||
+4
-4
@@ -1,6 +1,6 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Domain.SharedKernel.Common.Errors;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Common.Errors;
|
||||
using Lumina.Domain.Common.Models.Core;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
@@ -54,9 +54,9 @@ public sealed class MediaLibraryScanJobProgress : ValueObject
|
||||
/// <param name="totalItems">The total number of items of the media library scan job.</param>
|
||||
/// <param name="currentOperation">The current operation being performed by the media library scan job.</param>
|
||||
/// <returns>
|
||||
/// An <see cref="ErrorOr{TValue}"/> containing either a successfully created <see cref="MediaLibraryScanJobProgress"/>, or an error message.
|
||||
/// An <see cref="Result{TValue}"/> containing either a successfully created <see cref="MediaLibraryScanJobProgress"/>, or an error message.
|
||||
/// </returns>
|
||||
public static ErrorOr<MediaLibraryScanJobProgress> Create(int completedItems, int totalItems, string currentOperation)
|
||||
public static Result<MediaLibraryScanJobProgress> Create(int completedItems, int totalItems, string currentOperation)
|
||||
{
|
||||
if (totalItems < 0)
|
||||
return Errors.LibraryScanning.TotalScanJobItemsCountMustBePositive;
|
||||
|
||||
+4
-5
@@ -1,11 +1,10 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
||||
using Lumina.Domain.SharedKernel.Common.Errors;
|
||||
using Lumina.Domain.Common.Errors;
|
||||
using Lumina.Domain.Common.Models.Core;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryAggregate.ValueObjects;
|
||||
using Lumina.Domain.Core.BoundedContexts.UserManagementBoundedContext.UserAggregate.ValueObjects;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
@@ -97,9 +96,9 @@ public sealed class MediaLibraryScanProgress : ValueObject
|
||||
/// <param name="status">The status of the media library scan.</param>
|
||||
/// <param name="currentJobProgress">The optional current job progress of the media library scan.</param>
|
||||
/// <returns>
|
||||
/// An <see cref="ErrorOr{TValue}"/> containing either a successfully created <see cref="MediaLibraryScanProgress"/>, or an error message.
|
||||
/// An <see cref="Result{TValue}"/> containing either a successfully created <see cref="MediaLibraryScanProgress"/>, or an error message.
|
||||
/// </returns>
|
||||
public static ErrorOr<MediaLibraryScanProgress> Create(
|
||||
public static Result<MediaLibraryScanProgress> Create(
|
||||
ScanId scanId,
|
||||
UserId userId,
|
||||
LibraryId libraryId,
|
||||
|
||||
+2
-3
@@ -1,5 +1,4 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Domain.Common.Models.Core;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Core.BoundedContexts.MediaContributorBoundedContext.MediaContributorAggregate.ValueObjects;
|
||||
@@ -68,7 +67,7 @@ public class MediaContributor : AggregateRoot<MediaContributorId>
|
||||
/// </summary>
|
||||
/// <param name="name">The name of the contributor.</param>
|
||||
/// <returns>The created <see cref="MediaContributor"/> instance.</returns>
|
||||
public static ErrorOr<MediaContributor> Create(MediaContributorName name)
|
||||
public static Result<MediaContributor> Create(MediaContributorName name)
|
||||
{
|
||||
// TODO: enforce invariants
|
||||
throw new NotImplementedException();
|
||||
@@ -81,7 +80,7 @@ public class MediaContributor : AggregateRoot<MediaContributorId>
|
||||
/// <param name="id">The unique identifier of the contributor.</param>
|
||||
/// <param name="name">The name of the contributor.</param>
|
||||
/// <returns>The created <see cref="MediaContributor"/> instance.</returns>
|
||||
public static ErrorOr<MediaContributor> Create(
|
||||
public static Result<MediaContributor> Create(
|
||||
MediaContributorId id,
|
||||
MediaContributorName name,
|
||||
MediaContributorRole role,
|
||||
|
||||
+1
-2
@@ -1,5 +1,4 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Domain.Common.Models.Core;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using System.Collections.Generic;
|
||||
@@ -41,7 +40,7 @@ public sealed class MediaContributorName : ValueObject
|
||||
/// <param name="displayName">The name by which the contributor is popularly known.</param>
|
||||
/// <param name="legalName">The legal name of the contributor.</param>
|
||||
/// <returns>The created <see cref="MediaContributorName"/> instance.</returns>
|
||||
public static ErrorOr<MediaContributorName> Create(string displayName, Optional<string> legalName)
|
||||
public static Result<MediaContributorName> Create(string displayName, Optional<string> legalName)
|
||||
{
|
||||
// TODO: enforce invariants
|
||||
return new MediaContributorName(displayName, legalName);
|
||||
|
||||
+5
-5
@@ -1,5 +1,5 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Common.Models.Core;
|
||||
using Lumina.Domain.Core.BoundedContexts.UserManagementBoundedContext.UserAggregate.ValueObjects;
|
||||
using System.Diagnostics;
|
||||
@@ -33,9 +33,9 @@ public sealed class User : AggregateRoot<UserId>
|
||||
/// </summary>
|
||||
/// <param name="username">The username of the user.</param>
|
||||
/// <returns>
|
||||
/// An <see cref="ErrorOr{TValue}"/> containing either a successfully created <see cref="User"/>, or an error message.
|
||||
/// An <see cref="Result{TValue}"/> containing either a successfully created <see cref="User"/>, or an error message.
|
||||
/// </returns>
|
||||
public static ErrorOr<User> Create(string username)
|
||||
public static Result<User> Create(string username)
|
||||
{
|
||||
return new User(UserId.CreateUnique(), username);
|
||||
}
|
||||
@@ -46,9 +46,9 @@ public sealed class User : AggregateRoot<UserId>
|
||||
/// <param name="id">The object representing the unique identifier of the user.</param>
|
||||
/// <param name="username">The username of the user.</param>
|
||||
/// <returns>
|
||||
/// An <see cref="ErrorOr{TValue}"/> containing either a successfully created <see cref="User"/>, or an error message.
|
||||
/// An <see cref="Result{TValue}"/> containing either a successfully created <see cref="User"/>, or an error message.
|
||||
/// </returns>
|
||||
public static ErrorOr<User> Create(UserId id, string username)
|
||||
public static Result<User> Create(UserId id, string username)
|
||||
{
|
||||
return new User(id, username);
|
||||
}
|
||||
|
||||
+3
-3
@@ -1,5 +1,5 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Common.Models.Core;
|
||||
using Lumina.Domain.Common.ValueObjects.Metadata;
|
||||
using Lumina.Domain.Core.BoundedContexts.MediaContributorBoundedContext.MediaContributorAggregate.ValueObjects;
|
||||
@@ -56,7 +56,7 @@ public sealed class Movie : Entity<MovieId>
|
||||
/// <param name="contributors">The list of media contributors of the movie.</param>
|
||||
/// <param name="ratings">The list of ratings for the movie.</param>
|
||||
/// <returns>The created <see cref="Movie"/>.</returns>
|
||||
public static ErrorOr<Movie> Create(VideoMetadata metadata, List<MediaContributorId> contributors, List<Rating> ratings)
|
||||
public static Result<Movie> Create(VideoMetadata metadata, List<MediaContributorId> contributors, List<Rating> ratings)
|
||||
{
|
||||
// TODO: enforce invariants
|
||||
return new Movie(MovieId.CreateUnique(), metadata, contributors, ratings);
|
||||
@@ -70,7 +70,7 @@ public sealed class Movie : Entity<MovieId>
|
||||
/// <param name="contributors">The list of media contributors of the movie.</param>
|
||||
/// <param name="ratings">The list of ratings for the movie.</param>
|
||||
/// <returns>The created <see cref="Movie"/>.</returns>
|
||||
public static ErrorOr<Movie> Create(MovieId id, VideoMetadata metadata, List<MediaContributorId> contributors, List<Rating> ratings)
|
||||
public static Result<Movie> Create(MovieId id, VideoMetadata metadata, List<MediaContributorId> contributors, List<Rating> ratings)
|
||||
{
|
||||
// TODO: enforce invariants
|
||||
return new Movie(id, metadata, contributors, ratings);
|
||||
|
||||
+3
-4
@@ -1,5 +1,4 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Common.ValueObjects.Metadata;
|
||||
using System;
|
||||
@@ -96,9 +95,9 @@ public class VideoMetadata : BaseMetadata
|
||||
/// <param name="genres">The genres of the video.</param>
|
||||
/// <param name="tags">The tags associated with the video.</param>
|
||||
/// <returns>
|
||||
/// An <see cref="ErrorOr{TValue}"/> containing either a successfully created <see cref="VideoMetadata"/>, or an error message.
|
||||
/// An <see cref="Result{TValue}"/> containing either a successfully created <see cref="VideoMetadata"/>, or an error message.
|
||||
/// </returns>
|
||||
public static ErrorOr<VideoMetadata> Create(
|
||||
public static Result<VideoMetadata> Create(
|
||||
string title,
|
||||
Optional<string> originalTitle,
|
||||
int durationInSeconds,
|
||||
@@ -128,4 +127,4 @@ public class VideoMetadata : BaseMetadata
|
||||
yield return VideoCodec;
|
||||
yield return AudioCodec;
|
||||
}
|
||||
}
|
||||
}
|
||||
+10
-10
@@ -1,6 +1,6 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Domain.SharedKernel.Common.Errors;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Common.Errors;
|
||||
using Lumina.Domain.Common.Models.Core;
|
||||
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.ValueObjects;
|
||||
using System.Collections.Generic;
|
||||
@@ -56,9 +56,9 @@ public sealed class BookSeries : Entity<BookSeriesId>
|
||||
/// <param name="isComplete">The current status of the book series.</param>
|
||||
/// <param name="books">The books of the book series.</param>
|
||||
/// <returns>
|
||||
/// An <see cref="ErrorOr{TValue}"/> containing either a successfully created <see cref="BookSeries"/>, or an error message.
|
||||
/// An <see cref="Result{TValue}"/> containing either a successfully created <see cref="BookSeries"/>, or an error message.
|
||||
/// </returns>
|
||||
public static ErrorOr<BookSeries> Create(
|
||||
public static Result<BookSeries> Create(
|
||||
BookSeriesId id,
|
||||
WrittenContentMetadata metadata,
|
||||
bool isComplete,
|
||||
@@ -80,9 +80,9 @@ public sealed class BookSeries : Entity<BookSeriesId>
|
||||
/// <param name="isComplete">The current status of the book series.</param>
|
||||
/// <param name="books">The books of the book series.</param>
|
||||
/// <returns>
|
||||
/// An <see cref="ErrorOr{TValue}"/> containing either a successfully created <see cref="BookSeries"/>, or an error message.
|
||||
/// An <see cref="Result{TValue}"/> containing either a successfully created <see cref="BookSeries"/>, or an error message.
|
||||
/// </returns>
|
||||
public static ErrorOr<BookSeries> Create(
|
||||
public static Result<BookSeries> Create(
|
||||
WrittenContentMetadata metadata,
|
||||
bool isComplete,
|
||||
List<Book> books)
|
||||
@@ -99,8 +99,8 @@ public sealed class BookSeries : Entity<BookSeriesId>
|
||||
/// Adds a book to the series.
|
||||
/// </summary>
|
||||
/// <param name="book">The book to be added.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
public ErrorOr<Created> AddBook(Book book)
|
||||
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
public Result<Created> AddBook(Book book)
|
||||
{
|
||||
if (_books.Contains(book))
|
||||
return Errors.WrittenContent.TheBookIsAlreadyInTheSeries;
|
||||
@@ -112,8 +112,8 @@ public sealed class BookSeries : Entity<BookSeriesId>
|
||||
/// Removes a book from the series.
|
||||
/// </summary>
|
||||
/// <param name="book">The book to be removed.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
public ErrorOr<Deleted> RemoveBook(Book book)
|
||||
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
public Result<Deleted> RemoveBook(Book book)
|
||||
{
|
||||
if (!_books.Contains(book))
|
||||
return Errors.WrittenContent.TheBookIsNotInTheSeries;
|
||||
|
||||
+3
-3
@@ -1,5 +1,5 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Common.Models.Core;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -26,7 +26,7 @@ public sealed class BookLibraryId : EntityId<Guid> // TODO: to be removed
|
||||
/// Creates a new instance of the <see cref="BookLibraryId"/> class.
|
||||
/// </summary>
|
||||
/// <returns>The created <see cref="BookLibraryId"/> instance.</returns>
|
||||
public static ErrorOr<BookLibraryId> CreateUnique()
|
||||
public static Result<BookLibraryId> CreateUnique()
|
||||
{
|
||||
// TODO: enforce invariants
|
||||
return new BookLibraryId(Guid.NewGuid());
|
||||
@@ -37,7 +37,7 @@ public sealed class BookLibraryId : EntityId<Guid> // TODO: to be removed
|
||||
/// </summary>
|
||||
/// <param name="value">The value used to create the <see cref="BookLibraryId"/> instance.</param>
|
||||
/// <returns>The created <see cref="BookLibraryId"/> instance.</returns>
|
||||
public static ErrorOr<BookLibraryId> Create(Guid value)
|
||||
public static Result<BookLibraryId> Create(Guid value)
|
||||
{
|
||||
// TODO: enforce invariants
|
||||
return new BookLibraryId(value);
|
||||
|
||||
+4
-5
@@ -1,9 +1,8 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.BookLibrary;
|
||||
using Lumina.Domain.SharedKernel.Common.Errors;
|
||||
using Lumina.Domain.Common.Errors;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Common.ValueObjects.Metadata;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.BookLibrary;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
@@ -42,9 +41,9 @@ public class BookRating : Rating
|
||||
/// <param name="source">The optional source of the rating.</param>
|
||||
/// <param name="voteCount">The optional number of votes or reviews.</param>
|
||||
/// <returns>
|
||||
/// An <see cref="ErrorOr{TValue}"/> containing either a successfully created <see cref="Rating"/>, or an error message.
|
||||
/// An <see cref="Result{TValue}"/> containing either a successfully created <see cref="Rating"/>, or an error message.
|
||||
/// </returns>
|
||||
public static ErrorOr<BookRating> Create(decimal value, decimal maxValue, Optional<BookRatingSource> source, Optional<int> voteCount)
|
||||
public static Result<BookRating> Create(decimal value, decimal maxValue, Optional<BookRatingSource> source, Optional<int> voteCount)
|
||||
{
|
||||
if (maxValue < 0 || value < 0)
|
||||
return Errors.Metadata.RatingValueMustBePositive;
|
||||
|
||||
+3
-3
@@ -1,7 +1,7 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.BookLibrary;
|
||||
using Lumina.Domain.SharedKernel.Common.Errors;
|
||||
using Lumina.Domain.Common.Errors;
|
||||
using Lumina.Domain.Common.Models.Core;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
@@ -46,7 +46,7 @@ public sealed class Isbn : ValueObject
|
||||
/// <param name="value">The value representing this object.</param>
|
||||
/// <param name="format">The format of the ISBN representing this object.</param>
|
||||
/// <returns>The created <see cref="Isbn"/> instance.</returns>
|
||||
public static ErrorOr<Isbn> Create(string? value, IsbnFormat format)
|
||||
public static Result<Isbn> Create(string? value, IsbnFormat format)
|
||||
{
|
||||
// enforce invariants
|
||||
if (string.IsNullOrWhiteSpace(value))
|
||||
|
||||
+2
-4
@@ -1,6 +1,4 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Domain.SharedKernel.Common.Errors;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Common.ValueObjects.Metadata;
|
||||
using System.Collections.Generic;
|
||||
@@ -69,9 +67,9 @@ public class WrittenContentMetadata : BaseMetadata
|
||||
/// <param name="publisher">The publisher of the written content, if applicable.</param>
|
||||
/// <param name="pageCount">The number of pages in the written content, if applicable.</param>
|
||||
/// <returns>
|
||||
/// An <see cref="ErrorOr{TValue}"/> containing either a successfully created <see cref="WrittenContentMetadata"/>, or an error message.
|
||||
/// An <see cref="Result{TValue}"/> containing either a successfully created <see cref="WrittenContentMetadata"/>, or an error message.
|
||||
/// </returns>
|
||||
public static ErrorOr<WrittenContentMetadata> Create(
|
||||
public static Result<WrittenContentMetadata> Create(
|
||||
string title,
|
||||
Optional<string> originalTitle,
|
||||
Optional<string> description,
|
||||
|
||||
Reference in new issue
Block a user