Ready to test Windows Project
This commit is contained in:
@ -21,29 +21,44 @@ public record FileHolder(DateTime? CreationTime,
|
||||
return result;
|
||||
}
|
||||
|
||||
private static FileHolder GetExisting(NginxFileSystem nginxFileSystem, int? id) =>
|
||||
new(CreationTime: nginxFileSystem.LastModified,
|
||||
DirectoryFullPath: Path.GetDirectoryName(nginxFileSystem.URI?.OriginalString ?? throw new Exception()),
|
||||
Exists: true,
|
||||
ExtensionLowered: Path.GetExtension(nginxFileSystem.Name).ToLower(),
|
||||
FullName: nginxFileSystem.URI?.OriginalString ?? throw new Exception(),
|
||||
Id: id,
|
||||
LastWriteTime: nginxFileSystem.LastModified,
|
||||
Length: nginxFileSystem.Length is null ? null : (long)nginxFileSystem.Length.Value,
|
||||
Name: nginxFileSystem.Name,
|
||||
NameWithoutExtension: Path.GetFileNameWithoutExtension(nginxFileSystem.Name));
|
||||
|
||||
public static FileHolder Get(NginxFileSystem nginxFileSystem) =>
|
||||
GetExisting(nginxFileSystem, id: null);
|
||||
|
||||
private static FileHolder GetExisting(FileInfo fileInfo, int? id) =>
|
||||
new(fileInfo.CreationTime,
|
||||
fileInfo.DirectoryName,
|
||||
fileInfo.Exists,
|
||||
fileInfo.Extension.ToLower(),
|
||||
fileInfo.FullName,
|
||||
id,
|
||||
fileInfo.LastWriteTime,
|
||||
fileInfo.Length,
|
||||
fileInfo.Name,
|
||||
Path.GetFileNameWithoutExtension(fileInfo.FullName));
|
||||
new(CreationTime: fileInfo.CreationTime,
|
||||
DirectoryFullPath: fileInfo.DirectoryName,
|
||||
Exists: fileInfo.Exists,
|
||||
ExtensionLowered: fileInfo.Extension.ToLower(),
|
||||
FullName: fileInfo.FullName,
|
||||
Id: id,
|
||||
LastWriteTime: fileInfo.LastWriteTime,
|
||||
Length: fileInfo.Length,
|
||||
Name: fileInfo.Name,
|
||||
NameWithoutExtension: Path.GetFileNameWithoutExtension(fileInfo.FullName));
|
||||
|
||||
private static FileHolder GetNonExisting(FileInfo fileInfo, int? id) =>
|
||||
new(null,
|
||||
fileInfo.DirectoryName,
|
||||
fileInfo.Exists,
|
||||
fileInfo.Extension.ToLower(),
|
||||
fileInfo.FullName,
|
||||
id,
|
||||
null,
|
||||
null,
|
||||
fileInfo.Name,
|
||||
Path.GetFileNameWithoutExtension(fileInfo.FullName));
|
||||
new(CreationTime: null,
|
||||
DirectoryFullPath: fileInfo.DirectoryName,
|
||||
Exists: fileInfo.Exists,
|
||||
ExtensionLowered: fileInfo.Extension.ToLower(),
|
||||
FullName: fileInfo.FullName,
|
||||
Id: id,
|
||||
LastWriteTime: null,
|
||||
Length: null,
|
||||
Name: fileInfo.Name,
|
||||
NameWithoutExtension: Path.GetFileNameWithoutExtension(fileInfo.FullName));
|
||||
|
||||
public static FileHolder Get(FileInfo fileInfo, int? id) =>
|
||||
fileInfo.Exists ? GetExisting(fileInfo, id) : GetNonExisting(fileInfo, id);
|
||||
@ -52,42 +67,42 @@ public record FileHolder(DateTime? CreationTime,
|
||||
{
|
||||
FileHolder result;
|
||||
DateTime dateTime = new(filePath.CreationTicks);
|
||||
result = new(dateTime,
|
||||
filePath.DirectoryFullPath,
|
||||
true,
|
||||
filePath.ExtensionLowered,
|
||||
filePath.FullName,
|
||||
id,
|
||||
new(filePath.LastWriteTicks),
|
||||
filePath.Length,
|
||||
filePath.Name,
|
||||
Path.GetFileNameWithoutExtension(filePath.FullName));
|
||||
result = new(CreationTime: dateTime,
|
||||
DirectoryFullPath: filePath.DirectoryFullPath,
|
||||
Exists: true,
|
||||
ExtensionLowered: filePath.ExtensionLowered,
|
||||
FullName: filePath.FullName,
|
||||
Id: id,
|
||||
LastWriteTime: new(filePath.LastWriteTicks),
|
||||
Length: filePath.Length,
|
||||
Name: filePath.Name,
|
||||
NameWithoutExtension: Path.GetFileNameWithoutExtension(filePath.FullName));
|
||||
return result;
|
||||
}
|
||||
|
||||
private static FileHolder GetExisting(FileHolder fileHolder) =>
|
||||
new(fileHolder.CreationTime,
|
||||
fileHolder.DirectoryFullPath,
|
||||
fileHolder.Exists,
|
||||
fileHolder.ExtensionLowered,
|
||||
fileHolder.FullName,
|
||||
new(CreationTime: fileHolder.CreationTime,
|
||||
DirectoryFullPath: fileHolder.DirectoryFullPath,
|
||||
Exists: fileHolder.Exists,
|
||||
ExtensionLowered: fileHolder.ExtensionLowered,
|
||||
FullName: fileHolder.FullName,
|
||||
Id: null,
|
||||
fileHolder.LastWriteTime,
|
||||
fileHolder.Length,
|
||||
fileHolder.Name,
|
||||
Path.GetFileNameWithoutExtension(fileHolder.FullName));
|
||||
LastWriteTime: fileHolder.LastWriteTime,
|
||||
Length: fileHolder.Length,
|
||||
Name: fileHolder.Name,
|
||||
NameWithoutExtension: Path.GetFileNameWithoutExtension(fileHolder.FullName));
|
||||
|
||||
private static FileHolder GetNonExisting(FileHolder fileHolder) =>
|
||||
new(null,
|
||||
fileHolder.DirectoryFullPath,
|
||||
fileHolder.Exists,
|
||||
fileHolder.ExtensionLowered,
|
||||
fileHolder.FullName,
|
||||
new(CreationTime: null,
|
||||
DirectoryFullPath: fileHolder.DirectoryFullPath,
|
||||
Exists: fileHolder.Exists,
|
||||
ExtensionLowered: fileHolder.ExtensionLowered,
|
||||
FullName: fileHolder.FullName,
|
||||
Id: null,
|
||||
null,
|
||||
null,
|
||||
fileHolder.Name,
|
||||
Path.GetFileNameWithoutExtension(fileHolder.FullName));
|
||||
LastWriteTime: null,
|
||||
Length: null,
|
||||
Name: fileHolder.Name,
|
||||
NameWithoutExtension: Path.GetFileNameWithoutExtension(fileHolder.FullName));
|
||||
|
||||
public static FileHolder Get(FileHolder fileHolder) =>
|
||||
fileHolder.Exists ? GetExisting(fileHolder) : GetNonExisting(fileHolder);
|
||||
|
30
Shared/Models/FirstPass.cs
Normal file
30
Shared/Models/FirstPass.cs
Normal file
@ -0,0 +1,30 @@
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace View_by_Distance.Shared.Models;
|
||||
|
||||
public record FirstPass(ExifDirectory ExifDirectory,
|
||||
bool FastForwardMovingPictureExpertsGroupUsed,
|
||||
MinimumYearAndPathCombined MinimumYearAndPathCombined,
|
||||
FileHolder[] SidecarFiles)
|
||||
{
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
string result = JsonSerializer.Serialize(this, FirstPassSourceGenerationContext.Default.FilePath);
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
[JsonSourceGenerationOptions(WriteIndented = true)]
|
||||
[JsonSerializable(typeof(FirstPass))]
|
||||
public partial class FirstPassSourceGenerationContext : JsonSerializerContext
|
||||
{
|
||||
}
|
||||
|
||||
[JsonSourceGenerationOptions(WriteIndented = true)]
|
||||
[JsonSerializable(typeof(List<FirstPass>))]
|
||||
public partial class FirstPassCollectionSourceGenerationContext : JsonSerializerContext
|
||||
{
|
||||
}
|
@ -4,7 +4,7 @@ using System.Text.Json.Serialization;
|
||||
|
||||
namespace View_by_Distance.Shared.Models;
|
||||
|
||||
public record MetadataGroup(bool FastForwardMovingPictureExpertsGroupUsed, FilePath FilePath, FileInfo FileInfo, ExifDirectory ExifDirectory, ReadOnlyCollection<FileHolder> SidecarFiles)
|
||||
public record MetadataGroup(bool FastForwardMovingPictureExpertsGroupUsed, FilePath FilePath, MinimumYearAndPathCombined MinimumYearAndPathCombined, ExifDirectory ExifDirectory, ReadOnlyCollection<FileHolder> SidecarFiles)
|
||||
{
|
||||
|
||||
public override string ToString()
|
||||
|
22
Shared/Models/MinimumYearAndFullPath.cs
Normal file
22
Shared/Models/MinimumYearAndFullPath.cs
Normal file
@ -0,0 +1,22 @@
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace View_by_Distance.Shared.Models;
|
||||
|
||||
public record MinimumYearAndPathCombined(int MinimumYear,
|
||||
string PathCombined)
|
||||
{
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
string result = JsonSerializer.Serialize(this, MinimumYearAndPathCombinedSourceGenerationContext.Default.AviDirectory);
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
[JsonSourceGenerationOptions(WriteIndented = true)]
|
||||
[JsonSerializable(typeof(AviDirectory))]
|
||||
public partial class MinimumYearAndPathCombinedSourceGenerationContext : JsonSerializerContext
|
||||
{
|
||||
}
|
52
Shared/Models/NginxFileSystem.cs
Normal file
52
Shared/Models/NginxFileSystem.cs
Normal file
@ -0,0 +1,52 @@
|
||||
using System.Globalization;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace View_by_Distance.Shared.Models;
|
||||
|
||||
public record NginxFileSystem([property: JsonPropertyName("name")] string Name,
|
||||
DateTime? LastModified,
|
||||
[property: JsonPropertyName("mtime")] string MTime,
|
||||
Uri? URI,
|
||||
[property: JsonPropertyName("type")] string Type,
|
||||
[property: JsonPropertyName("size")] float? Length)
|
||||
{
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
string result = JsonSerializer.Serialize(this, NginxFileSystemSourceGenerationContext.Default.NginxFileSystem);
|
||||
return result;
|
||||
}
|
||||
|
||||
public static NginxFileSystem Get(string format, TimeZoneInfo timeZoneInfo, string name, string mTime, Uri uri, string type, float? size)
|
||||
{
|
||||
NginxFileSystem result;
|
||||
DateTime dateTime;
|
||||
DateTime? nullableDateTime;
|
||||
if (mTime.Length != format.Length + 4 || !DateTime.TryParseExact(mTime[..format.Length], format, CultureInfo.InvariantCulture, DateTimeStyles.None, out dateTime))
|
||||
nullableDateTime = null;
|
||||
else
|
||||
nullableDateTime = TimeZoneInfo.ConvertTimeBySystemTimeZoneId(dateTime, mTime[(format.Length + 1)..], timeZoneInfo.Id);
|
||||
result = new(name, nullableDateTime, mTime, new($"{uri.OriginalString}/{name}"), type, size);
|
||||
return result;
|
||||
}
|
||||
|
||||
public static string GetFormat() =>
|
||||
"ddd, dd MMM yyyy HH:mm:ss";
|
||||
|
||||
public static NginxFileSystem Get(string format, TimeZoneInfo timeZoneInfo, Uri uri, NginxFileSystem nginxFileSystem) =>
|
||||
Get(format, timeZoneInfo, nginxFileSystem.Name, nginxFileSystem.MTime, uri, nginxFileSystem.Type, nginxFileSystem.Length);
|
||||
|
||||
}
|
||||
|
||||
[JsonSourceGenerationOptions(WriteIndented = true, DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull)]
|
||||
[JsonSerializable(typeof(NginxFileSystem))]
|
||||
public partial class NginxFileSystemSourceGenerationContext : JsonSerializerContext
|
||||
{
|
||||
}
|
||||
|
||||
[JsonSourceGenerationOptions(WriteIndented = true, DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull)]
|
||||
[JsonSerializable(typeof(NginxFileSystem[]))]
|
||||
public partial class NginxFileSystemCollectionSourceGenerationContext : JsonSerializerContext
|
||||
{
|
||||
}
|
10
Shared/Models/Properties/IWindowsSettings.cs
Normal file
10
Shared/Models/Properties/IWindowsSettings.cs
Normal file
@ -0,0 +1,10 @@
|
||||
namespace View_by_Distance.Shared.Models.Properties;
|
||||
|
||||
public interface IWindowsSettings
|
||||
{
|
||||
|
||||
public string[] IgnoreExtensions { init; get; }
|
||||
public string[] ValidImageFormatExtensions { init; get; }
|
||||
public string[] ValidVideoFormatExtensions { init; get; }
|
||||
|
||||
}
|
@ -16,19 +16,19 @@ internal abstract class Age
|
||||
years += 1;
|
||||
}
|
||||
result = new(minuendTicks - check.AddYears(-1).Ticks);
|
||||
return (years, result);
|
||||
return new(years, result);
|
||||
}
|
||||
|
||||
internal static (int, TimeSpan) GetAge(long minuendTicks, DateTime subtrahend)
|
||||
{
|
||||
(int years, TimeSpan result) = GetAge(minuendTicks, subtrahend.Ticks);
|
||||
return (years, result);
|
||||
return new(years, result);
|
||||
}
|
||||
|
||||
internal static (int, TimeSpan) GetAge(DateTime minuend, DateTime subtrahend)
|
||||
{
|
||||
(int years, TimeSpan result) = GetAge(minuend.Ticks, subtrahend.Ticks);
|
||||
return (years, result);
|
||||
return new(years, result);
|
||||
}
|
||||
|
||||
internal static int? GetApproximateYears(char[] personCharacters, string personDisplayDirectoryName)
|
||||
|
@ -3,10 +3,10 @@ namespace View_by_Distance.Shared.Models.Stateless;
|
||||
public interface IDate
|
||||
{
|
||||
|
||||
(bool?, string[]) TestStatic_IsWrongYear(FilePath filePath, ExifDirectory exifDirectory) =>
|
||||
IsWrongYear(filePath, exifDirectory);
|
||||
static (bool?, string[]) IsWrongYear(FilePath filePath, ExifDirectory exifDirectory) =>
|
||||
XDate.IsWrongYear(filePath, exifDirectory);
|
||||
(bool?, string[]) TestStatic_IsWrongYear(DirectoryInfo directoryInfo, FilePath filePath, ExifDirectory exifDirectory) =>
|
||||
IsWrongYear(directoryInfo, filePath, exifDirectory);
|
||||
static (bool?, string[]) IsWrongYear(DirectoryInfo directoryInfo, FilePath filePath, ExifDirectory exifDirectory) =>
|
||||
XDate.IsWrongYear(directoryInfo, filePath, exifDirectory);
|
||||
|
||||
(int Season, string seasonName) TestStatic_GetSeason(int dayOfYear) =>
|
||||
GetSeason(dayOfYear);
|
||||
|
@ -8,6 +8,7 @@ public interface IRename
|
||||
|
||||
ReadOnlyCollection<string> ConvertAndGetFastForwardMovingPictureExpertsGroupFiles(IRenameSettings renameSettings, FilePath filePath);
|
||||
DeterministicHashCode GetDeterministicHashCode(FilePath filePath);
|
||||
void ConstructProgressBar(int maxTicks, string message);
|
||||
void Tick();
|
||||
|
||||
}
|
15
Shared/Models/Stateless/IWindows.cs
Normal file
15
Shared/Models/Stateless/IWindows.cs
Normal file
@ -0,0 +1,15 @@
|
||||
using System.Collections.ObjectModel;
|
||||
using View_by_Distance.Shared.Models.Properties;
|
||||
|
||||
namespace View_by_Distance.Shared.Models.Stateless;
|
||||
|
||||
public interface IWindows
|
||||
{
|
||||
|
||||
ReadOnlyCollection<string> ConvertAndGetFastForwardMovingPictureExpertsGroupFiles(IWindowsSettings windowsSettings, HttpClient? httpClient, FilePath filePath);
|
||||
DeterministicHashCode GetDeterministicHashCode(HttpClient? httpClient, FilePath filePath);
|
||||
DeterministicHashCode GetDeterministicHashCode(HttpClient httpClient, Uri uri);
|
||||
void ConstructProgressBar(int maxTicks, string message);
|
||||
void Tick();
|
||||
|
||||
}
|
@ -48,7 +48,7 @@ internal abstract class PersonBirthday
|
||||
if (birthday?.Value is null)
|
||||
throw new NullReferenceException(nameof(birthday.Value));
|
||||
(years, result) = Age.GetAge(dateTimeTicks, birthday.Value);
|
||||
return (years, result);
|
||||
return new(years, result);
|
||||
}
|
||||
|
||||
internal static (int, TimeSpan) GetAge(DateTime dateTime, Models.PersonBirthday birthday)
|
||||
@ -58,7 +58,7 @@ internal abstract class PersonBirthday
|
||||
if (birthday?.Value is null)
|
||||
throw new NullReferenceException(nameof(birthday.Value));
|
||||
(years, result) = Age.GetAge(dateTime, birthday.Value);
|
||||
return (years, result);
|
||||
return new(years, result);
|
||||
}
|
||||
|
||||
internal static (int, double) GetAge(DateTime dateTime, DateTime dayBeforeLeapDate, Models.PersonBirthday birthday)
|
||||
@ -69,7 +69,7 @@ internal abstract class PersonBirthday
|
||||
result = timeSpan.TotalDays / 365;
|
||||
else
|
||||
result = timeSpan.TotalDays / 366;
|
||||
return (years, result);
|
||||
return new(years, result);
|
||||
}
|
||||
|
||||
internal static double? GetAge(Models.PersonBirthday birthday)
|
||||
|
@ -58,7 +58,7 @@ internal abstract class XDate
|
||||
return result;
|
||||
}
|
||||
|
||||
internal static (bool?, string[]) IsWrongYear(FilePath filePath, ExifDirectory exifDirectory)
|
||||
internal static (bool?, string[]) IsWrongYear(DirectoryInfo directoryInfo, FilePath filePath, ExifDirectory exifDirectory)
|
||||
{
|
||||
string[] results = [];
|
||||
bool? result = null;
|
||||
@ -67,9 +67,6 @@ internal abstract class XDate
|
||||
string[] directorySegments;
|
||||
List<DateTime> collection = [];
|
||||
string? check = Path.GetFullPath(filePath.FullName);
|
||||
string? pathRoot = Path.GetPathRoot(filePath.FullName);
|
||||
if (string.IsNullOrEmpty(pathRoot))
|
||||
throw new Exception();
|
||||
DateTime? dateTimeOriginal = GetDateTimeOriginal(exifDirectory);
|
||||
if (dateTimeOriginal is not null)
|
||||
collection.Add(dateTimeOriginal.Value);
|
||||
@ -85,7 +82,7 @@ internal abstract class XDate
|
||||
for (int i = 0; i < int.MaxValue; i++)
|
||||
{
|
||||
check = Path.GetDirectoryName(check);
|
||||
if (string.IsNullOrEmpty(check) || check == pathRoot)
|
||||
if (string.IsNullOrEmpty(check) || check == directoryInfo.FullName)
|
||||
break;
|
||||
directoryName = Path.GetFileName(check);
|
||||
directorySegments = directoryName.Split(' ');
|
||||
|
@ -281,19 +281,19 @@ internal abstract class XPath
|
||||
result = check;
|
||||
converted = int.Parse(check);
|
||||
}
|
||||
return (result, converted);
|
||||
return new(result, converted);
|
||||
}
|
||||
|
||||
internal static (string, int) GetDirectoryNameAndIndex(ResultSettings resultSettings, int id)
|
||||
{
|
||||
(string result, int converted) = GetDirectoryNameAndIndex(resultSettings.ResultAllInOneSubdirectoryLength, id.ToString());
|
||||
return (result, converted);
|
||||
return new(result, converted);
|
||||
}
|
||||
|
||||
internal static (string, int) GetDirectoryNameAndIndex(ResultSettings resultSettings, FileHolder fileHolder)
|
||||
{
|
||||
(string result, int converted) = GetDirectoryNameAndIndex(resultSettings.ResultAllInOneSubdirectoryLength, fileHolder.NameWithoutExtension);
|
||||
return (result, converted);
|
||||
return new(result, converted);
|
||||
}
|
||||
|
||||
internal static (string, int) GetDirectoryNameAndIndex(ResultSettings resultSettings, FilePath filePath)
|
||||
@ -304,7 +304,7 @@ internal abstract class XPath
|
||||
(result, converted) = GetDirectoryNameAndIndex(resultSettings.ResultAllInOneSubdirectoryLength, filePath.Id.Value.ToString());
|
||||
else
|
||||
(result, converted) = GetDirectoryNameAndIndex(resultSettings.ResultAllInOneSubdirectoryLength, filePath.NameWithoutExtension);
|
||||
return (result, converted);
|
||||
return new(result, converted);
|
||||
}
|
||||
|
||||
private static ReadOnlyCollection<int> GetYears(ResultSettings resultSettings)
|
||||
|
Reference in New Issue
Block a user