#region ========================================================================= USING =====================================================================================
using Lumina.Application.Common.Mapping.FileSystemManagement.Directories;
using Lumina.Application.Common.Mapping.FileSystemManagement.Files;
using Lumina.Contracts.Entities.FileSystemManagement;
using Lumina.Contracts.Responses.FileSystemManagement.Common;
using Lumina.Domain.Core.Aggregates.FileSystemManagement.FileSystemManagementAggregate;
using Lumina.Domain.Core.Aggregates.FileSystemManagement.FileSystemManagementAggregate.Entities;
using System;
using System.Collections.Generic;
using System.Linq;
#endregion
namespace Lumina.Application.Common.Mapping.FileSystemManagement.FileSystem;
///
/// Extension methods for converting .
///
public static class FileSystemItemMapping
{
///
/// Converts to .
///
/// The domain model to be converted.
/// The converted model.
public static FileSystemItemEntity ToFileSystemItemModel(this FileSystemItem domainModel)
{
return new FileSystemItemEntity(
domainModel.Id.Path,
domainModel.Name,
DateTime.Now,
DateTime.Now
);
}
///
/// Converts to .
///
/// The domain model to be converted.
/// The converted model.
/// Thrown when the provided parameter is not an expected descendant of .
public static FileSystemTreeNodeResponse ToTreeNodeResponse(this FileSystemItem domainModel)
{
if (domainModel is Directory directory)
return directory.ToFileSystemTreeNodeResponse();
else if (domainModel is File file)
return file.ToFileSystemTreeNodeResponse();
else if (domainModel is WindowsRootItem windowsRootItem)
return windowsRootItem.ToTreeNodeResponse();
else if (domainModel is UnixRootItem unixRootItem)
return unixRootItem.ToTreeNodeResponse();
else
throw new ArgumentException("Invalid FileSystemItem");
}
///
/// Converts to .
///
/// The domain models to be converted.
/// The converted models.
public static IEnumerable ToTreeNodeResponses(this IEnumerable domainModels)
{
return domainModels.Select(domainModel => domainModel.ToTreeNodeResponse());
}
}