Implements directory browser dialog, part 1: file system treeview

This commit is contained in:
BinaryAlley committed 2024-09-15 13:07:53 +03:00
1 parent 4a53348013
commit 4e4ecbbfca
318 files changed
+6012 -1184

No files matched your search

@@ -1,4 +1,5 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate;
using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.Services;
using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.Strategies.Environment;
using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.Strategies.Path;
@@ -22,6 +23,7 @@ public static class DomainLayerServices
/// <returns>The updated <see cref="IServiceCollection"/>.</returns>
public static IServiceCollection AddDomainLayerServices(this IServiceCollection services)
{
services.AddScoped<IDriveService, DriveService>();
services.AddScoped<IDirectoryService, DirectoryService>();
services.AddScoped<IFileService, FileService>();
services.AddScoped<IFileSystemPermissionsService, FileSystemPermissionsService>();
@@ -1,27 +0,0 @@
namespace Lumina.Domain.Common.Enums;
/// <summary>
/// Enumeration for the various sources of audio ratings.
/// </summary>
public enum AudioRatingSource
{
/// <summary>
/// Ratings provided by users of the Lumina media library.
/// </summary>
User,
/// <summary>
/// Ratings sourced from MusicBrainz, an open music encyclopedia that collects music metadata.
/// </summary>
MusicBrainz,
/// <summary>
/// Ratings obtained from Discogs, a database and marketplace for music recordings.
/// </summary>
Discogs,
/// <summary>
/// Ratings from Last.fm, a music website that provides music recommendations based on user listening habits.
/// </summary>
LastFm,
}
@@ -1,67 +0,0 @@
namespace Lumina.Domain.Common.Enums;
/// <summary>
/// Enumeration for various book formats.
/// </summary>
public enum BookFormat
{
/// <summary>
/// A book bound with rigid protective covers (typically cardboard covered with cloth, heavy paper, or leather).
/// </summary>
Hardcover,
/// <summary>
/// A book with a flexible paper cover, typically less durable than a hardcover.
/// </summary>
Paperback,
/// <summary>
/// A small, usually non-illustrated, and inexpensive paperback book.
/// </summary>
MassMarketPaperback,
/// <summary>
/// A larger, often higher-quality paperback book, typically used for literary fiction and nonfiction.
/// </summary>
TradePaperback,
/// <summary>
/// A digital version of a book that can be read on electronic devices.
/// </summary>
eBook,
/// <summary>
/// A recorded audio version of a book, either on physical media or as a digital file.
/// </summary>
Audiobook,
/// <summary>
/// A book printed with larger text for easier reading, often used by those with visual impairments.
/// </summary>
LargePrint,
/// <summary>
/// A sturdy book with thick cardboard pages, typically designed for young children.
/// </summary>
BoardBook,
/// <summary>
/// A book bound with a spiral wire or plastic coil, allowing it to lay flat when open.
/// </summary>
SpiralBound,
/// <summary>
/// A reinforced binding designed for frequent use, often used in schools and public libraries.
/// </summary>
LibraryBinding,
/// <summary>
/// A book bound in leather, often used for luxury or collector's editions.
/// </summary>
LeatherBound,
/// <summary>
/// A book with three-dimensional paper engineering, creating pop-up or movable parts.
/// </summary>
PopupBook
}
@@ -1,27 +0,0 @@
namespace Lumina.Domain.Common.Enums;
/// <summary>
/// Enumeration for the various sources of book ratings.
/// </summary>
public enum BookRatingSource
{
/// <summary>
/// Ratings provided by users of the Lumina system.
/// </summary>
User,
/// <summary>
/// Ratings sourced from Goodreads, a social network for book readers that provides book recommendations and reviews.
/// </summary>
Goodreads,
/// <summary>
/// Ratings obtained from Amazon, an e-commerce platform that includes customer reviews and ratings for books.
/// </summary>
Amazon,
/// <summary>
/// Ratings from Google Books, a service that searches the full text of books and magazines that Google has scanned and converted to text.
/// </summary>
GoogleBooks,
}
@@ -1,37 +0,0 @@
namespace Lumina.Domain.Common.Enums;
/// <summary>
/// Enumeration for file access mode types.
/// </summary>
public enum FileAccessMode
{
/// <summary>
/// Represents the ability to list the contents of a directory.
/// </summary>
ListDirectory,
/// <summary>
/// Represents the ability to read file or directory properties.
/// </summary>
ReadProperties,
/// <summary>
/// Represents the ability to read the contents of a file.
/// </summary>
ReadContents,
/// <summary>
/// Represents the ability to write to a file or directory.
/// </summary>
Write,
/// <summary>
/// Represents the ability to execute a file.
/// </summary>
Execute,
/// <summary>
/// Represents the ability to delete a file or directory.
/// </summary>
Delete,
}
@@ -1,22 +0,0 @@
namespace Lumina.Domain.Common.Enums;
/// <summary>
/// Enumeration for file system item statuses types.
/// </summary>
public enum FileSystemItemStatus
{
/// <summary>
/// Indicates that the file system item is accessible.
/// </summary>
Accessible,
/// <summary>
/// Indicates that the file system item is inaccessible due to permissions or other restrictions.
/// </summary>
Inaccessible,
/// <summary>
/// Indicates that the status of the file system item could not be determined due to an unknown error.
/// </summary>
UnknownError
}
@@ -1,22 +0,0 @@
namespace Lumina.Domain.Common.Enums;
/// <summary>
/// Enumeration for the types of file system elements.
/// </summary>
public enum FileSystemItemType
{
/// <summary>
/// Represents a drive, such as a hard disk, USB drive, or network drive.
/// </summary>
Drive,
/// <summary>
/// Represents a directory, which is a directory that can contain other directories or files.
/// </summary>
Directory,
/// <summary>
/// Represents a file, which is a document, executable, or other data stored on the file system.
/// </summary>
File
}
@@ -1,24 +0,0 @@
namespace Lumina.Domain.Common.Enums;
/// <summary>
/// Enumeration for known image types.
/// </summary>
public enum ImageType
{
None,
BMP,
GIF,
PNG,
TIFF,
JPEG,
JPEG_CANON,
JPEG_UNKNOWN,
PICT,
ICO,
PSD,
JPEG2000,
AVIF,
WEBP,
TGA,
SVG,
}
@@ -1,19 +0,0 @@
namespace Lumina.Domain.Common.Enums;
/// <summary>
/// Enumeration for the different ISBN (International Standard Book Number) formats.
/// </summary>
public enum IsbnFormat
{
/// <summary>
/// The 10-digit ISBN format used for books published before 2007.
/// Example: 0-306-40615-2
/// </summary>
Isbn10,
/// <summary>
/// The 13-digit ISBN format introduced in 2007, now the standard for all new books.
/// Example: 978-0-306-40615-7
/// </summary>
Isbn13
}
@@ -1,17 +0,0 @@
namespace Lumina.Domain.Common.Enums;
/// <summary>
/// Enumeration for platform types.
/// </summary>
public enum PlatformType
{
/// <summary>
/// Represents Unix-based operating systems, including Linux and macOS.
/// </summary>
Unix,
/// <summary>
/// Represents Microsoft Windows operating systems.
/// </summary>
Windows,
}
@@ -1,32 +0,0 @@
namespace Lumina.Domain.Common.Enums;
/// <summary>
/// Enumeration for the various sources of video ratings.
/// </summary>
public enum VideoRatingSource
{
/// <summary>
/// Ratings provided by users of the Lumina media library.
/// </summary>
User,
/// <summary>
/// Ratings sourced from IMDb (Internet Movie Database), an online database of information related to films, TV programs, and video games.
/// </summary>
Imdb,
/// <summary>
/// Ratings obtained from TheTVDB, an open database for television shows, including episode information and user ratings.
/// </summary>
TheTvDb,
/// <summary>
/// Ratings from The Movie Database (TMDb), a community-built movie and TV database.
/// </summary>
TheMovieDb,
/// <summary>
/// Ratings from Rotten Tomatoes, a review-aggregation website for film and television.
/// </summary>
RottenTomatoes,
}
@@ -12,22 +12,23 @@ public static partial class Errors
public static class FileManagement
{
#region ==================================================================== PROPERTIES =================================================================================
public static Error ParentNodeCannotBeNull => Error.Failure(nameof(ParentNodeCannotBeNull));
public static Error FileCopyError => Error.Failure(nameof(FileCopyError));
public static Error FileMoveError => Error.Failure(nameof(FileMoveError));
public static Error DirectoryCopyError => Error.Failure(nameof(DirectoryCopyError));
public static Error DirectoryMoveError => Error.Failure(nameof(DirectoryMoveError));
public static Error FileNotFoundError => Error.NotFound(nameof(FileNotFoundError));
public static Error InvalidPathError => Error.Validation(nameof(InvalidPathError));
public static Error FileNotFound => Error.NotFound(nameof(FileNotFound));
public static Error InvalidPath => Error.Validation(nameof(InvalidPath));
public static Error PathCannotBeEmpty => Error.Validation(nameof(PathCannotBeEmpty));
public static Error ExtensionCannotBeEmpty => Error.Validation(nameof(ExtensionCannotBeEmpty));
public static Error StreamIdCannotBeEmpty => Error.Validation(nameof(StreamIdCannotBeEmpty));
public static Error CodecCannotBeEmpty => Error.Validation(nameof(CodecCannotBeEmpty));
public static Error BitrateMustBeAPositiveNumber => Error.Validation(nameof(BitrateMustBeAPositiveNumber));
public static Error CannotNavigateUpError => Error.Failure(nameof(CannotNavigateUpError));
public static Error NameCannotBeEmptyError => Error.Validation(nameof(NameCannotBeEmptyError));
public static Error FileAlreadyExistsError => Error.Conflict(nameof(FileAlreadyExistsError));
public static Error DirectoryNotFoundError => Error.NotFound(nameof(DirectoryNotFoundError));
public static Error DirectoryAlreadyExistsError => Error.Conflict(nameof(DirectoryAlreadyExistsError));
public static Error CannotNavigateUp => Error.Failure(nameof(CannotNavigateUp));
public static Error NameCannotBeEmpty => Error.Validation(nameof(NameCannotBeEmpty));
public static Error FileAlreadyExists => Error.Conflict(nameof(FileAlreadyExists));
public static Error DirectoryNotFound => Error.NotFound(nameof(DirectoryNotFound));
public static Error DirectoryAlreadyExists => Error.Conflict(nameof(DirectoryAlreadyExists));
#endregion
}
}
@@ -1,4 +1,8 @@
namespace Lumina.Domain.Common.Events;
#region ========================================================================= USING =====================================================================================
using System;
#endregion
namespace Lumina.Domain.Common.Events;
/// <summary>
/// Interface defining a domain event.
@@ -6,7 +10,14 @@
public interface IDomainEvent
{
#region ==================================================================== PROPERTIES =================================================================================
/// <summary>
/// Gets the id of the domain event.
/// </summary>
Guid Id { get; }
/// <summary>
/// Gets the date and time when the domain event occurred.
/// </summary>
DateTime OccurredOn { get; }
#endregion
}
@@ -1,4 +1,8 @@
namespace Lumina.Domain.Common.Models.Core;
#region ========================================================================= USING =====================================================================================
using System;
#endregion
namespace Lumina.Domain.Common.Models.Core;
/// <summary>
/// Base class for all domain Entities.
@@ -1,4 +1,5 @@
#region ========================================================================= USING =====================================================================================
using System.Collections.Generic;
using System.Diagnostics;
#endregion
@@ -12,12 +13,15 @@ namespace Lumina.Domain.Common.Models.Core;
public abstract class EntityId<TId> : ValueObject
{
#region ==================================================================== PROPERTIES =================================================================================
/// <summary>
/// Gets the value representing the entity identifier.
/// </summary>
public TId Value { get; }
#endregion
#region ====================================================================== CTOR =====================================================================================
/// <summary>
/// Overload C-tor.
/// Initializes a new instance of the <see cref="EntityId{TId}"/> class.
/// </summary>
/// <param name="value">The value representing this object.</param>
protected EntityId(TId value)
@@ -27,7 +31,7 @@ public abstract class EntityId<TId> : ValueObject
#pragma warning disable CS8618
/// <summary>
/// Default C-tor.
/// Initializes a new instance of the <see cref="EntityId{TId}"/> class.
/// </summary>
protected EntityId()
{
@@ -1,9 +1,14 @@
namespace Lumina.Domain.Common.Models.Core;
#region ========================================================================= USING =====================================================================================
using System;
using System.Collections.Generic;
using System.Linq;
#endregion
namespace Lumina.Domain.Common.Models.Core;
/// <summary>
/// Base class for all domain Value Objects.
/// </summary>
/// <typeparam name="TId">The type representing the unique identifier for the Entity. It should be a non-nullable type.</typeparam>
public abstract class ValueObject : IEquatable<ValueObject>
{
#region ===================================================================== METHODS ===================================================================================
+23 -23
View File
@@ -4,11 +4,11 @@ namespace Lumina.Domain.Common.Primitives;
/// Primitive struct for explicitly handling cases when a value might be unknown or not applicable,
/// distinguishing between "not set" and "intentionally empty".
/// </summary>
/// <typeparam name="T">The type of the value represented by this structure.</typeparam>
public readonly struct Optional<T>
/// <typeparam name="TValue">The type of the value represented by this structure.</typeparam>
public readonly struct Optional<TValue>
{
#region ================================================================== FIELD MEMBERS ================================================================================
private readonly T? _value;
private readonly TValue? _value;
#endregion
#region ==================================================================== PROPERTIES =================================================================================
@@ -20,7 +20,7 @@ public readonly struct Optional<T>
/// <summary>
/// Gets the value represented by this structure.
/// </summary>
public T Value
public TValue Value
{
get
{
@@ -31,11 +31,11 @@ public readonly struct Optional<T>
#region ====================================================================== CTOR =====================================================================================
/// <summary>
/// Initializes a new instance of the <see cref="Optional{T}"/> structure.
/// Initializes a new instance of the <see cref="Optional{TValue}"/> structure.
/// </summary>
/// <param name="value">The value represented by this structure.</param>
/// <param name="hasValue"><see langword="true"/> if <paramref name="value"/> is not <see langword="null"/>, <see langword="false"/>otherwise.</param>
private Optional(T? value, bool hasValue)
private Optional(TValue? value, bool hasValue)
{
_value = value;
HasValue = hasValue;
@@ -44,50 +44,50 @@ public readonly struct Optional<T>
#region ===================================================================== METHODS ===================================================================================
/// <summary>
/// Custom implementation operator for converting <paramref name="value"/> to an <see cref="Optional{T}"/>.
/// Custom implementation operator for converting <paramref name="value"/> to an <see cref="Optional{TValue}"/>.
/// </summary>
/// <param name="value">The value to be converted.</param>
public static implicit operator Optional<T>(T value)
public static implicit operator Optional<TValue>(TValue value)
{
return Some(value);
}
/// <summary>
/// Creates an <see cref="Optional{T}"/> with a value.
/// Creates an <see cref="Optional{TValue}"/> with a value.
/// </summary>
/// <param name="value">The value to wrap in the <see cref="Optional{T}"/>.</param>
/// <returns>An <see cref="Optional{T}"/> containing the specified value.</returns>
public static Optional<T> Some(T value)
/// <param name="value">The value to wrap in the <see cref="Optional{TValue}"/>.</param>
/// <returns>An <see cref="Optional{TValue}"/> containing the specified value.</returns>
public static Optional<TValue> Some(TValue value)
{
return new Optional<T>(value, true);
return new Optional<TValue>(value, true);
}
/// <summary>
/// Creates an <see cref="Optional{T}"/> with no value.
/// Creates an <see cref="Optional{TValue}"/> with no value.
/// </summary>
/// <returns>An empty <see cref="Optional{T}"/>.</returns>
public static Optional<T> None()
/// <returns>An empty <see cref="Optional{TValue}"/>.</returns>
public static Optional<TValue> None()
{
return new(default, false);
}
/// <summary>
/// Creates an <see cref="Optional{T}"/> from a nullable reference type.
/// Creates an <see cref="Optional{TValue}"/> from a nullable reference type.
/// </summary>
/// <param name="value">The nullable value to convert.</param>
/// <returns>An <see cref="Optional{T}"/> representing the nullable value.</returns>
public static Optional<T> FromNullable(T? value)
/// <returns>An <see cref="Optional{TValue}"/> representing the nullable value.</returns>
public static Optional<TValue> FromNullable(TValue? value)
{
return value is null ? None() : Some(value);
}
/// <summary>
/// Creates an <see cref="Optional{T}"/> from a nullable value type.
/// Creates an <see cref="Optional{TValue}"/> from a nullable value type.
/// </summary>
/// <typeparam name="TValue">The underlying value type.</typeparam>
/// <typeparam name="TNullableValue">The underlying value type.</typeparam>
/// <param name="value">The nullable value to convert.</param>
/// <returns>An <see cref="Optional{T}"/> representing the nullable value.</returns>
public static Optional<T> FromNullable<TValue>(TValue? value) where TValue : struct, T
/// <returns>An <see cref="Optional{TValue}"/> representing the nullable value.</returns>
public static Optional<TValue> FromNullable<TNullableValue>(TNullableValue? value) where TNullableValue : struct, TValue
{
return value.HasValue ? Some(value.Value) : None();
}
@@ -1,7 +1,9 @@
#region ========================================================================= USING =====================================================================================
using System.Diagnostics;
using Lumina.Domain.Common.Models.Core;
using Lumina.Domain.Common.Primitives;
using System;
using System.Collections.Generic;
using System.Diagnostics;
#endregion
namespace Lumina.Domain.Common.ValueObjects.Metadata;
@@ -1,6 +1,7 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Domain.Common.Models.Core;
using System.Collections.Generic;
using System.Diagnostics;
#endregion
@@ -36,7 +37,7 @@ public class Genre : ValueObject
/// </summary>
/// <param name="name">The value of the genre.</param>
/// <returns>
/// An <see cref="ErrorOr{T}"/> containing either a successfully created <see cref="Genre"/>, or an error message.
/// An <see cref="ErrorOr{TValue}"/> containing either a successfully created <see cref="Genre"/>, or an error message.
/// </returns>
public static ErrorOr<Genre> Create(string name)
{
@@ -2,6 +2,7 @@
using ErrorOr;
using Lumina.Domain.Common.Models.Core;
using Lumina.Domain.Common.Primitives;
using System.Collections.Generic;
using System.Diagnostics;
#endregion
@@ -53,7 +54,7 @@ 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{T}"/> containing either a successfully created <see cref="LanguageInfo"/>, or an error message.
/// An <see cref="ErrorOr{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)
{
@@ -2,6 +2,8 @@
using ErrorOr;
using Lumina.Domain.Common.Models.Core;
using Lumina.Domain.Common.Primitives;
using System;
using System.Collections.Generic;
using System.Diagnostics;
#endregion
@@ -84,7 +86,7 @@ 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{T}"/> containing either a successfully created <see cref="ReleaseInfo"/>, or an error message.
/// An <see cref="ErrorOr{TValue}"/> containing either a successfully created <see cref="ReleaseInfo"/>, or an error message.
/// </returns>
public static ErrorOr<ReleaseInfo> Create(
Optional<DateOnly> originalReleaseDate,
@@ -1,6 +1,7 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Domain.Common.Models.Core;
using System.Collections.Generic;
using System.Diagnostics;
#endregion
@@ -36,7 +37,7 @@ public class Tag : ValueObject
/// </summary>
/// <param name="name">The value of the tag.</param>
/// <returns>
/// An <see cref="ErrorOr{T}"/> containing either a successfully created <see cref="Tag"/>, or an error message.
/// An <see cref="ErrorOr{TValue}"/> containing either a successfully created <see cref="Tag"/>, or an error message.
/// </returns>
public static ErrorOr<Tag> Create(string name)
{
@@ -2,6 +2,7 @@
using ErrorOr;
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.Common.ValueObjects.Metadata;
using System.Collections.Generic;
using System.Diagnostics;
#endregion
@@ -106,7 +107,7 @@ 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{T}"/> containing either a successfully created <see cref="AudioMetadata"/>, or an error message.
/// An <see cref="ErrorOr{TValue}"/> containing either a successfully created <see cref="AudioMetadata"/>, or an error message.
/// </returns>
public static ErrorOr<AudioMetadata> Create(
string title,
@@ -1,4 +1,7 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Contracts.Enums.FileSystem;
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.ValueObjects;
using System;
using System.Collections.Generic;
@@ -11,13 +14,30 @@ namespace Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.E
/// Entity representing a file system directory.
/// </summary>
[DebuggerDisplay("{Id.Path}")]
public class Directory : FileSystemItem
public sealed class Directory : FileSystemItem
{
#region ================================================================== FIELD MEMBERS ================================================================================
private readonly List<FileSystemItem> _items = [];
#endregion
#region ==================================================================== PROPERTIES =================================================================================
/// <summary>
/// Gets or sets the collection of file system items that are children to the current directory entity.
/// Gets or sets the creation date of the file system item. Can be optional if the information is not available.
/// </summary>
public List<FileSystemItem> Items { get; private set; }
public Optional<DateTime> DateCreated { get; private set; }
/// <summary>
/// Gets or sets the last modification date of the file system item. Can be optional if the information is not available.
/// </summary>
public Optional<DateTime> DateModified { get; private set; }
/// <summary>
/// Gets the collection of file system items that are children to the current directory entity.
/// </summary>
public IReadOnlyCollection<FileSystemItem> Items
{
get { return _items.AsReadOnly(); }
}
#endregion
#region ====================================================================== CTOR =====================================================================================
@@ -26,31 +46,108 @@ public class Directory : FileSystemItem
/// </summary>
/// <param name="id">The unique identifier of the directory in the file system path.</param>
/// <param name="name">The name of the directory.</param>
/// <param name="dateCreated">The date and time the directory was created. Can be <see langword="null"/> if unknown.</param>
/// <param name="dateModified">The date and time the directory was last modified. Can be <see langword="null"/> if unknown.</param>
public Directory(FileSystemPathId id, string name, DateTime? dateCreated, DateTime? dateModified) : base(id, name, dateCreated, dateModified)
/// <param name="dateCreated">The date and time the directory was created. Can be optional if unknown.</param>
/// <param name="dateModified">The date and time the directory was last modified. Can be optional if unknown.</param>
private Directory(FileSystemPathId id, string name, Optional<DateTime> dateCreated, Optional<DateTime> dateModified) : base(id, name, FileSystemItemType.Directory)
{
Items = [];
DateCreated = dateCreated;
DateModified = dateModified;
}
#endregion
#region ===================================================================== METHODS ===================================================================================
/// <summary>
/// Creates a new instance of the <see cref="Directory"/> class.
/// </summary>
/// <param name="name">The name of the directory.</param>
/// <param name="dateCreated">The date and time the directory was created. Can be optional if unknown.</param>
/// <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.
/// </returns>
public static ErrorOr<Directory> Create(
string path,
string name,
Optional<DateTime> dateCreated,
Optional<DateTime> dateModified,
FileSystemItemStatus status = FileSystemItemStatus.Accessible)
{
// TODO: enforce invariants
ErrorOr<FileSystemPathId> createPathResult = FileSystemPathId.Create(path);
if (createPathResult.IsError)
return createPathResult.Errors;
Directory newDirectory = new Directory(
createPathResult.Value,
name,
dateCreated,
dateModified);
ErrorOr<Updated> setStatusResult = newDirectory.SetStatus(status);
if (setStatusResult.IsError)
return setStatusResult.Errors;
return newDirectory;
}
/// <summary>
/// Creates a new instance of the <see cref="Directory"/> class.
/// </summary>
/// <param name="name">The name of the directory.</param>
/// <param name="dateCreated">The date and time the directory was created. Can be optional if unknown.</param>
/// <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.
/// </returns>
public static ErrorOr<Directory> Create(
FileSystemPathId id,
string name,
Optional<DateTime> dateCreated,
Optional<DateTime> dateModified,
FileSystemItemStatus status = FileSystemItemStatus.Accessible)
{
// TODO: enforce invariants
Directory newDirectory = new Directory(
id,
name,
dateCreated,
dateModified);
ErrorOr<Updated> setStatusResult = newDirectory.SetStatus(status);
if (setStatusResult.IsError)
return setStatusResult.Errors;
return newDirectory;
}
/// <summary>
/// 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 successfull operation, or an error.</returns>
public ErrorOr<Updated> UpdateLastModified(DateTime date)
{
DateModified = date;
return Result.Updated;
}
/// <summary>
/// Adds a file system item to the directory.
/// </summary>
/// <param name="item">The file system item to add.</param>
public void AddItem(FileSystemItem item)
/// <returns>An <see cref="ErrorOr{TValue}"/> representing either a successfull operation, or an error.</returns>
public ErrorOr<Updated> AddItem(FileSystemItem item)
{
Items.Add(item);
_items.Add(item);
return Result.Updated;
}
/// <summary>
/// Removes a file system item from the directory.
/// </summary>
/// <param name="item">The file system item to remove.</param>
public void RemoveItem(FileSystemItem item)
/// <returns>An <see cref="ErrorOr{TValue}"/> representing either a successfull operation, or an error.</returns>
public ErrorOr<Updated> RemoveItem(FileSystemItem item)
{
Items.Remove(item);
_items.Remove(item);
return Result.Updated;
}
#endregion
}
@@ -1,4 +1,8 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Contracts.Enums.FileSystem;
using Lumina.Domain.Common.Errors;
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.ValueObjects;
using System;
using System.Diagnostics;
@@ -10,9 +14,19 @@ namespace Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.E
/// Entity representing a file system file.
/// </summary>
[DebuggerDisplay("{Id.Path}")]
public class File : FileSystemItem
public sealed class File : FileSystemItem
{
#region ==================================================================== PROPERTIES =================================================================================
/// <summary>
/// Gets or sets the creation date of the file system item. Can be optional if the information is not available.
/// </summary>
public Optional<DateTime> DateCreated { get; private set; }
/// <summary>
/// Gets or sets the last modification date of the file system item. Can be optional if the information is not available.
/// </summary>
public Optional<DateTime> DateModified { get; private set; }
/// <summary>
/// Gets or sets the size in bytes of the current file entity.
/// </summary>
@@ -25,23 +39,119 @@ public class File : FileSystemItem
/// </summary>
/// <param name="id">The unique identifier of the file in the file system path.</param>
/// <param name="name">The name of the file.</param>
/// <param name="dateCreated">The date and time the file was created. Can be <see langword="null"/> if unknown.</param>
/// <param name="dateModified">The date and time the file was last modified. Can be <see langword="null"/> if unknown.</param>
/// <param name="dateCreated">The date and time the file was created. Can be optional if unknown.</param>
/// <param name="dateModified">The date and time the file was last modified. Can be optional if unknown.</param>
/// <param name="size">The size of the file in bytes.</param>
public File(FileSystemPathId id, string name, DateTime? dateCreated, DateTime? dateModified, long size) : base(id, name, dateCreated, dateModified)
private File(FileSystemPathId id, string name, Optional<DateTime> dateCreated, Optional<DateTime> dateModified, long size) : base(id, name, FileSystemItemType.File)
{
DateCreated = dateCreated;
DateModified = dateModified;
Size = size;
}
#endregion
#region ===================================================================== METHODS ===================================================================================
/// <summary>
/// Creates a new instance of the <see cref="File"/> class.
/// </summary>
/// <param name="name">The name of the file.</param>
/// <param name="dateCreated">The date and time the file was created. Can be optional if unknown.</param>
/// <param name="dateModified">The date and time the file was last modified. Can be optional if unknown.</param>
/// <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.
/// </returns>
public static ErrorOr<File> Create(
string path,
string name,
Optional<DateTime> dateCreated,
Optional<DateTime> dateModified,
long size,
FileSystemItemStatus status = FileSystemItemStatus.Accessible)
{
// TODO: enforce invariants
ErrorOr<FileSystemPathId> createPathResult = FileSystemPathId.Create(path);
if (createPathResult.IsError)
return createPathResult.Errors;
File newFile = new File(
createPathResult.Value,
name,
dateCreated,
dateModified,
size);
ErrorOr<Updated> setStatusResult = newFile.SetStatus(status);
if (setStatusResult.IsError)
return setStatusResult.Errors;
return newFile;
}
/// <summary>
/// Creates a new instance of the <see cref="File"/> class.
/// </summary>
/// <param name="id">The unique identifier of the file in the file system path.</param>
/// <param name="name">The name of the file.</param>
/// <param name="dateCreated">The date and time the file was created. Can be optional if unknown.</param>
/// <param name="dateModified">The date and time the file was last modified. Can be optional if unknown.</param>
/// <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.
/// </returns>
public static ErrorOr<File> Create(
FileSystemPathId id,
string name,
Optional<DateTime> dateCreated,
Optional<DateTime> dateModified,
long size,
FileSystemItemStatus status = FileSystemItemStatus.Accessible)
{
// TODO: enforce invariants
File newFile = new File(
id,
name,
dateCreated,
dateModified,
size);
ErrorOr<Updated> setStatusResult = newFile.SetStatus(status);
if (setStatusResult.IsError)
return setStatusResult.Errors;
return newFile;
}
/// <summary>
/// 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 successfull operation, or an error.</returns>
public ErrorOr<Updated> UpdateLastModified(DateTime date)
{
DateModified = date;
return Result.Updated;
}
/// <summary>
/// Updates the size of the file.
/// </summary>
/// <param name="newSize">The new size, in bytes.</param>
public void UpdateSize(long newSize)
/// <returns>An <see cref="ErrorOr{TValue}"/> representing either a successfull operation, or an error.</returns>
public ErrorOr<Updated> UpdateSize(long newSize)
{
Size = newSize;
return Result.Updated;
}
/// <summary>
/// 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 successfull operation, or an error.</returns>
public ErrorOr<Updated> Rename(string newName)
{
if (string.IsNullOrWhiteSpace(newName))
return Errors.FileManagement.NameCannotBeEmpty;
Name = newName;
return Result.Updated;
}
#endregion
}
@@ -0,0 +1,66 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Contracts.Enums.FileSystem;
using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.ValueObjects;
using System.Collections.Generic;
using System.Diagnostics;
#endregion
namespace Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.Entities;
/// <summary>
/// Entity representing a file system root item on Unix platforms.
/// </summary>
[DebuggerDisplay("{Id.Path}")]
public sealed class UnixRootItem : FileSystemItem
{
#region ================================================================== FIELD MEMBERS ================================================================================
private readonly List<FileSystemItem> _items = [];
private const string PATH = "/";
#endregion
#region ==================================================================== PROPERTIES =================================================================================
/// <summary>
/// Gets the collection of file system items that are children to the current file system root entity.
/// </summary>
public IReadOnlyCollection<FileSystemItem> Items
{
get { return _items.AsReadOnly(); }
}
#endregion
#region ====================================================================== CTOR =====================================================================================
/// <summary>
/// Initializes a new instance of the <see cref="UnixRootItem"/> class.
/// </summary>
/// <param name="id">The unique identifier of the root item in the file system path.</param>
/// <param name="name">The name of the root item.</param>
private UnixRootItem(FileSystemPathId id, string name) : base(id, name, FileSystemItemType.Root)
{
}
#endregion
#region ===================================================================== METHODS ===================================================================================
/// <summary>
/// Creates a new instance of the <see cref="UnixRootItem"/> class.
/// </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.
/// </returns>
public static ErrorOr<UnixRootItem> Create(
FileSystemItemStatus status = FileSystemItemStatus.Accessible)
{
ErrorOr<FileSystemPathId> createPathResult = FileSystemPathId.Create(PATH);
if (createPathResult.IsError)
return createPathResult.Errors;
UnixRootItem newRoot = new UnixRootItem(
createPathResult.Value,
PATH);
ErrorOr<Updated> setStatusResult = newRoot.SetStatus(status);
if (setStatusResult.IsError)
return setStatusResult.Errors;
return newRoot;
}
#endregion
}
@@ -0,0 +1,94 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Contracts.Enums.FileSystem;
using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.ValueObjects;
using System.Collections.Generic;
using System.Diagnostics;
#endregion
namespace Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.Entities;
/// <summary>
/// Entity representing a file system root item on Windows platforms.
/// </summary>
[DebuggerDisplay("{Id.Path}")]
public sealed class WindowsRootItem : FileSystemItem
{
#region ================================================================== FIELD MEMBERS ================================================================================
private readonly List<FileSystemItem> _items = [];
#endregion
#region ==================================================================== PROPERTIES =================================================================================
/// <summary>
/// Gets the collection of file system items that are children to the current file system root entity.
/// </summary>
public IReadOnlyCollection<FileSystemItem> Items
{
get { return _items.AsReadOnly(); }
}
#endregion
#region ====================================================================== CTOR =====================================================================================
/// <summary>
/// Initializes a new instance of the <see cref="WindowsRootItem"/> class.
/// </summary>
/// <param name="id">The unique identifier of the root item in the file system path.</param>
/// <param name="name">The name of the root item.</param>
private WindowsRootItem(FileSystemPathId id, string name) : base(id, name, FileSystemItemType.Root)
{
}
#endregion
#region ===================================================================== METHODS ===================================================================================
/// <summary>
/// Creates a new instance of the <see cref="WindowsRootItem"/> class.
/// </summary>
/// <param name="path">The path of the file system root item.</param>
/// <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.
/// </returns>
public static ErrorOr<WindowsRootItem> Create(
string path,
string name,
FileSystemItemStatus status = FileSystemItemStatus.Accessible)
{
// TODO: enforce invariants
ErrorOr<FileSystemPathId> createPathResult = FileSystemPathId.Create(path);
if (createPathResult.IsError)
return createPathResult.Errors;
WindowsRootItem newRoot = new WindowsRootItem(
createPathResult.Value,
name);
ErrorOr<Updated> setStatusResult = newRoot.SetStatus(status);
if (setStatusResult.IsError)
return setStatusResult.Errors;
return newRoot;
}
/// <summary>
/// Creates a new instance of the <see cref="WindowsRootItem"/> class.
/// </summary>
/// <param name="id">The unique identifier of the file system root item in the file system path.</param>
/// <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.
/// </returns>
public static ErrorOr<WindowsRootItem> Create(
FileSystemPathId id,
string name,
FileSystemItemStatus status = FileSystemItemStatus.Accessible)
{
// TODO: enforce invariants
WindowsRootItem newFile = new WindowsRootItem(
id,
name);
ErrorOr<Updated> setStatusResult = newFile.SetStatus(status);
if (setStatusResult.IsError)
return setStatusResult.Errors;
return newFile;
}
#endregion
}
@@ -1,8 +1,10 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Domain.Common.Enums;
using ErrorOr;
using Lumina.Contracts.Enums.FileSystem;
using Lumina.Domain.Common.Errors;
using Lumina.Domain.Common.Models.Core;
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.ValueObjects;
using System;
using System.Diagnostics;
#endregion
@@ -21,22 +23,19 @@ public abstract class FileSystemItem : AggregateRoot<FileSystemPathId>
public string Name { get; protected set; }
/// <summary>
/// Gets or sets the creation date of the file system item.
/// Can be <see langword="null"/> if the information is not available.
/// Gets or sets the optional parent of the file system item.
/// </summary>
public DateTime? DateCreated { get; protected set; }
public Optional<FileSystemItem> Parent { get; protected set; }
/// <summary>
/// Gets or sets the last modification date of the file system item.
/// Can be <see langword="null"/> if the information is not available.
/// </summary>
public DateTime? DateModified { get; protected set; }
/// <summary>
/// Gets or sets the current status of the file system item.
/// Defaults to Accessible.
/// Gets or sets the current status of the file system item. Defaults to Accessible.
/// </summary>
public FileSystemItemStatus Status { get; protected set; } = FileSystemItemStatus.Accessible;
/// <summary>
/// Gets or sets the tpe of the file system item.
/// </summary>
public FileSystemItemType Type { get; protected set; }
#endregion
#region ====================================================================== CTOR =====================================================================================
@@ -45,45 +44,38 @@ public abstract class FileSystemItem : AggregateRoot<FileSystemPathId>
/// </summary>
/// <param name="id">The unique identifier for the file system path.</param>
/// <param name="name">The name of the file system item.</param>
/// <param name="dateModified">The date and time the file system item was last modified. Can be <see langword="null"/> if unknown.</param>
/// <param name="dateCreated">The date and time the file system item was created. Can be <see langword="null"/> if unknown.</param>
protected FileSystemItem(FileSystemPathId id, string name, DateTime? dateModified, DateTime? dateCreated) : base(id)
/// <param name="fileSystemItemType">The type of the file system item.</param>
protected FileSystemItem(FileSystemPathId id, string name, FileSystemItemType fileSystemItemType) : base(id)
{
Name = name;
DateCreated = dateCreated;
DateModified = dateModified;
Type = fileSystemItemType;
}
#endregion
#region ===================================================================== METHODS ===================================================================================
/// <summary>
/// Renames the file system item to the specified new name.
/// </summary>
/// <param name="newName">The new name for the file system item.</param>
/// <exception cref="ArgumentException">Thrown if the new name is null or whitespace.</exception>
public void Rename(string newName)
{
if (string.IsNullOrWhiteSpace(newName))
throw new ArgumentException("New name cannot be empty", nameof(newName));
Name = newName;
}
/// <summary>
/// Updates the last modified date of the file system item.
/// </summary>
/// <param name="date">The new date and time of last modification.</param>
public void UpdateLastModified(DateTime date)
{
DateModified = date;
}
/// <summary>
/// Sets the status of the filesystem item.
/// </summary>
/// <param name="status">The status to be set.</param>
public void SetStatus(FileSystemItemStatus status)
/// <returns>An <see cref="ErrorOr{TValue}"/> representing either a successfull operation, or an error.</returns>
public ErrorOr<Updated> SetStatus(FileSystemItemStatus status)
{
Status = status;
return Result.Updated;
}
/// <summary>
/// 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 successfull operation, or an error.</returns>
public ErrorOr<Updated> SetParent(FileSystemItem parent)
{
if (parent is not null)
Parent = parent;
else
return Errors.FileManagement.ParentNodeCannotBeNull;
return Result.Updated;
}
#endregion
}
}
@@ -1,13 +1,13 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Domain.Common.Enums;
using Lumina.Contracts.Enums.FileSystem;
using Lumina.Domain.Common.Errors;
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.ValueObjects;
using System;
using System.Collections.Generic;
using System.IO.Abstractions;
using System.Linq;
using System.Threading.Tasks;
#endregion
namespace Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.Services;
@@ -37,21 +37,21 @@ internal class DirectoryProviderService : IDirectoryProviderService
#region ===================================================================== METHODS ===================================================================================
/// <summary>
/// Retrieves a list of subdirectory paths from the specified path, asynchronously.
/// Retrieves a list of subdirectory paths from the specified path.
/// </summary>
/// <param name="path">The path from which to retrieve the subdirectory paths.</param>
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either a task representing the asynchronous operation for retrieving a collection of directory paths or an error.</returns>
public ErrorOr<Task<IEnumerable<FileSystemPathId>>> GetSubdirectoryPathsAsync(FileSystemPathId path)
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either a collection of directory paths or an error.</returns>
public ErrorOr<IEnumerable<FileSystemPathId>> GetSubdirectoryPaths(FileSystemPathId path)
{
// check if the user has access permissions to the provided path
if (!_fileSystemPermissionsService.CanAccessPath(path, FileAccessMode.ListDirectory, false))
return Errors.Permission.UnauthorizedAccess;
return Task.Run(() => _fileSystem.Directory.GetDirectories(path.Path)
.OrderBy(p => p)
.Select(p => FileSystemPathId.Create(p))
.Where(errorOrPathId => !errorOrPathId.IsError)
.Select(errorOrPathId => errorOrPathId.Value)
.AsEnumerable());
return ErrorOrFactory.From(_fileSystem.Directory.GetDirectories(path.Path)
.OrderBy(path => path)
.Select(path => FileSystemPathId.Create(path))
.Where(errorOrPathId => !errorOrPathId.IsError)
.Select(errorOrPathId => errorOrPathId.Value)
.AsEnumerable());
}
/// <summary>
@@ -79,26 +79,26 @@ 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 last write time of <paramref name="path"/>, or null if not available, or an error.</returns>
public ErrorOr<DateTime?> GetLastWriteTime(FileSystemPathId path)
/// <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)
{
// check if the user has access permissions to the provided path
if (!_fileSystemPermissionsService.CanAccessPath(path, FileAccessMode.ReadProperties, false))
return Errors.Permission.UnauthorizedAccess;
return _fileSystem.Directory.GetLastWriteTime(path.Path);
return Optional<DateTime>.FromNullable(_fileSystem.Directory.GetLastWriteTime(path.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 either the creation time of <paramref name="path"/>, or null if not available, or an error.</returns>
public ErrorOr<DateTime?> GetCreationTime(FileSystemPathId path)
/// <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)
{
// check if the user has access permissions to the provided path
if (!_fileSystemPermissionsService.CanAccessPath(path, FileAccessMode.ReadProperties, false))
return Errors.Permission.UnauthorizedAccess;
return _fileSystem.Directory.GetCreationTime(path.Path);
return Optional<DateTime>.FromNullable(_fileSystem.Directory.GetCreationTime(path.Path));
}
/// <summary>
@@ -128,7 +128,7 @@ internal class DirectoryProviderService : IDirectoryProviderService
{
// check if the source directory exists
if (!_fileSystem.Directory.Exists(sourcePath.Path))
return Errors.FileManagement.DirectoryNotFoundError;
return Errors.FileManagement.DirectoryNotFound;
string destPath = CreateUniqueDirectoryPath(destinationPath.Path);
try
{
@@ -191,7 +191,7 @@ internal class DirectoryProviderService : IDirectoryProviderService
{
// check if the source directory exists
if (!_fileSystem.Directory.Exists(sourcePath.Path))
return Errors.FileManagement.DirectoryNotFoundError;
return Errors.FileManagement.DirectoryNotFound;
try
{
// if the destination directory does not exist, perform a simple move
@@ -280,10 +280,10 @@ internal class DirectoryProviderService : IDirectoryProviderService
return newDirectoryPathResult.Value;
}
else
return Errors.FileManagement.InvalidPathError;
return Errors.FileManagement.InvalidPath;
}
else
return Errors.FileManagement.InvalidPathError;
return Errors.FileManagement.InvalidPath;
}
/// <summary>
@@ -291,13 +291,13 @@ internal class DirectoryProviderService : IDirectoryProviderService
/// </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<bool> DeleteDirectory(FileSystemPathId path)
public ErrorOr<Deleted> DeleteDirectory(FileSystemPathId path)
{
// check if the user has access permissions to the provided path
if (!_fileSystemPermissionsService.CanAccessPath(path, FileAccessMode.Delete, false))
return Errors.Permission.UnauthorizedAccess;
_fileSystem.DirectoryInfo.New(path.Path).Delete(true);
return true;
return Result.Deleted;
}
#endregion
}
@@ -1,14 +1,14 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Domain.Common.Enums;
using Lumina.Contracts.Enums.FileSystem;
using Lumina.Domain.Common.Errors;
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.Entities;
using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.Strategies.Environment;
using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.Strategies.Platform;
using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.ValueObjects;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
#endregion
namespace Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.Services;
@@ -25,7 +25,7 @@ public class DirectoryService : IDirectoryService
#region ====================================================================== CTOR =====================================================================================
/// <summary>
/// Initializes a new instance of the <see cref="DirectoryProviderService"/> class.
/// Initializes a new instance of the <see cref="DirectoryService"/> class.
/// </summary>
/// <param name="environmentContext">Injected facade service for environment contextual services.</param>
/// <param name="platformContextManager">Injected facade service for platform contextual services.</param>
@@ -42,12 +42,12 @@ public class DirectoryService : IDirectoryService
/// </summary>
/// <param name="path">String representation of the file path.</param>
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either a collection of subdirectories or an error.</returns>
public async Task<ErrorOr<IEnumerable<Directory>>> GetSubdirectoriesAsync(string path)
public ErrorOr<IEnumerable<Directory>> GetSubdirectories(string path)
{
var fileSystemPathIdResult = FileSystemPathId.Create(path);
ErrorOr<FileSystemPathId> fileSystemPathIdResult = FileSystemPathId.Create(path);
if (fileSystemPathIdResult.IsError)
return fileSystemPathIdResult.Errors;
return await GetSubdirectoriesAsync(fileSystemPathIdResult.Value).ConfigureAwait(false);
return GetSubdirectories(fileSystemPathIdResult.Value);
}
/// <summary>
@@ -55,9 +55,9 @@ public class DirectoryService : IDirectoryService
/// </summary>
/// <param name="directory">Directory object to retrieve subdirectories for.</param>
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either a collection of subdirectories or an error.</returns>
public async Task<ErrorOr<IEnumerable<Directory>>> GetSubdirectoriesAsync(Directory directory)
public ErrorOr<IEnumerable<Directory>> GetSubdirectories(Directory directory)
{
return await GetSubdirectoriesAsync(directory.Id).ConfigureAwait(false);
return GetSubdirectories(directory.Id);
}
/// <summary>
@@ -65,33 +65,40 @@ public class DirectoryService : IDirectoryService
/// </summary>
/// <param name="path">Identifier for the file path.</param>
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either a collection of subdirectories or an error.</returns>
public async Task<ErrorOr<IEnumerable<Directory>>> GetSubdirectoriesAsync(FileSystemPathId path)
public ErrorOr<IEnumerable<Directory>> GetSubdirectories(FileSystemPathId path)
{
// retrieve the list of subdirectories
ErrorOr<Task<IEnumerable<FileSystemPathId>>> subdirectoryPathsResult = _environmentContext.DirectoryProviderService.GetSubdirectoryPathsAsync(path);
ErrorOr<IEnumerable<FileSystemPathId>> subdirectoryPathsResult = _environmentContext.DirectoryProviderService.GetSubdirectoryPaths(path);
if (subdirectoryPathsResult.IsError)
return subdirectoryPathsResult.Errors;
List<Directory> result = new();
IEnumerable<FileSystemPathId> subdirectoryPaths = await subdirectoryPathsResult.Value.ConfigureAwait(false);
List<Directory> result = [];
IEnumerable<FileSystemPathId> subdirectoryPaths = subdirectoryPathsResult.Value;
foreach (FileSystemPathId subPath in subdirectoryPaths)
{
// extract directory details
ErrorOr<string> dirNameResult = _environmentContext.DirectoryProviderService.GetFileName(subPath);
ErrorOr<DateTime?> dateModifiedResult = _environmentContext.DirectoryProviderService.GetLastWriteTime(subPath);
ErrorOr<DateTime?> dateCreatedResult = _environmentContext.DirectoryProviderService.GetCreationTime(subPath);
ErrorOr<Optional<DateTime>> dateModifiedResult = _environmentContext.DirectoryProviderService.GetLastWriteTime(subPath);
ErrorOr<Optional<DateTime>> dateCreatedResult = _environmentContext.DirectoryProviderService.GetCreationTime(subPath);
// if any error occurred, mark directory as Inaccessible
if (dirNameResult.IsError || dateModifiedResult.IsError || dateCreatedResult.IsError)
{
Directory errorDir = new(subPath, !dirNameResult.IsError ? dirNameResult.Value : null!,
!dateCreatedResult.IsError ? dateCreatedResult.Value : null, !dateModifiedResult.IsError ? dateModifiedResult.Value : null);
errorDir.SetStatus(FileSystemItemStatus.Inaccessible);
result.Add(errorDir);
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)
return errorDirResult.Errors;
ErrorOr<Updated> setStatusResult = errorDirResult.Value.SetStatus(FileSystemItemStatus.Inaccessible);
if (setStatusResult.IsError)
return setStatusResult.Errors;
result.Add(errorDirResult.Value);
}
else
{
Directory subDirectory = new(subPath, dirNameResult.Value, dateCreatedResult.Value, dateModifiedResult.Value);
result.Add(subDirectory);
ErrorOr<Directory> subDirectoryResult = Directory.Create(subPath, dirNameResult.Value, dateCreatedResult.Value, dateModifiedResult.Value);
if (subDirectoryResult.IsError)
return subDirectoryResult.Errors;
result.Add(subDirectoryResult.Value);
}
}
return result;
@@ -105,7 +112,7 @@ public class DirectoryService : IDirectoryService
/// <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)
{
var fileSystemPathIdResult = FileSystemPathId.Create(path);
ErrorOr<FileSystemPathId> fileSystemPathIdResult = FileSystemPathId.Create(path);
if (fileSystemPathIdResult.IsError)
return fileSystemPathIdResult.Errors;
return CreateDirectory(fileSystemPathIdResult.Value, name);
@@ -120,14 +127,14 @@ public class DirectoryService : IDirectoryService
public ErrorOr<Directory> CreateDirectory(FileSystemPathId path, string name)
{
// first, check if the directory about to be created does not already exist
var combinedPath = _platformContext.PathStrategy.CombinePath(path, name);
ErrorOr<FileSystemPathId> combinedPath = _platformContext.PathStrategy.CombinePath(path, name);
if (combinedPath.IsError)
return combinedPath.Errors;
var directoryExists = _environmentContext.DirectoryProviderService.DirectoryExists(combinedPath.Value);
ErrorOr<bool> directoryExists = _environmentContext.DirectoryProviderService.DirectoryExists(combinedPath.Value);
if (directoryExists.IsError)
return directoryExists.Errors;
else if (directoryExists.Value == true)
return Errors.FileManagement.DirectoryAlreadyExistsError;
return Errors.FileManagement.DirectoryAlreadyExists;
else
{
// create the new directory
@@ -135,18 +142,23 @@ public class DirectoryService : IDirectoryService
if (newDirectoryPathResult.IsError)
return newDirectoryPathResult.Errors;
ErrorOr<string> dirNameResult = _environmentContext.DirectoryProviderService.GetFileName(path);
ErrorOr<DateTime?> dateModifiedResult = _environmentContext.DirectoryProviderService.GetLastWriteTime(path);
ErrorOr<DateTime?> dateCreatedResult = _environmentContext.DirectoryProviderService.GetCreationTime(path);
ErrorOr<Optional<DateTime>> dateModifiedResult = _environmentContext.DirectoryProviderService.GetLastWriteTime(path);
ErrorOr<Optional<DateTime>> dateCreatedResult = _environmentContext.DirectoryProviderService.GetCreationTime(path);
// if any error occurred, mark directory as Inaccessible
if (dirNameResult.IsError || dateModifiedResult.IsError || dateCreatedResult.IsError)
{
Directory errorDir = new(newDirectoryPathResult.Value, !dirNameResult.IsError ? dirNameResult.Value : null!,
!dateCreatedResult.IsError ? dateCreatedResult.Value : null, !dateModifiedResult.IsError ? dateModifiedResult.Value : null);
errorDir.SetStatus(FileSystemItemStatus.Inaccessible);
return errorDir;
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)
return errorDirResult.Errors;
ErrorOr<Updated> setStatusResult = errorDirResult.Value.SetStatus(FileSystemItemStatus.Inaccessible);
if (setStatusResult.IsError)
return setStatusResult.Errors;
return errorDirResult;
}
else
return new Directory(newDirectoryPathResult.Value, dirNameResult.Value, dateCreatedResult.Value, dateModifiedResult.Value);
return Directory.Create(newDirectoryPathResult.Value, dirNameResult.Value, dateCreatedResult.Value, dateModifiedResult.Value);
}
}
@@ -164,10 +176,10 @@ public class DirectoryService : IDirectoryService
sourcePath += _platformContext.PathStrategy.PathSeparator;
if (!destinationPath.EndsWith(_platformContext.PathStrategy.PathSeparator))
destinationPath += _platformContext.PathStrategy.PathSeparator;
var fileSystemSourcePathIdResult = FileSystemPathId.Create(sourcePath);
ErrorOr<FileSystemPathId> fileSystemSourcePathIdResult = FileSystemPathId.Create(sourcePath);
if (fileSystemSourcePathIdResult.IsError)
return fileSystemSourcePathIdResult.Errors;
var fileSystemDestinationPathIdResult = FileSystemPathId.Create(destinationPath);
ErrorOr<FileSystemPathId> fileSystemDestinationPathIdResult = FileSystemPathId.Create(destinationPath);
if (fileSystemDestinationPathIdResult.IsError)
return fileSystemDestinationPathIdResult.Errors;
return CopyDirectory(fileSystemSourcePathIdResult.Value, fileSystemDestinationPathIdResult.Value, overrideExisting ?? false);
@@ -182,11 +194,11 @@ public class DirectoryService : IDirectoryService
/// <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)
{
var directoryExists = _environmentContext.DirectoryProviderService.DirectoryExists(sourcePath);
ErrorOr<bool> directoryExists = _environmentContext.DirectoryProviderService.DirectoryExists(sourcePath);
if (directoryExists.IsError)
return directoryExists.Errors;
else if (directoryExists.Value == false)
return Errors.FileManagement.DirectoryNotFoundError;
return Errors.FileManagement.DirectoryNotFound;
else
{
// copy the directory
@@ -210,10 +222,10 @@ public class DirectoryService : IDirectoryService
sourcePath += _platformContext.PathStrategy.PathSeparator;
if (!destinationPath.EndsWith(_platformContext.PathStrategy.PathSeparator))
destinationPath += _platformContext.PathStrategy.PathSeparator;
var fileSystemSourcePathIdResult = FileSystemPathId.Create(sourcePath);
ErrorOr<FileSystemPathId> fileSystemSourcePathIdResult = FileSystemPathId.Create(sourcePath);
if (fileSystemSourcePathIdResult.IsError)
return fileSystemSourcePathIdResult.Errors;
var fileSystemDestinationPathIdResult = FileSystemPathId.Create(destinationPath);
ErrorOr<FileSystemPathId> fileSystemDestinationPathIdResult = FileSystemPathId.Create(destinationPath);
if (fileSystemDestinationPathIdResult.IsError)
return fileSystemDestinationPathIdResult.Errors;
return MoveDirectory(fileSystemSourcePathIdResult.Value, fileSystemDestinationPathIdResult.Value, overrideExisting ?? false);
@@ -228,11 +240,11 @@ public class DirectoryService : IDirectoryService
/// <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)
{
var directoryExists = _environmentContext.DirectoryProviderService.DirectoryExists(sourcePath);
ErrorOr<bool> directoryExists = _environmentContext.DirectoryProviderService.DirectoryExists(sourcePath);
if (directoryExists.IsError)
return directoryExists.Errors;
else if (directoryExists.Value == false)
return Errors.FileManagement.DirectoryNotFoundError;
return Errors.FileManagement.DirectoryNotFound;
else
{
// move the directory
@@ -250,7 +262,7 @@ public class DirectoryService : IDirectoryService
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either the renamed directory, or an error.</returns>
public ErrorOr<Directory> RenameDirectory(string path, string name)
{
var fileSystemPathIdResult = FileSystemPathId.Create(path);
ErrorOr<FileSystemPathId> fileSystemPathIdResult = FileSystemPathId.Create(path);
if (fileSystemPathIdResult.IsError)
return fileSystemPathIdResult.Errors;
return RenameDirectory(fileSystemPathIdResult.Value, name);
@@ -265,14 +277,14 @@ public class DirectoryService : IDirectoryService
public ErrorOr<Directory> RenameDirectory(FileSystemPathId path, string name)
{
// first, check if the directory about to be created does not already exist
var combinedPath = _platformContext.PathStrategy.CombinePath(path, name);
ErrorOr<FileSystemPathId> combinedPath = _platformContext.PathStrategy.CombinePath(path, name);
if (combinedPath.IsError)
return combinedPath.Errors;
var directoryExists = _environmentContext.DirectoryProviderService.DirectoryExists(combinedPath.Value);
ErrorOr<bool> directoryExists = _environmentContext.DirectoryProviderService.DirectoryExists(combinedPath.Value);
if (directoryExists.IsError)
return directoryExists.Errors;
else if (directoryExists.Value == true)
return Errors.FileManagement.DirectoryAlreadyExistsError;
return Errors.FileManagement.DirectoryAlreadyExists;
else
{
// rename the directory
@@ -280,18 +292,23 @@ public class DirectoryService : IDirectoryService
if (newDirectoryPathResult.IsError)
return newDirectoryPathResult.Errors;
ErrorOr<string> dirNameResult = _environmentContext.DirectoryProviderService.GetFileName(newDirectoryPathResult.Value);
ErrorOr<DateTime?> dateModifiedResult = _environmentContext.DirectoryProviderService.GetLastWriteTime(newDirectoryPathResult.Value);
ErrorOr<DateTime?> dateCreatedResult = _environmentContext.DirectoryProviderService.GetCreationTime(newDirectoryPathResult.Value);
ErrorOr<Optional<DateTime>> dateModifiedResult = _environmentContext.DirectoryProviderService.GetLastWriteTime(newDirectoryPathResult.Value);
ErrorOr<Optional<DateTime>> dateCreatedResult = _environmentContext.DirectoryProviderService.GetCreationTime(newDirectoryPathResult.Value);
// if any error occurred, mark directory as Inaccessible
if (dirNameResult.IsError || dateModifiedResult.IsError || dateCreatedResult.IsError)
{
Directory errorDir = new(newDirectoryPathResult.Value, !dirNameResult.IsError ? dirNameResult.Value : null!,
!dateCreatedResult.IsError ? dateCreatedResult.Value : null, !dateModifiedResult.IsError ? dateModifiedResult.Value : null);
errorDir.SetStatus(FileSystemItemStatus.Inaccessible);
return errorDir;
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)
return errorDirResult.Errors;
ErrorOr<Updated> setStatusResult = errorDirResult.Value.SetStatus(FileSystemItemStatus.Inaccessible);
if (setStatusResult.IsError)
return setStatusResult.Errors;
return errorDirResult;
}
else
return new Directory(newDirectoryPathResult.Value, dirNameResult.Value, dateCreatedResult.Value, dateModifiedResult.Value);
return Directory.Create(newDirectoryPathResult.Value, dirNameResult.Value, dateCreatedResult.Value, dateModifiedResult.Value);
}
}
@@ -300,9 +317,9 @@ public class DirectoryService : IDirectoryService
/// </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<bool> DeleteDirectory(string path)
public ErrorOr<Deleted> DeleteDirectory(string path)
{
var fileSystemPathIdResult = FileSystemPathId.Create(path);
ErrorOr<FileSystemPathId> fileSystemPathIdResult = FileSystemPathId.Create(path);
if (fileSystemPathIdResult.IsError)
return fileSystemPathIdResult.Errors;
return DeleteDirectory(fileSystemPathIdResult.Value);
@@ -313,7 +330,7 @@ public class DirectoryService : IDirectoryService
/// </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<bool> DeleteDirectory(FileSystemPathId path)
public ErrorOr<Deleted> DeleteDirectory(FileSystemPathId path)
{
return _environmentContext.DirectoryProviderService.DeleteDirectory(path);
}
@@ -0,0 +1,68 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Contracts.Enums.FileSystem;
using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.Entities;
using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.Strategies.Platform;
using System.Collections.Generic;
using System.IO.Abstractions;
using System.Linq;
#endregion
namespace Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.Services;
/// <summary>
/// Service for handling drives.
/// </summary>
public class DriveService : IDriveService
{
#region ================================================================== FIELD MEMBERS ================================================================================
private readonly IFileSystem _fileSystem;
private readonly IPlatformContext _platformContext;
#endregion
#region ====================================================================== CTOR =====================================================================================
/// <summary>
/// Initializes a new instance of the <see cref="DriveService"/> class.
/// </summary>
/// <param name="fileSystem">Injected service used to interact with the local filesystem.</param>
public DriveService(IFileSystem fileSystem, IPlatformContextManager platformContextManager)
{
_fileSystem = fileSystem;
_platformContext = platformContextManager.GetCurrentContext();
}
#endregion
#region ===================================================================== METHODS ===================================================================================
/// <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()
{
if (_platformContext.Platform == PlatformType.Unix)
{
var unixRootResult = UnixRootItem.Create(FileSystemItemStatus.Accessible);
if (unixRootResult.IsError)
return unixRootResult.Errors;
return new List<FileSystemItem>() { unixRootResult.Value };
}
else
return ErrorOrFactory.From(_fileSystem.DriveInfo.GetDrives()
.OrderBy(driveInfo => driveInfo.Name)
.Where(driveInfo => driveInfo.IsReady)
.Select(driveInfo =>
{
ErrorOr<FileSystemItem> root;
var windowsRootResult = WindowsRootItem.Create(driveInfo.Name, driveInfo.Name);
if (windowsRootResult.IsError)
return windowsRootResult.Errors;
else
root = windowsRootResult.Value;
return root;
})
.Where(errorOrDrive => !errorOrDrive.IsError)
.Select(errorOrDrive => errorOrDrive.Value)
.AsEnumerable());
}
#endregion
}
@@ -1,13 +1,13 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Domain.Common.Enums;
using Lumina.Contracts.Enums.FileSystem;
using Lumina.Domain.Common.Errors;
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.ValueObjects;
using System;
using System.Collections.Generic;
using System.IO.Abstractions;
using System.Linq;
using System.Threading.Tasks;
using Lumina.Domain.Common.Errors;
#endregion
namespace Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.Services;
@@ -40,18 +40,18 @@ internal class FileProviderService : IFileProviderService
/// Retrieves a list of file paths at the specified path.
/// </summary>
/// <param name="path">The path for which to retrieve the list of files.</param>
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either a task representing the asynchronous operation for retrieving a collection of file paths or an error.</returns>
public ErrorOr<Task<IEnumerable<FileSystemPathId>>> GetFilePathsAsync(FileSystemPathId path)
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either a collection of file paths or an error.</returns>
public ErrorOr<IEnumerable<FileSystemPathId>> GetFilePaths(FileSystemPathId path)
{
// check if the user has access permissions to the provided path
if (!_fileSystemPermissionsService.CanAccessPath(path, FileAccessMode.ListDirectory))
return Errors.Permission.UnauthorizedAccess;
return Task.Run(() => _fileSystem.Directory.GetFiles(path.Path)
.OrderBy(p => p)
.Select(p => FileSystemPathId.Create(p))
.Where(errorOrPathId => !errorOrPathId.IsError)
.Select(errorOrPathId => errorOrPathId.Value)
.AsEnumerable());
return ErrorOrFactory.From(_fileSystem.Directory.GetFiles(path.Path)
.OrderBy(p => p)
.Select(p => FileSystemPathId.Create(p))
.Where(errorOrPathId => !errorOrPathId.IsError)
.Select(errorOrPathId => errorOrPathId.Value)
.AsEnumerable());
}
/// <summary>
@@ -78,39 +78,39 @@ 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 a task representing the asynchronous operation for retrieving the contents of a file at the specified path, or an error.</returns>
public ErrorOr<Task<byte[]>> GetFileAsync(FileSystemPathId path)
/// <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)
{
// check if the user has access permissions to the provided path
if (!_fileSystemPermissionsService.CanAccessPath(path, FileAccessMode.ReadContents))
return Errors.Permission.UnauthorizedAccess;
return Task.Run(() => System.IO.File.ReadAllBytes(path.Path));
return System.IO.File.ReadAllBytes(path.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 last write time of <paramref name="path"/>, or null if not available, or an error.</returns>
public ErrorOr<DateTime?> GetLastWriteTime(FileSystemPathId path)
/// <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)
{
// check if the user has access permissions to the provided path
if (!_fileSystemPermissionsService.CanAccessPath(path, FileAccessMode.ReadProperties))
return Errors.Permission.UnauthorizedAccess;
return _fileSystem.File.GetLastWriteTime(path.Path);
return Optional<DateTime>.FromNullable(_fileSystem.File.GetLastWriteTime(path.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 creation time of <paramref name="path"/>, or null if not available, or an error.</returns>
public ErrorOr<DateTime?> GetCreationTime(FileSystemPathId path)
/// <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)
{
// check if the user has access permissions to the provided path
if (!_fileSystemPermissionsService.CanAccessPath(path, FileAccessMode.ReadProperties))
return Errors.Permission.UnauthorizedAccess;
return _fileSystem.File.GetCreationTime(path.Path);
return Optional<DateTime>.FromNullable(_fileSystem.File.GetCreationTime(path.Path));
}
/// <summary>
@@ -137,7 +137,7 @@ internal class FileProviderService : IFileProviderService
{
// check if the source file exists
if (!_fileSystem.File.Exists(sourceFilePath.Path))
return Errors.FileManagement.FileNotFoundError;
return Errors.FileManagement.FileNotFound;
string destinationFilePath;
string fileName = _fileSystem.Path.GetFileName(sourceFilePath.Path);
// when copying a file to the same location, just copy it with a new name
@@ -148,7 +148,7 @@ internal class FileProviderService : IFileProviderService
// check if there is already a file with the same name as the copied file, in the destination directory
if (_fileSystem.File.Exists(destinationDirectoryPath.Path + fileName))
if (!overrideExisting)
return Errors.FileManagement.FileAlreadyExistsError;
return Errors.FileManagement.FileAlreadyExists;
destinationFilePath = destinationDirectoryPath.Path + fileName;
}
try
@@ -193,7 +193,7 @@ internal class FileProviderService : IFileProviderService
{
// check if the source file exists
if (!_fileSystem.File.Exists(sourceFilePath.Path))
return Errors.FileManagement.FileNotFoundError;
return Errors.FileManagement.FileNotFound;
try
{
string fileName = _fileSystem.Path.GetFileName(sourceFilePath.Path);
@@ -206,7 +206,7 @@ internal class FileProviderService : IFileProviderService
if (overrideExisting)
_fileSystem.File.Move(sourceFilePath.Path, destinationFilePath, overrideExisting);
else
return Errors.FileManagement.FileAlreadyExistsError;
return Errors.FileManagement.FileAlreadyExists;
}
return FileSystemPathId.Create(destinationFilePath);
}
@@ -245,10 +245,10 @@ internal class FileProviderService : IFileProviderService
return newFilePathResult;
}
else
return Errors.FileManagement.InvalidPathError;
return Errors.FileManagement.InvalidPath;
}
else
return Errors.FileManagement.CannotNavigateUpError;
return Errors.FileManagement.CannotNavigateUp;
}
/// <summary>
@@ -256,13 +256,13 @@ internal class FileProviderService : IFileProviderService
/// </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<bool> DeleteFile(FileSystemPathId path)
public ErrorOr<Deleted> DeleteFile(FileSystemPathId path)
{
// check if the user has access permissions to the provided path
if (!_fileSystemPermissionsService.CanAccessPath(path, FileAccessMode.Delete))
return Errors.Permission.UnauthorizedAccess;
_fileSystem.File.Delete(path.Path);
return true;
return Result.Deleted;
}
#endregion
}
@@ -1,14 +1,14 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Domain.Common.Enums;
using Lumina.Contracts.Enums.FileSystem;
using Lumina.Domain.Common.Errors;
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.Entities;
using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.Strategies.Environment;
using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.Strategies.Platform;
using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.ValueObjects;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
#endregion
namespace Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.Services;
@@ -42,12 +42,12 @@ public class FileService : IFileService
/// </summary>
/// <param name="path">String representation of the file path.</param>
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either a collection of files or an error.</returns>
public async Task<ErrorOr<IEnumerable<File>>> GetFilesAsync(string path)
public ErrorOr<IEnumerable<File>> GetFiles(string path)
{
var fileSystemPathIdResult = FileSystemPathId.Create(path);
if (fileSystemPathIdResult.IsError)
return fileSystemPathIdResult.Errors;
return await GetFilesAsync(fileSystemPathIdResult.Value).ConfigureAwait(false);
return GetFiles(fileSystemPathIdResult.Value);
}
/// <summary>
@@ -55,9 +55,9 @@ public class FileService : IFileService
/// </summary>
/// <param name="file">The file object.</param>
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either a collection of files or an error.</returns>
public async Task<ErrorOr<IEnumerable<File>>> GetFilesAsync(File file)
public ErrorOr<IEnumerable<File>> GetFiles(File file)
{
return await GetFilesAsync(file.Id).ConfigureAwait(false);
return GetFiles(file.Id);
}
/// <summary>
@@ -65,34 +65,41 @@ public class FileService : IFileService
/// </summary>
/// <param name="path">Identifier for the file path.</param>
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either a collection of files or an error.</returns>
public async Task<ErrorOr<IEnumerable<File>>> GetFilesAsync(FileSystemPathId path)
public ErrorOr<IEnumerable<File>> GetFiles(FileSystemPathId path)
{
// retrieve the list of files
ErrorOr<Task<IEnumerable<FileSystemPathId>>> filePathsResult = _environmentContext.FileProviderService.GetFilePathsAsync(path);
ErrorOr<IEnumerable<FileSystemPathId>> filePathsResult = _environmentContext.FileProviderService.GetFilePaths(path);
if (filePathsResult.IsError)
return filePathsResult.Errors;
List<File> result = new();
IEnumerable<FileSystemPathId> filePaths = await filePathsResult.Value.ConfigureAwait(false);
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<DateTime?> dateModifiedResult = _environmentContext.FileProviderService.GetLastWriteTime(filePath);
ErrorOr<DateTime?> dateCreatedResult = _environmentContext.FileProviderService.GetCreationTime(filePath);
ErrorOr<Optional<DateTime>> dateModifiedResult = _environmentContext.FileProviderService.GetLastWriteTime(filePath);
ErrorOr<Optional<DateTime>> dateCreatedResult = _environmentContext.FileProviderService.GetCreationTime(filePath);
ErrorOr<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)
{
File errorFile = new(filePath, !fileNameResult.IsError ? fileNameResult.Value : null!,
!dateCreatedResult.IsError ? dateCreatedResult.Value : null, !dateModifiedResult.IsError ? dateModifiedResult.Value : null, size);
errorFile.SetStatus(FileSystemItemStatus.Inaccessible);
result.Add(errorFile);
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)
return errorFileResult.Errors;
ErrorOr<Updated> setStatusResult = errorFileResult.Value.SetStatus(FileSystemItemStatus.Inaccessible);
if (setStatusResult.IsError)
return setStatusResult.Errors;
result.Add(errorFileResult.Value);
}
else
{
File file = new(filePath, fileNameResult.Value, dateCreatedResult.Value, dateModifiedResult.Value, size);
result.Add(file);
var fileResult = File.Create(filePath, fileNameResult.Value, dateCreatedResult.Value, dateModifiedResult.Value, size);
if (fileResult.IsError)
return fileResult.Errors;
result.Add(fileResult.Value);
}
}
return result;
@@ -132,7 +139,7 @@ public class FileService : IFileService
if (fileExists.IsError)
return fileExists.Errors;
else if (fileExists.Value == false)
return Errors.FileManagement.FileNotFoundError;
return Errors.FileManagement.FileNotFound;
else
{
// copy the file
@@ -140,20 +147,25 @@ public class FileService : IFileService
if (copyFileResult.IsError)
return copyFileResult.Errors;
ErrorOr<string> fileNameResult = _environmentContext.FileProviderService.GetFileName(copyFileResult.Value);
ErrorOr<DateTime?> dateModifiedResult = _environmentContext.FileProviderService.GetLastWriteTime(copyFileResult.Value);
ErrorOr<DateTime?> dateCreatedResult = _environmentContext.FileProviderService.GetCreationTime(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);
long size = sizeResult.Value ?? 0;
// if any of the details returned an error, set inaccessible status
if (fileNameResult.IsError || dateModifiedResult.IsError || dateCreatedResult.IsError)
{
File errorFile = new(copyFileResult.Value, !fileNameResult.IsError ? fileNameResult.Value : null!,
!dateCreatedResult.IsError ? dateCreatedResult.Value : null, !dateModifiedResult.IsError ? dateModifiedResult.Value : null, size);
errorFile.SetStatus(FileSystemItemStatus.Inaccessible);
return errorFile;
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)
return errorFileResult.Errors;
ErrorOr<Updated> setStatusResult = errorFileResult.Value.SetStatus(FileSystemItemStatus.Inaccessible);
if (setStatusResult.IsError)
return setStatusResult.Errors;
return errorFileResult;
}
else
return new File(copyFileResult.Value, fileNameResult.Value, dateCreatedResult.Value, dateModifiedResult.Value, size);
return File.Create(copyFileResult.Value, fileNameResult.Value, dateCreatedResult.Value, dateModifiedResult.Value, size);
}
}
@@ -191,7 +203,7 @@ public class FileService : IFileService
if (fileExists.IsError)
return fileExists.Errors;
else if (fileExists.Value == false)
return Errors.FileManagement.FileNotFoundError;
return Errors.FileManagement.FileNotFound;
else
{
// move the file
@@ -199,20 +211,25 @@ public class FileService : IFileService
if (moveFileResult.IsError)
return moveFileResult.Errors;
ErrorOr<string> fileNameResult = _environmentContext.FileProviderService.GetFileName(moveFileResult.Value);
ErrorOr<DateTime?> dateModifiedResult = _environmentContext.FileProviderService.GetLastWriteTime(moveFileResult.Value);
ErrorOr<DateTime?> dateCreatedResult = _environmentContext.FileProviderService.GetCreationTime(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);
long size = sizeResult.Value ?? 0;
// if any of the details returned an error, set inaccessible status
if (fileNameResult.IsError || dateModifiedResult.IsError || dateCreatedResult.IsError)
{
File errorFile = new(moveFileResult.Value, !fileNameResult.IsError ? fileNameResult.Value : null!,
!dateCreatedResult.IsError ? dateCreatedResult.Value : null, !dateModifiedResult.IsError ? dateModifiedResult.Value : null, size);
errorFile.SetStatus(FileSystemItemStatus.Inaccessible);
return errorFile;
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)
return errorFileResult.Errors;
ErrorOr<Updated> setStatusResult = errorFileResult.Value.SetStatus(FileSystemItemStatus.Inaccessible);
if (setStatusResult.IsError)
return setStatusResult.Errors;
return errorFileResult;
}
else
return new File(moveFileResult.Value, fileNameResult.Value, dateCreatedResult.Value, dateModifiedResult.Value, size);
return File.Create(moveFileResult.Value, fileNameResult.Value, dateCreatedResult.Value, dateModifiedResult.Value, size);
}
}
@@ -246,7 +263,7 @@ public class FileService : IFileService
if (fileExists.IsError)
return fileExists.Errors;
else if (fileExists.Value == true)
return Errors.FileManagement.FileAlreadyExistsError;
return Errors.FileManagement.FileAlreadyExists;
else
{
// rename the file
@@ -254,20 +271,25 @@ public class FileService : IFileService
if (newFilePathResult.IsError)
return newFilePathResult.Errors;
ErrorOr<string> fileNameResult = _environmentContext.FileProviderService.GetFileName(newFilePathResult.Value);
ErrorOr<DateTime?> dateModifiedResult = _environmentContext.FileProviderService.GetLastWriteTime(newFilePathResult.Value);
ErrorOr<DateTime?> dateCreatedResult = _environmentContext.FileProviderService.GetCreationTime(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);
long size = sizeResult.Value ?? 0;
// if any of the details returned an error, set inaccessible status
if (fileNameResult.IsError || dateModifiedResult.IsError || dateCreatedResult.IsError)
{
File errorFile = new(newFilePathResult.Value, !fileNameResult.IsError ? fileNameResult.Value : null!,
!dateCreatedResult.IsError ? dateCreatedResult.Value : null, !dateModifiedResult.IsError ? dateModifiedResult.Value : null, size);
errorFile.SetStatus(FileSystemItemStatus.Inaccessible);
return errorFile;
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)
return errorFileResult.Errors;
ErrorOr<Updated> setStatusResult = errorFileResult.Value.SetStatus(FileSystemItemStatus.Inaccessible);
if (setStatusResult.IsError)
return setStatusResult.Errors;
return errorFileResult;
}
else
return new File(newFilePathResult.Value, fileNameResult.Value, dateCreatedResult.Value, dateModifiedResult.Value, size);
return File.Create(newFilePathResult.Value, fileNameResult.Value, dateCreatedResult.Value, dateModifiedResult.Value, size);
}
}
@@ -276,7 +298,7 @@ public class FileService : IFileService
/// </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<bool> DeleteFile(string path)
public ErrorOr<Deleted> DeleteFile(string path)
{
var fileSystemPathIdResult = FileSystemPathId.Create(path);
if (fileSystemPathIdResult.IsError)
@@ -289,7 +311,7 @@ public class FileService : IFileService
/// </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<bool> DeleteFile(FileSystemPathId path)
public ErrorOr<Deleted> DeleteFile(FileSystemPathId path)
{
return _environmentContext.FileProviderService.DeleteFile(path);
}
@@ -1,5 +1,5 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Domain.Common.Enums;
using Lumina.Contracts.Enums.FileSystem;
using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.Strategies.Platform;
using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.ValueObjects;
using Mono.Unix;
@@ -1,6 +1,7 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Domain.Common.Enums;
using Lumina.Contracts.Enums.FileSystem;
using Lumina.Contracts.Enums.PhotoLibrary;
using Lumina.Domain.Common.Errors;
using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.Entities;
using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.ValueObjects;
@@ -156,4 +157,4 @@ public class FileTypeService : IFileTypeService
return ImageType.None;
}
#endregion
}
}
@@ -1,9 +1,9 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.ValueObjects;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
#endregion
namespace Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.Services;
@@ -15,11 +15,11 @@ public interface IDirectoryProviderService
{
#region ===================================================================== METHODS ===================================================================================
/// <summary>
/// Retrieves a list of subdirectory paths from the specified path, asynchronously.
/// Retrieves a list of subdirectory paths from the specified path.
/// </summary>
/// <param name="path">The path from which to retrieve the subdirectory paths.</param>
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either a task representing the asynchronous operation for retrieving a collection of directory paths or an error.</returns>
ErrorOr<Task<IEnumerable<FileSystemPathId>>> GetSubdirectoryPathsAsync(FileSystemPathId path);
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either a collection of directory paths or an error.</returns>
ErrorOr<IEnumerable<FileSystemPathId>> GetSubdirectoryPaths(FileSystemPathId path);
/// <summary>
/// Checks if a directory with the specified path exists.
@@ -40,15 +40,15 @@ public interface IDirectoryProviderService
/// </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 last write time of <paramref name="path"/>, or null if not available, or an error.</returns>
ErrorOr<DateTime?> GetLastWriteTime(FileSystemPathId path);
/// <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);
/// <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 either the creation time of <paramref name="path"/>, or null if not available, or an error.</returns>
ErrorOr<DateTime?> GetCreationTime(FileSystemPathId path);
/// <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);
/// <summary>
/// Creates a new directory with the specified name, at the specified path.
@@ -89,6 +89,6 @@ public interface IDirectoryProviderService
/// </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<bool> DeleteDirectory(FileSystemPathId path);
ErrorOr<Deleted> DeleteDirectory(FileSystemPathId path);
#endregion
}
@@ -3,7 +3,6 @@ using ErrorOr;
using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.Entities;
using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.ValueObjects;
using System.Collections.Generic;
using System.Threading.Tasks;
#endregion
namespace Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.Services;
@@ -19,21 +18,21 @@ public interface IDirectoryService
/// </summary>
/// <param name="path">String representation of the file path.</param>
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either a collection of subdirectories or an error.</returns>
Task<ErrorOr<IEnumerable<Directory>>> GetSubdirectoriesAsync(string path);
ErrorOr<IEnumerable<Directory>> GetSubdirectories(string path);
/// <summary>
/// Retrieves subdirectories for the given directory.
/// </summary>
/// <param name="directory">Directory object to retrieve subdirectories for.</param>
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either a collection of subdirectories or an error.</returns>
Task<ErrorOr<IEnumerable<Directory>>> GetSubdirectoriesAsync(Directory directory);
ErrorOr<IEnumerable<Directory>> GetSubdirectories(Directory directory);
/// <summary>
/// Retrieves subdirectories for the specified file system path.
/// </summary>
/// <param name="path">Identifier for the file path.</param>
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either a collection of subdirectories or an error.</returns>
Task<ErrorOr<IEnumerable<Directory>>> GetSubdirectoriesAsync(FileSystemPathId path);
ErrorOr<IEnumerable<Directory>> GetSubdirectories(FileSystemPathId path);
/// <summary>
/// Creates a directory with the specified <paramref name="name"/>, at the specified <paramref name="path"/>.
@@ -74,6 +73,6 @@ public interface IDirectoryService
/// </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<bool> DeleteDirectory(string path);
ErrorOr<Deleted> DeleteDirectory(string path);
#endregion
}
}
@@ -0,0 +1,20 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using System.Collections.Generic;
#endregion
namespace Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.Services;
/// <summary>
/// Interface for the service for handling drives.
/// </summary>
public interface IDriveService
{
#region ===================================================================== METHODS ===================================================================================
/// <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();
#endregion
}
@@ -1,9 +1,9 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.ValueObjects;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
#endregion
namespace Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.Services;
@@ -18,15 +18,15 @@ public interface IFileProviderService
/// Retrieves a list of files at the specified path.
/// </summary>
/// <param name="path">The path for which to retrieve the list of files.</param>
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either a task representing the asynchronous operation for retrieving a collection of file paths, or an error.</returns>
ErrorOr<Task<IEnumerable<FileSystemPathId>>> GetFilePathsAsync(FileSystemPathId path);
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either a collection of file paths, or an error.</returns>
ErrorOr<IEnumerable<FileSystemPathId>> GetFilePaths(FileSystemPathId path);
/// <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 a task representing the asynchronous operation for retrieving the contents of a file at the specified path, or an error.</returns>
ErrorOr<Task<byte[]>> GetFileAsync(FileSystemPathId path);
/// <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);
/// <summary>
/// Checks if a file with the specified path exists.
@@ -46,15 +46,15 @@ public interface 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 last write time of <paramref name="path"/>, or null if not available, or an error.</returns>
ErrorOr<DateTime?> GetLastWriteTime(FileSystemPathId path);
/// <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);
/// <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 creation time of <paramref name="path"/>, or null if not available, or an error.</returns>
ErrorOr<DateTime?> GetCreationTime(FileSystemPathId path);
/// <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);
/// <summary>
/// Gets the size of a file at the specified path.
@@ -94,6 +94,6 @@ public interface IFileProviderService
/// </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<bool> DeleteFile(FileSystemPathId path);
ErrorOr<Deleted> DeleteFile(FileSystemPathId path);
#endregion
}
@@ -3,7 +3,6 @@ using ErrorOr;
using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.Entities;
using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.ValueObjects;
using System.Collections.Generic;
using System.Threading.Tasks;
#endregion
namespace Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.Services;
@@ -19,21 +18,21 @@ public interface IFileService
/// </summary>
/// <param name="path">String representation of the file path.</param>
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either a collection of files or an error.</returns>
Task<ErrorOr<IEnumerable<File>>> GetFilesAsync(string path);
ErrorOr<IEnumerable<File>> GetFiles(string path);
/// <summary>
/// Retrieves files associated with a given file.
/// </summary>
/// <param name="file">The file object.</param>
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either a collection of files or an error.</returns>
Task<ErrorOr<IEnumerable<File>>> GetFilesAsync(File file);
ErrorOr<IEnumerable<File>> GetFiles(File file);
/// <summary>
/// Retrieves files for a specified file path ID.
/// </summary>
/// <param name="path">Identifier for the file path.</param>
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either a collection of files or an error.</returns>
Task<ErrorOr<IEnumerable<File>>> GetFilesAsync(FileSystemPathId path);
ErrorOr<IEnumerable<File>> GetFiles(FileSystemPathId path);
/// <summary>
/// Copies a file located at <paramref name="sourcePath"/> to <paramref name="destinationPath"/>.
@@ -66,6 +65,6 @@ public interface IFileService
/// </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<bool> DeleteFile(string path);
ErrorOr<Deleted> DeleteFile(string path);
#endregion
}
@@ -1,5 +1,5 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Domain.Common.Enums;
using Lumina.Contracts.Enums.FileSystem;
using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.ValueObjects;
#endregion
@@ -1,6 +1,6 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Domain.Common.Enums;
using Lumina.Contracts.Enums.PhotoLibrary;
using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.Entities;
using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.ValueObjects;
using System.Threading.Tasks;
@@ -1,6 +1,7 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.ValueObjects;
using System;
using System.Collections.Generic;
#endregion
@@ -53,5 +54,12 @@ public interface IPathService
/// </summary>
/// <returns>A collection of characters that are invalid in the context of paths.</returns>
char[] GetInvalidPathCharsForPlatform();
/// <summary>
/// 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);
#endregion
}
@@ -102,5 +102,18 @@ public class PathService : IPathService
{
return _platformContext.PathStrategy.GetInvalidPathCharsForPlatform();
}
/// <summary>
/// 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)
{
ErrorOr<FileSystemPathId> newPathResult = FileSystemPathId.Create(path);
if (newPathResult.IsError)
return newPathResult.Errors;
return _platformContext.PathStrategy.GetPathRoot(newPathResult.Value);
}
#endregion
}
@@ -1,8 +1,7 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Domain.Common.Enums;
using Lumina.Contracts.Enums.PhotoLibrary;
using Lumina.Domain.Common.Errors;
using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.Services;
using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.Strategies.Environment;
using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.ValueObjects;
using SixLabors.ImageSharp;
@@ -69,7 +68,7 @@ public class ThumbnailService : IThumbnailService
var resultFileContents = _environmentContext.FileProviderService.GetFileAsync(path);
if (resultFileContents.IsError)
return resultFileContents.Errors;
byte[] fileContents = await resultFileContents.Value;
byte[] fileContents = resultFileContents.Value;
// finally, resize or adjust quality based on image type
byte[]? adjustedImage = null;
if (imageTypeResult.Value == ImageType.JPEG || imageTypeResult.Value == ImageType.JPEG_CANON || imageTypeResult.Value == ImageType.JPEG2000
@@ -50,5 +50,12 @@ public interface IPathStrategy
/// </summary>
/// <returns>A collection of characters that are invalid in the context of paths</returns>
char[] GetInvalidPathCharsForPlatform();
/// <summary>
/// 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);
#endregion
}
@@ -50,7 +50,7 @@ public class UnixPathStrategy : IUnixPathStrategy
public ErrorOr<FileSystemPathId> CombinePath(FileSystemPathId path, string name)
{
if (string.IsNullOrWhiteSpace(name))
return Errors.FileManagement.NameCannotBeEmptyError;
return Errors.FileManagement.NameCannotBeEmpty;
// trim any directory separator characters from the end of the path
string subpath = path.Path.TrimEnd(PathSeparator);
// if the name begins with a directory separator, remove it
@@ -68,9 +68,9 @@ public class UnixPathStrategy : IUnixPathStrategy
{
// if path starts with anything other than '/', it's considered relative and invalid for this parser
if (!path.Path.StartsWith(PathSeparator))
return Errors.FileManagement.InvalidPathError;
return Errors.FileManagement.InvalidPath;
// get the path segments
var splitSegments = path.Path.Split(new[] { PathSeparator }, StringSplitOptions.RemoveEmptyEntries).ToList();
List<string> splitSegments = [.. path.Path.Split(new[] { PathSeparator }, StringSplitOptions.RemoveEmptyEntries)];
IEnumerable<PathSegment> segments = splitSegments.Select((segment, index) =>
{
bool isDirectory;
@@ -79,7 +79,7 @@ public class UnixPathStrategy : IUnixPathStrategy
else
isDirectory = true;
return new PathSegment(segment, isDirectory, isDrive: false);
});
}).Prepend(new PathSegment(PathSeparator.ToString(), isDirectory: false, isDrive: true)); // UNIX paths have '/' as "root drive"
return ErrorOrFactory.From(segments);
}
@@ -92,7 +92,7 @@ public class UnixPathStrategy : IUnixPathStrategy
{
// validation: ensure the path is not null or empty
if (!IsValidPath(path))
return Errors.FileManagement.InvalidPathError;
return Errors.FileManagement.InvalidPath;
// trim trailing slash for consistent processing
string tempPath = path.Path;
if (tempPath.EndsWith("/"))
@@ -101,7 +101,7 @@ public class UnixPathStrategy : IUnixPathStrategy
var lastIndex = tempPath.LastIndexOf(PathSeparator);
// if there's no slash found (shouldn't happen due to previous steps), or if we are at the root level after trimming, return error
if (lastIndex < 0)
return Errors.FileManagement.CannotNavigateUpError;
return Errors.FileManagement.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)
@@ -117,5 +117,21 @@ public class UnixPathStrategy : IUnixPathStrategy
{
return ['\0'];
}
/// <summary>
/// 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)
{
if (!IsValidPath(path))
return Errors.FileManagement.InvalidPath;
// On Unix-like systems, the root is always "/"
if (path.Path.StartsWith(PathSeparator))
return new PathSegment(PathSeparator.ToString(), isDirectory: false, isDrive: true);
return Errors.FileManagement.InvalidPath;
}
#endregion
}
@@ -5,6 +5,7 @@ using System.Collections.Generic;
using Lumina.Domain.Common.Errors;
using System.Text.RegularExpressions;
using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.ValueObjects;
using System.Linq;
#endregion
namespace Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.Strategies.Path;
@@ -48,7 +49,7 @@ public class WindowsPathStrategy : IWindowsPathStrategy
public ErrorOr<FileSystemPathId> CombinePath(FileSystemPathId path, string name)
{
if (name == null)
return Errors.FileManagement.NameCannotBeEmptyError;
return Errors.FileManagement.NameCannotBeEmpty;
// trim any directory separator characters from the end of the path
string subpath = path.Path.TrimEnd(PathSeparator);
// if the name begins with a directory separator, remove it
@@ -66,7 +67,7 @@ public class WindowsPathStrategy : IWindowsPathStrategy
{
// Windows paths usually start with a drive letter and colon, e.g., "C:"
if (!path.Path.Contains(':') || !path.Path.Contains(PathSeparator) || !char.IsLetter(path.Path[0]) || path.Path[1] != ':' || path.Path[2] != PathSeparator)
return Errors.FileManagement.InvalidPathError;
return Errors.FileManagement.InvalidPath;
return ErrorOrFactory.From(GetPathSegments());
IEnumerable<PathSegment> GetPathSegments()
{
@@ -96,19 +97,19 @@ public class WindowsPathStrategy : IWindowsPathStrategy
{
// validation: ensure the path is not null or empty
if (!IsValidPath(path))
return Errors.FileManagement.InvalidPathError;
return Errors.FileManagement.InvalidPath;
// if path is just a drive letter followed by ":\", return null
if (Regex.IsMatch(path.Path, @"^[a-zA-Z]:\\?$"))
return Errors.FileManagement.CannotNavigateUpError;
return Errors.FileManagement.CannotNavigateUp;
// trim trailing slash for consistent processing
string tempPath = path.Path;
if (tempPath.EndsWith("\\"))
if (tempPath.EndsWith('\\'))
tempPath = tempPath.TrimEnd(PathSeparator);
// find the last occurrence of a slash
var lastIndex = tempPath.LastIndexOf(PathSeparator);
// if there's no slash found (shouldn't happen due to previous steps), or if we are at the root level after trimming, return error
if (lastIndex < 0)
return Errors.FileManagement.CannotNavigateUpError;
return Errors.FileManagement.CannotNavigateUp;
// if we are at the drive root level after trimming, return drive root, otherwise, return the path up to the last slash
ErrorOr<FileSystemPathId> newPathResult = FileSystemPathId.Create(lastIndex == 2 && tempPath[1] == ':' ? tempPath[..3] : tempPath[..lastIndex]);
if (newPathResult.IsError)
@@ -124,5 +125,39 @@ public class WindowsPathStrategy : IWindowsPathStrategy
{
return ['<', '>', '"', '/', '|', '?', '*'];
}
/// <summary>
/// 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)
{
if (!IsValidPath(path))
return Errors.FileManagement.InvalidPath;
// check if the path starts with a drive letter (e.g., "C:")
if (path.Path.Length >= 2 && char.IsLetter(path.Path[0]) && path.Path[1] == ':')
{
string root = path.Path[..2];
if (path.Path.Length > 2 && path.Path[2] == PathSeparator)
root += PathSeparator;
return new PathSegment(root, isDirectory: true, isDrive: true);
}
// check for UNC paths (e.g., "\\server\share")
if (path.Path.StartsWith('\\'))
{
var parseResult = ParsePath(path);
if (parseResult.IsError)
return parseResult.Errors;
var segments = parseResult.Value.ToList();
if (segments.Count >= 2)
{
string root = $@"\\{segments[0].Name}\{segments[1].Name}\";
return new PathSegment(root, isDirectory: true, isDrive: false);
}
}
return Errors.FileManagement.InvalidPath;
}
#endregion
}
@@ -1,5 +1,5 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Domain.Common.Enums;
using Lumina.Contracts.Enums.FileSystem;
using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.Strategies.Path;
#endregion
@@ -1,6 +1,6 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Contracts.Enums.FileSystem;
using System;
using Lumina.Domain.Common.Enums;
#endregion
namespace Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.Strategies.Platform;
@@ -1,5 +1,5 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Domain.Common.Enums;
using Lumina.Contracts.Enums.FileSystem;
using System;
using System.Runtime.InteropServices;
#endregion
@@ -1,5 +1,5 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Domain.Common.Enums;
using Lumina.Contracts.Enums.FileSystem;
using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.Strategies.Path;
#endregion
@@ -1,5 +1,5 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Domain.Common.Enums;
using Lumina.Contracts.Enums.FileSystem;
using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.Strategies.Path;
#endregion
@@ -49,7 +49,7 @@ public sealed class FileSystemPathId : ValueObject
public static ErrorOr<FileSystemPathId> Create(string path)
{
if (string.IsNullOrWhiteSpace(path))
return Errors.FileManagement.InvalidPathError;
return Errors.FileManagement.InvalidPath;
return new FileSystemPathId(path);
}
#endregion
@@ -1,5 +1,5 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Domain.Common.Enums;
using Lumina.Contracts.Enums.PhotoLibrary;
using Lumina.Domain.Common.Models.Core;
using System.Collections.Generic;
using System.Diagnostics;
@@ -1,10 +1,10 @@
#region ========================================================================= USING =====================================================================================
using System.Diagnostics;
using ErrorOr;
using Lumina.Domain.Common.Enums;
using Lumina.Domain.Common.Models.Core;
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.Core.Aggregates.MediaContributor.MediaContributorAggregate.ValueObjects;
using System;
using System.Diagnostics;
#endregion
@@ -71,7 +71,6 @@ public class MediaContributor : AggregateRoot<MediaContributorId>
/// <summary>
/// Creates a new instance of the <see cref="MediaContributor"/> class.
/// </summary>
/// <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(MediaContributorName name)
@@ -1,8 +1,9 @@
#region ========================================================================= USING =====================================================================================
using System.Diagnostics;
using ErrorOr;
using Lumina.Domain.Common.Models.Core;
using Lumina.Domain.Common.Primitives;
using System.Collections.Generic;
using System.Diagnostics;
#endregion
namespace Lumina.Domain.Core.Aggregates.MediaContributor.MediaContributorAggregate.ValueObjects;
@@ -1,5 +1,7 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Domain.Common.Models.Core;
using System;
using System.Collections.Generic;
#endregion
namespace Lumina.Domain.Core.Aggregates.MediaContributor.MediaContributorAggregate.ValueObjects;
@@ -1,6 +1,7 @@
#region ========================================================================= USING =====================================================================================
using System.Diagnostics;
using Lumina.Domain.Common.Models.Core;
using System.Collections.Generic;
using System.Diagnostics;
#endregion
namespace Lumina.Domain.Core.Aggregates.MediaContributor.MediaContributorAggregate.ValueObjects;
@@ -1,10 +1,11 @@
#region ========================================================================= USING =====================================================================================
using System.Diagnostics;
using ErrorOr;
using Lumina.Domain.Common.Models.Core;
using Lumina.Domain.Common.ValueObjects.Metadata;
using Lumina.Domain.Core.Aggregates.MediaContributor.MediaContributorAggregate.ValueObjects;
using Lumina.Domain.Core.Aggregates.VideoLibrary.MovieLibraryAggregate.ValueObjects;
using System.Collections.Generic;
using System.Diagnostics;
#endregion
namespace Lumina.Domain.Core.Aggregates.VideoLibrary.MovieLibraryAggregate;
@@ -1,7 +1,11 @@
#region ========================================================================= USING =====================================================================================
using System.Collections.Generic;
#endregion
namespace Lumina.Domain.Core.Aggregates.VideoLibrary.MovieLibraryAggregate.Services;
/// <summary>
/// Service for managing movie libraries.
/// Interface for the service for managing movie libraries.
/// </summary>
public interface IMovieLibraryService
{
@@ -1,5 +1,13 @@
#region ========================================================================= USING =====================================================================================
using System;
using System.Collections.Generic;
#endregion
namespace Lumina.Domain.Core.Aggregates.VideoLibrary.MovieLibraryAggregate.Services;
/// <summary>
/// Service for managing movie libraries.
/// </summary>
public sealed class MovieLibraryService : IMovieLibraryService
{
#region ==================================================================== PROPERTIES =================================================================================
@@ -1,5 +1,8 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Domain.Common.Models.Core;
using System;
using System.Collections.Generic;
using System.Diagnostics;
#endregion
namespace Lumina.Domain.Core.Aggregates.VideoLibrary.MovieLibraryAggregate.ValueObjects;
@@ -7,20 +10,16 @@ namespace Lumina.Domain.Core.Aggregates.VideoLibrary.MovieLibraryAggregate.Value
/// <summary>
/// Value Object for the Id of a movie.
/// </summary>
public sealed class MovieId : ValueObject
{
#region ==================================================================== PROPERTIES =================================================================================
public Guid Value { get; }
#endregion
[DebuggerDisplay("{Value}")]
public sealed class MovieId : EntityId<Guid>
{
#region ====================================================================== CTOR =====================================================================================
/// <summary>
/// Initializes a new instance of the <see cref="MovieId"/> class.
/// </summary>
/// <param name="value">The value representing this object.</param>
private MovieId(Guid value)
private MovieId(Guid value) : base(value)
{
Value = value;
}
#endregion
@@ -2,6 +2,8 @@
using ErrorOr;
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.Common.ValueObjects.Metadata;
using System;
using System.Collections.Generic;
using System.Diagnostics;
#endregion
@@ -98,9 +100,8 @@ public class VideoMetadata : BaseMetadata
/// <param name="audioCodec">The optional audio codec used.</param>
/// <param name="genres">The genres of the video.</param>
/// <param name="tags">The tags associated with the video.</param>
/// <param name="contributors">The list of contributors for this video.</param>
/// <returns>
/// An <see cref="ErrorOr{T}"/> containing either a successfully created <see cref="VideoMetadata"/>, or an error message.
/// An <see cref="ErrorOr{TValue}"/> containing either a successfully created <see cref="VideoMetadata"/>, or an error message.
/// </returns>
public static ErrorOr<VideoMetadata> Create(
string title,
@@ -1,15 +1,18 @@
namespace Lumina.Domain.Core.Aggregates.VideoLibrary.TvShowLibraryAggregate.Services
#region ========================================================================= USING =====================================================================================
using System.Collections.Generic;
#endregion
namespace Lumina.Domain.Core.Aggregates.VideoLibrary.TvShowLibraryAggregate.Services;
/// <summary>
/// Interface for the service for managing TV show libraries.
/// </summary>
public interface ITvShowLibraryService
{
#region ==================================================================== PROPERTIES =================================================================================
/// <summary>
/// Interface for the service for managing TV show libraries.
/// Gets the collection of TV shows in the library.
/// </summary>
public interface ITvShowLibraryService
{
#region ==================================================================== PROPERTIES =================================================================================
/// <summary>
/// Gets the collection of TV shows in the library.
/// </summary>
public ICollection<TvShow> TvShows { get; }
#endregion
}
public ICollection<TvShow> TvShows { get; }
#endregion
}
@@ -1,3 +1,8 @@
#region ========================================================================= USING =====================================================================================
using System;
using System.Collections.Generic;
#endregion
namespace Lumina.Domain.Core.Aggregates.VideoLibrary.TvShowLibraryAggregate.Services;
/// <summary>
@@ -1,5 +1,7 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Domain.Common.Models.Core;
using System;
using System.Collections.Generic;
#endregion
namespace Lumina.Domain.Core.Aggregates.VideoLibrary.TvShowLibraryAggregate.ValueObjects;
@@ -7,20 +9,15 @@ namespace Lumina.Domain.Core.Aggregates.VideoLibrary.TvShowLibraryAggregate.Valu
/// <summary>
/// Value Object for the Id of an episode.
/// </summary>
public sealed class EpisodeId : ValueObject
public sealed class EpisodeId : EntityId<Guid>
{
#region ==================================================================== PROPERTIES =================================================================================
public Guid Value { get; }
#endregion
#region ====================================================================== CTOR =====================================================================================
/// <summary>
/// Initializes a new instance of the <see cref="EpisodeId"/> class.
/// </summary>
/// <param name="value">The value representing this object.</param>
private EpisodeId(Guid value)
private EpisodeId(Guid value) : base(value)
{
Value = value;
}
#endregion
@@ -1,5 +1,7 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Domain.Common.Models.Core;
using System;
using System.Collections.Generic;
#endregion
namespace Lumina.Domain.Core.Aggregates.VideoLibrary.TvShowLibraryAggregate.ValueObjects;
@@ -7,20 +9,15 @@ namespace Lumina.Domain.Core.Aggregates.VideoLibrary.TvShowLibraryAggregate.Valu
/// <summary>
/// Value Object for the Id of a season.
/// </summary>
public sealed class SeasonId : ValueObject
public sealed class SeasonId : EntityId<Guid>
{
#region ==================================================================== PROPERTIES =================================================================================
public Guid Value { get; }
#endregion
#region ====================================================================== CTOR =====================================================================================
/// <summary>
/// Initializes a new instance of the <see cref="SeasonId"/> class.
/// </summary>
/// <param name="value">The value representing this object.</param>
private SeasonId(Guid value)
private SeasonId(Guid value) : base(value)
{
Value = value;
}
#endregion
@@ -1,5 +1,7 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Domain.Common.Models.Core;
using System;
using System.Collections.Generic;
#endregion
namespace Lumina.Domain.Core.Aggregates.VideoLibrary.TvShowLibraryAggregate.ValueObjects;
@@ -7,20 +9,15 @@ namespace Lumina.Domain.Core.Aggregates.VideoLibrary.TvShowLibraryAggregate.Valu
/// <summary>
/// Value Object for the Id of a TV show.
/// </summary>
public sealed class TvShowId : ValueObject
public sealed class TvShowId : EntityId<Guid>
{
#region ==================================================================== PROPERTIES =================================================================================
public Guid Value { get; }
#endregion
#region ====================================================================== CTOR =====================================================================================
/// <summary>
/// Initializes a new instance of the <see cref="TvShowId"/> class.
/// </summary>
/// <param name="value">The value representing this object.</param>
private TvShowId(Guid value)
private TvShowId(Guid value) : base(value)
{
Value = value;
}
#endregion
@@ -1,11 +1,13 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Domain.Common.Enums;
using Lumina.Contracts.Enums.BookLibrary;
using Lumina.Domain.Common.Models.Core;
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.Core.Aggregates.MediaContributor.MediaContributorAggregate.ValueObjects;
using Lumina.Domain.Core.Aggregates.WrittenContentLibrary.BookLibraryAggregate.Entities;
using Lumina.Domain.Core.Aggregates.WrittenContentLibrary.BookLibraryAggregate.ValueObjects;
using System;
using System.Collections.Generic;
using System.Diagnostics;
#endregion
@@ -50,47 +52,47 @@ public sealed class Book : AggregateRoot<BookId>
public Optional<BookSeries> Series { get; private set; }
/// <summary>
/// Gets the ASIN (Amazon Standard Identification Number) of the book.
/// Gets the ASIN (Amazon Standard Identification Number) of the book, if applicable.
/// </summary>
public Optional<string> ASIN { get; private set; }
/// <summary>
/// Gets the Goodreads ID of the book.
/// Gets the Goodreads ID of the book, if applicable.
/// </summary>
public Optional<string> GoodreadsId { get; private set; }
/// <summary>
/// Gets the Library of Congress Control Number (LCCN) of the book.
/// Gets the Library of Congress Control Number (LCCN) of the book, if applicable.
/// </summary>
public Optional<string> LCCN { get; private set; }
/// <summary>
/// Gets the OCLC Number (WorldCat identifier) of the book.
/// Gets the OCLC Number (WorldCat identifier) of the book, if applicable.
/// </summary>
public Optional<string> OCLCNumber { get; private set; }
/// <summary>
/// Gets the Open Library ID of the book.
/// Gets the Open Library ID of the book, if applicable.
/// </summary>
public Optional<string> OpenLibraryId { get; private set; }
/// <summary>
/// Gets the LibraryThing ID of the book.
/// Gets the LibraryThing ID of the book, if applicable.
/// </summary>
public Optional<string> LibraryThingId { get; private set; }
/// <summary>
/// Gets the Google Books ID of the book.
/// Gets the Google Books ID of the book, if applicable.
/// </summary>
public Optional<string> GoogleBooksId { get; private set; }
/// <summary>
/// Gets the Barnes & Noble ID of the book.
/// Gets the Barnes & Noble ID of the book, if applicable.
/// </summary>
public Optional<string> BarnesAndNobleId { get; private set; }
/// <summary>
/// Gets the Apple Books ID of the book.
/// Gets the Apple Books ID of the book, if applicable.
/// </summary>
public Optional<string> AppleBooksId { get; private set; }
@@ -220,7 +222,7 @@ public sealed class Book : AggregateRoot<BookId>
/// <param name="contributors">The list of media contributors of the book.</param>
/// <param name="ratings">The list of ratings for the book.</param>
/// <returns>
/// An <see cref="ErrorOr{T}"/> containing either a successfully created <see cref="Book"/>, or an error message.
/// An <see cref="ErrorOr{TValue}"/> containing either a successfully created <see cref="Book"/>, or an error message.
/// </returns>
public static ErrorOr<Book> Create(
WrittenContentMetadata metadata,
@@ -289,7 +291,7 @@ public sealed class Book : AggregateRoot<BookId>
/// <param name="contributors">The list of media contributors of the book.</param>
/// <param name="ratings">The list of ratings for the book.</param>
/// <returns>
/// An <see cref="ErrorOr{T}"/> containing either a successfully created <see cref="Book"/>, or an error message.
/// An <see cref="ErrorOr{TValue}"/> containing either a successfully created <see cref="Book"/>, or an error message.
/// </returns>
public static ErrorOr<Book> Create(
BookId id,
@@ -1,9 +1,10 @@
#region ========================================================================= USING =====================================================================================
using System.Diagnostics;
using ErrorOr;
using Lumina.Domain.Common.Errors;
using Lumina.Domain.Common.Models.Core;
using Lumina.Domain.Core.Aggregates.WrittenContentLibrary.BookLibraryAggregate.ValueObjects;
using System.Collections.Generic;
using System.Diagnostics;
#endregion
namespace Lumina.Domain.Core.Aggregates.WrittenContentLibrary.BookLibraryAggregate.Entities;
@@ -65,7 +66,7 @@ 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{T}"/> containing either a successfully created <see cref="BookSeries"/>, or an error message.
/// An <see cref="ErrorOr{TValue}"/> containing either a successfully created <see cref="BookSeries"/>, or an error message.
/// </returns>
public static ErrorOr<BookSeries> Create(
BookSeriesId id,
@@ -89,7 +90,7 @@ 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{T}"/> containing either a successfully created <see cref="BookSeries"/>, or an error message.
/// An <see cref="ErrorOr{TValue}"/> containing either a successfully created <see cref="BookSeries"/>, or an error message.
/// </returns>
public static ErrorOr<BookSeries> Create(
WrittenContentMetadata metadata,
@@ -108,7 +109,7 @@ 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{T}"/> representing either a successful operation, or an error.</returns>
/// <returns>An <see cref="ErrorOr{TValue}"/> representing either a successful operation, or an error.</returns>
public ErrorOr<Created> AddBook(Book book)
{
if (_books.Contains(book))
@@ -121,7 +122,7 @@ 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{T}"/> representing either a successful operation, or an error.</returns>
/// <returns>An <see cref="ErrorOr{TValue}"/> representing either a successful operation, or an error.</returns>
public ErrorOr<Deleted> RemoveBook(Book book)
{
if (!_books.Contains(book))
@@ -1,3 +1,8 @@
#region ========================================================================= USING =====================================================================================
using System;
using System.Collections.Generic;
#endregion
namespace Lumina.Domain.Core.Aggregates.WrittenContentLibrary.BookLibraryAggregate.Services;
/// <summary>
@@ -1,7 +1,11 @@
#region ========================================================================= USING =====================================================================================
using System.Collections.Generic;
#endregion
namespace Lumina.Domain.Core.Aggregates.WrittenContentLibrary.BookLibraryAggregate.Services;
/// <summary>
/// Service for managing book libraries.
/// Interface for the service for managing book libraries.
/// </summary>
public interface IBookLibraryService
{
@@ -1,5 +1,8 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Domain.Common.Models.Core;
using System;
using System.Collections.Generic;
using System.Diagnostics;
#endregion
namespace Lumina.Domain.Core.Aggregates.WrittenContentLibrary.BookLibraryAggregate.ValueObjects;
@@ -7,6 +10,7 @@ namespace Lumina.Domain.Core.Aggregates.WrittenContentLibrary.BookLibraryAggrega
/// <summary>
/// Value Object for the Id of a book.
/// </summary>
[DebuggerDisplay("{Value}")]
public sealed class BookId : EntityId<Guid>
{
#region ====================================================================== CTOR =====================================================================================
@@ -1,6 +1,9 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Domain.Common.Models.Core;
using System;
using System.Collections.Generic;
using System.Diagnostics;
#endregion
namespace Lumina.Domain.Core.Aggregates.WrittenContentLibrary.BookLibraryAggregate.ValueObjects;
@@ -8,20 +11,16 @@ namespace Lumina.Domain.Core.Aggregates.WrittenContentLibrary.BookLibraryAggrega
/// <summary>
/// Value Object for the Id of a book library.
/// </summary>
public sealed class BookLibraryId : ValueObject
[DebuggerDisplay("{Value}")]
public sealed class BookLibraryId : EntityId<Guid>
{
#region ==================================================================== PROPERTIES =================================================================================
public Guid Value { get; }
#endregion
#region ====================================================================== CTOR =====================================================================================
/// <summary>
/// Initializes a new instance of the <see cref="BookLibraryId"/> class.
/// </summary>
/// <param name="value">The value representing this object.</param>
private BookLibraryId(Guid value)
private BookLibraryId(Guid value) : base(value)
{
Value = value;
}
#endregion
@@ -1,10 +1,11 @@
#region ========================================================================= USING =====================================================================================
using System.Diagnostics;
using ErrorOr;
using Lumina.Domain.Common.Enums;
using Lumina.Contracts.Enums.BookLibrary;
using Lumina.Domain.Common.Errors;
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.Common.ValueObjects.Metadata;
using Lumina.Domain.Common.Errors;
using System.Collections.Generic;
using System.Diagnostics;
#endregion
namespace Lumina.Domain.Core.Aggregates.WrittenContentLibrary.BookLibraryAggregate.ValueObjects;
@@ -46,7 +47,7 @@ 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{T}"/> containing either a successfully created <see cref="Rating"/>, or an error message.
/// An <see cref="ErrorOr{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)
{
@@ -1,5 +1,8 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Domain.Common.Models.Core;
using System;
using System.Collections.Generic;
using System.Diagnostics;
#endregion
namespace Lumina.Domain.Core.Aggregates.WrittenContentLibrary.BookLibraryAggregate.ValueObjects;
@@ -7,6 +10,7 @@ namespace Lumina.Domain.Core.Aggregates.WrittenContentLibrary.BookLibraryAggrega
/// <summary>
/// Value Object for the Id of a book series.
/// </summary>
[DebuggerDisplay("{Value}")]
public sealed class BookSeriesId : ValueObject
{
#region ==================================================================== PROPERTIES =================================================================================
@@ -1,9 +1,11 @@
#region ========================================================================= USING =====================================================================================
using System.Text.RegularExpressions;
using ErrorOr;
using Lumina.Domain.Common.Enums;
using Lumina.Domain.Common.Models.Core;
using Lumina.Contracts.Enums.BookLibrary;
using Lumina.Domain.Common.Errors;
using Lumina.Domain.Common.Models.Core;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text.RegularExpressions;
#endregion
namespace Lumina.Domain.Core.Aggregates.WrittenContentLibrary.BookLibraryAggregate.ValueObjects;
@@ -11,6 +13,7 @@ namespace Lumina.Domain.Core.Aggregates.WrittenContentLibrary.BookLibraryAggrega
/// <summary>
/// Value Object for the ISBN of a book.
/// </summary>
[DebuggerDisplay("{Value} ({Format})")]
public sealed class Isbn : ValueObject
{
#region ================================================================== FIELD MEMBERS ================================================================================
@@ -1,9 +1,10 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Domain.Common.Errors;
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.Common.ValueObjects.Metadata;
using System.Collections.Generic;
using System.Diagnostics;
using Lumina.Domain.Common.Errors;
#endregion
namespace Lumina.Domain.Core.Aggregates.WrittenContentLibrary.BookLibraryAggregate.ValueObjects;
@@ -73,7 +74,7 @@ public class WrittenContentMetadata : BaseMetadata
/// <param name="publisher">The publisher of the written content.</param>
/// <param name="pageCount">The number of pages in the written content.</param>
/// <returns>
/// An <see cref="ErrorOr{T}"/> containing either a successfully created <see cref="WrittenContentMetadata"/>, or an error message.
/// An <see cref="ErrorOr{TValue}"/> containing either a successfully created <see cref="WrittenContentMetadata"/>, or an error message.
/// </returns>
public static ErrorOr<WrittenContentMetadata> Create(
string title,
+2 -2
View File
@@ -4,7 +4,7 @@
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>disable</ImplicitUsings>
<Nullable>enable</Nullable>
<BaseOutputPath>..\..\bin\</BaseOutputPath>
<BaseOutputPath>$(SolutionDir)..\bin\server\</BaseOutputPath>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
</PropertyGroup>
@@ -22,7 +22,7 @@
</ItemGroup>
<ItemGroup>
<Folder Include="Core\Aggregates\FileManagement\FileManagementAggregate\Entities\" />
<ProjectReference Include="..\Lumina.Contracts\Lumina.Contracts.csproj" />
</ItemGroup>
</Project>