2022-08-22 09:10:19 -07:00

97 lines
3.5 KiB
C#

using System.Text.Json;
using System.Text.Json.Serialization;
namespace View_by_Distance.Shared.Models;
public class Property : Properties.IProperty
{
protected DateTime _CreationTime;
protected DateTime? _DateTime;
protected DateTime? _DateTimeDigitized;
protected DateTime? _DateTimeOriginal;
protected long _FileSize;
protected DateTime? _GPSDateStamp;
protected int? _Height;
protected int? _Id;
protected int[] _Indices;
protected DateTime _LastWriteTime;
protected string _Make;
protected string _Model;
protected string _Orientation;
protected int? _Width;
public DateTime CreationTime => _CreationTime;
public DateTime? DateTime => _DateTime;
public DateTime? DateTimeDigitized => _DateTimeDigitized;
public DateTime? DateTimeOriginal => _DateTimeOriginal;
public long FileSize => _FileSize;
public DateTime? GPSDateStamp => _GPSDateStamp;
public int? Height => _Height;
public int? Id => _Id;
public int[] Indices => _Indices;
public DateTime LastWriteTime => _LastWriteTime;
public string Make => _Make;
public string Model => _Model;
public string Orientation => _Orientation;
public int? Width => _Width;
[JsonConstructor]
public Property(DateTime creationTime, DateTime? dateTime, DateTime? dateTimeDigitized, DateTime? dateTimeOriginal, long fileSize, DateTime? gpsDateStamp, int? height, int? id, int[] indices, DateTime lastWriteTime, string make, string model, string orientation, int? width)
{
_CreationTime = creationTime;
_DateTime = dateTime;
_DateTimeDigitized = dateTimeDigitized;
_DateTimeOriginal = dateTimeOriginal;
_FileSize = fileSize;
_GPSDateStamp = gpsDateStamp;
_Height = height;
_Id = id;
_Indices = indices;
_LastWriteTime = lastWriteTime;
_Make = make;
_Model = model;
_Orientation = orientation;
_Width = width;
}
public override string ToString()
{
string result = JsonSerializer.Serialize(this, new JsonSerializerOptions() { WriteIndented = true });
return result;
} // ...
public List<DateTime> GetDateTimes() => Stateless.Methods.Property.GetDateTimes(_CreationTime, _LastWriteTime, _DateTime, _DateTimeDigitized, _DateTimeOriginal, _GPSDateStamp);
public (bool?, string[]) IsWrongYear(string filteredSourceDirectoryFile, DateTime? minimumDateTime)
{
string[] results = Array.Empty<string>();
bool? result = null;
string year;
string directoryName;
string[] directorySegments;
string? check = Path.GetFullPath(filteredSourceDirectoryFile);
string? pathRoot = Path.GetPathRoot(filteredSourceDirectoryFile);
if (string.IsNullOrEmpty(pathRoot))
throw new Exception();
if (minimumDateTime.HasValue)
year = minimumDateTime.Value.ToString("yyyy");
else
{
List<DateTime> dateTimes = GetDateTimes();
year = dateTimes.Min().ToString("yyyy");
}
for (int i = 0; i < int.MaxValue; i++)
{
check = Path.GetDirectoryName(check);
if (string.IsNullOrEmpty(check) || check == pathRoot)
break;
directoryName = Path.GetFileName(check);
directorySegments = directoryName.Split(' ');
(result, results) = Stateless.Methods.Property.IsWrongYear(directorySegments, year);
if (result.HasValue)
break;
}
return new(result, results);
}
}