.editorconfig
JSON002
Private
IDE0230
Use Immich assets for random
This commit is contained in:
Mike Phares 2024-05-11 14:23:01 -07:00
parent c9dbce3b57
commit bf2d6849b3
26 changed files with 215 additions and 63 deletions

View File

@ -82,33 +82,60 @@ csharp_style_var_elsewhere = false:warning
csharp_style_var_for_built_in_types = false:warning csharp_style_var_for_built_in_types = false:warning
csharp_style_var_when_type_is_apparent = false:warning csharp_style_var_when_type_is_apparent = false:warning
csharp_using_directive_placement = outside_namespace csharp_using_directive_placement = outside_namespace
dotnet_analyzer_diagnostic.category-Design.severity = error
dotnet_analyzer_diagnostic.category-Documentation.severity = error
dotnet_analyzer_diagnostic.category-Globalization.severity = none
dotnet_analyzer_diagnostic.category-Interoperability.severity = error
dotnet_analyzer_diagnostic.category-Maintainability.severity = error
dotnet_analyzer_diagnostic.category-Naming.severity = none
dotnet_analyzer_diagnostic.category-Performance.severity = none
dotnet_analyzer_diagnostic.category-Reliability.severity = error
dotnet_analyzer_diagnostic.category-Security.severity = error
dotnet_analyzer_diagnostic.category-SingleFile.severity = error
dotnet_analyzer_diagnostic.category-Style.severity = error
dotnet_analyzer_diagnostic.category-Usage.severity = error
dotnet_code_quality_unused_parameters = all dotnet_code_quality_unused_parameters = all
dotnet_code_quality_unused_parameters = non_public # IDE0060: Remove unused parameter dotnet_code_quality_unused_parameters = non_public # IDE0060: Remove unused parameter
dotnet_code_quality.CAXXXX.api_surface = private, internal dotnet_code_quality.CAXXXX.api_surface = private, internal
dotnet_diagnostic.CA1001.severity = none # CA1001: Types that own disposable fields should be disposable
dotnet_diagnostic.CA1051.severity = none # CA1051: Do not declare visible instance fields
dotnet_diagnostic.CA1511.severity = warning # CA1511: Use 'ArgumentException.ThrowIfNullOrEmpty' instead of explicitly throwing a new exception instance dotnet_diagnostic.CA1511.severity = warning # CA1511: Use 'ArgumentException.ThrowIfNullOrEmpty' instead of explicitly throwing a new exception instance
dotnet_diagnostic.CA1511.severity = warning # CA1511: Use 'ArgumentException.ThrowIfNullOrEmpty' instead of explicitly throwing a new exception instance
dotnet_diagnostic.CA1513.severity = warning # Use 'ObjectDisposedException.ThrowIf' instead of explicitly throwing a new exception instance
dotnet_diagnostic.CA1816.severity = none # CA1816: Call GC.SuppressFinalize correctly
dotnet_diagnostic.CA1825.severity = warning # CA1823: Avoid zero-length array allocations dotnet_diagnostic.CA1825.severity = warning # CA1823: Avoid zero-length array allocations
dotnet_diagnostic.CA1829.severity = warning # CA1829: Use Length/Count property instead of Count() when available dotnet_diagnostic.CA1829.severity = warning # CA1829: Use Length/Count property instead of Count() when available
dotnet_diagnostic.CA1834.severity = warning # CA1834: Consider using 'StringBuilder.Append(char)' when applicable dotnet_diagnostic.CA1834.severity = warning # CA1834: Consider using 'StringBuilder.Append(char)' when applicable
dotnet_diagnostic.CA1854.severity = warning # CA1854: Prefer a 'TryGetValue' call over a Dictionary indexer access guarded by a 'ContainsKey' check to avoid double lookup
dotnet_diagnostic.CA1860.severity = warning # CA1860: Prefer comparing 'Count' to 0 rather than using 'Any()', both for clarity and for performance dotnet_diagnostic.CA1860.severity = warning # CA1860: Prefer comparing 'Count' to 0 rather than using 'Any()', both for clarity and for performance
dotnet_diagnostic.CA1861.severity = none # CA1861: Prefer 'static readonly' fields over constant array arguments
dotnet_diagnostic.CA1862.severity = warning # CA1862: Prefer using 'string.Equals(string, StringComparison)' to perform a case-insensitive comparison, but keep in mind that this might cause subtle changes in behavior, so make sure to conduct thorough testing after applying the suggestion, or if culturally sensitive comparison is not required, consider using 'StringComparison.OrdinalIgnoreCase' dotnet_diagnostic.CA1862.severity = warning # CA1862: Prefer using 'string.Equals(string, StringComparison)' to perform a case-insensitive comparison, but keep in mind that this might cause subtle changes in behavior, so make sure to conduct thorough testing after applying the suggestion, or if culturally sensitive comparison is not required, consider using 'StringComparison.OrdinalIgnoreCase'
dotnet_diagnostic.CA1866.severity = none # CA1866: Use 'string.EndsWith(char)' instead of 'string.EndsWith(string)' when you have a string with a single char
dotnet_diagnostic.CA1869.severity = none # CA1869: Avoid creating a new 'JsonSerializerOptions' instance for every serialization operation. Cache and reuse instances instead. dotnet_diagnostic.CA1869.severity = none # CA1869: Avoid creating a new 'JsonSerializerOptions' instance for every serialization operation. Cache and reuse instances instead.
dotnet_diagnostic.CA2201.severity = none # CA2201: Exception type System.NullReferenceException is reserved by the runtime
dotnet_diagnostic.CA2254.severity = none # CA2254: The logging message template should not vary between calls to 'LoggerExtensions.LogInformation(ILogger, string?, params object?[])' dotnet_diagnostic.CA2254.severity = none # CA2254: The logging message template should not vary between calls to 'LoggerExtensions.LogInformation(ILogger, string?, params object?[])'
dotnet_diagnostic.IDE0001.severity = warning # IDE0001: Simplify name dotnet_diagnostic.IDE0001.severity = warning # IDE0001: Simplify name
dotnet_diagnostic.IDE0002.severity = warning # Simplify (member access) - System.Version.Equals("1", "2"); Version.Equals("1", "2"); dotnet_diagnostic.IDE0002.severity = warning # Simplify (member access) - System.Version.Equals("1", "2"); Version.Equals("1", "2");
dotnet_diagnostic.IDE0004.severity = warning # IDE0004: Cast is redundant. dotnet_diagnostic.IDE0004.severity = warning # IDE0004: Cast is redundant.
dotnet_diagnostic.IDE0005.severity = warning # Using directive is unnecessary dotnet_diagnostic.IDE0005.severity = warning # Using directive is unnecessary
dotnet_diagnostic.IDE0010.severity = none # Add missing cases to switch statement (IDE0010)
dotnet_diagnostic.IDE0028.severity = warning # IDE0028: Collection initialization can be simplified dotnet_diagnostic.IDE0028.severity = warning # IDE0028: Collection initialization can be simplified
dotnet_diagnostic.IDE0031.severity = warning # Use null propagation (IDE0031) dotnet_diagnostic.IDE0031.severity = warning # Use null propagation (IDE0031)
dotnet_diagnostic.IDE0047.severity = warning # IDE0047: Parentheses can be removed dotnet_diagnostic.IDE0047.severity = warning # IDE0047: Parentheses can be removed
dotnet_diagnostic.IDE0048.severity = none # Parentheses preferences (IDE0047 and IDE0048)
dotnet_diagnostic.IDE0049.severity = warning # Use language keywords instead of framework type names for type references (IDE0049) dotnet_diagnostic.IDE0049.severity = warning # Use language keywords instead of framework type names for type references (IDE0049)
dotnet_diagnostic.IDE0051.severity = error # Private member '' is unused [, ]
dotnet_diagnostic.IDE0058.severity = warning # IDE0058: Expression value is never used dotnet_diagnostic.IDE0058.severity = warning # IDE0058: Expression value is never used
dotnet_diagnostic.IDE0060.severity = warning # IDE0060: Remove unused parameter dotnet_diagnostic.IDE0060.severity = warning # IDE0060: Remove unused parameter
dotnet_diagnostic.IDE0074.severity = warning # IDE0074: Use compound assignment dotnet_diagnostic.IDE0074.severity = warning # IDE0074: Use compound assignment
dotnet_diagnostic.IDE0130.severity = none # Namespace does not match folder structure (IDE0130)
dotnet_diagnostic.IDE0200.severity = warning # IDE0200: Lambda expression can be removed [Map] dotnet_diagnostic.IDE0200.severity = warning # IDE0200: Lambda expression can be removed [Map]
dotnet_diagnostic.IDE0230.severity = warning # IDE0230: Use UTF-8 string literal
dotnet_diagnostic.IDE0290.severity = none # Use primary constructor [Distance]csharp(IDE0290) dotnet_diagnostic.IDE0290.severity = none # Use primary constructor [Distance]csharp(IDE0290)
dotnet_diagnostic.IDE0300.severity = warning # IDE0300: Collection initialization can be simplified dotnet_diagnostic.IDE0300.severity = warning # IDE0300: Collection initialization can be simplified
dotnet_diagnostic.IDE0301.severity = warning #IDE0301: Collection initialization can be simplified dotnet_diagnostic.IDE0301.severity = warning #IDE0301: Collection initialization can be simplified
dotnet_diagnostic.IDE0305.severity = none # IDE0305: Collection initialization can be simplified dotnet_diagnostic.IDE0305.severity = none # IDE0305: Collection initialization can be simplified
dotnet_diagnostic.JSON002.severity = warning # JSON002: Probable JSON string detected
dotnet_naming_rule.abstract_method_should_be_pascal_case.severity = warning dotnet_naming_rule.abstract_method_should_be_pascal_case.severity = warning
dotnet_naming_rule.abstract_method_should_be_pascal_case.style = pascal_case dotnet_naming_rule.abstract_method_should_be_pascal_case.style = pascal_case
dotnet_naming_rule.abstract_method_should_be_pascal_case.symbols = abstract_method dotnet_naming_rule.abstract_method_should_be_pascal_case.symbols = abstract_method

2
.gitignore vendored
View File

@ -468,3 +468,5 @@ globalStorage/
[Ll]ib/ [Ll]ib/
Shared/.kanbn Shared/.kanbn
.Immich/immich-assets.json

3
.vscode/mklink.md vendored
View File

@ -7,8 +7,9 @@ updated: "2023-10-20T03:57:15.006Z"
# mklink # mklink
```bash ```bash
mklink /J "D:\1-Images-A\Images-4083e56a-Results\A2)People\4083e56a\{}\!" "D:\1-Images-A\Images-4083e56a-Results\E)Distance\4083e56a\{}\!"
``` ```
```bash ```bash
mklink /J "D:\1-Images-A\Images-4083e56a-Results\A2)People\4083e56a\{}\!" "D:\1-Images-A\Images-4083e56a-Results\E)Distance\4083e56a\{}\!" mklink /J "L:\Git\View-by-Distance-MKLink-Console\.Immich" "D:\1-Images-A\Images-c9dbce3b-Results\F)Immich\c9dbce3b\{}"
``` ```

View File

@ -20,6 +20,7 @@
"Hasher", "Hasher",
"Hmmss", "Hmmss",
"Hmmssfff", "Hmmssfff",
"Immich",
"jfif", "jfif",
"JOSN", "JOSN",
"mmod", "mmod",
@ -39,6 +40,7 @@
"Subfile", "Subfile",
"Subfiles", "Subfiles",
"Syncthing", "Syncthing",
"Thumbhash",
"Unmanaged", "Unmanaged",
"Upsample", "Upsample",
"Vericruz" "Vericruz"

View File

@ -341,8 +341,9 @@ public partial class E_Distance : IDistance
continue; continue;
if (!configuration.ReMap && face.Mapping.MappingFromPerson is not null) if (!configuration.ReMap && face.Mapping.MappingFromPerson is not null)
continue; continue;
if (!configuration.ReMap && face.FaceEncoding is not null && face.FaceDistance?.Encoding is not null && face.FaceDistance.Encoding is FaceRecognitionDotNet.FaceEncoding _) if (!configuration.ReMap && face.FaceEncoding is not null && face.FaceDistance?.Encoding is not null && face.FaceDistance.Encoding is FaceRecognitionDotNet.FaceEncoding)
throw new NotSupportedException($"{face.Mapping.MappingFromPerson} should not be null!"); // throw new NotSupportedException($"{face.FaceEncoding} should not be null!");
continue;
faces.Add(face); faces.Add(face);
} }
int totalSeconds = (int)Math.Floor(new TimeSpan(DateTime.Now.Ticks - ticks).TotalSeconds); int totalSeconds = (int)Math.Floor(new TimeSpan(DateTime.Now.Ticks - ticks).TotalSeconds);

View File

@ -59,7 +59,7 @@ public partial class DragDropExplorer : Form
Controls.Add(_FirstTextBox); Controls.Add(_FirstTextBox);
} }
void Form1_Load(object? sender, EventArgs e) private void Form1_Load(object? sender, EventArgs e)
{ {
try try
{ {
@ -81,7 +81,7 @@ public partial class DragDropExplorer : Form
return result; return result;
} }
void TextBox_LostFocus(object? sender, EventArgs e) private void TextBox_LostFocus(object? sender, EventArgs e)
{ {
try try
{ {
@ -99,7 +99,7 @@ public partial class DragDropExplorer : Form
} }
} }
void Form1_DragEnter(object? sender, DragEventArgs e) private void Form1_DragEnter(object? sender, DragEventArgs e)
{ {
try try
{ {
@ -112,7 +112,7 @@ public partial class DragDropExplorer : Form
} }
} }
void Form1_DragDrop(object? sender, DragEventArgs e) private void Form1_DragDrop(object? sender, DragEventArgs e)
{ {
try try
{ {

View File

@ -6,7 +6,7 @@ public class Program
/// The main entry point for the application. /// The main entry point for the application.
/// </summary> /// </summary>
[STAThread] [STAThread]
static void Main() private static void Main()
{ {
ApplicationConfiguration.Initialize(); ApplicationConfiguration.Initialize();
Application.Run(new DragDropExplorer()); Application.Run(new DragDropExplorer());

View File

@ -6,7 +6,7 @@ public class Program
/// The main entry point for the application. /// The main entry point for the application.
/// </summary> /// </summary>
[STAThread] [STAThread]
static void Main() private static void Main()
{ {
ApplicationConfiguration.Initialize(); ApplicationConfiguration.Initialize();
Application.Run(new DragDropMove()); Application.Run(new DragDropMove());

View File

@ -64,7 +64,7 @@ public partial class DragDropSearch : Form
Controls.Add(_TextBox); Controls.Add(_TextBox);
} }
void Form1_Load(object? sender, EventArgs e) private void Form1_Load(object? sender, EventArgs e)
{ {
try try
{ {
@ -79,7 +79,7 @@ public partial class DragDropSearch : Form
} }
} }
void TextBox_LostFocus(object? sender, EventArgs e) private void TextBox_LostFocus(object? sender, EventArgs e)
{ {
try try
{ {
@ -92,7 +92,7 @@ public partial class DragDropSearch : Form
} }
} }
void Form1_DragEnter(object? sender, DragEventArgs e) private void Form1_DragEnter(object? sender, DragEventArgs e)
{ {
try try
{ {
@ -105,7 +105,7 @@ public partial class DragDropSearch : Form
} }
} }
void LoadData() private void LoadData()
{ {
Container[] containers; Container[] containers;
string aPropertySingletonDirectory = Property.Models.Stateless.IResult.GetResultsDateGroupDirectory(_Configuration.PropertyConfiguration, nameof(A_Property), "{}"); string aPropertySingletonDirectory = Property.Models.Stateless.IResult.GetResultsDateGroupDirectory(_Configuration.PropertyConfiguration, nameof(A_Property), "{}");
@ -168,7 +168,7 @@ public partial class DragDropSearch : Form
} }
} }
void Form1_DragDrop(object? sender, DragEventArgs e) private void Form1_DragDrop(object? sender, DragEventArgs e)
{ {
try try
{ {

View File

@ -8,7 +8,7 @@ public class Program
/// The main entry point for the application. /// The main entry point for the application.
/// </summary> /// </summary>
[STAThread] [STAThread]
static void Main() private static void Main()
{ {
ApplicationConfiguration.Initialize(); ApplicationConfiguration.Initialize();
Application.Run(new DragDropSearch()); Application.Run(new DragDropSearch());

View File

@ -6,7 +6,7 @@ public class Program
/// The main entry point for the application. /// The main entry point for the application.
/// </summary> /// </summary>
[STAThread] [STAThread]
static void Main() private static void Main()
{ {
ApplicationConfiguration.Initialize(); ApplicationConfiguration.Initialize();
Application.Run(new DragDropSetPropertyItem()); Application.Run(new DragDropSetPropertyItem());

View File

@ -26,16 +26,15 @@ public abstract class DisposableObject : IDisposable
/// <summary> /// <summary>
/// If this object is disposed, then <see cref="ObjectDisposedException"/> is thrown. /// If this object is disposed, then <see cref="ObjectDisposedException"/> is thrown.
/// </summary> /// </summary>
public void ThrowIfDisposed() public void ThrowIfDisposed() =>
{ ObjectDisposedException.ThrowIf(IsDisposed, this);
if (IsDisposed)
throw new ObjectDisposedException(GetType().FullName);
}
internal void ThrowIfDisposed(string objectName) internal void ThrowIfDisposed(string objectName)
{ {
#pragma warning disable CA1513
if (IsDisposed) if (IsDisposed)
throw new ObjectDisposedException(objectName); throw new ObjectDisposedException(objectName);
#pragma warning restore CA1513
} }
#region Overrides #region Overrides

View File

@ -167,7 +167,13 @@ public class FaceRecognition : DisposableObject
} }
else else
{ {
ShapePredictor posePredictor = _PredictorModel switch { PredictorModel.Large => _PosePredictor68Point, PredictorModel.Small => _PosePredictor5Point, _ => throw new Exception() }; ShapePredictor posePredictor = _PredictorModel switch
{
PredictorModel.Large => _PosePredictor68Point,
PredictorModel.Small => _PosePredictor5Point,
PredictorModel.Custom => throw new NotImplementedException(),
_ => throw new Exception()
};
foreach (Location location in locations) foreach (Location location in locations)
{ {
DlibDotNet.Rectangle rectangle = new(location.Left, location.Top, location.Right, location.Bottom); DlibDotNet.Rectangle rectangle = new(location.Left, location.Top, location.Right, location.Bottom);
@ -422,8 +428,10 @@ public class FaceRecognition : DisposableObject
faceEncodingToCompare.ThrowIfDisposed(); faceEncodingToCompare.ThrowIfDisposed();
foreach (FaceDistance faceDistance in faceDistances) foreach (FaceDistance faceDistance in faceDistances)
{ {
#pragma warning disable CA1513
if (faceDistance.Encoding is not FaceEncoding faceEncoding || faceEncoding.IsDisposed) if (faceDistance.Encoding is not FaceEncoding faceEncoding || faceEncoding.IsDisposed)
throw new ObjectDisposedException($"{nameof(faceDistances)} contains disposed object."); throw new ObjectDisposedException($"{nameof(faceDistances)} contains disposed object.");
#pragma warning restore CA1513
using (Matrix<double> diff = faceEncoding.Encoding - faceEncodingToCompare.Encoding) using (Matrix<double> diff = faceEncoding.Encoding - faceEncodingToCompare.Encoding)
length = DlibDotNet.Dlib.Length(diff); length = DlibDotNet.Dlib.Length(diff);
result = new(faceDistance, length); result = new(faceDistance, length);

View File

@ -263,7 +263,7 @@ public partial class DlibDotNet
return new(results); return new(results);
} }
private static void DeleteContinueFiles(Property.Models.Configuration propertyConfiguration, ReadOnlyCollection<PersonContainer> personContainers) private static void DeleteContinueFiles(ReadOnlyCollection<PersonContainer> personContainers)
{ {
foreach (PersonContainer personContainer in personContainers) foreach (PersonContainer personContainer in personContainers)
{ {
@ -373,7 +373,7 @@ public partial class DlibDotNet
ReadOnlyCollection<Container> readOnlyContainers = new(containers); ReadOnlyCollection<Container> readOnlyContainers = new(containers);
SaveDistinctIds(_Configuration.PropertyConfiguration, bResultsFullGroupDirectory, readOnlyContainers); SaveDistinctIds(_Configuration.PropertyConfiguration, bResultsFullGroupDirectory, readOnlyContainers);
mapLogic ??= new(_AppSettings.MaxDegreeOfParallelism, _Configuration.PropertyConfiguration, _MapConfiguration, _Distance, personContainers, ticks, a2PeopleContentDirectory, a2PeopleSingletonDirectory, eDistanceContentDirectory); mapLogic ??= new(_AppSettings.MaxDegreeOfParallelism, _Configuration.PropertyConfiguration, _MapConfiguration, _Distance, personContainers, ticks, a2PeopleContentDirectory, a2PeopleSingletonDirectory, eDistanceContentDirectory);
DeleteContinueFiles(_Configuration.PropertyConfiguration, personContainers); DeleteContinueFiles(personContainers);
FullDoWork(argZero, propertyRoot, ticks, aResultsFullGroupDirectory, bResultsFullGroupDirectory, fPhotoPrismSingletonDirectory, t, readOnlyContainers, propertyLogic, mapLogic); FullDoWork(argZero, propertyRoot, ticks, aResultsFullGroupDirectory, bResultsFullGroupDirectory, fPhotoPrismSingletonDirectory, t, readOnlyContainers, propertyLogic, mapLogic);
ReadOnlyCollection<Item> distinctValidImageItems = Shared.Models.Stateless.Methods.IContainer.GetValidImageItems(_Configuration.PropertyConfiguration, readOnlyContainers, distinctItems: true, filterItems: true); ReadOnlyCollection<Item> distinctValidImageItems = Shared.Models.Stateless.Methods.IContainer.GetValidImageItems(_Configuration.PropertyConfiguration, readOnlyContainers, distinctItems: true, filterItems: true);
if (_Configuration.LookForAbandoned) if (_Configuration.LookForAbandoned)
@ -414,7 +414,7 @@ public partial class DlibDotNet
&& _Exceptions.Count == 0) && _Exceptions.Count == 0)
MapLogic(ticks, readOnlyContainers, fPhotoPrismContentDirectory, mapLogic, outputResolution, new(personKeyToIds), distinctValidImageFaces, distinctValidImageMappingCollection); MapLogic(ticks, readOnlyContainers, fPhotoPrismContentDirectory, mapLogic, outputResolution, new(personKeyToIds), distinctValidImageFaces, distinctValidImageMappingCollection);
if (runToDoCollectionFirst && _Configuration.SaveRandomForOutputResolutions.Contains(outputResolution) && personKeyToIds.Count > 0 && distinctValidImageMappingCollection.Count > 0) if (runToDoCollectionFirst && _Configuration.SaveRandomForOutputResolutions.Contains(outputResolution) && personKeyToIds.Count > 0 && distinctValidImageMappingCollection.Count > 0)
_Random.Random(_Configuration.PropertyConfiguration, _Configuration.RadomUseBirthdayMinimum, _Configuration.ValidKeyWordsToIgnoreInRandom, personKeyToIds, notNineCollection, distinctValidImageMappingCollection); _Random.Random(_Configuration.PropertyConfiguration, _Configuration.ImmichAssetsFile, _Configuration.RadomUseBirthdayMinimum, _Configuration.ValidKeyWordsToIgnoreInRandom, personKeyToIds, notNineCollection, distinctValidImageMappingCollection);
if (_IsEnvironment.Development) if (_IsEnvironment.Development)
continue; continue;
if (!_IsEnvironment.Development) if (!_IsEnvironment.Development)

View File

@ -27,6 +27,7 @@ public class Configuration
public bool? ForceMetadataLastWriteTimeToCreationTime { get; set; } public bool? ForceMetadataLastWriteTimeToCreationTime { get; set; }
public bool? ForceResizeLastWriteTimeToCreationTime { get; set; } public bool? ForceResizeLastWriteTimeToCreationTime { get; set; }
public string? GenealogicalDataCommunicationFile { get; set; } public string? GenealogicalDataCommunicationFile { get; set; }
public string? ImmichAssetsFile { get; set; }
public string[]? IgnoreExtensions { get; set; } public string[]? IgnoreExtensions { get; set; }
public string[]? JLinks { get; set; } public string[]? JLinks { get; set; }
public string? LinkedAlpha { get; set; } public string? LinkedAlpha { get; set; }
@ -145,6 +146,7 @@ public class Configuration
if (configuration?.ForceMetadataLastWriteTimeToCreationTime is null) throw new NullReferenceException(nameof(configuration.ForceMetadataLastWriteTimeToCreationTime)); if (configuration?.ForceMetadataLastWriteTimeToCreationTime is null) throw new NullReferenceException(nameof(configuration.ForceMetadataLastWriteTimeToCreationTime));
if (configuration?.ForceResizeLastWriteTimeToCreationTime is null) throw new NullReferenceException(nameof(configuration.ForceResizeLastWriteTimeToCreationTime)); if (configuration?.ForceResizeLastWriteTimeToCreationTime is null) throw new NullReferenceException(nameof(configuration.ForceResizeLastWriteTimeToCreationTime));
if (configuration?.GenealogicalDataCommunicationFile is null) throw new NullReferenceException(nameof(configuration.GenealogicalDataCommunicationFile)); if (configuration?.GenealogicalDataCommunicationFile is null) throw new NullReferenceException(nameof(configuration.GenealogicalDataCommunicationFile));
if (configuration?.ImmichAssetsFile is null) throw new NullReferenceException(nameof(configuration.ImmichAssetsFile));
// if (configuration?.IgnoreExtensions is null) throw new NullReferenceException(nameof(configuration.IgnoreExtensions)); // if (configuration?.IgnoreExtensions is null) throw new NullReferenceException(nameof(configuration.IgnoreExtensions));
// if (configuration?.JLinks is null) throw new NullReferenceException(nameof(configuration.JLinks)); // if (configuration?.JLinks is null) throw new NullReferenceException(nameof(configuration.JLinks));
// if (configuration?.LinkedAlpha is null) throw new NullReferenceException(nameof(configuration.LinkedAlpha)); // if (configuration?.LinkedAlpha is null) throw new NullReferenceException(nameof(configuration.LinkedAlpha));
@ -235,6 +237,7 @@ public class Configuration
configuration.ForceMetadataLastWriteTimeToCreationTime.Value, configuration.ForceMetadataLastWriteTimeToCreationTime.Value,
configuration.ForceResizeLastWriteTimeToCreationTime.Value, configuration.ForceResizeLastWriteTimeToCreationTime.Value,
configuration.GenealogicalDataCommunicationFile, configuration.GenealogicalDataCommunicationFile,
configuration.ImmichAssetsFile,
configuration.IgnoreExtensions ?? [], configuration.IgnoreExtensions ?? [],
configuration.JLinks ?? [], configuration.JLinks ?? [],
configuration.LinkedAlpha, configuration.LinkedAlpha,

View File

@ -21,6 +21,7 @@ public record Configuration(Property.Models.Configuration PropertyConfiguration,
bool ForceMetadataLastWriteTimeToCreationTime, bool ForceMetadataLastWriteTimeToCreationTime,
bool ForceResizeLastWriteTimeToCreationTime, bool ForceResizeLastWriteTimeToCreationTime,
string GenealogicalDataCommunicationFile, string GenealogicalDataCommunicationFile,
string ImmichAssetsFile,
string[] IgnoreExtensions, string[] IgnoreExtensions,
string[] JLinks, string[] JLinks,
string? LinkedAlpha, string? LinkedAlpha,

View File

@ -1,5 +1,6 @@
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.Text.Json; using System.Text.Json;
using View_by_Distance.Shared.Models;
namespace View_by_Distance.Instance.Models; namespace View_by_Distance.Instance.Models;
@ -24,14 +25,16 @@ internal class F_Random
return result; return result;
} }
private static ReadOnlyDictionary<string, List<string>> GetDayToRelativePaths(ReadOnlyCollection<Shared.Models.Mapping> distinctValidImageMappingCollection, string dateFormat, ReadOnlyDictionary<int, List<long>> idToPersonKeys) private static ReadOnlyDictionary<string, List<string>> GetDayToRelativePaths(ReadOnlyCollection<Mapping> distinctValidImageMappingCollection, string dateFormat, Dictionary<string, ImmichAsset> immichAssets, ReadOnlyDictionary<int, List<long>> idToPersonKeys)
{ {
Dictionary<string, List<string>> results = []; Dictionary<string, List<string>> results = [];
string key; string key;
DateTime dateTime; DateTime dateTime;
List<long>? personKeys; List<long>? personKeys;
ImmichAsset? immichAsset;
List<string>? relativePaths; List<string>? relativePaths;
foreach (Shared.Models.Mapping mapping in distinctValidImageMappingCollection) bool immichAssetsCountIsZero = immichAssets.Count == 0;
foreach (Mapping mapping in distinctValidImageMappingCollection)
{ {
if (mapping.MappingFromItem.FilePath.DirectoryName is null || mapping.MappingFromPerson is null) if (mapping.MappingFromItem.FilePath.DirectoryName is null || mapping.MappingFromPerson is null)
continue; continue;
@ -49,29 +52,55 @@ internal class F_Random
if (!results.TryGetValue(key, out relativePaths)) if (!results.TryGetValue(key, out relativePaths))
throw new Exception(); throw new Exception();
} }
relativePaths.Add(mapping.MappingFromItem.RelativePath); if (immichAssetsCountIsZero)
relativePaths.Add(mapping.MappingFromItem.RelativePath);
else
{
if (!immichAssets.TryGetValue(mapping.MappingFromItem.RelativePath, out immichAsset))
continue;
relativePaths.Add(immichAsset.PreviewPath);
}
} }
return new(results); return new(results);
} }
internal void Random(Property.Models.Configuration configuration, int radomUseBirthdayMinimum, string[] validKeyWordsToIgnoreInRandom, ReadOnlyDictionary<long, List<int>> personKeyToIds, ReadOnlyCollection<int>? notNineCollection, ReadOnlyCollection<Shared.Models.Mapping> distinctValidImageMappingCollection) private static Dictionary<string, ImmichAsset> GetImmichAssets(string immichAssetsFile)
{
Dictionary<string, ImmichAsset> results = [];
if (!string.IsNullOrEmpty(immichAssetsFile) && File.Exists(immichAssetsFile))
{
string json = File.ReadAllText(immichAssetsFile);
ImmichAsset[]? immichAssets = JsonSerializer.Deserialize(json, ImmichAssetCollectionSourceGenerationContext.Default.ImmichAssetArray);
if (immichAssets is not null)
{
foreach (ImmichAsset immichAsset in immichAssets)
results.Add(immichAsset.OriginalPath, immichAsset);
}
}
return results;
}
internal void Random(Property.Models.Configuration configuration, string immichAssetsFile, int radomUseBirthdayMinimum, string[] validKeyWordsToIgnoreInRandom, ReadOnlyDictionary<long, List<int>> personKeyToIds, ReadOnlyCollection<int>? notNineCollection, ReadOnlyCollection<Mapping> distinctValidImageMappingCollection)
{ {
string key; string key;
string json; string json;
string jsonFile; string jsonFile;
Random random = new(); Random random = new();
List<string>? collection; List<string>? collection;
ImmichAsset? immichAsset;
string dateFormat = "MM-dd"; string dateFormat = "MM-dd";
List<string> relativePaths = []; List<string> relativePaths = [];
List<int> distinctCollection = []; List<int> distinctCollection = [];
DateTime dateTime = new(2024, 1, 1); //Leap year DateTime dateTime = new(2024, 1, 1); //Leap year
Dictionary<string, ImmichAsset> immichAssets = GetImmichAssets(immichAssetsFile);
ReadOnlyDictionary<int, List<long>> idToPersonKeys = Map.Models.Stateless.Methods.IMapLogic.GetIdToPersonKeys(personKeyToIds); ReadOnlyDictionary<int, List<long>> idToPersonKeys = Map.Models.Stateless.Methods.IMapLogic.GetIdToPersonKeys(personKeyToIds);
ReadOnlyDictionary<string, List<string>> dayToRelativePaths = GetDayToRelativePaths(distinctValidImageMappingCollection, dateFormat, idToPersonKeys); ReadOnlyDictionary<string, List<string>> dayToRelativePaths = GetDayToRelativePaths(distinctValidImageMappingCollection, dateFormat, immichAssets, idToPersonKeys);
string fRandomCollectionDirectory = Property.Models.Stateless.IResult.GetResultsDateGroupDirectory(configuration, nameof(F_Random), "[]"); string fRandomCollectionDirectory = Property.Models.Stateless.IResult.GetResultsDateGroupDirectory(configuration, nameof(F_Random), "[]");
string[] files = Directory.GetFiles(fRandomCollectionDirectory, "*", SearchOption.TopDirectoryOnly); string[] files = Directory.GetFiles(fRandomCollectionDirectory, "*", SearchOption.TopDirectoryOnly);
foreach (string file in files) foreach (string file in files)
File.Delete(file); File.Delete(file);
foreach (Shared.Models.Mapping mapping in distinctValidImageMappingCollection) bool immichAssetsCountIsZero = immichAssets.Count == 0;
foreach (Mapping mapping in distinctValidImageMappingCollection)
{ {
if (distinctCollection.Contains(mapping.MappingFromItem.Id)) if (distinctCollection.Contains(mapping.MappingFromItem.Id))
continue; continue;
@ -81,7 +110,14 @@ internal class F_Random
continue; continue;
if (mapping.MappingFromItem.Keywords is not null && mapping.MappingFromItem.Keywords.Any(l => validKeyWordsToIgnoreInRandom.Contains(l))) if (mapping.MappingFromItem.Keywords is not null && mapping.MappingFromItem.Keywords.Any(l => validKeyWordsToIgnoreInRandom.Contains(l)))
continue; continue;
relativePaths.Add(mapping.MappingFromItem.RelativePath); if (immichAssetsCountIsZero)
relativePaths.Add(mapping.MappingFromItem.RelativePath);
else
{
if (!immichAssets.TryGetValue(mapping.MappingFromItem.RelativePath, out immichAsset))
continue;
relativePaths.Add(immichAsset.PreviewPath);
}
distinctCollection.Add(mapping.MappingFromItem.Id); distinctCollection.Add(mapping.MappingFromItem.Id);
} }
if (relativePaths.Count > 0) if (relativePaths.Count > 0)

View File

@ -254,7 +254,7 @@ internal abstract class RelationLogic
_ = Directory.CreateDirectory(vsCodeDirectory); _ = Directory.CreateDirectory(vsCodeDirectory);
if (displayDirectoryName is not null) if (displayDirectoryName is not null)
File.WriteAllText(Path.Combine(directory, $"_ {displayDirectoryName}.txt"), string.Empty); File.WriteAllText(Path.Combine(directory, $"_ {displayDirectoryName}.txt"), string.Empty);
json = "{ \"[markdown]\": { \"editor.wordWrap\": \"off\" }, \"foam.links.hover.enable\": false, \"foam.graph.style\": { \"background\": \"#202020\", \"node\": { \"note\": \"#f2cb1d\", \"distance\": \"green\", \"image\": \"orange\", \"placeholder\": \"white\", } } }"; json = /*lang=json*/ """{ "[markdown]": { "editor.wordWrap": "off" }, "foam.links.hover.enable": false, "foam.graph.style": { "background": "#202020", "node": { "note": "#f2cb1d", "distance": "green", "image": "orange", "placeholder": "white", } } }""";
_ = IPath.WriteAllText(Path.Combine(vsCodeDirectory, "settings.json"), json, updateDateWhenMatches: false, compareBeforeWrite: true, updateToWhenMatches: null); _ = IPath.WriteAllText(Path.Combine(vsCodeDirectory, "settings.json"), json, updateDateWhenMatches: false, compareBeforeWrite: true, updateToWhenMatches: null);
json = string.Concat("{ \"version\": \"2.0.0\", \"tasks\": [ { \"label\": \"MKLink\", \"type\": \"shell\", \"command\": \"New-Item\", \"args\": [ \"-ItemType\", \"Junction\", \"-Path\", \"'", directory.Replace('\\', '/'), "/()'\", \"-Target\", \"'", eDistanceContentDirectory.Replace('\\', '/'), "'\" ], \"problemMatcher\": [] } ] }"); json = string.Concat("{ \"version\": \"2.0.0\", \"tasks\": [ { \"label\": \"MKLink\", \"type\": \"shell\", \"command\": \"New-Item\", \"args\": [ \"-ItemType\", \"Junction\", \"-Path\", \"'", directory.Replace('\\', '/'), "/()'\", \"-Target\", \"'", eDistanceContentDirectory.Replace('\\', '/'), "'\" ], \"problemMatcher\": [] } ] }");
_ = IPath.WriteAllText(Path.Combine(vsCodeDirectory, "tasks.json"), json, updateDateWhenMatches: false, compareBeforeWrite: true, updateToWhenMatches: null); _ = IPath.WriteAllText(Path.Combine(vsCodeDirectory, "tasks.json"), json, updateDateWhenMatches: false, compareBeforeWrite: true, updateToWhenMatches: null);

View File

@ -312,10 +312,12 @@ public class C_Resize
{ {
if (mappingFromItem.ResizedFileHolder is null) if (mappingFromItem.ResizedFileHolder is null)
throw new NullReferenceException(nameof(mappingFromItem.ResizedFileHolder)); throw new NullReferenceException(nameof(mappingFromItem.ResizedFileHolder));
#pragma warning disable CA1854
if (!outputResolutionToResize.ContainsKey(_Original)) if (!outputResolutionToResize.ContainsKey(_Original))
throw new Exception(); throw new Exception();
if (!outputResolutionToResize.ContainsKey(outputResolution)) if (!outputResolutionToResize.ContainsKey(outputResolution))
throw new Exception(); throw new Exception();
#pragma warning restore CA1854
FileInfo fileInfo = new(mappingFromItem.ResizedFileHolder.FullName); FileInfo fileInfo = new(mappingFromItem.ResizedFileHolder.FullName);
bool check = false; bool check = false;
int[] resize = outputResolutionToResize[outputResolution]; int[] resize = outputResolutionToResize[outputResolution];

View File

@ -0,0 +1,33 @@
using System.Text.Json;
using System.Text.Json.Serialization;
namespace View_by_Distance.Shared.Models;
public record ImmichAsset([property: JsonPropertyName("id")] string Id,
[property: JsonPropertyName("deviceAssetId")] string DeviceAssetId,
[property: JsonPropertyName("originalPath")] string OriginalPath,
[property: JsonPropertyName("previewPath")] string PreviewPath,
[property: JsonPropertyName("isFavorite")] bool IsFavorite,
[property: JsonPropertyName("thumbnailPath")] string ThumbnailPath,
[property: JsonPropertyName("thumbhash")] string Thumbhash)
{
public override string ToString()
{
string result = JsonSerializer.Serialize(this, ImmichAssetSourceGenerationContext.Default.ImmichAsset);
return result;
}
}
[JsonSourceGenerationOptions(WriteIndented = true, DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull)]
[JsonSerializable(typeof(ImmichAsset))]
public partial class ImmichAssetSourceGenerationContext : JsonSerializerContext
{
}
[JsonSourceGenerationOptions(WriteIndented = true, DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull)]
[JsonSerializable(typeof(ImmichAsset[]))]
public partial class ImmichAssetCollectionSourceGenerationContext : JsonSerializerContext
{
}

View File

@ -81,6 +81,7 @@ internal abstract class ImageHelper
internal static Size GetDimensions(BinaryReader binaryReader, int? faceRight, int? faceBottom) internal static Size GetDimensions(BinaryReader binaryReader, int? faceRight, int? faceBottom)
{ {
Size? result = null; Size? result = null;
#pragma warning disable IDE0230
Dictionary<byte[], Func<BinaryReader, Size>> _ImageFormatDecoders = new() Dictionary<byte[], Func<BinaryReader, Size>> _ImageFormatDecoders = new()
{ {
{ new byte[] { 0x42, 0x4D }, DecodeBitmap }, { new byte[] { 0x42, 0x4D }, DecodeBitmap },
@ -89,6 +90,7 @@ internal abstract class ImageHelper
{ new byte[] { 0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A }, DecodePng }, { new byte[] { 0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A }, DecodePng },
{ new byte[] { 0xff, 0xd8 }, DecodeJfif }, { new byte[] { 0xff, 0xd8 }, DecodeJfif },
}; };
#pragma warning restore IDE0230
int maxMagicBytesLength = _ImageFormatDecoders.Keys.OrderByDescending(x => x.Length).First().Length; int maxMagicBytesLength = _ImageFormatDecoders.Keys.OrderByDescending(x => x.Length).First().Length;
byte[] magicBytes = new byte[maxMagicBytesLength]; byte[] magicBytes = new byte[maxMagicBytesLength];
for (int i = 0; i < maxMagicBytesLength; i += 1) for (int i = 0; i < maxMagicBytesLength; i += 1)

View File

@ -9,25 +9,28 @@ namespace Phares.Shared;
public static class RijndaelEncryption public static class RijndaelEncryption
{ {
/// <summary> /// <summary>
/// Change the Inputkey GUID when you use this code in your own program. /// Change the input key GUID when you use this code in your own program.
/// Keep this inputkey very safe and prevent someone from decoding it some way!! /// Keep this input key very safe and prevent someone from decoding it some way!!
/// Generated 2021-08-10 /// Generated 2021-08-10
/// </summary> /// </summary>
internal const string _Inputkey = "970CCEF6-4307-4F6A-9AC8-377DADB889BD"; internal const string _InputKey = "970CCEF6-4307-4F6A-9AC8-377DADB889BD";
/// <summary> /// <summary>
/// Encrypt the given text and give the byte array back as a BASE64 string /// Encrypt the given text and give the byte array back as a BASE64 string
/// </summary> /// </summary>
/// <param name="text">The text to encrypt</param> /// <param name="text">The text to encrypt</param>
/// <param name="salt">The pasword salt</param> /// <param name="salt">The password salt</param>
/// <returns>The encrypted text</returns> /// <returns>The encrypted text</returns>
public static string Encrypt(string text, string salt) public static string Encrypt(string text, string salt)
{ {
string result; string result;
if (string.IsNullOrEmpty(text)) if (string.IsNullOrEmpty(text))
throw new NullReferenceException(nameof(text)); throw new ArgumentNullException(nameof(text));
#pragma warning disable
RijndaelManaged aesAlg = NewRijndaelManaged(salt); RijndaelManaged aesAlg = NewRijndaelManaged(salt);
#pragma warning restore
ICryptoTransform encryptor = aesAlg.CreateEncryptor(aesAlg.Key, aesAlg.IV); ICryptoTransform encryptor = aesAlg.CreateEncryptor(aesAlg.Key, aesAlg.IV);
MemoryStream msEncrypt = new(); MemoryStream msEncrypt = new();
using (CryptoStream csEncrypt = new(msEncrypt, encryptor, CryptoStreamMode.Write)) using (CryptoStream csEncrypt = new(msEncrypt, encryptor, CryptoStreamMode.Write))
@ -46,7 +49,9 @@ public static class RijndaelEncryption
{ {
bool result; bool result;
base64String = base64String.Trim(); base64String = base64String.Trim();
#pragma warning disable
result = (base64String.Length % 4 == 0) && Regex.IsMatch(base64String, @"^[a-zA-Z0-9\+/]*={0,3}$", RegexOptions.None); result = (base64String.Length % 4 == 0) && Regex.IsMatch(base64String, @"^[a-zA-Z0-9\+/]*={0,3}$", RegexOptions.None);
#pragma warning restore
return result; return result;
} }
@ -54,16 +59,18 @@ public static class RijndaelEncryption
/// Decrypts the given text /// Decrypts the given text
/// </summary> /// </summary>
/// <param name="cipherText">The encrypted BASE64 text</param> /// <param name="cipherText">The encrypted BASE64 text</param>
/// <param name="salt">The pasword salt</param> /// <param name="salt">The password salt</param>
/// <returns>De gedecrypte text</returns> /// <returns>De gedecrypte text</returns>
public static string Decrypt(string cipherText, string salt) public static string Decrypt(string cipherText, string salt)
{ {
if (string.IsNullOrEmpty(cipherText)) if (string.IsNullOrEmpty(cipherText))
throw new NullReferenceException(nameof(cipherText)); throw new ArgumentNullException(nameof(cipherText));
if (!IsBase64String(cipherText)) if (!IsBase64String(cipherText))
throw new Exception("The cipherText input parameter is not base64 encoded"); throw new Exception("The cipherText input parameter is not base64 encoded");
string text; string text;
#pragma warning disable
RijndaelManaged aesAlg = NewRijndaelManaged(salt); RijndaelManaged aesAlg = NewRijndaelManaged(salt);
#pragma warning restore
ICryptoTransform decryptor = aesAlg.CreateDecryptor(aesAlg.Key, aesAlg.IV); ICryptoTransform decryptor = aesAlg.CreateDecryptor(aesAlg.Key, aesAlg.IV);
byte[] cipher = Convert.FromBase64String(cipherText); byte[] cipher = Convert.FromBase64String(cipherText);
using (MemoryStream msDecrypt = new(cipher)) using (MemoryStream msDecrypt = new(cipher))
@ -76,19 +83,22 @@ public static class RijndaelEncryption
} }
/// <summary> /// <summary>
/// GetPersonName a new RijndaelManaged class and initialize it /// Create a new RijndaelManaged class and initialize it
/// </summary> /// </summary>
/// <param name="salt">The pasword salt</param> /// <param name="salt">The password salt</param>
/// <returns></returns> /// <returns></returns>
#pragma warning disable
private static RijndaelManaged NewRijndaelManaged(string salt) private static RijndaelManaged NewRijndaelManaged(string salt)
{ {
if (salt == null) if (salt == null)
throw new NullReferenceException(nameof(salt)); throw new ArgumentNullException(nameof(salt));
byte[] saltBytes = Encoding.ASCII.GetBytes(salt); byte[] saltBytes = Encoding.ASCII.GetBytes(salt);
Rfc2898DeriveBytes key = new(_Inputkey, saltBytes); Rfc2898DeriveBytes key = new(_InputKey, saltBytes);
RijndaelManaged aesAlg = new(); RijndaelManaged aesAlg = new();
#pragma warning restore
aesAlg.Key = key.GetBytes(aesAlg.KeySize / 8); aesAlg.Key = key.GetBytes(aesAlg.KeySize / 8);
aesAlg.IV = key.GetBytes(aesAlg.BlockSize / 8); aesAlg.IV = key.GetBytes(aesAlg.BlockSize / 8);
return aesAlg; return aesAlg;
} }
} }

View File

@ -27,6 +27,7 @@ public class Configuration
public bool? ForceMetadataLastWriteTimeToCreationTime { get; set; } public bool? ForceMetadataLastWriteTimeToCreationTime { get; set; }
public bool? ForceResizeLastWriteTimeToCreationTime { get; set; } public bool? ForceResizeLastWriteTimeToCreationTime { get; set; }
public string? GenealogicalDataCommunicationFile { get; set; } public string? GenealogicalDataCommunicationFile { get; set; }
public string? ImmichAssetsFile { get; set; }
public string[]? IgnoreExtensions { get; set; } public string[]? IgnoreExtensions { get; set; }
public string[]? JLinks { get; set; } public string[]? JLinks { get; set; }
public string[]? LoadOrCreateThenSaveDistanceResultsForOutputResolutions { get; set; } public string[]? LoadOrCreateThenSaveDistanceResultsForOutputResolutions { get; set; }
@ -140,6 +141,7 @@ public class Configuration
if (configuration?.ForceMetadataLastWriteTimeToCreationTime is null) throw new NullReferenceException(nameof(configuration.ForceMetadataLastWriteTimeToCreationTime)); if (configuration?.ForceMetadataLastWriteTimeToCreationTime is null) throw new NullReferenceException(nameof(configuration.ForceMetadataLastWriteTimeToCreationTime));
if (configuration?.ForceResizeLastWriteTimeToCreationTime is null) throw new NullReferenceException(nameof(configuration.ForceResizeLastWriteTimeToCreationTime)); if (configuration?.ForceResizeLastWriteTimeToCreationTime is null) throw new NullReferenceException(nameof(configuration.ForceResizeLastWriteTimeToCreationTime));
if (configuration?.GenealogicalDataCommunicationFile is null) throw new NullReferenceException(nameof(configuration.GenealogicalDataCommunicationFile)); if (configuration?.GenealogicalDataCommunicationFile is null) throw new NullReferenceException(nameof(configuration.GenealogicalDataCommunicationFile));
if (configuration?.ImmichAssetsFile is null) throw new NullReferenceException(nameof(configuration.ImmichAssetsFile));
// if (configuration?.IgnoreExtensions is null) throw new NullReferenceException(nameof(configuration.IgnoreExtensions)); // if (configuration?.IgnoreExtensions is null) throw new NullReferenceException(nameof(configuration.IgnoreExtensions));
// if (configuration?.JLinks is null) throw new NullReferenceException(nameof(configuration.JLinks)); // if (configuration?.JLinks is null) throw new NullReferenceException(nameof(configuration.JLinks));
// if (configuration?.LoadOrCreateThenSaveDistanceResultsForOutputResolutions is null) throw new NullReferenceException(nameof(configuration.LoadOrCreateThenSaveDistanceResultsForOutputResolutions)); // if (configuration?.LoadOrCreateThenSaveDistanceResultsForOutputResolutions is null) throw new NullReferenceException(nameof(configuration.LoadOrCreateThenSaveDistanceResultsForOutputResolutions));
@ -223,6 +225,7 @@ public class Configuration
configuration.ForceMetadataLastWriteTimeToCreationTime.Value, configuration.ForceMetadataLastWriteTimeToCreationTime.Value,
configuration.ForceResizeLastWriteTimeToCreationTime.Value, configuration.ForceResizeLastWriteTimeToCreationTime.Value,
configuration.GenealogicalDataCommunicationFile, configuration.GenealogicalDataCommunicationFile,
configuration.ImmichAssetsFile,
configuration.IgnoreExtensions ?? [], configuration.IgnoreExtensions ?? [],
configuration.JLinks ?? [], configuration.JLinks ?? [],
configuration.LoadOrCreateThenSaveDistanceResultsForOutputResolutions ?? [], configuration.LoadOrCreateThenSaveDistanceResultsForOutputResolutions ?? [],

View File

@ -21,6 +21,7 @@ public record Configuration(Property.Models.Configuration PropertyConfiguration,
bool ForceMetadataLastWriteTimeToCreationTime, bool ForceMetadataLastWriteTimeToCreationTime,
bool ForceResizeLastWriteTimeToCreationTime, bool ForceResizeLastWriteTimeToCreationTime,
string GenealogicalDataCommunicationFile, string GenealogicalDataCommunicationFile,
string ImmichAssetsFile,
string[] IgnoreExtensions, string[] IgnoreExtensions,
string[] JLinks, string[] JLinks,
string[] LoadOrCreateThenSaveDistanceResultsForOutputResolutions, string[] LoadOrCreateThenSaveDistanceResultsForOutputResolutions,

View File

@ -4,6 +4,7 @@ using Phares.Shared;
using System.Diagnostics; using System.Diagnostics;
using System.Globalization; using System.Globalization;
using System.Reflection; using System.Reflection;
using System.Text.Json;
using View_by_Distance.Shared.Models; using View_by_Distance.Shared.Models;
using View_by_Distance.Shared.Models.Stateless.Methods; using View_by_Distance.Shared.Models.Stateless.Methods;
using View_by_Distance.Tests.Models; using View_by_Distance.Tests.Models;
@ -14,6 +15,7 @@ namespace View_by_Distance.Tests;
public partial class UnitTestHardCoded public partial class UnitTestHardCoded
{ {
private readonly string _Git;
private readonly AppSettings _AppSettings; private readonly AppSettings _AppSettings;
private readonly string _WorkingDirectory; private readonly string _WorkingDirectory;
private readonly Configuration _Configuration; private readonly Configuration _Configuration;
@ -43,6 +45,7 @@ public partial class UnitTestHardCoded
Environment.SetEnvironmentVariable(nameof(workingDirectory), workingDirectory); Environment.SetEnvironmentVariable(nameof(workingDirectory), workingDirectory);
propertyConfiguration = Property.Models.Binder.Configuration.Get(isEnvironment, configurationRoot); propertyConfiguration = Property.Models.Binder.Configuration.Get(isEnvironment, configurationRoot);
configuration = Models.Binder.Configuration.Get(isEnvironment, configurationRoot, propertyConfiguration); configuration = Models.Binder.Configuration.Get(isEnvironment, configurationRoot, propertyConfiguration);
_Git = "c9dbce3b";
_AppSettings = appSettings; _AppSettings = appSettings;
_Configuration = configuration; _Configuration = configuration;
_IsEnvironment = isEnvironment; _IsEnvironment = isEnvironment;
@ -86,7 +89,7 @@ public partial class UnitTestHardCoded
[TestMethod] [TestMethod]
public void TestMethodGetApproximateYears() public void TestMethodGetApproximateYears()
{ {
string personDisplayDirectory = "D:/1-Images-A/Images-7007a9df-Results/A2)People/7007a9df/{}/^/Sydney Dupray^9"; string personDisplayDirectory = string.Concat($"D:/1-Images-A/Images-{_Git}-Results/A2)People/{_Git}", "/{}/^/Sydney Dupray^9");
if (Directory.Exists(Directory.GetDirectoryRoot(personDisplayDirectory)) && Directory.Exists(personDisplayDirectory)) if (Directory.Exists(Directory.GetDirectoryRoot(personDisplayDirectory)) && Directory.Exists(personDisplayDirectory))
{ {
char numberSign = '#'; char numberSign = '#';
@ -189,7 +192,7 @@ public partial class UnitTestHardCoded
[TestMethod] [TestMethod]
public void TestMethodRenameAbandoned() public void TestMethodRenameAbandoned()
{ {
string directory = "D:/1-Images-A/Images-7007a9df-Results/A2)People/7007a9df/{}/!/Abandoned"; string directory = string.Concat($"D:/1-Images-A/Images-{_Git}-Results/A2)People/{_Git}", "/{}/!/Abandoned");
if (Directory.Exists(Path.GetPathRoot(directory)) && Directory.Exists(directory)) if (Directory.Exists(Path.GetPathRoot(directory)) && Directory.Exists(directory))
{ {
string checkFile; string checkFile;
@ -209,7 +212,7 @@ public partial class UnitTestHardCoded
[TestMethod] [TestMethod]
public void TestMethodRenameDelete() public void TestMethodRenameDelete()
{ {
string directory = "D:/1-Images-A/Images-7007a9df-Results/A)Property/7007a9df/{}"; string directory = string.Concat($"D:/1-Images-A/Images-{_Git}-Results/A)Property/{_Git}", "/{}");
if (Directory.Exists(Path.GetPathRoot(directory)) && Directory.Exists(directory)) if (Directory.Exists(Path.GetPathRoot(directory)) && Directory.Exists(directory))
{ {
string checkFile; string checkFile;
@ -229,7 +232,7 @@ public partial class UnitTestHardCoded
[TestMethod] [TestMethod]
public void TestMethodRenameOld() public void TestMethodRenameOld()
{ {
string directory = "D:/1-Images-A/Images-7007a9df-Results/E)Distance/7007a9df/()"; string directory = $"D:/1-Images-A/Images-{_Git}-Results/E)Distance/{_Git}/()";
if (Directory.Exists(Path.GetPathRoot(directory)) && Directory.Exists(directory)) if (Directory.Exists(Path.GetPathRoot(directory)) && Directory.Exists(directory))
{ {
string checkFile; string checkFile;
@ -250,7 +253,7 @@ public partial class UnitTestHardCoded
public void TestMethodRenameDup() public void TestMethodRenameDup()
{ {
string directory; string directory;
directory = "D:/1-Images-A/Images-7007a9df-Results/E)Distance/7007a9df/()"; directory = $"D:/1-Images-A/Images-{_Git}-Results/E)Distance/{_Git}/()";
if (Directory.Exists(Path.GetPathRoot(directory)) && Directory.Exists(directory)) if (Directory.Exists(Path.GetPathRoot(directory)) && Directory.Exists(directory))
{ {
string checkFile; string checkFile;
@ -264,7 +267,7 @@ public partial class UnitTestHardCoded
} }
Assert.IsTrue(true); Assert.IsTrue(true);
} }
directory = "D:/1-Images-A/Images-7007a9df-Results/A2)People/7007a9df/{}/!"; directory = string.Concat($"D:/1-Images-A/Images-{_Git}-Results/A2)People/{_Git}", "/{}/!");
if (Directory.Exists(Path.GetPathRoot(directory)) && Directory.Exists(directory)) if (Directory.Exists(Path.GetPathRoot(directory)) && Directory.Exists(directory))
{ {
string checkFile; string checkFile;
@ -284,9 +287,9 @@ public partial class UnitTestHardCoded
[TestMethod] [TestMethod]
public void TestMethodRename() public void TestMethodRename()
{ {
// string directory = "D:/2-Images-B/Not-Copy-Copy-7007a9df"; // string $directory = "D:/2-Images-B/Not-Copy-Copy-{_Git}";
string directory = "D:/1-Images-A/Images-7007a9df"; string directory = $"D:/1-Images-A/Images-{_Git}";
// string directory = "D:/2-Images-B/Not-Copy-Copy-7007a9df"; // string $directory = "D:/2-Images-B/Not-Copy-Copy-{_Git}";
if (Directory.Exists(Path.GetPathRoot(directory)) && Directory.Exists(directory)) if (Directory.Exists(Path.GetPathRoot(directory)) && Directory.Exists(directory))
{ {
string[] directories = Directory.GetDirectories(directory, "*;*", SearchOption.AllDirectories); string[] directories = Directory.GetDirectories(directory, "*;*", SearchOption.AllDirectories);
@ -303,7 +306,7 @@ public partial class UnitTestHardCoded
[TestMethod] [TestMethod]
public void TestMethodRenameForUnknown() public void TestMethodRenameForUnknown()
{ {
string directory = "D:/1-Images-A/Images-7007a9df-Results/E)Distance/7007a9df/(RectInt-2023-06-19-less-0.99)"; string directory = $"D:/1-Images-A/Images-{_Git}-Results/E)Distance/{_Git}/(RectInt-2023-06-19-less-0.99)";
if (Directory.Exists(Path.GetPathRoot(directory)) && Directory.Exists(directory)) if (Directory.Exists(Path.GetPathRoot(directory)) && Directory.Exists(directory))
{ {
string[] files = Directory.GetFiles(directory, "*.unk", SearchOption.AllDirectories); string[] files = Directory.GetFiles(directory, "*.unk", SearchOption.AllDirectories);
@ -316,13 +319,13 @@ public partial class UnitTestHardCoded
[TestMethod] [TestMethod]
public void TestMethodRenameForTicks() public void TestMethodRenameForTicks()
{ {
string directory = "D:/1-Images-A/Images-7007a9df-Results/A2)People/7007a9df/([])/ged"; string directory = $"D:/1-Images-A/Images-{_Git}-Results/A2)People/{_Git}/([])/ged";
if (Directory.Exists(Path.GetPathRoot(directory)) && Directory.Exists(directory)) if (Directory.Exists(Path.GetPathRoot(directory)) && Directory.Exists(directory))
{ {
string checkName; string checkName;
DateTime dateTime; DateTime dateTime;
string weekOfYear; string weekOfYear;
string checkDirectoy; string checkDirectory;
Calendar calendar = new CultureInfo("en-US").Calendar; Calendar calendar = new CultureInfo("en-US").Calendar;
string[] files = Directory.GetFiles(directory, "*.ged", SearchOption.TopDirectoryOnly); string[] files = Directory.GetFiles(directory, "*.ged", SearchOption.TopDirectoryOnly);
foreach (string file in files) foreach (string file in files)
@ -331,10 +334,10 @@ public partial class UnitTestHardCoded
continue; continue;
dateTime = new(ticks); dateTime = new(ticks);
weekOfYear = calendar.GetWeekOfYear(dateTime, CalendarWeekRule.FirstDay, DayOfWeek.Sunday).ToString("00"); weekOfYear = calendar.GetWeekOfYear(dateTime, CalendarWeekRule.FirstDay, DayOfWeek.Sunday).ToString("00");
checkDirectoy = Path.Combine(directory, dateTime.Year.ToString(), $"{dateTime.Year}-Week-{weekOfYear}"); checkDirectory = Path.Combine(directory, dateTime.Year.ToString(), $"{dateTime.Year}-Week-{weekOfYear}");
checkName = Path.Combine(checkDirectoy, Path.GetFileName(file)); checkName = Path.Combine(checkDirectory, Path.GetFileName(file));
if (!Directory.Exists(checkDirectoy)) if (!Directory.Exists(checkDirectory))
_ = Directory.CreateDirectory(checkDirectoy); _ = Directory.CreateDirectory(checkDirectory);
if (File.Exists(checkName)) if (File.Exists(checkName))
continue; continue;
File.Move(file, checkName); File.Move(file, checkName);
@ -343,4 +346,22 @@ public partial class UnitTestHardCoded
NonThrowTryCatch(); NonThrowTryCatch();
} }
[TestMethod]
public void TestMethodImmichAsset()
{
if (!string.IsNullOrEmpty(_Configuration.ImmichAssetsFile) && File.Exists(_Configuration.ImmichAssetsFile))
{
Dictionary<string, ImmichAsset> keyValuePairs = [];
string json = File.ReadAllText(_Configuration.ImmichAssetsFile);
ImmichAsset[]? immichAssets = JsonSerializer.Deserialize(json, ImmichAssetCollectionSourceGenerationContext.Default.ImmichAssetArray);
if (immichAssets is not null)
{
foreach (ImmichAsset immichAsset in immichAssets)
keyValuePairs.Add(immichAsset.OriginalPath, immichAsset);
}
Assert.IsTrue(keyValuePairs.Count > 0);
}
NonThrowTryCatch();
}
} }

View File

@ -11,13 +11,13 @@ public static partial class ThumbHash
private const int _MinHash = 5; private const int _MinHash = 5;
[DoesNotReturn] [DoesNotReturn]
static void ThrowIfLessThan<T>(T value, T other, [CallerArgumentExpression(nameof(value))] string? paramName = null) => throw new ArgumentOutOfRangeException(paramName, value, $"'{value}' must be greater than or equal to '{other}'."); private static void ThrowIfLessThan<T>(T value, T other, [CallerArgumentExpression(nameof(value))] string? paramName = null) => throw new ArgumentOutOfRangeException(paramName, value, $"'{value}' must be greater than or equal to '{other}'.");
[DoesNotReturn] [DoesNotReturn]
static void ThrowIfGreaterThan<T>(T value, T other, [CallerArgumentExpression(nameof(value))] string? paramName = null) => throw new ArgumentOutOfRangeException(paramName, value, $"'{paramName}' must be less than or equal to '{other}'."); private static void ThrowIfGreaterThan<T>(T value, T other, [CallerArgumentExpression(nameof(value))] string? paramName = null) => throw new ArgumentOutOfRangeException(paramName, value, $"'{paramName}' must be less than or equal to '{other}'.");
[DoesNotReturn] [DoesNotReturn]
static void ThrowNotEqual<T>(T value, T other, [CallerArgumentExpression(nameof(value))] string? paramName = null, [CallerArgumentExpression(nameof(other))] string? otherName = null) => throw new ArgumentOutOfRangeException(paramName, value, $"'{paramName}' must be equal to '{other}' ('{otherName}')."); private static void ThrowNotEqual<T>(T value, T other, [CallerArgumentExpression(nameof(value))] string? paramName = null, [CallerArgumentExpression(nameof(other))] string? otherName = null) => throw new ArgumentOutOfRangeException(paramName, value, $"'{paramName}' must be equal to '{other}' ('{otherName}').");
/// <summary> /// <summary>
/// Encodes an RGBA image to a ThumbHash. /// Encodes an RGBA image to a ThumbHash.