This commit is contained in:
2022-05-08 12:28:50 -07:00
commit 4a3e24236f
313 changed files with 22395 additions and 0 deletions

View File

@ -0,0 +1 @@
[]

30
PrepareForOld/.vscode/launch.json vendored Normal file
View File

@ -0,0 +1,30 @@
{
"version": "0.2.0",
"configurations": [
{
// Use IntelliSense to find out which attributes exist for C# debugging
// Use hover for the description of the existing attributes
// For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
"name": ".NET Core Launch (console)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
// If you have changed target frameworks, make sure to update the program path.
"program": "${workspaceFolder}/bin/Debug/net6.0/win-x64/PrepareForOld.dll",
"args": [],
"env": {
"ASPNETCORE_ENVIRONMENT": "Development",
},
"cwd": "${workspaceFolder}",
// For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console
"console": "externalTerminal",
"stopAtEntry": false
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach",
"processName": "PrepareForOld"
}
]
}

14
PrepareForOld/.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,14 @@
{
"cSpell.words": [
"Barrick",
"bcdfghjklmnpqrstvwxyz",
"Beichler",
"Bohdi",
"Dlib",
"exif",
"nosj",
"Phares",
"Serilog",
"Vericruz"
]
}

42
PrepareForOld/.vscode/tasks.json vendored Normal file
View File

@ -0,0 +1,42 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"command": "dotnet",
"type": "process",
"args": [
"build",
"${workspaceFolder}/PrepareForOld.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
},
{
"label": "publish",
"command": "dotnet",
"type": "process",
"args": [
"publish",
"${workspaceFolder}/PrepareForOld.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
},
{
"label": "watch",
"command": "dotnet",
"type": "process",
"args": [
"watch",
"run",
"${workspaceFolder}/PrepareForOld.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
}
]
}

View File

@ -0,0 +1,35 @@
using System.Text.Json;
using System.Text.Json.Serialization;
namespace View_by_Distance.PrepareForOld.Models;
public class AppSettings
{
protected string _Company;
protected string _WorkingDirectoryName;
protected int? _MaxDegreeOfParallelism;
public string Company => _Company;
public string WorkingDirectoryName => _WorkingDirectoryName;
public int? MaxDegreeOfParallelism => _MaxDegreeOfParallelism;
// public AppSettings()
// {
// }
[JsonConstructor]
public AppSettings(string company, string workingDirectoryName, int? maxDegreeOfParallelism)
{
_Company = company;
_WorkingDirectoryName = workingDirectoryName;
_MaxDegreeOfParallelism = maxDegreeOfParallelism;
}
public override string ToString()
{
string result = JsonSerializer.Serialize(this, new JsonSerializerOptions() { WriteIndented = true });
return result;
}
}

View File

@ -0,0 +1,26 @@
using System.ComponentModel.DataAnnotations;
using System.Text.Json;
namespace View_by_Distance.PrepareForOld.Models.Binder;
public class AppSettings
{
[Display(Name = "Company"), Required] public string Company { get; set; }
[Display(Name = "Working Directory Name"), Required] public string WorkingDirectoryName { get; set; }
[Display(Name = "Max Degree Of Parallelism"), Required] public int? MaxDegreeOfParallelism { get; set; }
public AppSettings()
{
Company = string.Empty;
WorkingDirectoryName = string.Empty;
MaxDegreeOfParallelism = -1;
}
public override string ToString()
{
string result = JsonSerializer.Serialize(this, new JsonSerializerOptions() { WriteIndented = true });
return result;
}
}

View File

@ -0,0 +1,20 @@
using System.ComponentModel.DataAnnotations;
using System.Text.Json;
namespace View_by_Distance.PrepareForOld.Models.Binder;
public class Configuration
{
[Display(Name = "Property Configuration"), Required] public Property.Models.Configuration? PropertyConfiguration { get; set; }
[Display(Name = "Spelling"), Required] public string[] Spelling { get; set; }
public Configuration() => Spelling = Array.Empty<string>();
public override string ToString()
{
string result = JsonSerializer.Serialize(this, new JsonSerializerOptions() { WriteIndented = true });
return result;
}
}

View File

@ -0,0 +1,31 @@
using System.Text.Json;
using System.Text.Json.Serialization;
namespace View_by_Distance.PrepareForOld.Models;
public class Configuration
{
protected Property.Models.Configuration? _PropertyConfiguration;
protected readonly string[] _Spelling;
public Property.Models.Configuration? PropertyConfiguration => _PropertyConfiguration;
public string[] Spelling => _Spelling;
[JsonConstructor]
public Configuration(Property.Models.Configuration? propertyConfiguration, string[] spelling)
{
_PropertyConfiguration = propertyConfiguration;
_Spelling = spelling;
}
public override string ToString()
{
string result = JsonSerializer.Serialize(this, new JsonSerializerOptions() { WriteIndented = true });
return result;
}
public void Set(Property.Models.Configuration propertyConfiguration) => _PropertyConfiguration = propertyConfiguration;
public void Update() => _PropertyConfiguration?.Update();
}

View File

@ -0,0 +1,17 @@
namespace View_by_Distance.PrepareForOld.Models.SaveTabSeparatedValues;
public class ImageExifInfo
{
public int Index { get; set; }
public DateTime CreationTime { get; set; }
public DateTime LastWriteTime { get; set; }
public DateTime? DateTime { get; set; }
public DateTime? DateTimeDigitized { get; set; }
public DateTime? DateTimeOriginal { get; set; }
public DateTime? GPSDateStamp { get; set; }
public string? Make { get; set; }
public string? Model { get; set; }
public string? Orientation { get; set; }
public int Width { get; set; }
public int Height { get; set; }
}

View File

@ -0,0 +1,8 @@
namespace View_by_Distance.PrepareForOld.Models.SaveTabSeparatedValues;
public class IndexInfo
{
public int Index { get; set; }
public string[]? FileSegmentCollection { get; set; }
public DateTime DateTime { get; set; }
}

View File

@ -0,0 +1,40 @@
using Microsoft.Extensions.Configuration;
using System.Text.Json;
namespace View_by_Distance.PrepareForOld.Models.Stateless;
public abstract class AppSettings
{
public static Models.AppSettings Get(IConfigurationRoot configurationRoot)
{
Models.AppSettings? result;
Binder.AppSettings appSettings = configurationRoot.Get<Binder.AppSettings>();
string json = JsonSerializer.Serialize(appSettings, new JsonSerializerOptions() { WriteIndented = true });
result = JsonSerializer.Deserialize<Models.AppSettings>(json);
if (result is null)
throw new Exception(json);
if (string.IsNullOrEmpty(result.Company))
throw new Exception(json);
string jsonThis = result.ToString();
if (jsonThis != json)
{
int? check = null;
int min = new int[] { json.Length, jsonThis.Length }.Min();
for (int i = 0; i < min; i++)
{
if (json[i] == jsonThis[i])
continue;
check = i;
break;
}
if (check is null)
throw new Exception();
string a = json[..check.Value].Split(',')[^1];
string b = json[check.Value..].Split(',')[0];
throw new Exception($"{a}{b}");
}
return result;
}
}

View File

@ -0,0 +1,44 @@
using Microsoft.Extensions.Configuration;
using Phares.Shared;
using System.Text.Json;
namespace View_by_Distance.PrepareForOld.Models.Stateless;
public abstract class Configuration
{
public static Models.Configuration Get(IsEnvironment isEnvironment, IConfigurationRoot configurationRoot, string workingDirectory, Property.Models.Configuration propertyConfiguration)
{
Models.Configuration? result;
string environmentName = IsEnvironment.GetEnvironmentName(isEnvironment);
string section = string.Concat(environmentName, ":", nameof(Binder.Configuration));
IConfigurationSection configurationSection = configurationRoot.GetSection(section);
Binder.Configuration configuration = configurationSection.Get<Binder.Configuration>();
string json = JsonSerializer.Serialize(configuration, new JsonSerializerOptions() { WriteIndented = true });
result = JsonSerializer.Deserialize<Models.Configuration>(json);
if (result is null)
throw new Exception(json);
string jsonThis = result.ToString();
result.Set(propertyConfiguration);
result.Update();
if (jsonThis != json)
{
int? check = null;
int min = new int[] { json.Length, jsonThis.Length }.Min();
for (int i = 0; i < min; i++)
{
if (json[i] == jsonThis[i])
continue;
check = i;
break;
}
if (check is null)
throw new Exception();
string a = json[..check.Value].Split(',')[^1];
string b = json[check.Value..].Split(',')[0];
throw new Exception($"{a}{b}");
}
return result;
}
}

View File

@ -0,0 +1,10 @@
namespace View_by_Distance.PrepareForOld.Models.Stateless;
public static class SerilogExtensionMethods
{
internal static void Warn(this Serilog.ILogger log, string messageTemplate) => log.Warning(messageTemplate);
internal static void Info(this Serilog.ILogger log, string messageTemplate) => log.Information(messageTemplate);
}

View File

@ -0,0 +1,666 @@
using Microsoft.Extensions.Configuration;
using Phares.Shared;
using System.Text.Json;
using System.Text.RegularExpressions;
using View_by_Distance.PrepareForOld.Models;
using View_by_Distance.Property.Models;
using View_by_Distance.Shared.Models.Methods;
namespace View_by_Distance.PrepareForOld;
public class PrepareForOld
{
private readonly Serilog.ILogger? _Log;
private readonly AppSettings _AppSettings;
private readonly List<string> _Exceptions;
private readonly IsEnvironment _IsEnvironment;
private readonly Models.Configuration _Configuration;
private readonly List<KeyValuePair<string, string>> _FileKeyValuePairs;
private readonly List<(string Find, string Replace)> _SpellingFindReplace;
private readonly Dictionary<string, List<Tuple<string, A_Property>>> _FilePropertiesKeyValuePairs;
public PrepareForOld(List<string> args, IsEnvironment isEnvironment, IConfigurationRoot configurationRoot, AppSettings appSettings, string workingDirectory, bool isSilent, IConsole console)
{
if (isSilent)
{ }
if (console is null)
{ }
string spellingA;
string spellingB;
_AppSettings = appSettings;
if (appSettings.MaxDegreeOfParallelism is null)
throw new Exception($"{nameof(appSettings.MaxDegreeOfParallelism)} is null!");
_SpellingFindReplace = new();
_IsEnvironment = isEnvironment;
_Exceptions = new List<string>();
_Log = Serilog.Log.ForContext<PrepareForOld>();
_FileKeyValuePairs = new List<KeyValuePair<string, string>>();
_FilePropertiesKeyValuePairs = new Dictionary<string, List<Tuple<string, A_Property>>>();
Property.Models.Configuration propertyConfiguration = Property.Models.Stateless.Configuration.Get(isEnvironment, configurationRoot, workingDirectory);
Property.Models.Configuration.Verify(propertyConfiguration);
Models.Configuration configuration = Models.Stateless.Configuration.Get(isEnvironment, configurationRoot, workingDirectory, propertyConfiguration);
Verify(configuration);
if (propertyConfiguration.IgnoreExtensions is null)
throw new Exception($"{nameof(propertyConfiguration.IgnoreExtensions)} is null!");
if (propertyConfiguration.MaxImagesInDirectoryForTopLevelFirstPass is null)
throw new Exception($"{nameof(propertyConfiguration.MaxImagesInDirectoryForTopLevelFirstPass)} is null!");
for (int i = 0; i < configuration.Spelling.Length; i++)
{
spellingA = configuration.Spelling[i];
spellingB = configuration.Spelling[i + 1];
if (spellingB.Contains(spellingA))
throw new Exception("Change configuration!");
_SpellingFindReplace.Add(new(spellingA, spellingB));
i += 1;
}
string[] dbFiles = Directory.GetFiles(propertyConfiguration.RootDirectory, "*.db", SearchOption.AllDirectories);
foreach (string dbFile in dbFiles)
File.Delete(dbFile);
string aPropertySingletonDirectory = Property.Models.Stateless.IResult.GetResultsDateGroupDirectory(propertyConfiguration, nameof(A_Property), "{}");
if (!Directory.Exists(aPropertySingletonDirectory))
throw new Exception(aPropertySingletonDirectory);
ConsoleKey? consoleKey = null;
for (int y = 0; y < int.MaxValue; y++)
{
_Log.Information($"Execute {nameof(VerifyAgainstIndexInfoJsonFiles)} \"Y(es)\" or \"N(o)\"?");
consoleKey = Console.ReadKey().Key;
if (consoleKey is ConsoleKey.Y or ConsoleKey.N)
break;
}
_Log.Information(". . .");
if (consoleKey == ConsoleKey.Y)
VerifyAgainstIndexInfoJsonFiles(propertyConfiguration, aPropertySingletonDirectory);
for (int y = 0; y < int.MaxValue; y++)
{
_Log.Information($"Execute {nameof(SaveTabSeparatedValues)} \"Y(es)\" or \"N(o)\"?");
consoleKey = Console.ReadKey().Key;
if (consoleKey is ConsoleKey.Y or ConsoleKey.N)
break;
}
_Log.Information(". . .");
if (consoleKey == ConsoleKey.Y)
SaveTabSeparatedValues(propertyConfiguration, aPropertySingletonDirectory);
for (int y = 0; y < int.MaxValue; y++)
{
_Log.Information($"Execute {nameof(ReSaveJsonFiles)} \"Y(es)\" or \"N(o)\"?");
consoleKey = Console.ReadKey().Key;
if (consoleKey is ConsoleKey.Y or ConsoleKey.N)
break;
}
_Log.Information(". . .");
if (consoleKey == ConsoleKey.Y)
ReSaveJsonFiles();
for (int y = 0; y < int.MaxValue; y++)
{
_Log.Information($"Execute {nameof(CopyMissingImagesLogs)} \"Y(es)\" or \"N(o)\"?");
consoleKey = Console.ReadKey().Key;
if (consoleKey is ConsoleKey.Y or ConsoleKey.N)
break;
}
_Log.Information(". . .");
if (consoleKey == ConsoleKey.Y)
CopyMissingImagesLogs();
string message = $"There were {_Exceptions.Count} exception(s) thrown! {Environment.NewLine}{string.Join(Environment.NewLine, _Exceptions)}";
_Log.Information(message);
if (_Exceptions.Count != 0)
throw new Exception(message);
_Configuration = configuration;
}
private static void Verify(Models.Configuration configuration)
{
if (configuration.Spelling is null || !configuration.Spelling.Any())
throw new Exception($"{nameof(configuration.Spelling)} should have at least one!");
}
private static List<Models.SaveTabSeparatedValues.ImageExifInfo> GetExifCollection(string infoDirectory, string infoDirectoryExtra, bool checkDistinct)
{
List<Models.SaveTabSeparatedValues.ImageExifInfo> results = new();
string json;
Models.SaveTabSeparatedValues.ImageExifInfo[]? exifCollection;
List<string> exifInfoFiles = Directory.GetFiles(infoDirectory, "ImageExifInfo.json", SearchOption.AllDirectories).ToList();
if (!string.IsNullOrEmpty(infoDirectoryExtra))
exifInfoFiles.AddRange(Directory.GetFiles(infoDirectoryExtra, "ImageExifInfo.json", SearchOption.AllDirectories));
foreach (string exifInfoFile in exifInfoFiles)
{
json = File.ReadAllText(exifInfoFile);
exifCollection = JsonSerializer.Deserialize<Models.SaveTabSeparatedValues.ImageExifInfo[]>(json);
if (exifCollection is null)
continue;
results.AddRange(exifCollection);
}
if (checkDistinct)
{
int[] check = (from l in results select l.Index).Distinct().ToArray();
if (check.Length != results.Count)
throw new Exception();
}
return results;
}
private List<(int Index, long Ticks, string RelativeDirectory, string FileNameWithoutExtension, string Extension, string RegexResult)> GetIndexCollection(string infoDirectory, string infoDirectoryExtra, bool checkDistinct)
{
List<(int Index, long Ticks, string RelativeDirectory, string FileNameWithoutExtension, string Extension, string RegexResult)> results = new();
if (_Configuration?.PropertyConfiguration is null)
throw new Exception($"{nameof(_Configuration.PropertyConfiguration)} must be set!");
long ticks;
string json;
string extension;
string corrected;
string regexResult;
string relativeDirectory;
List<DateTime> dateTimes;
string fileNameWithoutExtension;
string firstFileSegmentCollection;
Dictionary<int, long> keyValuePairs = new();
Models.SaveTabSeparatedValues.IndexInfo[]? indexCollection;
List<Models.SaveTabSeparatedValues.ImageExifInfo> exifCollection = GetExifCollection(infoDirectory, infoDirectoryExtra, checkDistinct);
List<string> indexInfoFiles = Directory.GetFiles(infoDirectory, "IndexInfo.json", SearchOption.AllDirectories).ToList();
if (!string.IsNullOrEmpty(infoDirectoryExtra))
indexInfoFiles.AddRange(Directory.GetFiles(infoDirectoryExtra, "IndexInfo.json", SearchOption.AllDirectories));
foreach (Models.SaveTabSeparatedValues.ImageExifInfo exifInfo in exifCollection)
{
dateTimes = Property.Models.Stateless.A_Property.GetDateTimes(exifInfo.CreationTime, exifInfo.LastWriteTime, exifInfo.DateTime, exifInfo.DateTimeDigitized, exifInfo.DateTimeOriginal, exifInfo.GPSDateStamp);
if (!checkDistinct && keyValuePairs.ContainsKey(exifInfo.Index))
continue;
keyValuePairs.Add(exifInfo.Index, dateTimes.Min().Ticks);
}
foreach (string indexInfoFile in indexInfoFiles)
{
json = File.ReadAllText(indexInfoFile);
indexCollection = JsonSerializer.Deserialize<Models.SaveTabSeparatedValues.IndexInfo[]>(json);
if (indexCollection is null)
continue;
foreach (Models.SaveTabSeparatedValues.IndexInfo indexInfo in indexCollection)
{
if (indexInfo.FileSegmentCollection is null)
continue;
// if (indexInfo.FileSegmentCollection.Length != 1)
// continue;
ticks = keyValuePairs[indexInfo.Index];
firstFileSegmentCollection = indexInfo.FileSegmentCollection[0];
extension = Path.GetExtension(firstFileSegmentCollection);
fileNameWithoutExtension = Path.GetFileNameWithoutExtension(firstFileSegmentCollection);
corrected = firstFileSegmentCollection[..(firstFileSegmentCollection.Length - extension.Length)];
relativeDirectory = firstFileSegmentCollection[..(firstFileSegmentCollection.Length - fileNameWithoutExtension.Length - extension.Length)];
if ((from l in _SpellingFindReplace where corrected.Contains(l.Find) select true).Any())
{
foreach ((string find, string replace) in _SpellingFindReplace)
corrected = corrected.Replace(find, replace);
}
if (string.IsNullOrEmpty(_Configuration.PropertyConfiguration.Pattern))
regexResult = corrected;
else
regexResult = Regex.Replace(corrected, _Configuration.PropertyConfiguration.Pattern, string.Empty);
results.Add(new(indexInfo.Index, ticks, relativeDirectory, fileNameWithoutExtension, extension, regexResult));
}
}
return results;
}
private static List<int> GetUseTabSeparatedValueIndices(string useDirectory)
{
List<int> results = new();
string[] lines;
string[] segments;
string[] tabSeparatedValueFiles = Directory.GetFiles(useDirectory, "*.tsv", SearchOption.TopDirectoryOnly);
foreach (string tabSeparatedValueFile in tabSeparatedValueFiles)
{
lines = File.ReadAllLines(tabSeparatedValueFile);
foreach (string line in lines)
{
if (string.IsNullOrEmpty(line))
continue;
segments = line.Split('\t');
if (segments.Length < 1)
continue;
if (!int.TryParse(segments[0], out int index))
continue;
results.Add(index);
}
}
return results.Distinct().OrderBy(l => l).ToList();
}
private void SaveTabSeparatedValues(Property.Models.Configuration configuration, string aPropertySingletonDirectory)
{
if (_Log is null)
throw new Exception($"{nameof(_Log)} is null!");
if (_AppSettings.MaxDegreeOfParallelism is null)
throw new Exception($"{nameof(_AppSettings.MaxDegreeOfParallelism)} is null!");
if (_Configuration?.PropertyConfiguration is null)
throw new Exception($"{nameof(_Configuration.PropertyConfiguration)} must be set!");
string? rootDirectoryParent = Path.GetDirectoryName(_Configuration.PropertyConfiguration.RootDirectory);
if (string.IsNullOrEmpty(rootDirectoryParent))
throw new Exception($"{nameof(rootDirectoryParent)} is null!");
int z = 0;
int mappedIndex;
int? propertyId;
long? propertyTicks;
int loadLessThan = 7;
string useDirectory = Path.Combine(rootDirectoryParent, "Use - ==");
if (!Directory.Exists(useDirectory))
_ = Directory.CreateDirectory(useDirectory);
string tempDirectory = Path.Combine(rootDirectoryParent, "Tmp");
if (!Directory.Exists(tempDirectory))
_ = Directory.CreateDirectory(tempDirectory);
string diffRootDirectory = string.Empty;
List<PropertyCompare.Models.PropertyCompare> duplicates = new();
string imageSharedDirectory = Path.Combine(rootDirectoryParent, "Images - Shared");
string namedFaceInfoFile = Path.Combine(imageSharedDirectory, "NamedFaceInfo.json");
string infoDirectory = Path.Combine(imageSharedDirectory, "Images - 4) Info", "2020-06-07");
string infoDirectoryExtra = Path.Combine(imageSharedDirectory, "Images - 4) Info - - - Extra", "2022-04-14");
List<int> mappedIndices = GetUseTabSeparatedValueIndices(useDirectory);
List<(int Index, string RelativeDirectory, string FileName, string RegexResult, long Ticks, int? PropertyId, long? PropertyTicks)> collection = new();
PropertyCompare.Models.PropertyCompareLogic propertyCompareLogic = new(_AppSettings.MaxDegreeOfParallelism.Value, _Configuration.PropertyConfiguration, _SpellingFindReplace, diffRootDirectory);
PropertyCompare.Models.PropertyCompare[] propertyCompareCollection = propertyCompareLogic.Get(aPropertySingletonDirectory, loadLessThan, duplicates, deleteExtension: false);
{
long ticks = DateTime.Now.Ticks;
string[] lines = (from l in propertyCompareCollection select l.GetSelect()).ToArray();
string aPropertyCollectionDirectory = Property.Models.Stateless.IResult.GetResultsDateGroupDirectory(configuration, nameof(A_Property), "[{}]");
File.WriteAllLines(Path.Join(aPropertyCollectionDirectory, $". . . Ids - {ticks}.txt"), lines);
string json = JsonSerializer.Serialize(propertyCompareCollection, new JsonSerializerOptions { WriteIndented = true });
File.WriteAllText(Path.Join(aPropertyCollectionDirectory, $". . . Ids - {ticks}.nosj"), json);
}
List<(int Index, long Ticks, string RelativeDirectory, string FileNameWithoutExtension, string Extension, string RegexResult)> indexCollection = GetIndexCollection(infoDirectory, infoDirectoryExtra, checkDistinct: true);
foreach ((int index, long ticks, string relativeDirectory, string fileNameWithoutExtension, string extension, string regexResult) in indexCollection)
{
z += 1;
if (_IsEnvironment.Development && z % 1000 == 0)
_Log.Debug($"{z}) Loop {_Configuration.PropertyConfiguration.RootDirectory}");
propertyId = null;
propertyTicks = null;
foreach (PropertyCompare.Models.PropertyCompare propertyCompare in propertyCompareCollection)
{
if (propertyCompare?.Property?.Id is null)
continue;
if (ticks != propertyCompare.MinimumDateTime.Ticks)
{
// if (ticks > propertyCompare.MinimumDateTime.AddHours(18).Ticks || ticks < propertyCompare.MinimumDateTime.AddHours(-18).Ticks)
continue;
}
if (!regexResult.Equals(propertyCompare.RegexResult, StringComparison.CurrentCultureIgnoreCase))
continue;
propertyId = propertyCompare.Property.Id;
propertyTicks = propertyCompare.MinimumDateTime.Ticks;
mappedIndex = mappedIndices.IndexOf(index);
if (mappedIndex > -1)
mappedIndices.RemoveAt(mappedIndex);
break;
}
collection.Add(new(index, relativeDirectory, $"{fileNameWithoutExtension}{extension}", regexResult, ticks, propertyId, propertyTicks));
}
(int Index, string RelativeDirectory, string FileName, string RegexResult, long Ticks, int? PropertyId, long? PropertyTicks)[] matched = (from l in collection where l.PropertyId.HasValue select l).ToArray();
(int Index, string RelativeDirectory, string FileName, string RegexResult, long Ticks, int? PropertyId, long? PropertyTicks)[] notMatched = (from l in collection where l.PropertyId is null select l).ToArray();
string[] duplicatesLines = (
from l
in duplicates
select $"{l.Property.Id}\t{l.RegexResult}\t{l.MinimumDateTime:yyyy-MM-dd_HH-mm-ss}\t{l.MinimumDateTime}\t{l.RelativeDirectory}\t{l.FileNameWithoutExtension}{l.Extension}.___"
).ToArray();
string[] matchedLines = (
from l
in matched
select $"{l.Index}\t{l.PropertyId}\t{l.RegexResult}\t{new DateTime(l.Ticks):yyyy-MM-dd_HH-mm-ss}\t{l.PropertyTicks}\t{l.RelativeDirectory}\t{l.FileName}"
).ToArray();
List<string> notMatchedLines = (
from l
in notMatched
where !mappedIndices.Contains(l.Index)
select $"{l.Index}\t______________\t{l.RegexResult}\t{new DateTime(l.Ticks):yyyy-MM-dd_HH-mm-ss}\t_________________\t{l.RelativeDirectory}\t{l.FileName}"
).ToList();
{
long ticks = DateTime.Now.Ticks;
notMatchedLines.AddRange(from l in mappedIndices select $"{l}\tFrom other files");
File.WriteAllLines($"{tempDirectory}/{collection.Count}-{ticks}.tsv", matchedLines);
File.WriteAllLines($"{tempDirectory}/{collection.Count}-{ticks}.txt", duplicatesLines);
File.WriteAllLines($"{tempDirectory}/{collection.Count}-{ticks}-Not.tsv", notMatchedLines);
}
_Log.Debug($"Done with {nameof(SaveTabSeparatedValues)}");
}
private static void GetUseTabSeparatedValueLines(string useDirectory, Dictionary<int, List<string>> mappedLines)
{
string[] lines;
string[] segments;
string useDirectoryName = Path.GetFileName(useDirectory).Split('-')[1].Trim();
string[] tabSeparatedValueFiles = Directory.GetFiles(useDirectory, "*.tsv", SearchOption.TopDirectoryOnly);
foreach (string tabSeparatedValueFile in tabSeparatedValueFiles)
{
lines = File.ReadAllLines(tabSeparatedValueFile);
foreach (string line in lines)
{
if (string.IsNullOrEmpty(line))
continue;
segments = line.Split('\t');
if (segments.Length < 1)
continue;
if (!int.TryParse(segments[0], out int index))
continue;
if (!mappedLines.ContainsKey(index))
mappedLines.Add(index, new());
mappedLines[index].Add($"{line},\t{useDirectoryName}");
}
}
}
private static void Populate(Dictionary<int, List<int>> keyValuePairs, Dictionary<int, List<string>> mappedLines)
{
string[] segments;
foreach (KeyValuePair<int, List<string>> keyValuePair in mappedLines)
{
segments = keyValuePair.Value[0].Split('\t');
if (segments.Length < 2)
continue;
if (!int.TryParse(segments[1], out int id))
continue;
if (!keyValuePairs.ContainsKey(id))
keyValuePairs.Add(id, new() { id });
keyValuePairs[id].Add(keyValuePair.Key);
}
}
private static Dictionary<int, int> GetUseTabSeparatedValue(string useEqualsDirectory, string use18HoursDirectory, string useAnyDateDirectory, Dictionary<int, List<int>> keyValuePairs, List<string> lines)
{
Dictionary<int, int> results = new();
string[] segments;
Dictionary<int, List<string>> mappedLines = new();
GetUseTabSeparatedValueLines(useEqualsDirectory, mappedLines);
GetUseTabSeparatedValueLines(use18HoursDirectory, mappedLines);
GetUseTabSeparatedValueLines(useAnyDateDirectory, mappedLines);
Populate(keyValuePairs, mappedLines);
foreach (KeyValuePair<int, List<string>> keyValuePair in mappedLines)
{
segments = keyValuePair.Value[0].Split('\t');
if (segments.Length < 2)
continue;
if (!int.TryParse(segments[1], out int id))
continue;
foreach (string line in keyValuePair.Value)
lines.Add(line);
results.Add(keyValuePair.Key, id);
}
return results;
}
private static void ReSaveExifFiles(string infoDirectory, string infoDirectoryIgnore, Dictionary<int, int> findReplace, List<int> missingIndices)
{
string json;
int propertyId;
Models.SaveTabSeparatedValues.ImageExifInfo[]? exifCollection;
List<string> exifInfoFiles = Directory.GetFiles(infoDirectory, "ImageExifInfo.json", SearchOption.AllDirectories).ToList();
exifInfoFiles.AddRange(Directory.GetFiles(infoDirectoryIgnore, "ImageExifInfo.json", SearchOption.AllDirectories));
foreach (string exifInfoFile in exifInfoFiles)
{
json = File.ReadAllText(exifInfoFile);
exifCollection = JsonSerializer.Deserialize<Models.SaveTabSeparatedValues.ImageExifInfo[]>(json);
if (exifCollection is null)
continue;
foreach (Models.SaveTabSeparatedValues.ImageExifInfo exifInfo in exifCollection)
{
if (missingIndices.Contains(exifInfo.Index))
continue;
propertyId = findReplace[exifInfo.Index];
exifInfo.Index = propertyId;
}
json = JsonSerializer.Serialize(exifCollection);
File.WriteAllText(exifInfoFile, json);
}
}
private static void ReSaveNamedFaceInfoFile(string namedFaceInfoFile, Dictionary<int, int> findReplace, List<int> missingIndices)
{
Dictionary<int, string[]> destination = new();
string json = File.ReadAllText(namedFaceInfoFile);
List<(int PropertyId, string[] Birthdays)> collection = new();
JsonSerializerOptions jsonSerializerOptions = new() { WriteIndented = true };
Dictionary<int, string[]>? source = JsonSerializer.Deserialize<Dictionary<int, string[]>>(json);
if (source is null)
throw new Exception($"{nameof(source)} is null!");
{
int propertyId;
foreach (KeyValuePair<int, string[]> keyValuePair in source)
{
if (missingIndices.Contains(keyValuePair.Key))
continue;
propertyId = findReplace[keyValuePair.Key];
collection.Add(new(propertyId, keyValuePair.Value));
}
}
foreach ((int propertyId, string[] birthdays) in collection.OrderBy(l => l.PropertyId))
{
if (destination.ContainsKey(propertyId))
{
if (birthdays.Length != destination[propertyId].Length)
throw new Exception($"{birthdays.Length} != {destination[propertyId].Length}");
if (birthdays[0] != destination[propertyId][0])
throw new Exception($"{birthdays[0]} != {destination[propertyId][0]}");
continue;
}
destination.Add(propertyId, birthdays);
}
json = JsonSerializer.Serialize(destination, jsonSerializerOptions);
File.WriteAllText(namedFaceInfoFile, json);
}
private static void ReSaveIndexFiles(string infoDirectory, string infoDirectoryIgnore, Dictionary<int, int> findReplace, List<int> missingIndices)
{
string json;
int propertyId;
Models.SaveTabSeparatedValues.IndexInfo[]? indexCollection;
List<string> indexInfoFiles = Directory.GetFiles(infoDirectory, "IndexInfo.json", SearchOption.AllDirectories).ToList();
indexInfoFiles.AddRange(Directory.GetFiles(infoDirectoryIgnore, "IndexInfo.json", SearchOption.AllDirectories));
foreach (string indexInfoFile in indexInfoFiles)
{
json = File.ReadAllText(indexInfoFile);
indexCollection = JsonSerializer.Deserialize<Models.SaveTabSeparatedValues.IndexInfo[]>(json);
if (indexCollection is null)
continue;
foreach (Models.SaveTabSeparatedValues.IndexInfo indexInfo in indexCollection)
{
if (missingIndices.Contains(indexInfo.Index))
continue;
propertyId = findReplace[indexInfo.Index];
indexInfo.Index = propertyId;
}
json = JsonSerializer.Serialize(indexCollection);
File.WriteAllText(indexInfoFile, json);
}
}
private void ReSaveJsonFiles()
{
if (_Log is null)
throw new Exception($"{nameof(_Log)} is null!");
if (_Configuration?.PropertyConfiguration is null)
throw new Exception($"{nameof(_Configuration.PropertyConfiguration)} must be set!");
string? rootDirectoryParent = Path.GetDirectoryName(_Configuration.PropertyConfiguration.RootDirectory);
if (string.IsNullOrEmpty(rootDirectoryParent))
throw new Exception($"{nameof(rootDirectoryParent)} is null!");
int z = 0;
int propertyId;
List<int> missingIndices = new();
Dictionary<int, int> findReplace = new();
List<string> useTabSeparatedValueLines = new();
Dictionary<int, List<int>> keyValuePairs = new();
string tempDirectory = Path.Combine(rootDirectoryParent, "Tmp");
string useEqualsDirectory = Path.Combine(rootDirectoryParent, "Use - ==");
string use18HoursDirectory = Path.Combine(rootDirectoryParent, "Use - 18 Hours");
string useAnyDateDirectory = Path.Combine(rootDirectoryParent, "Use - Any Date");
string imageSharedDirectory = Path.Combine(rootDirectoryParent, "Images - Shared");
string namedFaceInfoFile = Path.Combine(imageSharedDirectory, "NamedFaceInfo.json");
string infoDirectory = Path.Combine(imageSharedDirectory, "Images - 4) Info", "2020-06-07");
string infoDirectoryIgnore = Path.Combine(imageSharedDirectory, "Images - 4) Info - - - Ignore", "2022-04-14");
Dictionary<int, int> useTabSeparatedValueCollection = GetUseTabSeparatedValue(useEqualsDirectory, use18HoursDirectory, useAnyDateDirectory, keyValuePairs, useTabSeparatedValueLines);
{
long ticks = DateTime.Now.Ticks;
string json = JsonSerializer.Serialize(keyValuePairs, new JsonSerializerOptions { WriteIndented = true });
File.WriteAllText($"{tempDirectory}/{nameof(keyValuePairs)}-{ticks}.json", json);
}
List<(int Index, long Ticks, string RelativeDirectory, string FileNameWithoutExtension, string Extension, string RegexResult)> indexCollection = GetIndexCollection(infoDirectory, infoDirectoryIgnore, checkDistinct: true);
foreach ((int index, long ticks, string relativeDirectory, string fileNameWithoutExtension, string extension, string regexResult) in indexCollection)
{
z += 1;
if (_IsEnvironment.Development && z % 1000 == 0)
_Log.Debug($"{z}) Loop {_Configuration.PropertyConfiguration.RootDirectory}");
if (!useTabSeparatedValueCollection.ContainsKey(index))
{
missingIndices.Add(index);
continue;
}
propertyId = useTabSeparatedValueCollection[index];
findReplace.Add(index, propertyId);
}
ReSaveIndexFiles(infoDirectory, infoDirectoryIgnore, findReplace, missingIndices);
ReSaveExifFiles(infoDirectory, infoDirectoryIgnore, findReplace, missingIndices);
ReSaveNamedFaceInfoFile(namedFaceInfoFile, findReplace, missingIndices);
{
long ticks = DateTime.Now.Ticks;
File.WriteAllLines($"{tempDirectory}/{nameof(useTabSeparatedValueLines)}-{ticks}.tsv", useTabSeparatedValueLines);
File.WriteAllText($"{tempDirectory}/{nameof(missingIndices)}-{ticks}.txt", string.Join(Environment.NewLine, missingIndices));
}
_Log.Debug($"Done with {nameof(ReSaveJsonFiles)}");
}
private void CopyMissingImagesLogs()
{
if (_Log is null)
throw new Exception($"{nameof(_Log)} is null!");
if (_Configuration?.PropertyConfiguration is null)
throw new Exception($"{nameof(_Configuration.PropertyConfiguration)} must be set!");
string? rootDirectoryParent = Path.GetDirectoryName(_Configuration.PropertyConfiguration.RootDirectory);
if (_Configuration?.PropertyConfiguration is null)
throw new Exception($"{nameof(_Configuration.PropertyConfiguration)} must be set!");
if (string.IsNullOrEmpty(rootDirectoryParent))
throw new Exception($"{nameof(rootDirectoryParent)} is null!");
int z = 0;
int propertyId;
Dictionary<int, int> findReplace = new();
List<int> missingIndices = new();
List<string> useTabSeparatedValueLines = new();
Dictionary<int, List<int>> keyValuePairs = new();
string tempDirectory = Path.Combine(rootDirectoryParent, "Tmp");
string currentDirectory = Path.Combine(rootDirectoryParent, "@) Images");
string useEqualsDirectory = Path.Combine(rootDirectoryParent, "Use - ==");
string use18HoursDirectory = Path.Combine(rootDirectoryParent, "Use - 18 Hours");
string useAnyDateDirectory = Path.Combine(rootDirectoryParent, "Use - Any Date");
string imageSharedDirectory = Path.Combine(rootDirectoryParent, "Images - Shared");
string namedFaceInfoFile = Path.Combine(imageSharedDirectory, "NamedFaceInfo.json");
string infoDirectory = Path.Combine(imageSharedDirectory, "Images - 4) Info", "2020-06-07");
string infoDirectoryIgnore = Path.Combine(imageSharedDirectory, "Images - 4) Info - - - Ignore", "2022-04-14");
Dictionary<int, int> useTabSeparatedValueCollection = GetUseTabSeparatedValue(useEqualsDirectory, use18HoursDirectory, useAnyDateDirectory, keyValuePairs, useTabSeparatedValueLines);
{
long ticks = DateTime.Now.Ticks;
string json = JsonSerializer.Serialize(keyValuePairs, new JsonSerializerOptions { WriteIndented = true });
File.WriteAllText($"{tempDirectory}/{nameof(keyValuePairs)}-{ticks}.json", json);
}
List<(int Index, long Ticks, string RelativeDirectory, string FileNameWithoutExtension, string Extension, string RegexResult)> indexCollection = GetIndexCollection(infoDirectory, infoDirectoryIgnore, checkDistinct: false);
foreach ((int index, long ticks, string relativeDirectory, string fileNameWithoutExtension, string extension, string regexResult) in indexCollection)
{
z += 1;
if (_IsEnvironment.Development && z % 1000 == 0)
_Log.Debug($"{z}) Loop {_Configuration.PropertyConfiguration.RootDirectory}");
if (!useTabSeparatedValueCollection.ContainsKey(index))
{
missingIndices.Add(index);
continue;
}
propertyId = useTabSeparatedValueCollection[index];
findReplace.Add(index, propertyId);
}
{
long ticks = DateTime.Now.Ticks;
File.WriteAllLines($"{tempDirectory}/{nameof(useTabSeparatedValueLines)}-{ticks}.tsv", useTabSeparatedValueLines);
File.WriteAllText($"{tempDirectory}/{nameof(missingIndices)}-{ticks}.txt", string.Join(Environment.NewLine, missingIndices));
}
_Log.Debug($"Done with {nameof(CopyMissingImagesLogs)}");
}
private static Dictionary<int, List<PropertyCompare.Models.PropertyCompare>> GetKeyValuePairs(PropertyCompare.Models.PropertyCompare[] propertyCompares)
{
Dictionary<int, List<PropertyCompare.Models.PropertyCompare>> results = new();
foreach (PropertyCompare.Models.PropertyCompare propertyCompare in propertyCompares)
{
if (propertyCompare?.Property?.Id is null)
continue;
if (!results.ContainsKey(propertyCompare.Property.Id.Value))
results.Add(propertyCompare.Property.Id.Value, new());
results[propertyCompare.Property.Id.Value].Add(propertyCompare);
}
return results;
}
private void VerifyAgainstIndexInfoJsonFiles(Property.Models.Configuration configuration, string aPropertySingletonDirectory)
{
if (_Log is null)
throw new Exception($"{nameof(_Log)} is null!");
if (_AppSettings.MaxDegreeOfParallelism is null)
throw new Exception($"{nameof(_AppSettings.MaxDegreeOfParallelism)} is null!");
if (_Configuration?.PropertyConfiguration is null)
throw new Exception($"{nameof(_Configuration.PropertyConfiguration)} must be set!");
string? rootDirectoryParent = Path.GetDirectoryName(_Configuration.PropertyConfiguration.RootDirectory);
if (string.IsNullOrEmpty(rootDirectoryParent))
throw new Exception($"{nameof(rootDirectoryParent)} is null!");
int z = 0;
int? propertyId;
long? propertyTicks;
int loadLessThan = 7;
string diffRootDirectory = string.Empty;
PropertyCompare.Models.PropertyCompare propertyCompare;
string tempDirectory = Path.Combine(rootDirectoryParent, "Tmp");
if (!Directory.Exists(tempDirectory))
_ = Directory.CreateDirectory(tempDirectory);
string imageSharedDirectory = Path.Combine(rootDirectoryParent, "Images - Shared");
string namedFaceInfoFile = Path.Combine(imageSharedDirectory, "NamedFaceInfo.json");
string infoDirectory = Path.Combine(imageSharedDirectory, "Images - 4) Info", "2020-06-07");
List<(int Index, string RelativeDirectory, string FileName, string RegexResult, long Ticks, int? PropertyId, long? PropertyTicks)> collection = new();
PropertyCompare.Models.PropertyCompareLogic propertyCompareLogic = new(_AppSettings.MaxDegreeOfParallelism.Value, _Configuration.PropertyConfiguration, _SpellingFindReplace, diffRootDirectory);
PropertyCompare.Models.PropertyCompare[] propertyCompareCollection = propertyCompareLogic.Get(aPropertySingletonDirectory, loadLessThan);
{
long ticks = DateTime.Now.Ticks;
string[] lines = (from l in propertyCompareCollection select l.GetSelect()).ToArray();
string aPropertyCollectionDirectory = Property.Models.Stateless.IResult.GetResultsDateGroupDirectory(configuration, nameof(A_Property), "[{}]");
File.WriteAllLines(Path.Join(aPropertyCollectionDirectory, $". . . Ids - {ticks}.txt"), lines);
string json = JsonSerializer.Serialize(propertyCompareCollection, new JsonSerializerOptions { WriteIndented = true });
File.WriteAllText(Path.Join(aPropertyCollectionDirectory, $". . . Ids - {ticks}.nosj"), json);
}
Dictionary<int, List<PropertyCompare.Models.PropertyCompare>> keyValuePairs = GetKeyValuePairs(propertyCompareCollection);
List<(int Index, long Ticks, string RelativeDirectory, string FileNameWithoutExtension, string Extension, string RegexResult)> indexCollection = GetIndexCollection(infoDirectory, infoDirectoryExtra: string.Empty, checkDistinct: false);
foreach ((int index, long ticks, string relativeDirectory, string fileNameWithoutExtension, string extension, string regexResult) in indexCollection)
{
z += 1;
if (_IsEnvironment.Development && z % 1000 == 0)
_Log.Debug($"{z}) Loop {_Configuration.PropertyConfiguration.RootDirectory}");
propertyId = null;
propertyTicks = null;
if (keyValuePairs.ContainsKey(index))
{
propertyCompare = keyValuePairs[index][0];
if (propertyCompare?.Property?.Id is null)
continue;
propertyId = propertyCompare.Property.Id;
propertyTicks = propertyCompare.MinimumDateTime.Ticks;
}
collection.Add(new(index, relativeDirectory, $"{fileNameWithoutExtension}{extension}", regexResult, ticks, propertyId, propertyTicks));
}
(int Index, string RelativeDirectory, string FileName, string RegexResult, long Ticks, int? PropertyId, long? PropertyTicks)[] matched = (from l in collection where l.PropertyId.HasValue select l).ToArray();
(int Index, string RelativeDirectory, string FileName, string RegexResult, long Ticks, int? PropertyId, long? PropertyTicks)[] notMatched = (from l in collection where l.PropertyId is null select l).ToArray();
string[] matchedLines = (
from l
in matched
select $"{l.Index}\t{l.PropertyId}\t{l.RegexResult}\t{new DateTime(l.Ticks):yyyy-MM-dd_HH-mm-ss}\t{l.PropertyTicks}\t{l.RelativeDirectory}\t{l.FileName}"
).ToArray();
List<string> notMatchedLines = (
from l
in notMatched
select $"{l.Index}\t______________\t{l.RegexResult}\t{new DateTime(l.Ticks):yyyy-MM-dd_HH-mm-ss}\t_________________\t{l.RelativeDirectory}\t{l.FileName}"
).ToList();
{
long ticks = DateTime.Now.Ticks;
File.WriteAllLines($"{tempDirectory}/{collection.Count}-{ticks}.tsv", matchedLines);
File.WriteAllLines($"{tempDirectory}/{collection.Count}-{ticks}-Not.tsv", notMatchedLines);
}
_Log.Debug($"Done with {nameof(VerifyAgainstIndexInfoJsonFiles)}");
}
}

View File

@ -0,0 +1,60 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<ImplicitUsings>enable</ImplicitUsings>
<LangVersion>10.0</LangVersion>
<Nullable>enable</Nullable>
<OutputType>Exe</OutputType>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>
<PropertyGroup>
<PackageId>Phares.View.by.Distance.PrepareForOld</PackageId>
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
<Version>5.0.402.104</Version>
<Authors>Mike Phares</Authors>
<Company>Phares</Company>
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
</PropertyGroup>
<PropertyGroup>
<IsWindows Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::Windows)))' == 'true'">true</IsWindows>
<IsOSX Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::OSX)))' == 'true'">true</IsOSX>
<IsLinux Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::Linux)))' == 'true'">true</IsLinux>
</PropertyGroup>
<PropertyGroup Condition="'$(IsWindows)'=='true'">
<DefineConstants>Windows</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition="'$(IsOSX)'=='true'">
<DefineConstants>OSX</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition="'$(IsLinux)'=='true'">
<DefineConstants>Linux</DefineConstants>
</PropertyGroup>
<ItemGroup Condition="'$(RuntimeIdentifier)' == 'browser-wasm'">
<SupportedPlatform Include="browser" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Hosting" Version="6.0.0" />
<PackageReference Include="ShellProgressBar" Version="5.1.0" />
<PackageReference Include="Serilog" Version="2.10.0" />
<PackageReference Include="Serilog.Settings.Configuration" Version="3.3.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="4.0.1" />
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
<PackageReference Include="System.Drawing.Common" Version="6.0.0" />
<PackageReference Include="System.Text.Json" Version="6.0.0" />
<PackageReference Include="MetadataExtractor" Version="2.7.1" />
<PackageReference Include="Microsoft.AspNetCore.Cryptography.KeyDerivation" Version="6.0.1" />
<PackageReference Include="Microsoft.Extensions.Identity.Core" Version="6.0.1" />
<PackageReference Include="Microsoft.Extensions.Options" Version="6.0.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Shared\View-by-Distance.Shared.csproj" />
<ProjectReference Include="..\Property\Property.csproj" />
<ProjectReference Include="..\Property-Compare\Property-Compare.csproj" />
</ItemGroup>
<ItemGroup>
<None Include="appsettings.Development.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>

71
PrepareForOld/Program.cs Normal file
View File

@ -0,0 +1,71 @@
using Microsoft.Extensions.Configuration;
using Phares.Shared;
using Serilog;
using System.Diagnostics;
using System.Reflection;
using View_by_Distance.PrepareForOld.Models;
using View_by_Distance.Shared.Models.Stateless.Methods;
namespace View_by_Distance.PrepareForOld;
public class Program
{
public static void Secondary(List<string> args)
{
LoggerConfiguration loggerConfiguration = new();
Assembly assembly = Assembly.GetExecutingAssembly();
bool debuggerWasAttachedAtLineZero = Debugger.IsAttached || assembly.Location.Contains(@"\bin\Debug");
IsEnvironment isEnvironment = new(processesCount: null, nullASPNetCoreEnvironmentIsDevelopment: debuggerWasAttachedAtLineZero, nullASPNetCoreEnvironmentIsProduction: !debuggerWasAttachedAtLineZero);
IConfigurationBuilder configurationBuilder = new ConfigurationBuilder()
.AddEnvironmentVariables()
.AddJsonFile(isEnvironment.AppSettingsFileName, optional: false, reloadOnChange: true);
IConfigurationRoot configurationRoot = configurationBuilder.Build();
AppSettings appSettings = Models.Stateless.AppSettings.Get(configurationRoot);
if (appSettings.MaxDegreeOfParallelism is null)
throw new Exception("MaxDegreeOfParallelism must be set!");
if (appSettings.MaxDegreeOfParallelism.Value > Environment.ProcessorCount)
throw new Exception("MaxDegreeOfParallelism must be =< Environment.ProcessorCount!");
if (string.IsNullOrEmpty(appSettings.WorkingDirectoryName))
throw new Exception("Working directory name must have a value!");
string workingDirectory = IWorkingDirectory.GetWorkingDirectory(assembly.GetName().Name, appSettings.WorkingDirectoryName);
Environment.SetEnvironmentVariable(nameof(workingDirectory), workingDirectory);
_ = ConfigurationLoggerConfigurationExtensions.Configuration(loggerConfiguration.ReadFrom, configurationRoot);
Log.Logger = loggerConfiguration.CreateLogger();
ILogger log = Log.ForContext<Program>();
int silentIndex = args.IndexOf("s");
if (silentIndex > -1)
args.RemoveAt(silentIndex);
try
{
if (args is null)
throw new Exception("args is null!");
Shared.Models.Console console = new();
PrepareForOld dlibDotNet = new(args, isEnvironment, configurationRoot, appSettings, workingDirectory, silentIndex > -1, console);
}
catch (Exception ex)
{
log.Fatal(string.Concat(ex.Message, Environment.NewLine, ex.StackTrace));
}
finally
{
Log.CloseAndFlush();
}
if (silentIndex > -1)
log.Debug("Done. Bye");
else
{
log.Debug("Done. Press 'Enter' to end");
_ = Console.ReadLine();
}
}
public static void Main(string[] args)
{
if (args is not null)
Secondary(args.ToList());
else
Secondary(new List<string>());
}
}

View File

@ -0,0 +1,364 @@
{
"Company": "Mike Phares",
"Linux": {},
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Log4netProvider": "Debug",
"Microsoft.Hosting.Lifetime": "Information"
}
},
"MaxDegreeOfParallelism": 6,
"Serilog": {
"Using": [
"Serilog.Sinks.Console",
"Serilog.Sinks.File"
],
"MinimumLevel": "Debug",
"WriteTo": [
{
"Name": "Debug",
"Args": {
"outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level}] ({SourceContext}.{MethodName}) ({InstanceId}) ({RemoteIpAddress}) {Message}{NewLine}{Exception}"
}
},
{
"Name": "Console",
"Args": {
"outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level}] ({SourceContext}.{MethodName}) ({InstanceId}) ({RemoteIpAddress}) {Message}{NewLine}{Exception}"
}
},
{
"Name": "File",
"Args": {
"path": "%workingDirectory% - Log/log-.txt",
"outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level}] ({SourceContext}.{MethodName}) ({InstanceId}) ({RemoteIpAddress}) {Message}{NewLine}{Exception}",
"rollingInterval": "Hour"
}
}
],
"Enrich": [
"FromLogContext",
"WithMachineName",
"WithThreadId"
],
"Properties": {
"Application": "Sample"
}
},
"WorkingDirectoryName": "PharesApps",
"Windows": {
"Configuration": {
"DateGroup": "2022-04-07",
"FileNameDirectorySeparator": ".Z.",
"ForcePropertyLastWriteTimeToCreationTime": false,
"KeepFullPath": false,
"MaxImagesInDirectoryForTopLevelFirstPass": 50,
"Pattern": "[^ABCDEFGHIJKLMNOPQRSTUVWXYZbcdfghjklmnpqrstvwxyz0-9]",
"PopulatePropertyId": false,
"PropertiesChangedForProperty": false,
"RootDirectory": "C:/Tmp/Phares/Pictures",
"WriteBitmapDataBytes": false,
"IgnoreExtensions": [
".gif",
".GIF"
],
"PropertyContentCollectionFiles": [],
"Spelling": [
"Bday",
"Birthday",
"Childrens",
"Children's",
"Darrens",
"Darren's",
"Febuary",
"February",
"Feburay",
"February",
"Frist",
"First",
"Goolgle",
"Google",
"Kristys",
"Kristy's",
"Micael's",
"Michael's",
"Origanls",
"Originals",
"Patrict",
"Patrick",
"Sebtember",
"September"
],
"ValidImageFormatExtensions": [
".bmp",
".BMP",
".gif",
".GIF",
".jpeg",
".JPEG",
".jpg",
".JPG",
".png",
".PNG",
".tiff",
".TIFF"
],
"ValidMetadataExtensions": [
".3gp",
".3GP",
".amr",
".AMR",
".avi",
".AVI",
".bmp",
".BMP",
".gif",
".GIF",
".ico",
".ICO",
".jpeg",
".JPEG",
".jpg",
".JPG",
".m4v",
".M4V",
".mov",
".MOV",
".mp4",
".MP4",
".mta",
".MTA",
".png",
".PNG",
".tiff",
".TIFF"
],
"VerifyToSeason": [
". 2000",
". 2001",
". 2002",
". 2003",
". 2004",
". 2005",
". 2006",
". 2007",
". 2008",
". 2009",
". 2010",
". 2011",
". 2012",
". 2013",
". 2014",
". 2015",
". 2016",
". 2017",
". 2018",
". 2019",
". 2020",
". 2021",
". 2022",
". 2023",
". 2024",
". 2025",
". 2026",
". 2027",
". 2028",
". 2029",
"=2000.0 Winter",
"=2002.1 Spring",
"=2002.4 Winter",
"=2003.0 Winter",
"=2003.1 Spring",
"=2003.3 Fall",
"=2003.4 Winter",
"=2004.0 Winter",
"=2005.1 Spring",
"=2005.2 Summer",
"=2005.3 Fall",
"=2005.4 Winter",
"=2006.0 Winter",
"=2006.1 Spring",
"=2006.3 Fall",
"=2007.0 Winter",
"=2007.2 Summer Logan Michael",
"=2007.2 Summer",
"=2007.3 Fall Logan Michael",
"=2007.4 Winter Logan Michael",
"=2008.0 Winter Logan Michael",
"=2008.1 Spring Logan Michael",
"=2008.2 Summer Logan Michael",
"=2008.2 Summer",
"=2008.3 Fall Logan Michael",
"=2009.0 Winter Logan Michael",
"=2009.0 Winter",
"=2009.1 Spring Logan Michael",
"=2009.1 Spring",
"=2009.2 Summer Logan Michael",
"=2009.2 Summer",
"=2009.3 Fall Logan Michael",
"=2009.3 Fall",
"=2009.4 Winter Logan Michael",
"=2009.4 Winter",
"=2010.0 Winter Logan Michael",
"=2010.0 Winter",
"=2010.1 Spring Logan Michael",
"=2010.1 Spring",
"=2010.2 Summer",
"=2010.3 Fall Logan Michael",
"=2010.3 Fall",
"=2010.4 Winter",
"=2011.0 Winter",
"=2011.1 Spring",
"=2011.2 Summer",
"=2011.3 Fall",
"=2011.4 Winter",
"=2012.0 Winter Chelsea 2012",
"=2012.0 Winter Chelsea",
"=2012.0 Winter",
"=2012.1 Spring Chelsea",
"=2012.1 Spring",
"=2012.2 Summer Chelsea",
"=2012.2 Summer",
"=2012.3 Fall Chelsea",
"=2012.3 Fall",
"=2012.4 Winter Chelsea",
"=2012.4 Winter",
"=2013.0 Winter Chelsea 2013",
"=2013.0 Winter Chelsea",
"=2013.0 Winter",
"=2013.1 Spring",
"=2013.2 Summer Chelsea",
"=2013.2 Summer",
"=2013.3 Fall Chelsea",
"=2013.3 Fall",
"=2013.4 Winter",
"=2014.0 Winter",
"=2014.1 Spring",
"=2014.2 Summer",
"=2014.3 Fall",
"=2014.4 Winter",
"=2015.0 Winter",
"=2015.1 Spring",
"=2015.2 Summer",
"=2015.3 Fall",
"=2015.4 Winter",
"=2016.0 Winter",
"=2016.1 Spring",
"=2016.2 Summer",
"=2016.3 Fall",
"=2016.4 Winter",
"=2017.1 Spring",
"=2017.2 Summer",
"=2017.3 Fall",
"=2017.4 Winter",
"=2018.0 Winter",
"=2018.1 Spring",
"=2018.3 Fall",
"=2018.4 Winter",
"=2019.0 Winter",
"=2019.1 Spring",
"=2019.2 Summer",
"=2019.3 Fall",
"=2019.4 Winter",
"=2020.0 Winter",
"=2020.1 Spring",
"=2020.2 Summer",
"=2020.3 Fall",
"=2020.4 Winter",
"=2021.1 Spring",
"=2021.2 Summer",
"=2021.3 Fall",
"=2021.4 Winter",
"=2022.0 Winter",
"=2022.1 Spring",
"Anthem 2015",
"April 2010",
"April 2013",
"December 2006",
"December 2010",
"Fall 2005",
"Fall 2015",
"Fall 2016",
"Fall 2017",
"Fall 2018",
"Fall 2019",
"Fall 2020",
"Fall 2021",
"February 2010",
"January 2015",
"July 2010",
"June 2010",
"Kids 2005",
"March 2013",
"May 2010",
"May 2011",
"May 2013",
"October 2005",
"October 2014",
"Spring 2013",
"Spring 2014",
"Spring 2016",
"Spring 2018",
"Spring 2019",
"Spring 2020",
"Summer 2011",
"Summer 2012",
"Summer 2013",
"Summer 2014",
"Summer 2015",
"Summer 2016",
"Summer 2017",
"Summer 2018",
"Summer 2020",
"Summer 2021",
"Winter 2015",
"Winter 2016",
"Winter 2017",
"Winter 2018",
"Winter 2019-2020",
"Winter 2020",
"zzz =2005.0 Winter Tracy Pictures",
"zzz =2005.1 Spring Tracy Pictures",
"zzz =2005.2 Summer Tracy Pictures",
"zzz =2005.3 Fall Tracy Pictures",
"zzz =2005.4 Winter Tracy Pictures",
"zzz =2006.1 Spring Tracy Pictures",
"zzz =2007.0 Winter Tracy Pictures",
"zzz =2007.2 Summer Tracy Pictures",
"zzz =2008.0 Winter Tracy Pictures",
"zzz =2008.2 Summer Tracy Pictures",
"zzz =2009.0 Winter Tracy Pictures",
"zzz =2009.2 Summer Tracy Pictures",
"zzz =2009.3 Fall Tracy Pictures",
"zzz =2009.4 Winter Tracy Pictures",
"zzz =2010.0 Winter Tracy Pictures",
"zzz =2010.1 Spring Tracy Pictures",
"zzz =2010.2 Summer Tracy Pictures",
"zzz =2010.3 Fall Tracy Pictures",
"zzz =2011.0 Winter Tracy Pictures",
"zzz =2011.1 Spring Tracy Pictures",
"zzz =2011.2 Summer Tracy Pictures",
"zzz =2011.3 Fall Tracy Pictures",
"zzz =2011.4 Winter Tracy Pictures",
"zzz =2012.0 Winter Tracy Pictures",
"zzz =2012.1 Spring Tracy Pictures",
"zzz =2012.2 Summer Tracy Pictures",
"zzz =2012.3 Fall Tracy Pictures",
"zzz =2012.4 Winter Tracy Pictures",
"zzz =2013.0 Winter Tracy Pictures",
"zzz =2013.1 Spring Tracy Pictures",
"zzz =2013.2 Summer Tracy Pictures",
"zzz =2013.3 Fall Tracy Pictures",
"zzz =2013.4 Winter Tracy Pictures",
"zzz =2014.0 Winter Tracy Pictures",
"zzz =2014.1 Spring Tracy Pictures",
"zzz =2014.2 Summer Tracy Pictures",
"zzz =2014.3 Fall Tracy Pictures",
"zzz =2014.4 Winter Tracy Pictures",
"zzz =2015.0 Winter Tracy Pictures"
]
}
}
}