mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 04:11:10 +00:00
Implements directory browser dialog, part 1: file system treeview
This commit is contained in:
1 parent
4a53348013
commit
4e4ecbbfca
318 files changed
+6012
-1184
No files matched your search
+2
-1
@@ -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,
|
||||
|
||||
+108
-11
@@ -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
|
||||
}
|
||||
+115
-5
@@ -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
|
||||
}
|
||||
+66
@@ -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
|
||||
}
|
||||
+94
@@ -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
|
||||
}
|
||||
+33
-41
@@ -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
|
||||
}
|
||||
}
|
||||
+23
-23
@@ -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
|
||||
}
|
||||
+70
-53
@@ -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);
|
||||
}
|
||||
|
||||
+68
@@ -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
|
||||
}
|
||||
+28
-28
@@ -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
|
||||
}
|
||||
+65
-43
@@ -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
-1
@@ -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;
|
||||
|
||||
+3
-2
@@ -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
|
||||
}
|
||||
}
|
||||
+9
-9
@@ -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
|
||||
}
|
||||
+5
-6
@@ -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
|
||||
}
|
||||
}
|
||||
+20
@@ -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
|
||||
}
|
||||
+10
-10
@@ -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
|
||||
}
|
||||
+4
-5
@@ -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
-1
@@ -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
-1
@@ -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;
|
||||
|
||||
+8
@@ -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
|
||||
}
|
||||
+13
@@ -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
|
||||
}
|
||||
+2
-3
@@ -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
|
||||
|
||||
+7
@@ -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
|
||||
}
|
||||
+22
-6
@@ -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
|
||||
}
|
||||
+41
-6
@@ -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
-1
@@ -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
-1
@@ -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
-1
@@ -1,5 +1,5 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.Common.Enums;
|
||||
using Lumina.Contracts.Enums.FileSystem;
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
#endregion
|
||||
|
||||
+1
-1
@@ -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
-1
@@ -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
-1
@@ -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
-1
@@ -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;
|
||||
|
||||
+2
-3
@@ -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)
|
||||
|
||||
+2
-1
@@ -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;
|
||||
|
||||
+2
@@ -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;
|
||||
|
||||
+2
-1
@@ -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;
|
||||
|
||||
+5
-1
@@ -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
|
||||
{
|
||||
|
||||
+8
@@ -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 =================================================================================
|
||||
|
||||
+7
-8
@@ -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
|
||||
|
||||
|
||||
+3
-2
@@ -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,
|
||||
|
||||
+14
-11
@@ -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
|
||||
}
|
||||
+5
@@ -1,3 +1,8 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.Core.Aggregates.VideoLibrary.TvShowLibraryAggregate.Services;
|
||||
|
||||
/// <summary>
|
||||
|
||||
+4
-7
@@ -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
|
||||
|
||||
|
||||
+4
-7
@@ -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
|
||||
|
||||
|
||||
+4
-7
@@ -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
|
||||
|
||||
|
||||
+14
-12
@@ -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,
|
||||
|
||||
+6
-5
@@ -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))
|
||||
|
||||
+5
@@ -1,3 +1,8 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.Core.Aggregates.WrittenContentLibrary.BookLibraryAggregate.Services;
|
||||
|
||||
/// <summary>
|
||||
|
||||
+5
-1
@@ -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
|
||||
{
|
||||
|
||||
+4
@@ -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 =====================================================================================
|
||||
|
||||
+6
-7
@@ -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
|
||||
|
||||
|
||||
+5
-4
@@ -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)
|
||||
{
|
||||
|
||||
+4
@@ -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 =================================================================================
|
||||
|
||||
+6
-3
@@ -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 ================================================================================
|
||||
|
||||
+3
-2
@@ -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,
|
||||
|
||||
Reference in new issue
Block a user