mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 13: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
@@ -0,0 +1,33 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.Common.Errors;
|
||||
|
||||
/// <summary>
|
||||
/// File management error types.
|
||||
/// </summary>
|
||||
public static partial class Errors
|
||||
{
|
||||
public static class FileSystemManagement
|
||||
{
|
||||
public static Error ParentNodeCannotBeNull => Error.Failure(description: nameof(ParentNodeCannotBeNull));
|
||||
public static Error PathMustBeMaximum260CharactersLong => Error.Failure(description: nameof(PathMustBeMaximum260CharactersLong));
|
||||
public static Error FileCopyError => Error.Failure(description: nameof(FileCopyError));
|
||||
public static Error FileMoveError => Error.Failure(description: nameof(FileMoveError));
|
||||
public static Error DirectoryCopyError => Error.Failure(description: nameof(DirectoryCopyError));
|
||||
public static Error DirectoryMoveError => Error.Failure(description: nameof(DirectoryMoveError));
|
||||
public static Error FileNotFound => Error.NotFound(description: nameof(FileNotFound));
|
||||
public static Error InvalidPath => Error.Validation(description: nameof(InvalidPath));
|
||||
public static Error PathCannotBeEmpty => Error.Validation(description: nameof(PathCannotBeEmpty));
|
||||
public static Error ExtensionCannotBeEmpty => Error.Validation(description: nameof(ExtensionCannotBeEmpty));
|
||||
public static Error StreamIdCannotBeEmpty => Error.Validation(description: nameof(StreamIdCannotBeEmpty));
|
||||
public static Error CodecCannotBeEmpty => Error.Validation(description: nameof(CodecCannotBeEmpty));
|
||||
public static Error BitrateMustBeAPositiveNumber => Error.Validation(description: nameof(BitrateMustBeAPositiveNumber));
|
||||
public static Error CannotNavigateUp => Error.Failure(description: nameof(CannotNavigateUp));
|
||||
public static Error NameCannotBeEmpty => Error.Validation(description: nameof(NameCannotBeEmpty));
|
||||
public static Error FileAlreadyExists => Error.Conflict(description: nameof(FileAlreadyExists));
|
||||
public static Error DirectoryNotFound => Error.NotFound(description: nameof(DirectoryNotFound));
|
||||
public static Error DirectoryAlreadyExists => Error.Conflict(description: nameof(DirectoryAlreadyExists));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.Common.Errors;
|
||||
|
||||
/// <summary>
|
||||
/// Media Library error types.
|
||||
/// </summary>
|
||||
public static partial class Errors
|
||||
{
|
||||
public static class Library
|
||||
{
|
||||
public static Error CannotScanLockedLibrary => Error.Forbidden(description: nameof(CannotScanLockedLibrary));
|
||||
public static Error CannotScanDisabledLibrary => Error.Forbidden(description: nameof(CannotScanDisabledLibrary));
|
||||
public static Error LibraryIdCannotBeEmpty => Error.Validation(description: nameof(LibraryIdCannotBeEmpty));
|
||||
public static Error LibraryAlreadyExists => Error.Conflict(description: nameof(LibraryAlreadyExists));
|
||||
public static Error LibraryNotFound => Error.NotFound(description: nameof(LibraryNotFound));
|
||||
public static Error LibraryTypeCannotBeNull => Error.Validation(description: nameof(LibraryTypeCannotBeNull));
|
||||
public static Error CoverFileMustBeAnImage => Error.Validation(description: nameof(CoverFileMustBeAnImage));
|
||||
public static Error UnknownLibraryType => Error.Unexpected(description: nameof(UnknownLibraryType));
|
||||
public static Error PathsListCannotBeNull => Error.Validation(description: nameof(PathsListCannotBeNull));
|
||||
public static Error PathsListCannotBeEmpty => Error.Validation(description: nameof(PathsListCannotBeEmpty));
|
||||
public static Error TitleCannotBeEmpty => Error.Validation(description: nameof(TitleCannotBeEmpty));
|
||||
public static Error TitleMustBeMaximum255CharactersLong => Error.Validation(description: nameof(TitleMustBeMaximum255CharactersLong));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.Common.Errors;
|
||||
|
||||
/// <summary>
|
||||
/// Media Library Scan error types.
|
||||
/// </summary>
|
||||
public static partial class Errors
|
||||
{
|
||||
public static class LibraryScanning
|
||||
{
|
||||
public static Error LibraryScanIdCannotBeEmpty => Error.Validation(description: nameof(LibraryScanIdCannotBeEmpty));
|
||||
public static Error CanOnlyStartPendingScans => Error.Forbidden(description: nameof(CanOnlyStartPendingScans));
|
||||
public static Error CanOnlyCompleteRunningScans => Error.Forbidden(description: nameof(CanOnlyCompleteRunningScans));
|
||||
public static Error CanOnlyCancelRunningScans => Error.Forbidden(description: nameof(CanOnlyCancelRunningScans));
|
||||
public static Error CanOnlyFailRunningScans => Error.Forbidden(description: nameof(CanOnlyFailRunningScans));
|
||||
public static Error ScanIdCannotBeEmpty => Error.Validation(description: nameof(ScanIdCannotBeEmpty));
|
||||
public static Error LibraryScanAlreadyExists => Error.Conflict(description: nameof(LibraryScanAlreadyExists));
|
||||
public static Error LibraryAlreadyBeingScanned => Error.Forbidden(description: nameof(LibraryAlreadyBeingScanned));
|
||||
public static Error LibraryScanNotFound => Error.NotFound(description: nameof(LibraryScanNotFound));
|
||||
public static Error TotalScanJobItemsCountMustBePositive => Error.Validation(description: nameof(TotalScanJobItemsCountMustBePositive));
|
||||
public static Error TotalScanJobsCountMustBePositive => Error.Validation(description: nameof(TotalScanJobsCountMustBePositive));
|
||||
public static Error CompletedScanJobItemsCountMustBePositive => Error.Validation(description: nameof(CompletedScanJobItemsCountMustBePositive));
|
||||
public static Error CompletedScanJobsCountMustBePositive => Error.Validation(description: nameof(CompletedScanJobsCountMustBePositive));
|
||||
public static Error CompletedScanJobItemsCountCantExceedTotalScanJobItemsCount => Error.Validation(description: nameof(CompletedScanJobItemsCountCantExceedTotalScanJobItemsCount));
|
||||
public static Error CompletedScanJobsCountCantExceedTotalScanJobsCount => Error.Validation(description: nameof(CompletedScanJobsCountCantExceedTotalScanJobsCount));
|
||||
public static Error ScanJobCurrentOperationCannotBeEmpty => Error.Validation(description: nameof(ScanJobCurrentOperationCannotBeEmpty));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.Common.Errors;
|
||||
|
||||
/// <summary>
|
||||
/// Media contributor error types.
|
||||
/// </summary>
|
||||
public static partial class Errors
|
||||
{
|
||||
public static class MediaContributor
|
||||
{
|
||||
public static Error ContributorsListCannotBeNull => Error.Validation(description: nameof(ContributorsListCannotBeNull));
|
||||
public static Error ContributorNameCannotBeEmpty => Error.Validation(description: nameof(ContributorNameCannotBeEmpty));
|
||||
public static Error ContributorDisplayNameCannotBeEmpty => Error.Validation(description: nameof(ContributorDisplayNameCannotBeEmpty));
|
||||
public static Error ContributorDisplayNameMustBeMaximum100CharactersLong => Error.Validation(description: nameof(ContributorDisplayNameMustBeMaximum100CharactersLong));
|
||||
public static Error ContributorLegalNameMustBeMaximum100CharactersLong => Error.Validation(description: nameof(ContributorLegalNameMustBeMaximum100CharactersLong));
|
||||
public static Error RoleNameCannotBeEmpty => Error.Validation(description: nameof(RoleNameCannotBeEmpty));
|
||||
public static Error RoleNameMustBeMaximum50CharactersLong => Error.Validation(description: nameof(RoleNameMustBeMaximum50CharactersLong));
|
||||
public static Error RoleCategoryCannotBeEmpty => Error.Validation(description: nameof(RoleCategoryCannotBeEmpty));
|
||||
public static Error RoleCategoryMustBeMaximum50CharactersLong => Error.Validation(description: nameof(RoleCategoryMustBeMaximum50CharactersLong));
|
||||
public static Error ContributorRoleCannotBeNull => Error.Validation(description: nameof(ContributorRoleCannotBeNull));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.Common.Errors;
|
||||
|
||||
/// <summary>
|
||||
/// Metadata error types.
|
||||
/// </summary>
|
||||
public static partial class Errors
|
||||
{
|
||||
public static class Metadata
|
||||
{
|
||||
public static Error MetadataCannotBeNull => Error.Validation(description: nameof(MetadataCannotBeNull));
|
||||
public static Error TitleCannotBeEmpty => Error.Validation(description: nameof(TitleCannotBeEmpty));
|
||||
public static Error TitleMustBeMaximum255CharactersLong => Error.Validation(description: nameof(TitleMustBeMaximum255CharactersLong));
|
||||
public static Error OriginalTitleMustBeMaximum255CharactersLong => Error.Validation(description: nameof(OriginalTitleMustBeMaximum255CharactersLong));
|
||||
public static Error DescriptionMustBeMaximum2000CharactersLong => Error.Validation(description: nameof(DescriptionMustBeMaximum2000CharactersLong));
|
||||
public static Error GenresListCannotBeNull => Error.Validation(description: nameof(GenresListCannotBeNull));
|
||||
public static Error GenreNameCannotBeEmpty => Error.Validation(description: nameof(GenreNameCannotBeEmpty));
|
||||
public static Error GenreNameMustBeMaximum50CharactersLong => Error.Validation(description: nameof(GenreNameMustBeMaximum50CharactersLong));
|
||||
public static Error TagsListCannotBeNull => Error.Validation(description: nameof(TagsListCannotBeNull));
|
||||
public static Error TagNameCannotBeEmpty => Error.Validation(description: nameof(TagNameCannotBeEmpty));
|
||||
public static Error TagNameMustBeMaximum50CharactersLong => Error.Validation(description: nameof(TagNameMustBeMaximum50CharactersLong));
|
||||
public static Error LanguageCodeCannotBeEmpty => Error.Validation(description: nameof(LanguageCodeCannotBeEmpty));
|
||||
public static Error LanguageNameCannotBeEmpty => Error.Validation(description: nameof(LanguageNameCannotBeEmpty));
|
||||
public static Error LanguageCodeMustBe2CharactersLong => Error.Validation(description: nameof(LanguageCodeMustBe2CharactersLong));
|
||||
public static Error LanguageNameMustBeMaximum50CharactersLong => Error.Validation(description: nameof(LanguageNameMustBeMaximum50CharactersLong));
|
||||
public static Error LanguageNativeNameMustBeMaximum50CharactersLong => Error.Validation(description: nameof(LanguageNativeNameMustBeMaximum50CharactersLong));
|
||||
public static Error OriginalReleaseYearMustBeBetween1And9999 => Error.Validation(description: nameof(OriginalReleaseYearMustBeBetween1And9999));
|
||||
public static Error ReReleaseYearMustBeBetween1And9999 => Error.Validation(description: nameof(ReReleaseYearMustBeBetween1And9999));
|
||||
public static Error ReReleaseYearCannotBeEarlierThanOriginalReleaseYear => Error.Validation(description: nameof(ReReleaseYearCannotBeEarlierThanOriginalReleaseYear));
|
||||
public static Error CountryCodeMustBe2CharactersLong => Error.Validation(description: nameof(CountryCodeMustBe2CharactersLong));
|
||||
public static Error ReleaseVersionMustBeMaximum50CharactersLong => Error.Validation(description: nameof(ReleaseVersionMustBeMaximum50CharactersLong));
|
||||
public static Error OriginalReleaseDateAndYearMustMatch => Error.Validation(description: nameof(OriginalReleaseDateAndYearMustMatch));
|
||||
public static Error ReReleaseDateAndYearMustMatch => Error.Validation(description: nameof(ReReleaseDateAndYearMustMatch));
|
||||
public static Error ReReleaseDateCannotBeEarlierThanOriginalReleaseDate => Error.Validation(description: nameof(ReReleaseDateCannotBeEarlierThanOriginalReleaseDate));
|
||||
public static Error ReleaseInfoCannotBeNull => Error.Validation(description: nameof(ReleaseInfoCannotBeNull));
|
||||
public static Error RatingValueMustBePositive => Error.Validation(description: nameof(RatingValueMustBePositive));
|
||||
public static Error RatingMaxValueMustBePositive => Error.Validation(description: nameof(RatingMaxValueMustBePositive));
|
||||
public static Error RatingValueCannotBeGreaterThanMaxValue => Error.Validation(description: nameof(RatingValueCannotBeGreaterThanMaxValue));
|
||||
public static Error RatingVoteCountMustBePositive => Error.Validation(description: nameof(RatingVoteCountMustBePositive));
|
||||
public static Error RatingsListCannotBeNull => Error.Validation(description: nameof(RatingsListCannotBeNull));
|
||||
public static Error InvalidIsoCode => Error.Validation(description: nameof(InvalidIsoCode));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.Common.Errors;
|
||||
|
||||
/// <summary>
|
||||
/// Domain permission related error types.
|
||||
/// </summary>
|
||||
public static partial class Errors
|
||||
{
|
||||
public static class Permission
|
||||
{
|
||||
public static Error UnauthorizedAccess => Error.Failure(description: nameof(UnauthorizedAccess));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.Common.Errors;
|
||||
|
||||
/// <summary>
|
||||
/// Plugin error types.
|
||||
/// </summary>
|
||||
public static partial class Errors
|
||||
{
|
||||
public static class Plugins
|
||||
{
|
||||
public static Error PluginNotFound => Error.NotFound(description: nameof(PluginNotFound));
|
||||
public static Error PluginIdCannotBeEmpty => Error.Validation(description: nameof(PluginIdCannotBeEmpty));
|
||||
public static Error PluginSettingsCannotBeNull => Error.Validation(description: nameof(PluginSettingsCannotBeNull));
|
||||
public static Error LibraryIdCannotBeEmpty => Error.Validation(description: nameof(LibraryIdCannotBeEmpty));
|
||||
public static Error PluginIdsListCannotBeNull => Error.Validation(description: nameof(PluginIdsListCannotBeNull));
|
||||
public static Error PluginIdsListCannotBeEmpty => Error.Validation(description: nameof(PluginIdsListCannotBeEmpty));
|
||||
public static Error LibraryMetadataProviderConfigurationNotFound => Error.NotFound(description: nameof(LibraryMetadataProviderConfigurationNotFound));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.Common.Errors;
|
||||
|
||||
/// <summary>
|
||||
/// Domain thumbnails related error types.
|
||||
/// </summary>
|
||||
public static partial class Errors
|
||||
{
|
||||
public static class Thumbnails
|
||||
{
|
||||
public static Error NoThumbnail => Error.Failure(description: nameof(NoThumbnail));
|
||||
public static Error ImageQualityMustBeBetweenZeroAndOneHundred => Error.Validation(description: nameof(ImageQualityMustBeBetweenZeroAndOneHundred));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.Common.Errors;
|
||||
|
||||
/// <summary>
|
||||
/// Users error types.
|
||||
/// </summary>
|
||||
public static partial class Errors
|
||||
{
|
||||
public static class Users
|
||||
{
|
||||
public static Error UserAlreadyExists => Error.Conflict(description: nameof(UserAlreadyExists));
|
||||
public static Error UserDoesNotExist => Error.NotFound(description: nameof(UserDoesNotExist));
|
||||
public static Error UserIdCannotBeEmpty => Error.Validation(description: nameof(UserIdCannotBeEmpty));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.Common.Errors;
|
||||
|
||||
/// <summary>
|
||||
/// Written content error types.
|
||||
/// </summary>
|
||||
public static partial class Errors
|
||||
{
|
||||
public static class WrittenContent
|
||||
{
|
||||
public static Error BookAlreadyExists => Error.Conflict(description: nameof(BookAlreadyExists));
|
||||
public static Error IsbnValueCannotBeEmpty => Error.Validation(description: nameof(IsbnValueCannotBeEmpty));
|
||||
public static Error IsbnListCannotBeNull => Error.Validation(description: nameof(IsbnListCannotBeNull));
|
||||
public static Error InvalidIsbn10Format => Error.Validation(description: nameof(InvalidIsbn10Format));
|
||||
public static Error InvalidIsbn13Format => Error.Validation(description: nameof(InvalidIsbn13Format));
|
||||
public static Error UnknownIsbnFormat => Error.Unexpected(description: nameof(UnknownIsbnFormat));
|
||||
public static Error TheBookIsAlreadyInTheSeries => Error.Forbidden(description: nameof(TheBookIsAlreadyInTheSeries));
|
||||
public static Error TheBookIsNotInTheSeries => Error.Forbidden(description: nameof(TheBookIsNotInTheSeries));
|
||||
public static Error AsinMustBe10CharactersLong => Error.Validation(description: nameof(AsinMustBe10CharactersLong));
|
||||
public static Error GoodreadsIdMustBeNumeric => Error.Validation(description: nameof(GoodreadsIdMustBeNumeric));
|
||||
public static Error InvalidLccnFormat => Error.Validation(description: nameof(InvalidLccnFormat));
|
||||
public static Error InvalidOclcFormat => Error.Validation(description: nameof(InvalidOclcFormat));
|
||||
public static Error InvalidOpenLibraryId => Error.Validation(description: nameof(InvalidOpenLibraryId));
|
||||
public static Error LibraryThingIdMustBeMaximum50CharactersLong => Error.Validation(description: nameof(LibraryThingIdMustBeMaximum50CharactersLong));
|
||||
public static Error GoogleBooksIdMustBe12CharactersLong => Error.Validation(description: nameof(GoogleBooksIdMustBe12CharactersLong));
|
||||
public static Error InvalidGoogleBooksIdFormat => Error.Validation(description: nameof(InvalidGoogleBooksIdFormat));
|
||||
public static Error BarnesAndNoblesIdMustBe10CharactersLong => Error.Validation(description: nameof(BarnesAndNoblesIdMustBe10CharactersLong));
|
||||
public static Error InvalidBarnesAndNoblesIdFormat => Error.Validation(description: nameof(InvalidBarnesAndNoblesIdFormat));
|
||||
public static Error InvalidAppleBooksIdFormat => Error.Validation(description: nameof(InvalidAppleBooksIdFormat));
|
||||
public static Error PublisherMustBeMaximum100CharactersLong => Error.Validation(description: nameof(PublisherMustBeMaximum100CharactersLong));
|
||||
public static Error PageCountMustBeGreaterThanZero => Error.Validation(description: nameof(PageCountMustBeGreaterThanZero));
|
||||
public static Error UnknownBookFormat => Error.Validation(description: nameof(UnknownBookFormat));
|
||||
public static Error EditionMustBeMaximum50CharactersLong => Error.Validation(description: nameof(EditionMustBeMaximum50CharactersLong));
|
||||
public static Error VolumeNumberMustBeGreaterThanZero => Error.Validation(description: nameof(VolumeNumberMustBeGreaterThanZero));
|
||||
public static Error BookLibraryCannotBeNull => Error.Validation(description: nameof(BookLibraryCannotBeNull));
|
||||
public static Error BookPathCannotBeEmpty => Error.Validation(description: nameof(BookPathCannotBeEmpty));
|
||||
public static Error BookNotFound => Error.NotFound(description: nameof(BookNotFound));
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
#endregion
|
||||
|
||||
@@ -1,10 +1,28 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.Primitives;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.Common.Primitives;
|
||||
|
||||
/// <summary>
|
||||
/// Error representing that the operation could not be completed due to a conflict with the current state.
|
||||
/// </summary>
|
||||
/// <param name="Code">The error code that uniquely identifies this error type.</param>
|
||||
/// <param name="Description">The human-readable description of the error.</param>
|
||||
public record ConflictError(string Code, string Description) : Error
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the type of this error.
|
||||
/// </summary>
|
||||
public override ErrorType Type => ErrorType.Conflict;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the error code that uniquely identifies this error type.
|
||||
/// </summary>
|
||||
public override string Code { get; } = Code;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the human-readable description of the error.
|
||||
/// </summary>
|
||||
public override string Description { get; } = Description;
|
||||
}
|
||||
@@ -1,10 +1,19 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.Primitives;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.Common.Primitives;
|
||||
|
||||
/// <summary>
|
||||
/// Represents an error that can be implicitly converted to a Results.
|
||||
/// Represents an error that can be implicitly converted to a Result.
|
||||
/// </summary>
|
||||
public abstract record Error
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the type of this error.
|
||||
/// </summary>
|
||||
public abstract ErrorType Type { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the error code that uniquely identifies this error type.
|
||||
/// </summary>
|
||||
@@ -25,112 +34,134 @@ public abstract record Error
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new NotFoundError with the specified description.
|
||||
/// Creates a new NotFoundError.
|
||||
/// </summary>
|
||||
/// <param name="code">The error code, defaults to "General.NotFound" when null.</param>
|
||||
/// <param name="description">The human-readable description of the error.</param>
|
||||
/// <returns>A new NotFoundError instance with code "NotFound".</returns>
|
||||
public static NotFoundError NotFound(string description)
|
||||
/// <returns>A new NotFoundError instance.</returns>
|
||||
public static NotFoundError NotFound(string? code = null, string? description = null)
|
||||
{
|
||||
return new("NotFound", description);
|
||||
return new(code ?? "General.NotFound", description ?? "A 'Not Found' error has occurred.");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new InvalidOperationError with the specified description.
|
||||
/// Creates a new InvalidOperationError.
|
||||
/// </summary>
|
||||
/// <param name="code">The error code, defaults to "General.InvalidOperation" when null.</param>
|
||||
/// <param name="description">The human-readable description of the error.</param>
|
||||
/// <returns>A new InvalidOperationError instance with code "InvalidOperation".</returns>
|
||||
public static InvalidOperationError InvalidOperation(string description)
|
||||
/// <returns>A new InvalidOperationError instance.</returns>
|
||||
public static InvalidOperationError InvalidOperation(string? code = null, string? description = null)
|
||||
{
|
||||
return new("InvalidOperation", description);
|
||||
return new(code ?? "General.InvalidOperation", description ?? "An invalid operation error has occurred.");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new ForbiddenError with the specified description.
|
||||
/// Creates a new ForbiddenError.
|
||||
/// </summary>
|
||||
/// <param name="code">The error code, defaults to "General.Forbidden" when null.</param>
|
||||
/// <param name="description">The human-readable description of the error.</param>
|
||||
/// <returns>A new ForbiddenError instance with code "Forbidden".</returns>
|
||||
public static ForbiddenError Forbidden(string description)
|
||||
/// <returns>A new ForbiddenError instance.</returns>
|
||||
public static ForbiddenError Forbidden(string? code = null, string? description = null)
|
||||
{
|
||||
return new("Forbidden", description);
|
||||
return new(code ?? "General.Forbidden", description ?? "A 'Forbidden' error has occurred.");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new FailureError with the specified description.
|
||||
/// Creates a new FailureError.
|
||||
/// </summary>
|
||||
/// <param name="code">The error code, defaults to "General.Failure" when null.</param>
|
||||
/// <param name="description">The human-readable description of the error.</param>
|
||||
/// <returns>A new FailureError instance with code "Failure".</returns>
|
||||
public static FailureError Failure(string description)
|
||||
/// <returns>A new FailureError instance.</returns>
|
||||
public static FailureError Failure(string? code = null, string? description = null)
|
||||
{
|
||||
return new("Failure", description);
|
||||
return new(code ?? "General.Failure", description ?? "A failure has occurred.");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new ValidationError with the specified description.
|
||||
/// Creates a new ValidationError.
|
||||
/// </summary>
|
||||
/// <param name="code">The error code, defaults to "General.Validation" when null.</param>
|
||||
/// <param name="description">The human-readable description of the error.</param>
|
||||
/// <returns>A new ValidationError instance with code "Validation".</returns>
|
||||
public static ValidationError Validation(string description)
|
||||
/// <returns>A new ValidationError instance.</returns>
|
||||
public static ValidationError Validation(string? code = null, string? description = null)
|
||||
{
|
||||
return new("Validation", description);
|
||||
return new(code ?? "General.Validation", description ?? "A validation error has occurred.");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new ConflictError with the specified description.
|
||||
/// Creates a new ConflictError.
|
||||
/// </summary>
|
||||
/// <param name="code">The error code, defaults to "General.Conflict" when null.</param>
|
||||
/// <param name="description">The human-readable description of the error.</param>
|
||||
/// <returns>A new ConflictError instance with code "Conflict".</returns>
|
||||
public static ConflictError Conflict(string description)
|
||||
/// <returns>A new ConflictError instance.</returns>
|
||||
public static ConflictError Conflict(string? code = null, string? description = null)
|
||||
{
|
||||
return new("Conflict", description);
|
||||
return new(code ?? "General.Conflict", description ?? "A conflict error has occurred.");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new TimeoutError with the specified description.
|
||||
/// Creates a new TimeoutError.
|
||||
/// </summary>
|
||||
/// <param name="code">The error code, defaults to "General.Timeout" when null.</param>
|
||||
/// <param name="description">The human-readable description of the error.</param>
|
||||
/// <returns>A new TimeoutError instance with code "Timeout".</returns>
|
||||
public static TimeoutError Timeout(string description)
|
||||
/// <returns>A new TimeoutError instance.</returns>
|
||||
public static TimeoutError Timeout(string? code = null, string? description = null)
|
||||
{
|
||||
return new("Timeout", description);
|
||||
return new(code ?? "General.Timeout", description ?? "The operation timed out.");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new UnauthorizedError with the specified description.
|
||||
/// Creates a new UnauthorizedError.
|
||||
/// </summary>
|
||||
/// <param name="code">The error code, defaults to "General.Unauthorized" when null.</param>
|
||||
/// <param name="description">The human-readable description of the error.</param>
|
||||
/// <returns>A new UnauthorizedError instance with code "Unauthorized".</returns>
|
||||
public static UnauthorizedError Unauthorized(string description)
|
||||
/// <returns>A new UnauthorizedError instance.</returns>
|
||||
public static UnauthorizedError Unauthorized(string? code = null, string? description = null)
|
||||
{
|
||||
return new("Unauthorized", description);
|
||||
return new(code ?? "General.Unauthorized", description ?? "An 'Unauthorized' error has occurred.");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new InternalError with the specified description.
|
||||
/// Creates a new UnexpectedError.
|
||||
/// </summary>
|
||||
/// <param name="code">The error code, defaults to "General.Unexpected" when null.</param>
|
||||
/// <param name="description">The human-readable description of the error.</param>
|
||||
/// <returns>A new InternalError instance with code "Internal".</returns>
|
||||
public static InternalError Internal(string description)
|
||||
/// <returns>A new UnexpectedError instance.</returns>
|
||||
public static UnexpectedError Unexpected(string? code = null, string? description = null)
|
||||
{
|
||||
return new("Internal", description);
|
||||
return new(code ?? "General.Unexpected", description ?? "An unexpected error has occurred.");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new ResourceUnavailableError with the specified description.
|
||||
/// Creates a new InternalError.
|
||||
/// </summary>
|
||||
/// <param name="code">The error code, defaults to "General.Internal" when null.</param>
|
||||
/// <param name="description">The human-readable description of the error.</param>
|
||||
/// <returns>A new ResourceUnavailableError instance with code "ResourceUnavailable".</returns>
|
||||
public static ResourceUnavailableError ResourceUnavailable(string description)
|
||||
/// <returns>A new InternalError instance.</returns>
|
||||
public static InternalError Internal(string? code = null, string? description = null)
|
||||
{
|
||||
return new("ResourceUnavailable", description);
|
||||
return new(code ?? "General.Internal", description ?? "An internal error has occurred.");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new NotImplementedError with the specified description.
|
||||
/// Creates a new ResourceUnavailableError.
|
||||
/// </summary>
|
||||
/// <param name="code">The error code, defaults to "General.ResourceUnavailable" when null.</param>
|
||||
/// <param name="description">The human-readable description of the error.</param>
|
||||
/// <returns>A new NotImplementedError instance with code "NotImplemented".</returns>
|
||||
public static NotImplementedError NotImplemented(string description)
|
||||
/// <returns>A new ResourceUnavailableError instance.</returns>
|
||||
public static ResourceUnavailableError ResourceUnavailable(string? code = null, string? description = null)
|
||||
{
|
||||
return new("NotImplemented", description);
|
||||
return new(code ?? "General.ResourceUnavailable", description ?? "The required resource is currently unavailable.");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new NotImplementedError.
|
||||
/// </summary>
|
||||
/// <param name="code">The error code, defaults to "General.NotImplemented" when null.</param>
|
||||
/// <param name="description">The human-readable description of the error.</param>
|
||||
/// <returns>A new NotImplementedError instance.</returns>
|
||||
public static NotImplementedError NotImplemented(string? code = null, string? description = null)
|
||||
{
|
||||
return new(code ?? "General.NotImplemented", description ?? "The requested functionality is not implemented.");
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,28 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.Primitives;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.Common.Primitives;
|
||||
|
||||
/// <summary>
|
||||
/// Error representing that some operation failing.
|
||||
/// </summary>
|
||||
/// <param name="Code">The error code that uniquely identifies this error type.</param>
|
||||
/// <param name="Description">The human-readable description of the error.</param>
|
||||
public record FailureError(string Code, string Description) : Error
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the type of this error.
|
||||
/// </summary>
|
||||
public override ErrorType Type => ErrorType.Failure;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the error code that uniquely identifies this error type.
|
||||
/// </summary>
|
||||
public override string Code { get; } = Code;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the human-readable description of the error.
|
||||
/// </summary>
|
||||
public override string Description { get; } = Description;
|
||||
}
|
||||
@@ -1,10 +1,28 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.Primitives;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.Common.Primitives;
|
||||
|
||||
/// <summary>
|
||||
/// Error representing that the operation is not allowed due to insufficient permissions or restrictions.
|
||||
/// </summary>
|
||||
/// <param name="Code">The error code that uniquely identifies this error type.</param>
|
||||
/// <param name="Description">The human-readable description of the error.</param>
|
||||
public record ForbiddenError(string Code, string Description) : Error
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the type of this error.
|
||||
/// </summary>
|
||||
public override ErrorType Type => ErrorType.Forbidden;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the error code that uniquely identifies this error type.
|
||||
/// </summary>
|
||||
public override string Code { get; } = Code;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the human-readable description of the error.
|
||||
/// </summary>
|
||||
public override string Description { get; } = Description;
|
||||
}
|
||||
@@ -1,10 +1,28 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.Primitives;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.Common.Primitives;
|
||||
|
||||
/// <summary>
|
||||
/// Error representing that an unexpected internal error occurred.
|
||||
/// </summary>
|
||||
/// <param name="Code">The error code that uniquely identifies this error type.</param>
|
||||
/// <param name="Description">The human-readable description of the error.</param>
|
||||
public record InternalError(string Code, string Description) : Error
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the type of this error.
|
||||
/// </summary>
|
||||
public override ErrorType Type => ErrorType.Unexpected;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the error code that uniquely identifies this error type.
|
||||
/// </summary>
|
||||
public override string Code { get; } = Code;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the human-readable description of the error.
|
||||
/// </summary>
|
||||
public override string Description { get; } = Description;
|
||||
}
|
||||
@@ -1,10 +1,28 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.Primitives;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.Common.Primitives;
|
||||
|
||||
/// <summary>
|
||||
/// Error representing that the operation is invalid in the current state or context.
|
||||
/// </summary>
|
||||
/// <param name="Code">The error code that uniquely identifies this error type.</param>
|
||||
/// <param name="Description">The human-readable description of the error.</param>
|
||||
public record InvalidOperationError(string Code, string Description) : Error
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the type of this error.
|
||||
/// </summary>
|
||||
public override ErrorType Type => ErrorType.Unexpected;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the error code that uniquely identifies this error type.
|
||||
/// </summary>
|
||||
public override string Code { get; } = Code;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the human-readable description of the error.
|
||||
/// </summary>
|
||||
public override string Description { get; } = Description;
|
||||
}
|
||||
@@ -1,10 +1,28 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.Primitives;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.Common.Primitives;
|
||||
|
||||
/// <summary>
|
||||
/// Error representing that the requested resource or entity was not found.
|
||||
/// </summary>
|
||||
/// <param name="Code">The error code that uniquely identifies this error type.</param>
|
||||
/// <param name="Description">The human-readable description of the error.</param>
|
||||
public record NotFoundError(string Code, string Description) : Error
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the type of this error.
|
||||
/// </summary>
|
||||
public override ErrorType Type => ErrorType.NotFound;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the error code that uniquely identifies this error type.
|
||||
/// </summary>
|
||||
public override string Code { get; } = Code;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the human-readable description of the error.
|
||||
/// </summary>
|
||||
public override string Description { get; } = Description;
|
||||
}
|
||||
@@ -1,10 +1,28 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.Primitives;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.Common.Primitives;
|
||||
|
||||
/// <summary>
|
||||
/// Error representing that the requested functionality is not implemented.
|
||||
/// </summary>
|
||||
/// <param name="Code">The error code that uniquely identifies this error type.</param>
|
||||
/// <param name="Description">The human-readable description of the error.</param>
|
||||
public record NotImplementedError(string Code, string Description) : Error
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the type of this error.
|
||||
/// </summary>
|
||||
public override ErrorType Type => ErrorType.Unexpected;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the error code that uniquely identifies this error type.
|
||||
/// </summary>
|
||||
public override string Code { get; } = Code;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the human-readable description of the error.
|
||||
/// </summary>
|
||||
public override string Description { get; } = Description;
|
||||
}
|
||||
@@ -1,10 +1,28 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.Primitives;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.Common.Primitives;
|
||||
|
||||
/// <summary>
|
||||
/// Error representing that the required resource is currently unavailable.
|
||||
/// </summary>
|
||||
/// <param name="Code">The error code that uniquely identifies this error type.</param>
|
||||
/// <param name="Description">The human-readable description of the error.</param>
|
||||
public record ResourceUnavailableError(string Code, string Description) : Error
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the type of this error.
|
||||
/// </summary>
|
||||
public override ErrorType Type => ErrorType.Unexpected;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the error code that uniquely identifies this error type.
|
||||
/// </summary>
|
||||
public override string Code { get; } = Code;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the human-readable description of the error.
|
||||
/// </summary>
|
||||
public override string Description { get; } = Description;
|
||||
}
|
||||
+13
-2
@@ -1,9 +1,9 @@
|
||||
namespace Lumina.Domain.Common.Primitives;
|
||||
|
||||
/// <summary>
|
||||
/// Provides predefined success results for operations that don't return meaningful data.
|
||||
/// Provides predefined success results for operations that don't return meaningful data, and factory methods for results.
|
||||
/// </summary>
|
||||
public static class Results
|
||||
public static class Result
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a successful operation.
|
||||
@@ -24,4 +24,15 @@ public static class Results
|
||||
/// Represents a successful deletion operation.
|
||||
/// </summary>
|
||||
public static Deleted Deleted { get; } = new();
|
||||
|
||||
/// <summary>
|
||||
/// Creates a successful result wrapping the provided value.
|
||||
/// </summary>
|
||||
/// <typeparam name="TValue">The type of the value to wrap.</typeparam>
|
||||
/// <param name="value">The value to wrap in a successful result.</param>
|
||||
/// <returns>A successful result containing the provided value.</returns>
|
||||
public static Result<TValue> From<TValue>(TValue value)
|
||||
{
|
||||
return Result<TValue>.Success(value);
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,9 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.Common.Primitives;
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -1,10 +1,28 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.Primitives;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.Common.Primitives;
|
||||
|
||||
/// <summary>
|
||||
/// Error representing that the operation timed out before completion.
|
||||
/// </summary>
|
||||
/// <param name="Code">The error code that uniquely identifies this error type.</param>
|
||||
/// <param name="Description">The human-readable description of the error.</param>
|
||||
public record TimeoutError(string Code, string Description) : Error
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the type of this error.
|
||||
/// </summary>
|
||||
public override ErrorType Type => ErrorType.Unexpected;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the error code that uniquely identifies this error type.
|
||||
/// </summary>
|
||||
public override string Code { get; } = Code;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the human-readable description of the error.
|
||||
/// </summary>
|
||||
public override string Description { get; } = Description;
|
||||
}
|
||||
@@ -1,10 +1,28 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.Primitives;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.Common.Primitives;
|
||||
|
||||
/// <summary>
|
||||
/// Error representing that authentication is required or has failed.
|
||||
/// </summary>
|
||||
/// <param name="Code">The error code that uniquely identifies this error type.</param>
|
||||
/// <param name="Description">The human-readable description of the error.</param>
|
||||
public record UnauthorizedError(string Code, string Description) : Error
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the type of this error.
|
||||
/// </summary>
|
||||
public override ErrorType Type => ErrorType.Unauthorized;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the error code that uniquely identifies this error type.
|
||||
/// </summary>
|
||||
public override string Code { get; } = Code;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the human-readable description of the error.
|
||||
/// </summary>
|
||||
public override string Description { get; } = Description;
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.Primitives;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.Common.Primitives;
|
||||
|
||||
/// <summary>
|
||||
/// Error representing that an unexpected error occurred.
|
||||
/// </summary>
|
||||
/// <param name="Code">The error code that uniquely identifies this error type.</param>
|
||||
/// <param name="Description">The human-readable description of the error.</param>
|
||||
public record UnexpectedError(string Code, string Description) : Error
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the type of this error.
|
||||
/// </summary>
|
||||
public override ErrorType Type => ErrorType.Unexpected;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the error code that uniquely identifies this error type.
|
||||
/// </summary>
|
||||
public override string Code { get; } = Code;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the human-readable description of the error.
|
||||
/// </summary>
|
||||
public override string Description { get; } = Description;
|
||||
}
|
||||
@@ -1,10 +1,28 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.Primitives;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.Common.Primitives;
|
||||
|
||||
/// <summary>
|
||||
/// Error representing that the input or data failed validation rules.
|
||||
/// </summary>
|
||||
/// <param name="Code">The error code that uniquely identifies this error type.</param>
|
||||
/// <param name="Description">The human-readable description of the error.</param>
|
||||
public record ValidationError(string Code, string Description) : Error
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the type of this error.
|
||||
/// </summary>
|
||||
public override ErrorType Type => ErrorType.Validation;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the error code that uniquely identifies this error type.
|
||||
/// </summary>
|
||||
public override string Code { get; } = Code;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the human-readable description of the error.
|
||||
/// </summary>
|
||||
public override string Description { get; } = Description;
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Domain.Common.Models.Core;
|
||||
using Lumina.Domain.SharedKernel.Common.Errors;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
@@ -33,12 +32,12 @@ public class Genre : ValueObject
|
||||
/// </summary>
|
||||
/// <param name="name">The value of the genre.</param>
|
||||
/// <returns>
|
||||
/// An <see cref="ErrorOr{TValue}"/> containing either a successfully created <see cref="Genre"/>, or an error message.
|
||||
/// An <see cref="Result{TValue}"/> containing either a successfully created <see cref="Genre"/>, or an error message.
|
||||
/// </returns>
|
||||
public static ErrorOr<Genre> Create(string? name)
|
||||
public static Result<Genre> Create(string? name)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(name))
|
||||
return Errors.Metadata.GenreNameCannotBeEmpty;
|
||||
return Errors.Errors.Metadata.GenreNameCannotBeEmpty;
|
||||
return new Genre(name);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Domain.Common.Models.Core;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.SharedKernel.Common.Errors;
|
||||
using Lumina.Domain.Common.Models.Core;
|
||||
|
||||
using Lumina.Domain.Common.Errors;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
@@ -50,16 +50,16 @@ public class LanguageInfo : ValueObject
|
||||
/// <param name="languageName">The full name of the language in English.</param>
|
||||
/// <param name="nativeName">The optional native name of the language.</param>
|
||||
/// <returns>
|
||||
/// An <see cref="ErrorOr{TValue}"/> containing either a successfully created <see cref="LanguageInfo"/>, or an error message.
|
||||
/// An <see cref="Result{TValue}"/> containing either a successfully created <see cref="LanguageInfo"/>, or an error message.
|
||||
/// </returns>
|
||||
public static ErrorOr<LanguageInfo> Create(string? languageCode, string? languageName, Optional<string> nativeName)
|
||||
public static Result<LanguageInfo> Create(string? languageCode, string? languageName, Optional<string> nativeName)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(languageCode))
|
||||
return Errors.Metadata.LanguageCodeCannotBeEmpty;
|
||||
return Errors.Errors.Metadata.LanguageCodeCannotBeEmpty;
|
||||
if (string.IsNullOrWhiteSpace(languageName))
|
||||
return Errors.Metadata.LanguageNameCannotBeEmpty;
|
||||
return Errors.Errors.Metadata.LanguageNameCannotBeEmpty;
|
||||
if (languageCode.Length != 2)
|
||||
return Errors.Metadata.InvalidIsoCode;
|
||||
return Errors.Errors.Metadata.InvalidIsoCode;
|
||||
return new LanguageInfo(languageCode, languageName, nativeName);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Domain.Common.Models.Core;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using Lumina.Domain.SharedKernel.Common.Errors;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.Common.ValueObjects.Metadata;
|
||||
@@ -82,9 +80,9 @@ public class ReleaseInfo : ValueObject
|
||||
/// <param name="releaseCountry">The optional country or region of release.</param>
|
||||
/// <param name="releaseVersion">The optional release version or edition.</param>
|
||||
/// <returns>
|
||||
/// An <see cref="ErrorOr{TValue}"/> containing either a successfully created <see cref="ReleaseInfo"/>, or an error message.
|
||||
/// An <see cref="Result{TValue}"/> containing either a successfully created <see cref="ReleaseInfo"/>, or an error message.
|
||||
/// </returns>
|
||||
public static ErrorOr<ReleaseInfo> Create(
|
||||
public static Result<ReleaseInfo> Create(
|
||||
Optional<DateOnly> originalReleaseDate,
|
||||
Optional<int> originalReleaseYear,
|
||||
Optional<DateOnly> reReleaseDate,
|
||||
@@ -93,13 +91,13 @@ public class ReleaseInfo : ValueObject
|
||||
Optional<string> releaseVersion)
|
||||
{
|
||||
if (originalReleaseDate.HasValue && originalReleaseYear.HasValue && originalReleaseDate.Value.Year != originalReleaseYear.Value)
|
||||
return Errors.Metadata.OriginalReleaseDateAndYearMustMatch;
|
||||
return Errors.Errors.Metadata.OriginalReleaseDateAndYearMustMatch;
|
||||
if (reReleaseDate.HasValue && reReleaseYear.HasValue && reReleaseDate.Value.Year != reReleaseYear.Value)
|
||||
return Errors.Metadata.ReReleaseDateAndYearMustMatch;
|
||||
return Errors.Errors.Metadata.ReReleaseDateAndYearMustMatch;
|
||||
if (originalReleaseDate.HasValue && reReleaseDate.HasValue && originalReleaseDate.Value > reReleaseDate.Value)
|
||||
return Errors.Metadata.ReReleaseDateCannotBeEarlierThanOriginalReleaseDate;
|
||||
return Errors.Errors.Metadata.ReReleaseDateCannotBeEarlierThanOriginalReleaseDate;
|
||||
if (originalReleaseYear.HasValue && reReleaseYear.HasValue && originalReleaseYear.Value > reReleaseYear.Value)
|
||||
return Errors.Metadata.ReReleaseYearCannotBeEarlierThanOriginalReleaseYear;
|
||||
return Errors.Errors.Metadata.ReReleaseYearCannotBeEarlierThanOriginalReleaseYear;
|
||||
return new ReleaseInfo(originalReleaseDate, originalReleaseYear, reReleaseDate, reReleaseYear, releaseCountry, releaseVersion);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Common.Models.Core;
|
||||
using Lumina.Domain.SharedKernel.Common.Errors;
|
||||
using Lumina.Domain.Common.Errors;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
@@ -33,12 +33,12 @@ public class Tag : ValueObject
|
||||
/// </summary>
|
||||
/// <param name="name">The value of the tag.</param>
|
||||
/// <returns>
|
||||
/// An <see cref="ErrorOr{TValue}"/> containing either a successfully created <see cref="Tag"/>, or an error message.
|
||||
/// An <see cref="Result{TValue}"/> containing either a successfully created <see cref="Tag"/>, or an error message.
|
||||
/// </returns>
|
||||
public static ErrorOr<Tag> Create(string? name)
|
||||
public static Result<Tag> Create(string? name)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(name))
|
||||
return Errors.Metadata.TagNameCannotBeEmpty;
|
||||
return Errors.Errors.Metadata.TagNameCannotBeEmpty;
|
||||
return new Tag(name);
|
||||
}
|
||||
|
||||
|
||||
+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,
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="ErrorOr" Version="2.0.1" />
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="10.0.0" />
|
||||
<PackageReference Include="SixLabors.ImageSharp" Version="3.1.5" />
|
||||
<PackageReference Include="System.IO.Abstractions" Version="21.1.3" />
|
||||
|
||||
Reference in new issue
Block a user