Removed E2_Navigate, G_Index, G2_Identify and
NotCopyCopy
This commit is contained in:
@ -22,10 +22,8 @@ public partial class DlibDotNet
|
||||
{
|
||||
|
||||
private readonly D_Face _Faces;
|
||||
private readonly G_Index _Index;
|
||||
private readonly C_Resize _Resize;
|
||||
private readonly F_Random _Random;
|
||||
private readonly E3_Rename _Rename;
|
||||
private readonly IConsole _Console;
|
||||
private readonly E_Distance _Distance;
|
||||
private readonly Serilog.ILogger? _Log;
|
||||
@ -62,9 +60,7 @@ public partial class DlibDotNet
|
||||
Verify(configuration);
|
||||
VerifyExtra(args, propertyConfiguration, configuration);
|
||||
_Configuration = configuration;
|
||||
_Index = new(configuration);
|
||||
_Random = new(configuration);
|
||||
_Rename = new(configuration);
|
||||
if (configuration.IgnoreExtensions is null)
|
||||
throw new NullReferenceException(nameof(configuration.IgnoreExtensions));
|
||||
string propertyRoot = Property.Models.Stateless.IResult.GetResultsGroupDirectory(propertyConfiguration, nameof(A_Property), create: false);
|
||||
@ -121,12 +117,6 @@ public partial class DlibDotNet
|
||||
Storage storage = new(rootDirectory, rootResultsDirectory, peopleRootDirectory);
|
||||
_PersonContainers = Shared.Models.Stateless.Methods.IPersonContainer.GetPersonContainers(storage, configuration.PersonBirthdayFormat, configuration.PersonCharacters.ToArray(), _Faces.FileNameExtension);
|
||||
}
|
||||
if (!isSilent && configuration.TestDistanceResults)
|
||||
{
|
||||
E2_Navigate e2Navigate = new(console, configuration, argZero);
|
||||
e2Navigate.Navigate(propertyConfiguration, configuration.OutputResolutions[0]);
|
||||
_Log.Information(propertyConfiguration.RootDirectory);
|
||||
}
|
||||
{
|
||||
(ImageCodecInfo imageCodecInfo, EncoderParameters encoderParameters, string filenameExtension) = C_Resize.GetTuple(
|
||||
configuration.OutputExtension,
|
||||
@ -144,16 +134,6 @@ public partial class DlibDotNet
|
||||
Search(ticks, argZero, propertyRoot);
|
||||
if (!_PropertyRootExistedBefore && !_IsEnvironment.Development && _Exceptions.Count == 0 && _ArgZeroIsConfigurationRootDirectory)
|
||||
{
|
||||
List<string[]> directoryCollections = _Rename.GetDirectoryRenameCollections(
|
||||
propertyConfiguration,
|
||||
relativePath: string.Empty,
|
||||
newDirectoryName: string.Empty,
|
||||
jsonFiles4InfoAny: false);
|
||||
foreach (string[] directoryCollection in directoryCollections)
|
||||
{
|
||||
_Log.Information(string.Concat("Cleaning <", directoryCollection[0], ">"));
|
||||
_ = Shared.Models.Stateless.Methods.IPath.DeleteEmptyDirectories(directoryCollection[0]);
|
||||
}
|
||||
string d2FacePartsRootDirectory = Property.Models.Stateless.IResult.GetResultsDateGroupDirectory(propertyConfiguration, nameof(D2_FaceParts));
|
||||
_Log.Information(string.Concat("Cleaning <", d2FacePartsRootDirectory, ">"));
|
||||
_ = Shared.Models.Stateless.Methods.IPath.DeleteEmptyDirectories(d2FacePartsRootDirectory);
|
||||
@ -225,8 +205,6 @@ public partial class DlibDotNet
|
||||
throw new NullReferenceException(nameof(configuration.PredictorModelName));
|
||||
if (string.IsNullOrEmpty(configuration.ModelDirectory) || !Directory.Exists(configuration.ModelDirectory))
|
||||
throw new NullReferenceException(nameof(configuration.ModelDirectory));
|
||||
if (configuration.MappedMaxIndex.HasValue && configuration.LoadOrCreateThenSaveIndex && !_IsEnvironment.DebuggerWasAttachedDuringConstructor)
|
||||
throw new NullReferenceException(nameof(configuration.MappedMaxIndex));
|
||||
}
|
||||
|
||||
private void VerifyExtra(List<string> args, Property.Models.Configuration propertyConfiguration, Models.Configuration configuration)
|
||||
@ -1116,11 +1094,6 @@ public partial class DlibDotNet
|
||||
_Random.Random(_Configuration.PropertyConfiguration, outputResolution, personKeyToIds, mappingCollection);
|
||||
if (_IsEnvironment.Development)
|
||||
continue;
|
||||
G2_Identify identify = new(_Configuration);
|
||||
List<G2_Identify> identifiedCollection = identify.GetIdentifiedCollection(_IsEnvironment, _Configuration.PropertyConfiguration, _Faces.FileNameExtension);
|
||||
identify.WriteAllText(_Configuration.PropertyConfiguration, _Configuration.OutputResolutions[0], identifiedCollection);
|
||||
if (_Configuration.LoadOrCreateThenSaveIndex)
|
||||
_Index.SetIndex(_Configuration.PropertyConfiguration, _Configuration.OutputResolutions[0]);
|
||||
if (!_IsEnvironment.Development)
|
||||
{
|
||||
_ = Shared.Models.Stateless.Methods.IPath.DeleteEmptyDirectories(Path.Combine(aResultsFullGroupDirectory, "{}"));
|
||||
@ -1132,6 +1105,4 @@ public partial class DlibDotNet
|
||||
}
|
||||
}
|
||||
|
||||
internal void RenameQueue() => _Rename.RenameQueue(_Configuration.PropertyConfiguration);
|
||||
|
||||
}
|
@ -30,10 +30,8 @@ public class Configuration
|
||||
[Display(Name = "Julie Phares Copy Birthdays"), Required] public string[] JLinks { get; set; }
|
||||
[Display(Name = "Load Or Create Then Save Distance Results"), Required] public string[] LoadOrCreateThenSaveDistanceResultsForOutputResolutions { get; set; }
|
||||
[Display(Name = "Load Or Create Then Save Image Faces Results"), Required] public string[] LoadOrCreateThenSaveImageFacesResultsForOutputResolutions { get; set; }
|
||||
[Display(Name = "Load Or Create Then Save Index"), Required] public bool? LoadOrCreateThenSaveIndex { get; set; }
|
||||
[Display(Name = "Location Digits"), Required] public int? LocationDigits { get; set; }
|
||||
[Display(Name = "Location Factor"), Required] public int? LocationFactor { get; set; }
|
||||
[Display(Name = "Mapped Max Index"), Required] public int? MappedMaxIndex { get; set; }
|
||||
[Display(Name = "Mapping Default Name"), Required] public string MappingDefaultName { get; set; }
|
||||
[Display(Name = "Mapping Use Deterministic Hash Code Unknown Face Key Value Pairs for Add to Mapping"), Required] public bool? MappingUseDeterministicHashCodeUnknownFaceKeyValuePairsForAddToMapping { get; set; }
|
||||
[Display(Name = "Mapping Use Deterministic Hash Code Unknown Face Key Value Pairs for Save Mapping"), Required] public bool? MappingUseDeterministicHashCodeUnknownFaceKeyValuePairsForSaveMapping { get; set; }
|
||||
@ -130,8 +128,6 @@ public class Configuration
|
||||
throw new NullReferenceException(nameof(configuration.IgnoreRelativePaths));
|
||||
configuration.LoadOrCreateThenSaveDistanceResultsForOutputResolutions ??= Array.Empty<string>();
|
||||
configuration.LoadOrCreateThenSaveImageFacesResultsForOutputResolutions ??= Array.Empty<string>();
|
||||
if (configuration.LoadOrCreateThenSaveIndex is null)
|
||||
throw new NullReferenceException(nameof(configuration.LoadOrCreateThenSaveIndex));
|
||||
if (configuration.LocationDigits is null)
|
||||
throw new NullReferenceException(nameof(configuration.LocationDigits));
|
||||
if (configuration.LocationFactor is null)
|
||||
@ -235,10 +231,8 @@ public class Configuration
|
||||
configuration.JLinks,
|
||||
configuration.LoadOrCreateThenSaveDistanceResultsForOutputResolutions,
|
||||
configuration.LoadOrCreateThenSaveImageFacesResultsForOutputResolutions,
|
||||
configuration.LoadOrCreateThenSaveIndex.Value,
|
||||
configuration.LocationDigits.Value,
|
||||
configuration.LocationFactor.Value,
|
||||
configuration.MappedMaxIndex,
|
||||
configuration.MappingDefaultName,
|
||||
configuration.MappingUseDeterministicHashCodeUnknownFaceKeyValuePairsForAddToMapping.Value,
|
||||
configuration.MappingUseDeterministicHashCodeUnknownFaceKeyValuePairsForSaveMapping.Value,
|
||||
|
@ -29,10 +29,8 @@ public class Configuration
|
||||
public string[] JLinks { init; get; }
|
||||
public string[] LoadOrCreateThenSaveDistanceResultsForOutputResolutions { init; get; }
|
||||
public string[] LoadOrCreateThenSaveImageFacesResultsForOutputResolutions { init; get; }
|
||||
public bool LoadOrCreateThenSaveIndex { init; get; }
|
||||
public int LocationDigits { init; get; }
|
||||
public int LocationFactor { init; get; }
|
||||
public int? MappedMaxIndex { init; get; }
|
||||
public string MappingDefaultName { init; get; }
|
||||
public bool MappingUseDeterministicHashCodeUnknownFaceKeyValuePairsForAddToMapping { init; get; }
|
||||
public bool MappingUseDeterministicHashCodeUnknownFaceKeyValuePairsForSaveMapping { init; get; }
|
||||
@ -99,10 +97,8 @@ public class Configuration
|
||||
string[] jLinks,
|
||||
string[] loadOrCreateThenSaveDistanceResultsForOutputResolutions,
|
||||
string[] loadOrCreateThenSaveImageFacesResultsForOutputResolutions,
|
||||
bool loadOrCreateThenSaveIndex,
|
||||
int locationDigits,
|
||||
int locationFactor,
|
||||
int? mappedMaxIndex,
|
||||
string mappingDefaultName,
|
||||
bool mappingUseDeterministicHashCodeUnknownFaceKeyValuePairsForAddToMapping,
|
||||
bool mappingUseDeterministicHashCodeUnknownFaceKeyValuePairsForSaveMapping,
|
||||
@ -168,10 +164,8 @@ public class Configuration
|
||||
JLinks = jLinks;
|
||||
LoadOrCreateThenSaveDistanceResultsForOutputResolutions = loadOrCreateThenSaveDistanceResultsForOutputResolutions;
|
||||
LoadOrCreateThenSaveImageFacesResultsForOutputResolutions = loadOrCreateThenSaveImageFacesResultsForOutputResolutions;
|
||||
LoadOrCreateThenSaveIndex = loadOrCreateThenSaveIndex;
|
||||
LocationDigits = locationDigits;
|
||||
LocationFactor = locationFactor;
|
||||
MappedMaxIndex = mappedMaxIndex;
|
||||
MappingDefaultName = mappingDefaultName;
|
||||
MappingUseDeterministicHashCodeUnknownFaceKeyValuePairsForAddToMapping = mappingUseDeterministicHashCodeUnknownFaceKeyValuePairsForAddToMapping;
|
||||
MappingUseDeterministicHashCodeUnknownFaceKeyValuePairsForSaveMapping = mappingUseDeterministicHashCodeUnknownFaceKeyValuePairsForSaveMapping;
|
||||
|
@ -1,232 +0,0 @@
|
||||
using System.Text.Json;
|
||||
using View_by_Distance.Distance.Models;
|
||||
using View_by_Distance.Face.Models;
|
||||
using View_by_Distance.Instance.Models.Stateless;
|
||||
using View_by_Distance.Metadata.Models;
|
||||
using View_by_Distance.Resize.Models;
|
||||
using View_by_Distance.Shared.Models;
|
||||
using View_by_Distance.Shared.Models.Methods;
|
||||
|
||||
namespace View_by_Distance.Instance.Models;
|
||||
|
||||
/// <summary>
|
||||
// N/A
|
||||
/// </summary>
|
||||
internal class E2_Navigate
|
||||
{
|
||||
|
||||
private readonly string _ArgZero;
|
||||
private readonly E3_Rename _Rename;
|
||||
private readonly IConsole _Console;
|
||||
private readonly Serilog.ILogger? _Log;
|
||||
private readonly Configuration _Configuration;
|
||||
|
||||
internal E2_Navigate(IConsole console, Configuration configuration, string argZero)
|
||||
{
|
||||
_Console = console;
|
||||
_ArgZero = argZero;
|
||||
_Configuration = configuration;
|
||||
_Rename = new E3_Rename(configuration);
|
||||
_Log = Serilog.Log.ForContext<E2_Navigate>();
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
string result = JsonSerializer.Serialize(this, new JsonSerializerOptions() { WriteIndented = true });
|
||||
return result;
|
||||
}
|
||||
|
||||
private void DisplayTags(Property.Models.Configuration configuration, string outputResolution, string[] directories, Dictionary<ConsoleKey, int> directoryKeyValuePairs, string[] files, Dictionary<ConsoleKey, int> fileKeyValuePairs)
|
||||
{
|
||||
if (_Log is null)
|
||||
throw new NullReferenceException(nameof(_Log));
|
||||
bool all = false;
|
||||
FileSystem fileSystem;
|
||||
string requestPath = "/RootResultsDirectory";
|
||||
string? rootResultsDirectory = Path.GetDirectoryName(Property.Models.Stateless.IResult.GetResultsGroupDirectory(configuration, nameof(B_Metadata)));
|
||||
if (string.IsNullOrEmpty(rootResultsDirectory))
|
||||
throw new Exception();
|
||||
string rootResultsDirectoryAbsoluteUri = new Uri(rootResultsDirectory).AbsoluteUri;
|
||||
string dFacesContentDirectory = Path.Combine(Property.Models.Stateless.IResult.GetResultsFullGroupDirectory(configuration, nameof(D_Face), outputResolution, includeResizeGroup: true, includeModel: true, includePredictorModel: true), "()");
|
||||
string cResizeContentDirectory = Path.Combine(Property.Models.Stateless.IResult.GetResultsFullGroupDirectory(configuration, nameof(C_Resize), outputResolution, includeResizeGroup: true, includeModel: false, includePredictorModel: false), "()");
|
||||
string eDistanceCollectionDirectory = Path.Combine(Property.Models.Stateless.IResult.GetResultsFullGroupDirectory(configuration, nameof(E_Distance), outputResolution, includeResizeGroup: true, includeModel: true, includePredictorModel: true), "[]");
|
||||
(string RootResultsDirectoryAbsoluteUri, string C_ResizeContentDirectory, string D_FacesContentDirectory, string E_DistanceCollectionDirectory) tuple = new(rootResultsDirectoryAbsoluteUri, cResizeContentDirectory, dFacesContentDirectory, eDistanceCollectionDirectory);
|
||||
List<FileSystem> fileSystemCollection = Shared.Models.Stateless.Methods.IFileSystem.GetFileSystemCollection(requestPath, tuple, directories, files, all);
|
||||
Queue<FileSystem> queue = new(fileSystemCollection);
|
||||
foreach (KeyValuePair<ConsoleKey, int> element in directoryKeyValuePairs)
|
||||
{
|
||||
fileSystem = queue.Dequeue();
|
||||
_Log.Warn(string.Concat(element.Key, " - D) ", " <", fileSystem.Display, ">"));
|
||||
// _Log.Info(string.Join(Environment.NewLine, from l in fileSystem where !string.IsNullOrEmpty(l) select l));
|
||||
_Log.Info(string.Empty);
|
||||
}
|
||||
foreach (KeyValuePair<ConsoleKey, int> element in fileKeyValuePairs)
|
||||
{
|
||||
fileSystem = queue.Dequeue();
|
||||
_Log.Warn(string.Concat(element.Key, " - F) [", fileSystem.Display, '}'));
|
||||
// _Log.Info(string.Join(Environment.NewLine, from l in fileSystem where !string.IsNullOrEmpty(l) select l));
|
||||
_Log.Info(string.Empty);
|
||||
}
|
||||
}
|
||||
|
||||
private void DisplayFaces(Property.Models.Configuration configuration, string outputResolution, string selectedFileFullName)
|
||||
{
|
||||
if (_Log is null)
|
||||
throw new NullReferenceException(nameof(_Log));
|
||||
string requestPath = "/RootResultsDirectory";
|
||||
string? rootResultsDirectory = Path.GetDirectoryName(Property.Models.Stateless.IResult.GetResultsGroupDirectory(configuration, nameof(B_Metadata)));
|
||||
if (string.IsNullOrEmpty(rootResultsDirectory))
|
||||
throw new Exception();
|
||||
string rootResultsDirectoryAbsoluteUri = new Uri(rootResultsDirectory).AbsoluteUri;
|
||||
string dFacesContentDirectory = Path.Combine(Property.Models.Stateless.IResult.GetResultsFullGroupDirectory(configuration, nameof(D_Face), outputResolution, includeResizeGroup: true, includeModel: true, includePredictorModel: true), "()");
|
||||
string cResizeContentDirectory = Path.Combine(Property.Models.Stateless.IResult.GetResultsFullGroupDirectory(configuration, nameof(C_Resize), outputResolution, includeResizeGroup: true, includeModel: false, includePredictorModel: false), "()");
|
||||
string eDistanceCollectionDirectory = Path.Combine(Property.Models.Stateless.IResult.GetResultsFullGroupDirectory(configuration, nameof(E_Distance), outputResolution, includeResizeGroup: true, includeModel: true, includePredictorModel: true), "[]");
|
||||
(string RootResultsDirectoryAbsoluteUri, string C_ResizeContentDirectory, string D_FacesContentDirectory, string E_DistanceCollectionDirectory) tuple = new(rootResultsDirectoryAbsoluteUri, cResizeContentDirectory, dFacesContentDirectory, eDistanceCollectionDirectory);
|
||||
FaceFileSystem[] faceFileSystemCollection = Shared.Models.Stateless.Methods.IFaceFileSystem.GetFaceFileSystemCollection(requestPath, tuple, selectedFileFullName);
|
||||
for (int i = 0; i < faceFileSystemCollection.Length; i++)
|
||||
{
|
||||
_Log.Warn(string.Concat(i, " - F) [", faceFileSystemCollection[i].Display, '}'));
|
||||
// _Log.Info(string.Join(Environment.NewLine, from l in fileSystemCollection[i] where !string.IsNullOrEmpty(l) select l));
|
||||
_Log.Info(string.Empty);
|
||||
}
|
||||
// }
|
||||
}
|
||||
|
||||
private string Rename(Property.Models.Configuration configuration, string subSourceDirectory)
|
||||
{
|
||||
string result;
|
||||
if (_Log is null)
|
||||
throw new NullReferenceException(nameof(_Log));
|
||||
_Log.Warn(string.Concat("What is the new name for [", Path.GetFileName(subSourceDirectory), "]<", subSourceDirectory, ">?"));
|
||||
string? newDirectoryName = _Console.ReadLine();
|
||||
_Log.Warn("Are you sure y[es] || n[o]?");
|
||||
if (string.IsNullOrEmpty(newDirectoryName) || _Console.ReadKey() != ConsoleKey.Y)
|
||||
{
|
||||
_Log.Warn(string.Empty);
|
||||
_Log.Warn("No changes made.");
|
||||
result = subSourceDirectory;
|
||||
}
|
||||
else
|
||||
{
|
||||
_Log.Warn(string.Empty);
|
||||
string eDistanceCollectionDirectory = Path.Combine(Property.Models.Stateless.IResult.GetResultsFullGroupDirectory(configuration, nameof(E_Distance), _Configuration.ValidResolutions[0], includeResizeGroup: true, includeModel: true, includePredictorModel: true), "[]");
|
||||
string relativePath = Shared.Models.Stateless.Methods.IPath.GetRelativePath(subSourceDirectory, eDistanceCollectionDirectory.Length);
|
||||
if (relativePath.Length == 1)
|
||||
throw new Exception();
|
||||
if (Directory.Exists(Path.Combine(string.Concat(_Configuration.PropertyConfiguration.RootDirectory, Path.GetDirectoryName(relativePath)), newDirectoryName)))
|
||||
{
|
||||
_Log.Warn("\"To\" directory already exits!");
|
||||
result = subSourceDirectory;
|
||||
}
|
||||
else
|
||||
{
|
||||
_Rename.DirectoryRename(configuration, relativePath, newDirectoryName);
|
||||
_Log.Warn("Renamed...");
|
||||
string? directoryName = Path.GetDirectoryName(subSourceDirectory);
|
||||
if (string.IsNullOrEmpty(directoryName))
|
||||
throw new Exception();
|
||||
result = Path.Combine(directoryName, newDirectoryName);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
internal void Navigate(Property.Models.Configuration configuration, string outputResolution)
|
||||
{
|
||||
if (_Log is null)
|
||||
throw new NullReferenceException(nameof(_Log));
|
||||
string[] subFiles;
|
||||
ConsoleKey consoleKey;
|
||||
string[] subDirectories;
|
||||
string selectedFileFullName;
|
||||
string rootDirectory = string.Empty;
|
||||
string? subSourceDirectory = string.Empty;
|
||||
Dictionary<ConsoleKey, int> fileKeyValuePairs = new();
|
||||
Dictionary<ConsoleKey, int> directoryKeyValuePairs = new();
|
||||
string eDistanceCollectionDirectory = Path.Combine(Property.Models.Stateless.IResult.GetResultsFullGroupDirectory(configuration, nameof(E_Distance), _Configuration.OutputResolutions[0], includeResizeGroup: true, includeModel: true, includePredictorModel: true), "[]");
|
||||
if (!Directory.Exists(eDistanceCollectionDirectory))
|
||||
_ = Directory.CreateDirectory(eDistanceCollectionDirectory);
|
||||
for (int z = 0; z < int.MaxValue; z++)
|
||||
{
|
||||
if (string.IsNullOrEmpty(subSourceDirectory))
|
||||
{
|
||||
rootDirectory = eDistanceCollectionDirectory;
|
||||
subSourceDirectory = rootDirectory;
|
||||
}
|
||||
subFiles = Directory.GetFiles(subSourceDirectory, "*.json", SearchOption.TopDirectoryOnly);
|
||||
subDirectories = Directory.GetDirectories(subSourceDirectory, "*", SearchOption.TopDirectoryOnly);
|
||||
directoryKeyValuePairs.Clear();
|
||||
for (int i = (int)ConsoleKey.A; i < (subDirectories.Length + (int)ConsoleKey.A) && i <= (int)ConsoleKey.RightWindows; i++)
|
||||
directoryKeyValuePairs.Add((ConsoleKey)i, i - (int)ConsoleKey.A);
|
||||
fileKeyValuePairs.Clear();
|
||||
for (int i = (int)ConsoleKey.A + subDirectories.Length; i < (subFiles.Length + (int)ConsoleKey.A + subDirectories.Length) && i <= (int)ConsoleKey.RightWindows; i++)
|
||||
fileKeyValuePairs.Add((ConsoleKey)i, i - (int)ConsoleKey.A);
|
||||
if (!directoryKeyValuePairs.Any() && !fileKeyValuePairs.Any())
|
||||
break;
|
||||
_Log.Warn("");
|
||||
DisplayTags(configuration, outputResolution, subDirectories, directoryKeyValuePairs, subFiles, fileKeyValuePairs);
|
||||
_Log.Warn(string.Empty);
|
||||
_Log.Warn(string.Empty);
|
||||
_Log.Warn(string.Empty);
|
||||
_Log.Warn("Select a file system object. Enter \"Backspace\" to go up a directory, \"F2\" to rename and \"Esc\" to end navigation.");
|
||||
consoleKey = _Console.ReadKey();
|
||||
_Log.Warn(string.Empty);
|
||||
if (consoleKey == ConsoleKey.Escape)
|
||||
break;
|
||||
if (consoleKey == ConsoleKey.F2)
|
||||
{
|
||||
if (subSourceDirectory == rootDirectory)
|
||||
{
|
||||
_Log.Warn("Root directory can not be renamed! Try again.");
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
subSourceDirectory = Rename(configuration, subSourceDirectory);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
else if (consoleKey is ConsoleKey.Backspace or ConsoleKey.LeftArrow)
|
||||
{
|
||||
if (subSourceDirectory != rootDirectory)
|
||||
subSourceDirectory = Path.GetDirectoryName(subSourceDirectory);
|
||||
else
|
||||
{
|
||||
_Log.Warn("At root directory. Try again.");
|
||||
continue;
|
||||
}
|
||||
}
|
||||
else if (directoryKeyValuePairs.ContainsKey(consoleKey))
|
||||
{
|
||||
subSourceDirectory = subDirectories[directoryKeyValuePairs[consoleKey]];
|
||||
_Log.Warn(string.Concat(">>> [", Path.GetFileName(subSourceDirectory), "]<", subSourceDirectory, ">?"));
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!fileKeyValuePairs.ContainsKey(consoleKey))
|
||||
{
|
||||
subSourceDirectory = _ArgZero;
|
||||
_Log.Warn("Invalid selection. Try again.");
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
selectedFileFullName = subFiles[fileKeyValuePairs[consoleKey]];
|
||||
_Log.Warn(string.Concat(">>> [", Path.GetFileName(selectedFileFullName), "]<", selectedFileFullName, ">?"));
|
||||
DisplayFaces(configuration, outputResolution, selectedFileFullName);
|
||||
_Log.Warn(string.Empty);
|
||||
_Log.Warn(string.Empty);
|
||||
_Log.Warn(string.Empty);
|
||||
_Log.Warn("Go up a directory? Enter escape end.");
|
||||
consoleKey = _Console.ReadKey();
|
||||
if (consoleKey == ConsoleKey.Escape)
|
||||
break;
|
||||
subSourceDirectory = Path.GetDirectoryName(subSourceDirectory);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,336 +0,0 @@
|
||||
using System.Text.Json;
|
||||
using View_by_Distance.Distance.Models;
|
||||
using View_by_Distance.Face.Models;
|
||||
using View_by_Distance.FaceParts.Models;
|
||||
using View_by_Distance.Metadata.Models;
|
||||
using View_by_Distance.Resize.Models;
|
||||
|
||||
namespace View_by_Distance.Instance.Models;
|
||||
|
||||
/// <summary>
|
||||
// N/A
|
||||
/// </summary>
|
||||
internal class E3_Rename
|
||||
{
|
||||
|
||||
private readonly Serilog.ILogger? _Log;
|
||||
private readonly Configuration _Configuration;
|
||||
private readonly JsonSerializerOptions _WriteIndentedJsonSerializerOptions;
|
||||
|
||||
internal E3_Rename(Configuration configuration)
|
||||
{
|
||||
_Configuration = configuration;
|
||||
_Log = Serilog.Log.ForContext<G2_Identify>();
|
||||
_WriteIndentedJsonSerializerOptions = new JsonSerializerOptions { WriteIndented = true };
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
string result = JsonSerializer.Serialize(this, new JsonSerializerOptions() { WriteIndented = true });
|
||||
return result;
|
||||
}
|
||||
|
||||
internal string[] GetDirectoryRenameCollection(Property.Models.Configuration configuration, string relativePath, string newDirectoryName, bool jsonFiles4InfoAny)
|
||||
{
|
||||
List<string> results = new();
|
||||
bool add;
|
||||
string to;
|
||||
string dFacesContentDirectory;
|
||||
string cResizeContentDirectory;
|
||||
string dFacesCollectionDirectory;
|
||||
string cResizeSingletonDirectory;
|
||||
string eDistanceContentDirectory;
|
||||
string aPropertySingletonDirectory;
|
||||
string d2FacePartsContentDirectory;
|
||||
string bMetadataSingletonDirectory;
|
||||
string eDistanceCollectionDirectory;
|
||||
string g2IdentifyCollectionDirectory;
|
||||
add = Directory.Exists(string.Concat(Path.Combine(Property.Models.Stateless.IResult.GetResultsFullGroupDirectory(configuration, nameof(C_Resize), _Configuration.ValidResolutions[0], includeResizeGroup: true, includeModel: false, includePredictorModel: false), "()"), relativePath));
|
||||
bMetadataSingletonDirectory = Property.Models.Stateless.IResult.GetResultsDateGroupDirectory(configuration, nameof(B_Metadata), "{}");
|
||||
if (Directory.Exists(bMetadataSingletonDirectory))
|
||||
{
|
||||
to = Path.Combine(string.Concat(bMetadataSingletonDirectory, Path.GetDirectoryName(relativePath)), newDirectoryName);
|
||||
results.Add(to);
|
||||
}
|
||||
aPropertySingletonDirectory = Property.Models.Stateless.IResult.GetResultsDateGroupDirectory(configuration, nameof(Property.Models.A_Property), "{}");
|
||||
if (Directory.Exists(aPropertySingletonDirectory))
|
||||
{
|
||||
to = Path.Combine(string.Concat(aPropertySingletonDirectory, Path.GetDirectoryName(relativePath)), newDirectoryName);
|
||||
results.Add(to);
|
||||
}
|
||||
cResizeContentDirectory = Path.Combine(Property.Models.Stateless.IResult.GetResultsFullGroupDirectory(configuration, nameof(C_Resize), _Configuration.ValidResolutions[0], includeResizeGroup: true, includeModel: false, includePredictorModel: false), "()");
|
||||
if (Directory.Exists(cResizeContentDirectory))
|
||||
{
|
||||
to = Path.Combine(string.Concat(cResizeContentDirectory, Path.GetDirectoryName(relativePath)), newDirectoryName);
|
||||
results.Add(to);
|
||||
}
|
||||
foreach (string outputResolution in _Configuration.ValidResolutions)
|
||||
{
|
||||
cResizeSingletonDirectory = Path.Combine(Property.Models.Stateless.IResult.GetResultsFullGroupDirectory(configuration, nameof(C_Resize), outputResolution, includeResizeGroup: true, includeModel: false, includePredictorModel: false), "{}");
|
||||
if (Directory.Exists(cResizeSingletonDirectory))
|
||||
{
|
||||
to = Path.Combine(string.Concat(cResizeSingletonDirectory, Path.GetDirectoryName(relativePath)), newDirectoryName);
|
||||
results.Add(to);
|
||||
}
|
||||
dFacesContentDirectory = Path.Combine(Property.Models.Stateless.IResult.GetResultsFullGroupDirectory(configuration, nameof(D_Face), outputResolution, includeResizeGroup: true, includeModel: true, includePredictorModel: true), "()");
|
||||
if (Directory.Exists(dFacesContentDirectory))
|
||||
{
|
||||
to = Path.Combine(string.Concat(dFacesContentDirectory, Path.GetDirectoryName(relativePath)), newDirectoryName);
|
||||
results.Add(to);
|
||||
}
|
||||
dFacesCollectionDirectory = Path.Combine(Property.Models.Stateless.IResult.GetResultsFullGroupDirectory(configuration, nameof(D_Face), outputResolution, includeResizeGroup: true, includeModel: true, includePredictorModel: true), "[]");
|
||||
if (Directory.Exists(dFacesCollectionDirectory))
|
||||
{
|
||||
to = Path.Combine(string.Concat(dFacesCollectionDirectory, Path.GetDirectoryName(relativePath)), newDirectoryName);
|
||||
results.Add(to);
|
||||
}
|
||||
d2FacePartsContentDirectory = Path.Combine(Property.Models.Stateless.IResult.GetResultsFullGroupDirectory(configuration, nameof(D2_FaceParts), outputResolution, includeResizeGroup: true, includeModel: true, includePredictorModel: true), "()");
|
||||
if (add && _Configuration.SaveFaceLandmarkForOutputResolutions.Contains(outputResolution) && Directory.Exists(d2FacePartsContentDirectory))
|
||||
{
|
||||
to = Path.Combine(string.Concat(d2FacePartsContentDirectory, Path.GetDirectoryName(relativePath)), newDirectoryName);
|
||||
results.Add(to);
|
||||
}
|
||||
eDistanceContentDirectory = Path.Combine(Property.Models.Stateless.IResult.GetResultsFullGroupDirectory(configuration, nameof(E_Distance), outputResolution, includeResizeGroup: true, includeModel: true, includePredictorModel: true), "()");
|
||||
if (Directory.Exists(eDistanceContentDirectory))
|
||||
{
|
||||
to = Path.Combine(string.Concat(eDistanceContentDirectory, Path.GetDirectoryName(relativePath)), newDirectoryName);
|
||||
results.Add(to);
|
||||
}
|
||||
eDistanceCollectionDirectory = Path.Combine(Property.Models.Stateless.IResult.GetResultsFullGroupDirectory(configuration, nameof(E_Distance), outputResolution, includeResizeGroup: true, includeModel: true, includePredictorModel: true), "[]");
|
||||
if (Directory.Exists(eDistanceCollectionDirectory))
|
||||
{
|
||||
to = Path.Combine(string.Concat(eDistanceCollectionDirectory, Path.GetDirectoryName(relativePath)), newDirectoryName);
|
||||
results.Add(to);
|
||||
}
|
||||
g2IdentifyCollectionDirectory = Property.Models.Stateless.IResult.GetResultsDateGroupDirectory(configuration, nameof(G2_Identify), "[]");
|
||||
if (add && jsonFiles4InfoAny && Directory.Exists(g2IdentifyCollectionDirectory))
|
||||
{
|
||||
to = Path.Combine(string.Concat(g2IdentifyCollectionDirectory, Path.GetDirectoryName(relativePath)), newDirectoryName);
|
||||
results.Add(to);
|
||||
}
|
||||
}
|
||||
return results.ToArray();
|
||||
}
|
||||
|
||||
internal List<string[]> GetDirectoryRenameCollections(Property.Models.Configuration configuration, string relativePath, string newDirectoryName, bool jsonFiles4InfoAny)
|
||||
{
|
||||
List<string[]> results = new();
|
||||
bool add;
|
||||
string to;
|
||||
bool exists;
|
||||
string from;
|
||||
string dFacesContentDirectory;
|
||||
string cResizeContentDirectory;
|
||||
string dFacesCollectionDirectory;
|
||||
string cResizeSingletonDirectory;
|
||||
string eDistanceContentDirectory;
|
||||
string bMetadataSingletonDirectory;
|
||||
string aPropertySingletonDirectory;
|
||||
string d2FacePartsContentDirectory;
|
||||
string eDistanceCollectionDirectory;
|
||||
string g2IdentifyCollectionDirectory;
|
||||
if (!string.IsNullOrEmpty(relativePath))
|
||||
{
|
||||
from = string.Concat(_Configuration.PropertyConfiguration.RootDirectory, relativePath);
|
||||
to = Path.Combine(string.Concat(_Configuration.PropertyConfiguration.RootDirectory, Path.GetDirectoryName(relativePath)), newDirectoryName);
|
||||
results.Add(new string[] { from, to });
|
||||
}
|
||||
foreach (string outputResolution in _Configuration.ValidResolutions)
|
||||
{
|
||||
add = Directory.Exists(string.Concat(Path.Combine(Property.Models.Stateless.IResult.GetResultsFullGroupDirectory(configuration, nameof(C_Resize), outputResolution, includeResizeGroup: true, includeModel: false, includePredictorModel: false), "()"), relativePath));
|
||||
bMetadataSingletonDirectory = Property.Models.Stateless.IResult.GetResultsDateGroupDirectory(configuration, nameof(B_Metadata), "{}");
|
||||
from = string.Concat(bMetadataSingletonDirectory, relativePath);
|
||||
exists = Directory.Exists(bMetadataSingletonDirectory);
|
||||
if (exists)
|
||||
{
|
||||
to = Path.Combine(string.Concat(bMetadataSingletonDirectory, Path.GetDirectoryName(relativePath)), newDirectoryName);
|
||||
results.Add(new string[] { from, to });
|
||||
}
|
||||
aPropertySingletonDirectory = Property.Models.Stateless.IResult.GetResultsDateGroupDirectory(configuration, nameof(Property.Models.A_Property), "{}");
|
||||
from = string.Concat(aPropertySingletonDirectory, relativePath);
|
||||
exists = Directory.Exists(aPropertySingletonDirectory);
|
||||
if (exists)
|
||||
{
|
||||
to = Path.Combine(string.Concat(aPropertySingletonDirectory, Path.GetDirectoryName(relativePath)), newDirectoryName);
|
||||
results.Add(new string[] { from, to });
|
||||
}
|
||||
cResizeContentDirectory = Path.Combine(Property.Models.Stateless.IResult.GetResultsFullGroupDirectory(configuration, nameof(C_Resize), outputResolution, includeResizeGroup: true, includeModel: false, includePredictorModel: false), "()");
|
||||
from = string.Concat(cResizeContentDirectory, relativePath);
|
||||
exists = Directory.Exists(cResizeContentDirectory);
|
||||
if (exists)
|
||||
{
|
||||
to = Path.Combine(string.Concat(cResizeContentDirectory, Path.GetDirectoryName(relativePath)), newDirectoryName);
|
||||
results.Add(new string[] { from, to });
|
||||
}
|
||||
cResizeSingletonDirectory = Path.Combine(Property.Models.Stateless.IResult.GetResultsFullGroupDirectory(configuration, nameof(C_Resize), outputResolution, includeResizeGroup: true, includeModel: false, includePredictorModel: false), "{}");
|
||||
from = string.Concat(cResizeSingletonDirectory, relativePath);
|
||||
exists = Directory.Exists(cResizeSingletonDirectory);
|
||||
if (exists)
|
||||
{
|
||||
to = Path.Combine(string.Concat(cResizeSingletonDirectory, Path.GetDirectoryName(relativePath)), newDirectoryName);
|
||||
results.Add(new string[] { from, to });
|
||||
}
|
||||
dFacesContentDirectory = Path.Combine(Property.Models.Stateless.IResult.GetResultsFullGroupDirectory(configuration, nameof(D_Face), outputResolution, includeResizeGroup: true, includeModel: true, includePredictorModel: true), "()");
|
||||
from = string.Concat(dFacesContentDirectory, relativePath);
|
||||
exists = Directory.Exists(dFacesContentDirectory);
|
||||
if (exists)
|
||||
{
|
||||
to = Path.Combine(string.Concat(dFacesContentDirectory, Path.GetDirectoryName(relativePath)), newDirectoryName);
|
||||
results.Add(new string[] { from, to });
|
||||
}
|
||||
dFacesCollectionDirectory = Path.Combine(Property.Models.Stateless.IResult.GetResultsFullGroupDirectory(configuration, nameof(D_Face), outputResolution, includeResizeGroup: true, includeModel: true, includePredictorModel: true), "[]");
|
||||
from = string.Concat(dFacesCollectionDirectory, relativePath);
|
||||
exists = Directory.Exists(dFacesCollectionDirectory);
|
||||
if (exists)
|
||||
{
|
||||
to = Path.Combine(string.Concat(dFacesCollectionDirectory, Path.GetDirectoryName(relativePath)), newDirectoryName);
|
||||
results.Add(new string[] { from, to });
|
||||
}
|
||||
d2FacePartsContentDirectory = Path.Combine(Property.Models.Stateless.IResult.GetResultsFullGroupDirectory(configuration, nameof(D2_FaceParts), outputResolution, includeResizeGroup: true, includeModel: true, includePredictorModel: true), "()");
|
||||
from = string.Concat(d2FacePartsContentDirectory, relativePath);
|
||||
exists = Directory.Exists(d2FacePartsContentDirectory);
|
||||
if (!exists && add && _Configuration.SaveFaceLandmarkForOutputResolutions.Contains(outputResolution))
|
||||
results.Add(new string[] { from });
|
||||
else if (exists)
|
||||
{
|
||||
to = Path.Combine(string.Concat(d2FacePartsContentDirectory, Path.GetDirectoryName(relativePath)), newDirectoryName);
|
||||
results.Add(new string[] { from, to });
|
||||
}
|
||||
eDistanceContentDirectory = Path.Combine(Property.Models.Stateless.IResult.GetResultsFullGroupDirectory(configuration, nameof(E_Distance), outputResolution, includeResizeGroup: true, includeModel: true, includePredictorModel: true), "()");
|
||||
from = string.Concat(eDistanceContentDirectory, relativePath);
|
||||
exists = Directory.Exists(eDistanceContentDirectory);
|
||||
if (exists)
|
||||
{
|
||||
to = Path.Combine(string.Concat(eDistanceContentDirectory, Path.GetDirectoryName(relativePath)), newDirectoryName);
|
||||
results.Add(new string[] { from, to });
|
||||
}
|
||||
eDistanceCollectionDirectory = Path.Combine(Property.Models.Stateless.IResult.GetResultsFullGroupDirectory(configuration, nameof(E_Distance), outputResolution, includeResizeGroup: true, includeModel: true, includePredictorModel: true), "[]");
|
||||
from = string.Concat(eDistanceCollectionDirectory, relativePath);
|
||||
exists = Directory.Exists(eDistanceCollectionDirectory);
|
||||
if (exists)
|
||||
{
|
||||
to = Path.Combine(string.Concat(eDistanceCollectionDirectory, Path.GetDirectoryName(relativePath)), newDirectoryName);
|
||||
results.Add(new string[] { from, to });
|
||||
}
|
||||
g2IdentifyCollectionDirectory = Property.Models.Stateless.IResult.GetResultsDateGroupDirectory(configuration, nameof(G2_Identify), "[]");
|
||||
from = string.Concat(g2IdentifyCollectionDirectory, relativePath);
|
||||
exists = Directory.Exists(g2IdentifyCollectionDirectory);
|
||||
if (!exists && add && jsonFiles4InfoAny)
|
||||
results.Add(new string[] { from });
|
||||
else if (exists)
|
||||
{
|
||||
to = Path.Combine(string.Concat(g2IdentifyCollectionDirectory, Path.GetDirectoryName(relativePath)), newDirectoryName);
|
||||
results.Add(new string[] { from, to });
|
||||
}
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
internal void DirectoryRename(Property.Models.Configuration configuration, string relativePath, string newDirectoryName)
|
||||
{
|
||||
string json;
|
||||
FileInfo current;
|
||||
FileInfo fileInfo;
|
||||
string error = "Error";
|
||||
string target = "Target";
|
||||
string pending = "Pending";
|
||||
DirectoryInfo directoryInfo;
|
||||
IEnumerator<FileInfo> fileInfoCollection;
|
||||
string oldValue = string.Concat("\"", relativePath);
|
||||
string oldDirectoryName = Path.GetFileName(relativePath);
|
||||
string traceFileName = string.Concat(DateTime.Now.Ticks, ".tsv");
|
||||
string directoryName = Path.GetFileName(_Configuration.PropertyConfiguration.RootDirectory);
|
||||
string? relativePathParent = Path.GetDirectoryName(relativePath);
|
||||
if (string.IsNullOrEmpty(relativePathParent))
|
||||
throw new Exception();
|
||||
string newValue = string.Concat("\"", Path.Combine(relativePathParent, newDirectoryName));
|
||||
string e3RenameContentDirectory = Property.Models.Stateless.IResult.GetResultsDateGroupDirectory(configuration, nameof(E3_Rename), "()");
|
||||
string jsonRootDirectory = Path.Combine(string.Concat(_Configuration.PropertyConfiguration.RootDirectory, " - Copied"), string.Concat(directoryName, " - 4) Info"), _Configuration.PropertyConfiguration.DateGroup, "[]");
|
||||
directoryInfo = new DirectoryInfo(jsonRootDirectory);
|
||||
if (!directoryInfo.Exists)
|
||||
directoryInfo.Create();
|
||||
IEnumerator<FileInfo> fileInfoCollection4 = directoryInfo.EnumerateFiles("*.json", SearchOption.AllDirectories).GetEnumerator();
|
||||
bool fileInfoCollection4MoveNext = fileInfoCollection4.MoveNext();
|
||||
if (!fileInfoCollection4MoveNext)
|
||||
current = new(string.Empty);
|
||||
else
|
||||
current = fileInfoCollection4.Current;
|
||||
List<string[]> directoryCollections = GetDirectoryRenameCollections(configuration, relativePath, newDirectoryName, fileInfoCollection4MoveNext);
|
||||
if ((from l in directoryCollections where l.Length != 2 select true).Any())
|
||||
throw new Exception();
|
||||
if (!Directory.Exists(e3RenameContentDirectory))
|
||||
{
|
||||
_ = Directory.CreateDirectory(e3RenameContentDirectory);
|
||||
_ = Directory.CreateDirectory(Path.Combine(e3RenameContentDirectory, error));
|
||||
_ = Directory.CreateDirectory(Path.Combine(e3RenameContentDirectory, target));
|
||||
_ = Directory.CreateDirectory(Path.Combine(e3RenameContentDirectory, "Test"));
|
||||
_ = Directory.CreateDirectory(Path.Combine(e3RenameContentDirectory, pending));
|
||||
}
|
||||
string fRandomSingletonDirectory = Property.Models.Stateless.IResult.GetResultsDateGroupDirectory(configuration, nameof(F_Random), "{}");
|
||||
string[] files = Directory.GetFiles(fRandomSingletonDirectory, "*", SearchOption.TopDirectoryOnly);
|
||||
foreach (string file in files)
|
||||
File.Delete(file);
|
||||
File.WriteAllText(Path.Combine(e3RenameContentDirectory, pending, traceFileName), string.Concat(relativePath, newDirectoryName, Environment.NewLine));
|
||||
try
|
||||
{
|
||||
foreach (string[] directoryCollection in directoryCollections)
|
||||
{
|
||||
directoryInfo = new DirectoryInfo(directoryCollection[0]);
|
||||
if (!directoryInfo.Exists)
|
||||
continue;
|
||||
fileInfoCollection = directoryInfo.EnumerateFiles("*.json", SearchOption.AllDirectories).GetEnumerator();
|
||||
for (int i = 0; i < int.MaxValue; i++)
|
||||
{
|
||||
if (fileInfoCollection.MoveNext())
|
||||
fileInfo = fileInfoCollection.Current;
|
||||
else if (fileInfoCollection4MoveNext && fileInfoCollection4.MoveNext())
|
||||
fileInfo = fileInfoCollection4.Current;
|
||||
else if (fileInfoCollection4MoveNext && current is not null)
|
||||
{
|
||||
fileInfo = current;
|
||||
current = new(string.Empty);
|
||||
}
|
||||
else
|
||||
break;
|
||||
json = Shared.Models.Stateless.Methods.IIndex.GetJson(fileInfo.FullName, fileInfo);
|
||||
if (json.Contains(oldValue))
|
||||
{
|
||||
json = json.Replace(oldValue, newValue);
|
||||
if (!Shared.Models.Stateless.Methods.IPath.WriteAllText(fileInfo.FullName, json, updateDateWhenMatches: true, compareBeforeWrite: true))
|
||||
continue;
|
||||
File.SetLastWriteTime(fileInfo.FullName, fileInfo.LastWriteTime);
|
||||
}
|
||||
}
|
||||
Directory.Move(directoryCollection[0], directoryCollection[1]);
|
||||
}
|
||||
File.Move(Path.Combine(e3RenameContentDirectory, pending, traceFileName), Path.Combine(e3RenameContentDirectory, target, traceFileName));
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
File.Move(Path.Combine(e3RenameContentDirectory, pending, traceFileName), Path.Combine(e3RenameContentDirectory, error, traceFileName));
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
internal void RenameQueue(Property.Models.Configuration configuration)
|
||||
{
|
||||
string[] lines;
|
||||
string[] segments;
|
||||
string e3RenameContentDirectory = Property.Models.Stateless.IResult.GetResultsDateGroupDirectory(configuration, nameof(E3_Rename), "()");
|
||||
string[] files = Directory.GetFiles(e3RenameContentDirectory, "*.tsv", SearchOption.TopDirectoryOnly);
|
||||
foreach (string file in files)
|
||||
{
|
||||
lines = File.ReadAllLines(file);
|
||||
foreach (string line in lines)
|
||||
{
|
||||
if (string.IsNullOrEmpty(line) || !line.Contains('\t'))
|
||||
continue;
|
||||
segments = line.Split('\t');
|
||||
if (segments.Length != 2)
|
||||
throw new Exception();
|
||||
DirectoryRename(configuration, segments[0], segments[1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,234 +0,0 @@
|
||||
using Phares.Shared;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using View_by_Distance.Shared.Models;
|
||||
using View_by_Distance.Shared.Models.Methods;
|
||||
|
||||
namespace View_by_Distance.Instance.Models;
|
||||
|
||||
/// <summary>
|
||||
// List<G2_Identify>
|
||||
/// </summary>
|
||||
public class G2_Identify : Shared.Models.Properties.IIdentify, IIdentify
|
||||
{
|
||||
|
||||
protected int _DirectoryCount;
|
||||
protected string _ParentDirectoryName;
|
||||
protected string _Person;
|
||||
protected string _PossibleYear;
|
||||
protected string _RelativePath;
|
||||
public int DirectoryCount => _DirectoryCount;
|
||||
public string ParentDirectoryName => _ParentDirectoryName;
|
||||
public string Person => _Person;
|
||||
public string PossibleYear => _PossibleYear;
|
||||
public string RelativePath => _RelativePath;
|
||||
|
||||
private readonly Serilog.ILogger? _Log;
|
||||
private readonly Configuration _Configuration;
|
||||
private readonly JsonSerializerOptions _WriteIndentedJsonSerializerOptions;
|
||||
|
||||
#nullable disable
|
||||
[JsonConstructor]
|
||||
public G2_Identify(int directoryCount, string parentDirectoryName, string person, string possibleYear, string relativePath)
|
||||
{
|
||||
_DirectoryCount = directoryCount;
|
||||
_ParentDirectoryName = parentDirectoryName;
|
||||
_Person = person;
|
||||
_PossibleYear = possibleYear;
|
||||
_RelativePath = relativePath;
|
||||
}
|
||||
|
||||
internal G2_Identify(Configuration configuration)
|
||||
{
|
||||
_DirectoryCount = 0;
|
||||
_ParentDirectoryName = string.Empty;
|
||||
_Person = string.Empty;
|
||||
_PossibleYear = string.Empty;
|
||||
_RelativePath = string.Empty;
|
||||
_Configuration = configuration;
|
||||
_Log = Serilog.Log.ForContext<G2_Identify>();
|
||||
_WriteIndentedJsonSerializerOptions = new JsonSerializerOptions { WriteIndented = true };
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
string result = JsonSerializer.Serialize(this, new JsonSerializerOptions() { WriteIndented = true });
|
||||
return result;
|
||||
}
|
||||
|
||||
private FileInfo GetNamed()
|
||||
{
|
||||
FileInfo result;
|
||||
string[] jsonFiles = Directory.GetFiles(_Configuration.PropertyConfiguration.RootDirectory, "*Named*.json", SearchOption.TopDirectoryOnly);
|
||||
if (!jsonFiles.Any())
|
||||
result = null;
|
||||
else
|
||||
result = new FileInfo(jsonFiles[0]);
|
||||
return result;
|
||||
}
|
||||
|
||||
private void CheckLastWriteTimes(IsEnvironment isEnvironment, string facesFileNameExtension, FileInfo named, string g2IdentifySingletonDirectory)
|
||||
{
|
||||
string json;
|
||||
FileInfo fileInfo;
|
||||
DateTime dateTime = DateTime.MinValue;
|
||||
string[] jsonFiles = Directory.GetFiles(g2IdentifySingletonDirectory, "*.json", SearchOption.AllDirectories);
|
||||
foreach (string jsonFile in jsonFiles)
|
||||
{
|
||||
fileInfo = new(jsonFile);
|
||||
if (dateTime < fileInfo.LastWriteTime)
|
||||
dateTime = fileInfo.LastWriteTime;
|
||||
}
|
||||
if (named.LastWriteTime > dateTime)
|
||||
{
|
||||
if (!isEnvironment.DebuggerWasAttachedDuringConstructor)
|
||||
throw new Exception("Only allowed when debugger is attached during constructor!");
|
||||
foreach (string file in jsonFiles)
|
||||
File.Delete(file);
|
||||
}
|
||||
json = File.ReadAllText(named.FullName);
|
||||
Dictionary<string, string[]> resultKeyValuePairs = new();
|
||||
string rootDirectory = _Configuration.PropertyConfiguration.RootDirectory;
|
||||
string peopleRootDirectory = Property.Models.Stateless.IResult.GetResultsDateGroupDirectory(_Configuration.PropertyConfiguration, nameof(A2_People));
|
||||
string rootResultsDirectory = Path.GetDirectoryName(Path.GetDirectoryName(peopleRootDirectory));
|
||||
if (rootResultsDirectory is null)
|
||||
throw new Exception();
|
||||
Storage storage = new(rootDirectory, rootResultsDirectory, peopleRootDirectory);
|
||||
PersonContainer[] personContainers = Shared.Models.Stateless.Methods.IPersonContainer.GetPersonContainers(storage, _Configuration.PersonBirthdayFormat, _Configuration.PersonCharacters.ToArray(), facesFileNameExtension);
|
||||
string[] peopleBirthDates = (from l in personContainers select Shared.Models.Stateless.Methods.IPersonBirthday.GetFormatted(_Configuration.PersonBirthdayFormat, l.Person.Birthday)).ToArray();
|
||||
Dictionary<string, string[]> sourceKeyValuePairs = JsonSerializer.Deserialize<Dictionary<string, string[]>>(json);
|
||||
foreach (KeyValuePair<string, string[]> keyValuePair in sourceKeyValuePairs)
|
||||
{
|
||||
if (!(from l in keyValuePair.Value where peopleBirthDates.Contains(l) select false).Any())
|
||||
continue;
|
||||
resultKeyValuePairs.Add(keyValuePair.Key, keyValuePair.Value);
|
||||
}
|
||||
if (resultKeyValuePairs.Count != sourceKeyValuePairs.Count)
|
||||
{
|
||||
json = JsonSerializer.Serialize(resultKeyValuePairs, _WriteIndentedJsonSerializerOptions);
|
||||
if (!isEnvironment.DebuggerWasAttachedDuringConstructor)
|
||||
throw new Exception("Only allowed when debugger is attached during constructor!");
|
||||
_ = Shared.Models.Stateless.Methods.IPath.WriteAllText(named.FullName, json, updateDateWhenMatches: true, compareBeforeWrite: true);
|
||||
}
|
||||
}
|
||||
|
||||
internal List<G2_Identify> GetIdentifiedCollection(IsEnvironment isEnvironment, Property.Models.Configuration configuration, string facesFileNameExtension)
|
||||
{
|
||||
List<G2_Identify> results = new();
|
||||
string json;
|
||||
string[] people;
|
||||
string[] jsonFiles;
|
||||
int directoryCount;
|
||||
string possibleYear;
|
||||
G2_Identify identify;
|
||||
FileInfo named = GetNamed();
|
||||
string testDirectoryFullName;
|
||||
string checkDirectoryFullName;
|
||||
Dictionary<int, string[]> keyValuePairs;
|
||||
List<string> missing = new();
|
||||
List<G_Index> indices = new();
|
||||
string directoryName = Path.GetFileName(_Configuration.PropertyConfiguration.RootDirectory);
|
||||
string g2IdentifySingletonDirectory = Property.Models.Stateless.IResult.GetResultsDateGroupDirectory(configuration, nameof(G2_Identify), "[]");
|
||||
string jsonRootDirectory = Path.Combine(string.Concat(_Configuration.PropertyConfiguration.RootDirectory, " - Copied"), string.Concat(directoryName, " - 4) Info"), _Configuration.PropertyConfiguration.DateGroup, "[]");
|
||||
if (named is not null && named.Exists)
|
||||
CheckLastWriteTimes(isEnvironment, facesFileNameExtension, named, g2IdentifySingletonDirectory);
|
||||
if (Directory.Exists(jsonRootDirectory))
|
||||
{
|
||||
jsonFiles = Directory.GetFiles(jsonRootDirectory, "*.json", SearchOption.AllDirectories);
|
||||
for (int i = 0; i < jsonFiles.Length; i++)
|
||||
{
|
||||
json = Shared.Models.Stateless.Methods.IIndex.GetJson(jsonFiles[i], fileInfo: null);
|
||||
indices.AddRange(JsonSerializer.Deserialize<List<G_Index>>(json));
|
||||
}
|
||||
if (named is not null && named.Exists)
|
||||
{
|
||||
json = File.ReadAllText(named.FullName);
|
||||
keyValuePairs = JsonSerializer.Deserialize<Dictionary<int, string[]>>(json);
|
||||
foreach (G_Index index in indices)
|
||||
{
|
||||
if (index?.Index is null)
|
||||
continue;
|
||||
if (!keyValuePairs.ContainsKey(index.Index.Value))
|
||||
{
|
||||
missing.Add(index.Index.Value.ToString());
|
||||
continue;
|
||||
}
|
||||
if (index.RelativePaths is null)
|
||||
{
|
||||
missing.Add(index.Index.Value.ToString());
|
||||
continue;
|
||||
}
|
||||
people = keyValuePairs[index.Index.Value];
|
||||
foreach (string relativePath in index.RelativePaths)
|
||||
{
|
||||
foreach (string person in people)
|
||||
{
|
||||
directoryCount = 0;
|
||||
checkDirectoryFullName = string.Concat(_Configuration.PropertyConfiguration.RootDirectory, relativePath);
|
||||
for (int i = 0; i < int.MaxValue; i++)
|
||||
{
|
||||
testDirectoryFullName = Path.GetDirectoryName(checkDirectoryFullName);
|
||||
if (testDirectoryFullName == _Configuration.PropertyConfiguration.RootDirectory)
|
||||
break;
|
||||
directoryCount += 1;
|
||||
checkDirectoryFullName = testDirectoryFullName;
|
||||
}
|
||||
possibleYear = checkDirectoryFullName.Split(' ').Last();
|
||||
if (possibleYear.Length != 4)
|
||||
possibleYear = "0000";
|
||||
identify = new G2_Identify(directoryCount, Path.GetFileName(checkDirectoryFullName), person, possibleYear, relativePath);
|
||||
results.Add(identify);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
results = (from l in results orderby l.PossibleYear descending, l.DirectoryCount, l.ParentDirectoryName, l.RelativePath select l).ToList();
|
||||
return results;
|
||||
}
|
||||
|
||||
internal void WriteAllText(Property.Models.Configuration configuration, string outputResolution, List<G2_Identify> identifiedCollection)
|
||||
{
|
||||
string key;
|
||||
string json;
|
||||
string jsonFile;
|
||||
string directoryFullName;
|
||||
string fileNameWithoutExtension;
|
||||
string aPropertySingletonDirectory = Property.Models.Stateless.IResult.GetResultsDateGroupDirectory(configuration, nameof(Property.Models.A_Property), "{}");
|
||||
string g2IdentifyCollectionDirectory = Property.Models.Stateless.IResult.GetResultsDateGroupDirectory(configuration, nameof(G2_Identify), "[]");
|
||||
Dictionary<string, List<KeyValuePair<string, string>>> keyValuePairs = new();
|
||||
foreach (G2_Identify identified in identifiedCollection)
|
||||
{
|
||||
key = Path.GetDirectoryName(identified.RelativePath);
|
||||
if (!keyValuePairs.ContainsKey(key))
|
||||
keyValuePairs.Add(key, new List<KeyValuePair<string, string>>());
|
||||
keyValuePairs[key].Add(new KeyValuePair<string, string>(identified.RelativePath, identified.Person));
|
||||
}
|
||||
foreach (KeyValuePair<string, List<KeyValuePair<string, string>>> keyValuePair in keyValuePairs)
|
||||
{
|
||||
directoryFullName = string.Concat(aPropertySingletonDirectory, keyValuePair.Key);
|
||||
if (!Directory.Exists(directoryFullName))
|
||||
continue;
|
||||
foreach (KeyValuePair<string, string> keyValue in keyValuePair.Value)
|
||||
{
|
||||
fileNameWithoutExtension = Path.GetFileNameWithoutExtension(keyValue.Key);
|
||||
jsonFile = Path.Combine(directoryFullName, $"{fileNameWithoutExtension}.json");
|
||||
if (!File.Exists(jsonFile))
|
||||
{
|
||||
directoryFullName = string.Empty;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (string.IsNullOrEmpty(directoryFullName))
|
||||
continue;
|
||||
directoryFullName = Path.GetDirectoryName(string.Concat(g2IdentifyCollectionDirectory, keyValuePair.Key));
|
||||
if (!Directory.Exists(directoryFullName))
|
||||
_ = Directory.CreateDirectory(directoryFullName);
|
||||
jsonFile = string.Concat(g2IdentifyCollectionDirectory, keyValuePair.Key, ".json");
|
||||
json = JsonSerializer.Serialize(keyValuePair.Value, _WriteIndentedJsonSerializerOptions);
|
||||
if (!Shared.Models.Stateless.Methods.IPath.WriteAllText(jsonFile, json, updateDateWhenMatches: true, compareBeforeWrite: true))
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,202 +0,0 @@
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using View_by_Distance.Shared.Models.Methods;
|
||||
|
||||
namespace View_by_Distance.Instance.Models;
|
||||
|
||||
/// <summary>
|
||||
// G_Index && G_Index[]
|
||||
/// </summary>
|
||||
public class G_Index : Shared.Models.Properties.IIndex, IIndex
|
||||
{
|
||||
|
||||
private readonly Serilog.ILogger? _Log;
|
||||
private readonly Configuration _Configuration;
|
||||
private readonly JsonSerializerOptions _WriteIndentedJsonSerializerOptions;
|
||||
|
||||
protected DateTime? _DateTime;
|
||||
protected int? _Index;
|
||||
protected List<string> _RelativePaths;
|
||||
public DateTime? DateTime => _DateTime;
|
||||
public int? Index => _Index;
|
||||
public List<string> RelativePaths => _RelativePaths;
|
||||
|
||||
#nullable disable
|
||||
[JsonConstructor]
|
||||
public G_Index(DateTime? dateTime, int? index, List<string> relativePaths)
|
||||
{
|
||||
_DateTime = dateTime;
|
||||
_Index = index;
|
||||
_RelativePaths = relativePaths;
|
||||
}
|
||||
|
||||
internal G_Index()
|
||||
{
|
||||
_DateTime = null;
|
||||
_Index = null;
|
||||
_RelativePaths = new();
|
||||
}
|
||||
|
||||
internal G_Index(Configuration configuration)
|
||||
{
|
||||
_Configuration = configuration;
|
||||
_Log = Serilog.Log.ForContext<G_Index>();
|
||||
_WriteIndentedJsonSerializerOptions = new JsonSerializerOptions { WriteIndented = true };
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
string result = JsonSerializer.Serialize(this, new JsonSerializerOptions() { WriteIndented = true });
|
||||
return result;
|
||||
}
|
||||
|
||||
private G_Index GetIndexInfo(FileInfo fileInfo, List<string> parseExceptions)
|
||||
{
|
||||
G_Index result;
|
||||
List<int> indices = new();
|
||||
string json = File.ReadAllText(fileInfo.FullName);
|
||||
try
|
||||
{
|
||||
result = JsonSerializer.Deserialize<G_Index>(json);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
result = null;
|
||||
parseExceptions.Add(nameof(G_Index));
|
||||
}
|
||||
if (_Configuration.MappedMaxIndex.HasValue && result.Index.HasValue && _Configuration.MappedMaxIndex.Value < result.Index.Value)
|
||||
{
|
||||
result = null;
|
||||
File.Delete(fileInfo.FullName);
|
||||
}
|
||||
else if (result.Index is null)
|
||||
result = null;
|
||||
return result;
|
||||
}
|
||||
|
||||
private void WriteNeeded(List<int> indices, List<Tuple<List<string>, string, Shared.Models.Property>> neededTuples)
|
||||
{
|
||||
string json;
|
||||
DateTime dateTime;
|
||||
Shared.Models.Property property;
|
||||
G_Index indexInfo;
|
||||
int maxIndexPlusOne;
|
||||
DateTime?[] dateTimes;
|
||||
if (indices.Any())
|
||||
maxIndexPlusOne = indices.Max() + 1;
|
||||
else
|
||||
{
|
||||
maxIndexPlusOne = 1000000;
|
||||
throw new Exception("Are you sure exception. Use debugger to step over.");
|
||||
}
|
||||
foreach (Tuple<List<string>, string, Shared.Models.Property> tuple in neededTuples)
|
||||
{
|
||||
maxIndexPlusOne += 1;
|
||||
property = tuple.Item3;
|
||||
dateTimes = new DateTime?[] { property.CreationTime, property.LastWriteTime, property.DateTime, property.DateTimeDigitized, property.DateTimeOriginal, property.GPSDateStamp };
|
||||
dateTime = (from l in dateTimes where l.HasValue select l.Value).Min();
|
||||
indexInfo = new(dateTime, maxIndexPlusOne, tuple.Item1);
|
||||
json = JsonSerializer.Serialize(indexInfo, _WriteIndentedJsonSerializerOptions);
|
||||
if (!Shared.Models.Stateless.Methods.IPath.WriteAllText(tuple.Item2, json, updateDateWhenMatches: true, compareBeforeWrite: true))
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
private void WriteGroup(Property.Models.Configuration configuration, string outputResolution, List<Tuple<string, Dictionary<int, G_Index>>> indexInfoTuples)
|
||||
{
|
||||
string json;
|
||||
G_Index[] indices;
|
||||
List<string> directoryInfoCollection;
|
||||
foreach (Tuple<string, Dictionary<int, G_Index>> tuple in indexInfoTuples)
|
||||
{
|
||||
indices = (from l in tuple.Item2 select l.Value).ToArray();
|
||||
directoryInfoCollection = Property.Models.Stateless.IResult.GetDirectoryInfoCollection(configuration, tuple.Item1, nameof(G_Index), outputResolution, includeResizeGroup: false, includeModel: false, includePredictorModel: false, contentDescription: string.Empty, singletonDescription: string.Empty, collectionDescription: "Unknown A");
|
||||
json = JsonSerializer.Serialize(indices, _WriteIndentedJsonSerializerOptions);
|
||||
if (!Shared.Models.Stateless.Methods.IPath.WriteAllText(string.Concat(directoryInfoCollection[0].Replace("<>", "[]"), ".json"), json, updateDateWhenMatches: true, compareBeforeWrite: true))
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
private void AppendTSV(Property.Models.Configuration configuration, string outputResolution, Dictionary<string, List<Tuple<string, Shared.Models.Property>>> filePropertiesKeyValuePairs)
|
||||
{
|
||||
Shared.Models.Property property;
|
||||
DateTime?[] dateTimes;
|
||||
DateTime? maximumDateTime;
|
||||
DateTime? minimumDateTime;
|
||||
List<string> directoryInfoCollection;
|
||||
long ticks = System.DateTime.Now.Ticks;
|
||||
foreach (KeyValuePair<string, List<Tuple<string, Shared.Models.Property>>> tuples in filePropertiesKeyValuePairs)
|
||||
{
|
||||
maximumDateTime = null;
|
||||
minimumDateTime = null;
|
||||
foreach (Tuple<string, Shared.Models.Property> tuple in tuples.Value)
|
||||
{
|
||||
property = tuple.Item2;
|
||||
dateTimes = new DateTime?[] { maximumDateTime, minimumDateTime, property.CreationTime, property.LastWriteTime, property.DateTime, property.DateTimeDigitized, property.DateTimeOriginal, property.GPSDateStamp };
|
||||
maximumDateTime = (from l in dateTimes where l.HasValue select l.Value).Max();
|
||||
minimumDateTime = (from l in dateTimes where l.HasValue select l.Value).Min();
|
||||
}
|
||||
directoryInfoCollection = Property.Models.Stateless.IResult.GetDirectoryInfoCollection(configuration, tuples.Key, nameof(G_Index), outputResolution, includeResizeGroup: false, includeModel: false, includePredictorModel: false, contentDescription: string.Empty, singletonDescription: "Unkown B", collectionDescription: string.Empty);
|
||||
}
|
||||
}
|
||||
|
||||
internal void SetIndex(Property.Models.Configuration configuration, string outputResolution)
|
||||
{
|
||||
Dictionary<string, List<Tuple<string, Shared.Models.Property>>> filePropertiesKeyValuePairs = new();
|
||||
FileInfo fileInfo;
|
||||
G_Index indexInfo;
|
||||
List<int> indices = new();
|
||||
Dictionary<int, G_Index> valuePairs;
|
||||
List<string> directoryInfoCollection;
|
||||
List<string> parseExceptions = new();
|
||||
List<Tuple<List<string>, string, Shared.Models.Property>> neededTuples = new();
|
||||
List<Tuple<string, Dictionary<int, G_Index>>> indexInfoTuples = new();
|
||||
for (short i = 0; i < short.MaxValue; i++)
|
||||
{
|
||||
if (i != 0)
|
||||
{
|
||||
if (!neededTuples.Any() && !parseExceptions.Any())
|
||||
break;
|
||||
indices.Clear();
|
||||
indexInfoTuples.Clear();
|
||||
parseExceptions.Clear();
|
||||
}
|
||||
neededTuples.Clear();
|
||||
foreach (KeyValuePair<string, List<Tuple<string, Shared.Models.Property>>> tuples in filePropertiesKeyValuePairs)
|
||||
{
|
||||
valuePairs = new Dictionary<int, G_Index>();
|
||||
directoryInfoCollection = Property.Models.Stateless.IResult.GetDirectoryInfoCollection(configuration, tuples.Key, nameof(G_Index), outputResolution, includeResizeGroup: false, includeModel: false, includePredictorModel: false, contentDescription: string.Empty, singletonDescription: "Unknown C", collectionDescription: string.Empty);
|
||||
foreach (Tuple<string, Shared.Models.Property> tuple in tuples.Value)
|
||||
{
|
||||
fileInfo = new FileInfo(Path.Combine(directoryInfoCollection[0].Replace("<>", "{}"), string.Concat(Path.GetFileNameWithoutExtension(tuple.Item1), ".json")));
|
||||
if (_Configuration.PropertiesChangedForIndex)
|
||||
indexInfo = null;
|
||||
else if (!fileInfo.Exists)
|
||||
indexInfo = null;
|
||||
else
|
||||
indexInfo = GetIndexInfo(fileInfo, parseExceptions);
|
||||
if (indexInfo?.Index is not null)
|
||||
{
|
||||
indices.Add(indexInfo.Index.Value);
|
||||
valuePairs.Add(indexInfo.Index.Value, indexInfo);
|
||||
}
|
||||
else
|
||||
neededTuples.Add(new Tuple<List<string>, string, Shared.Models.Property>(new List<string> { tuple.Item1 }, fileInfo.FullName, tuple.Item2));
|
||||
}
|
||||
indexInfoTuples.Add(new Tuple<string, Dictionary<int, G_Index>>(tuples.Key, valuePairs));
|
||||
}
|
||||
if (_Configuration.MappedMaxIndex.HasValue)
|
||||
break;
|
||||
WriteNeeded(indices, neededTuples);
|
||||
}
|
||||
if (parseExceptions.Any())
|
||||
throw new Exception(string.Join(Environment.NewLine, parseExceptions));
|
||||
if (neededTuples.Any())
|
||||
throw new Exception();
|
||||
WriteGroup(configuration, outputResolution, indexInfoTuples);
|
||||
AppendTSV(configuration, outputResolution, filePropertiesKeyValuePairs);
|
||||
}
|
||||
|
||||
string Shared.Models.Stateless.Methods.IIndex.TestStatic_GetJson(string jsonFileFullName, FileInfo fileInfo) => throw new NotImplementedException();
|
||||
|
||||
}
|
@ -68,10 +68,8 @@
|
||||
"ForceMetadataLastWriteTimeToCreationTime": false,
|
||||
"ForcePropertyLastWriteTimeToCreationTime": false,
|
||||
"ForceResizeLastWriteTimeToCreationTime": false,
|
||||
"LoadOrCreateThenSaveIndex": false,
|
||||
"LocationDigits": 9,
|
||||
"LocationFactor": 10000,
|
||||
"MappedMaxIndex": 1034720,
|
||||
"MappingDefaultName": "John Doe~25",
|
||||
"MappingUseDeterministicHashCodeUnknownFaceKeyValuePairsForAddToMapping": false,
|
||||
"MappingUseDeterministicHashCodeUnknownFaceKeyValuePairsForSaveMapping": false,
|
||||
|
Reference in New Issue
Block a user