95 lines
3.9 KiB
C#
95 lines
3.9 KiB
C#
using System.Text.Json;
|
|
using System.Text.Json.Serialization;
|
|
|
|
namespace View_by_Distance.Shared.Models;
|
|
|
|
public class Item : Properties.IItem
|
|
{
|
|
|
|
protected readonly bool? _Abandoned;
|
|
protected readonly bool? _Changed;
|
|
protected List<Closest> _Closest;
|
|
protected List<Face> _Faces;
|
|
protected readonly FileHolder? _ImageFileHolder;
|
|
protected List<Mapping> _Mapping;
|
|
protected bool? _Moved;
|
|
protected readonly bool? _NoJson;
|
|
protected Property? _Property;
|
|
protected readonly string _RelativePath;
|
|
protected FileHolder? _ResizedFileHolder;
|
|
protected readonly string _SourceDirectoryFile;
|
|
protected bool _ValidImageFormatExtension;
|
|
public bool? Abandoned => _Abandoned;
|
|
public bool? Changed => _Changed;
|
|
public List<Closest> Closest => _Closest;
|
|
public List<Face> Faces => _Faces;
|
|
public FileHolder? ImageFileHolder => _ImageFileHolder;
|
|
public List<Mapping> Mapping => _Mapping;
|
|
public bool? Moved => _Moved;
|
|
public bool? NoJson => _NoJson;
|
|
public Property? Property => _Property;
|
|
public string RelativePath => _RelativePath;
|
|
public FileHolder? ResizedFileHolder => _ResizedFileHolder;
|
|
public string SourceDirectoryFile => _SourceDirectoryFile;
|
|
public bool ValidImageFormatExtension => _ValidImageFormatExtension;
|
|
|
|
[JsonConstructor]
|
|
public Item(bool? abandoned, bool? changed, List<Closest> closest, List<Face> faces, FileHolder? imageFileHolder, List<Mapping> mapping, bool? moved, bool? noJson, Property? property, string relativePath, FileHolder? resizedFileHolder, string sourceDirectoryFile, bool validImageFormatExtension)
|
|
{
|
|
_Abandoned = abandoned;
|
|
_Changed = changed;
|
|
_Closest = closest;
|
|
_Faces = faces;
|
|
_ImageFileHolder = imageFileHolder;
|
|
_Mapping = mapping;
|
|
_Moved = moved;
|
|
_NoJson = noJson;
|
|
_Property = property;
|
|
_RelativePath = relativePath;
|
|
_ResizedFileHolder = resizedFileHolder;
|
|
_SourceDirectoryFile = sourceDirectoryFile;
|
|
_ValidImageFormatExtension = validImageFormatExtension;
|
|
}
|
|
|
|
public Item(string sourceDirectoryFile, string relativePath, FileHolder? imageFileInfo, bool isValidImageFormatExtension, Property? property, bool? abandoned, bool? changed)
|
|
{
|
|
_Faces = new();
|
|
_Mapping = new();
|
|
_Closest = new();
|
|
_Changed = changed;
|
|
_Property = property;
|
|
_Abandoned = abandoned;
|
|
_NoJson = abandoned is null;
|
|
_RelativePath = relativePath;
|
|
_ImageFileHolder = imageFileInfo;
|
|
_SourceDirectoryFile = sourceDirectoryFile;
|
|
_ValidImageFormatExtension = isValidImageFormatExtension;
|
|
if (relativePath.EndsWith(".json"))
|
|
throw new ArgumentException("Can not be a *.json file!");
|
|
if (imageFileInfo is not null && imageFileInfo.ExtensionLowered is ".json")
|
|
throw new ArgumentException("Can not be a *.json file!");
|
|
}
|
|
|
|
public override string ToString()
|
|
{
|
|
string result = JsonSerializer.Serialize(this, new JsonSerializerOptions() { WriteIndented = true });
|
|
return result;
|
|
}
|
|
|
|
public void SetMoved(bool moved) => _Moved = moved;
|
|
|
|
public void SetResizedFileHolder(string filenameExtension, FileHolder fileHolder)
|
|
{
|
|
if (fileHolder.ExtensionLowered == filenameExtension)
|
|
_ResizedFileHolder = fileHolder;
|
|
else if (fileHolder.ExtensionLowered.Length > 3 && fileHolder.ExtensionLowered[3] == 'e' && fileHolder.ExtensionLowered.Remove(3, 1) == filenameExtension)
|
|
_ResizedFileHolder = fileHolder;
|
|
else
|
|
_ResizedFileHolder = fileHolder;
|
|
}
|
|
|
|
public bool Any() => (_Abandoned.HasValue && _Abandoned.Value) || (_Changed.HasValue && _Changed.Value) || (_Moved.HasValue && _Moved.Value) || (_NoJson.HasValue && _NoJson.Value);
|
|
|
|
public void Update(Property property) => _Property = property;
|
|
|
|
} |