FilePath ready to test
This commit is contained in:
@ -1,75 +1,57 @@
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace View_by_Distance.Shared.Models;
|
||||
|
||||
public class FileHolder : Properties.IFileHolder
|
||||
public record FileHolder(DateTime? CreationTime,
|
||||
string? DirectoryName,
|
||||
bool Exists,
|
||||
string ExtensionLowered,
|
||||
string FullName,
|
||||
DateTime? LastWriteTime,
|
||||
long? Length,
|
||||
string Name,
|
||||
string NameWithoutExtension)
|
||||
{
|
||||
|
||||
protected readonly DateTime? _CreationTime;
|
||||
protected readonly string? _DirectoryName;
|
||||
protected readonly bool _Exists;
|
||||
protected readonly string _ExtensionLowered;
|
||||
protected readonly string _FullName;
|
||||
protected readonly int? _Id;
|
||||
protected readonly DateTime? _LastWriteTime;
|
||||
protected readonly long? _Length;
|
||||
protected readonly string _Name;
|
||||
protected readonly string _NameWithoutExtension;
|
||||
public DateTime? CreationTime => _CreationTime;
|
||||
public string? DirectoryName => _DirectoryName;
|
||||
public bool Exists => _Exists;
|
||||
public string ExtensionLowered => _ExtensionLowered;
|
||||
public string FullName => _FullName;
|
||||
public int? Id => _Id;
|
||||
public DateTime? LastWriteTime => _LastWriteTime;
|
||||
public long? Length => _Length;
|
||||
public string Name => _Name;
|
||||
public string NameWithoutExtension => _NameWithoutExtension;
|
||||
|
||||
public FileHolder(DateTime? creationTime, string? directoryName, bool exists, string extensionLowered, string fullName, int? id, DateTime? lastWriteTime, long? length, string name, string nameWithoutExtension)
|
||||
{
|
||||
_CreationTime = creationTime;
|
||||
_DirectoryName = directoryName;
|
||||
_Exists = exists;
|
||||
_ExtensionLowered = extensionLowered;
|
||||
_FullName = fullName;
|
||||
_Id = id;
|
||||
_LastWriteTime = lastWriteTime;
|
||||
_Length = length;
|
||||
_Name = name;
|
||||
_NameWithoutExtension = nameWithoutExtension;
|
||||
}
|
||||
|
||||
public FileHolder(FileInfo fileInfo, int? id)
|
||||
{
|
||||
if (fileInfo.Exists)
|
||||
{
|
||||
_CreationTime = fileInfo.CreationTime;
|
||||
_CreationTime = fileInfo.CreationTime;
|
||||
_LastWriteTime = fileInfo.LastWriteTime;
|
||||
_Length = fileInfo.Length;
|
||||
}
|
||||
_DirectoryName = fileInfo.DirectoryName;
|
||||
_Exists = fileInfo.Exists;
|
||||
_ExtensionLowered = fileInfo.Extension.ToLower();
|
||||
_Id = id;
|
||||
_FullName = fileInfo.FullName;
|
||||
_Name = fileInfo.Name;
|
||||
_NameWithoutExtension = Path.GetFileNameWithoutExtension(fileInfo.FullName);
|
||||
}
|
||||
|
||||
public FileHolder(string fileName) :
|
||||
this(new FileInfo(fileName), null)
|
||||
{ }
|
||||
|
||||
public FileHolder(string fileName, int? id) :
|
||||
this(new FileInfo(fileName), id)
|
||||
{ }
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
string result = JsonSerializer.Serialize(this, new JsonSerializerOptions() { WriteIndented = true });
|
||||
string result = JsonSerializer.Serialize(this, FileHolderSourceGenerationContext.Default.FileHolder);
|
||||
return result;
|
||||
}
|
||||
|
||||
public static FileHolder Get(FileInfo fileInfo)
|
||||
{
|
||||
FileHolder result;
|
||||
if (!fileInfo.Exists)
|
||||
result = new(null,
|
||||
fileInfo.DirectoryName,
|
||||
fileInfo.Exists,
|
||||
fileInfo.Extension.ToLower(),
|
||||
fileInfo.FullName,
|
||||
null,
|
||||
null,
|
||||
fileInfo.Name,
|
||||
Path.GetFileNameWithoutExtension(fileInfo.FullName));
|
||||
else
|
||||
{
|
||||
result = new(fileInfo.CreationTime,
|
||||
fileInfo.DirectoryName,
|
||||
fileInfo.Exists,
|
||||
fileInfo.Extension.ToLower(),
|
||||
fileInfo.FullName,
|
||||
fileInfo.LastWriteTime,
|
||||
fileInfo.Length,
|
||||
fileInfo.Name,
|
||||
Path.GetFileNameWithoutExtension(fileInfo.FullName));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
[JsonSourceGenerationOptions(WriteIndented = true)]
|
||||
[JsonSerializable(typeof(FileHolder))]
|
||||
public partial class FileHolderSourceGenerationContext : JsonSerializerContext
|
||||
{
|
||||
}
|
Reference in New Issue
Block a user