Re-write
This commit is contained in:
@ -1,283 +0,0 @@
|
||||
namespace View_by_Distance.Property.Models.Stateless;
|
||||
|
||||
public static class A_Property
|
||||
{
|
||||
|
||||
public static string DateTimeFormat() => "yyyy:MM:dd HH:mm:ss";
|
||||
|
||||
public static (int Season, string seasonName) GetSeason(int dayOfYear)
|
||||
{
|
||||
(int Season, string seasonName) result = dayOfYear switch
|
||||
{
|
||||
< 78 => new(0, "Winter"),
|
||||
< 171 => new(1, "Spring"),
|
||||
< 264 => new(2, "Summer"),
|
||||
< 354 => new(3, "Fall"),
|
||||
_ => new(4, "Winter")
|
||||
};
|
||||
return result;
|
||||
}
|
||||
|
||||
public static List<Models.Container> Get(Models.Configuration configuration, PropertyLogic propertyLogic)
|
||||
{
|
||||
List<Models.Container> results;
|
||||
long ticks = DateTime.Now.Ticks;
|
||||
List<string> exceptionsDirectories = new();
|
||||
results = Container.GetContainers(configuration, propertyLogic);
|
||||
propertyLogic.ParallelWork(ticks, results, firstPass: false);
|
||||
if (exceptionsDirectories.Any())
|
||||
throw new Exception();
|
||||
return results;
|
||||
}
|
||||
|
||||
public static int GetDeterministicHashCode(byte[] value)
|
||||
{
|
||||
int result;
|
||||
unchecked
|
||||
{
|
||||
int hash1 = (5381 << 16) + 5381;
|
||||
int hash2 = hash1;
|
||||
for (int i = 0; i < value.Length; i += 2)
|
||||
{
|
||||
hash1 = ((hash1 << 5) + hash1) ^ value[i];
|
||||
if (i == value.Length - 1)
|
||||
break;
|
||||
hash2 = ((hash2 << 5) + hash2) ^ value[i + 1];
|
||||
}
|
||||
result = hash1 + (hash2 * 1566083941);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static int GetDeterministicHashCode(string value)
|
||||
{
|
||||
int result;
|
||||
unchecked
|
||||
{
|
||||
int hash1 = (5381 << 16) + 5381;
|
||||
int hash2 = hash1;
|
||||
for (int i = 0; i < value.Length; i += 2)
|
||||
{
|
||||
hash1 = ((hash1 << 5) + hash1) ^ value[i];
|
||||
if (i == value.Length - 1)
|
||||
break;
|
||||
hash2 = ((hash2 << 5) + hash2) ^ value[i + 1];
|
||||
}
|
||||
result = hash1 + (hash2 * 1566083941);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static (bool?, string[]) IsWrongYear(string[] segments, string year)
|
||||
{
|
||||
bool? result;
|
||||
string[] results = (
|
||||
from l
|
||||
in segments
|
||||
where l?.Length > 2
|
||||
&& (
|
||||
l[..2] is "19" or "20"
|
||||
|| (l.Length == 5 && l.Substring(1, 2) is "19" or "20" && (l[0] is '~' or '=' or '-' or '^' or '#'))
|
||||
|| (l.Length == 6 && l[..2] is "19" or "20" && l[4] == '.')
|
||||
|| (l.Length == 7 && l.Substring(1, 2) is "19" or "20" && l[5] == '.')
|
||||
)
|
||||
select l
|
||||
).ToArray();
|
||||
string[] matches = (
|
||||
from l
|
||||
in results
|
||||
where l == year
|
||||
|| (l.Length == 5 && l.Substring(1, 4) == year && (l[0] is '~' or '=' or '-' or '^' or '#'))
|
||||
|| (l.Length == 6 && l[..4] == year && l[4] == '.')
|
||||
|| (l.Length == 7 && l.Substring(1, 4) == year && l[5] == '.')
|
||||
select l
|
||||
).ToArray();
|
||||
if (!results.Any())
|
||||
result = null;
|
||||
else
|
||||
result = !matches.Any();
|
||||
return new(result, results);
|
||||
}
|
||||
|
||||
public static List<DateTime> GetDateTimes(DateTime creationTime, DateTime lastWriteTime, DateTime? dateTime, DateTime? dateTimeDigitized, DateTime? dateTimeOriginal, DateTime? gpsDateStamp)
|
||||
{
|
||||
List<DateTime> results = new()
|
||||
{
|
||||
creationTime,
|
||||
lastWriteTime
|
||||
};
|
||||
if (dateTime.HasValue)
|
||||
results.Add(dateTime.Value);
|
||||
if (dateTimeDigitized.HasValue)
|
||||
results.Add(dateTimeDigitized.Value);
|
||||
if (dateTimeOriginal.HasValue)
|
||||
results.Add(dateTimeOriginal.Value);
|
||||
if (gpsDateStamp.HasValue)
|
||||
results.Add(gpsDateStamp.Value);
|
||||
return results;
|
||||
}
|
||||
|
||||
public static DateTime GetDateTime(Models.A_Property? property)
|
||||
{
|
||||
DateTime result;
|
||||
if (property is null)
|
||||
result = DateTime.MinValue;
|
||||
else
|
||||
{
|
||||
List<DateTime> dateTimes = new()
|
||||
{
|
||||
property.CreationTime,
|
||||
property.LastWriteTime
|
||||
};
|
||||
if (property.DateTime.HasValue)
|
||||
dateTimes.Add(property.DateTime.Value);
|
||||
if (property.DateTimeDigitized.HasValue)
|
||||
dateTimes.Add(property.DateTimeDigitized.Value);
|
||||
if (property.DateTimeOriginal.HasValue)
|
||||
dateTimes.Add(property.DateTimeOriginal.Value);
|
||||
if (property.GPSDateStamp.HasValue)
|
||||
dateTimes.Add(property.GPSDateStamp.Value);
|
||||
result = dateTimes.Min();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static List<DateTime> GetDateTimes(Models.A_Property property) => GetDateTimes(property.CreationTime, property.LastWriteTime, property.DateTime, property.DateTimeDigitized, property.DateTimeOriginal, property.GPSDateStamp);
|
||||
|
||||
public static DateTime GetMinimumDateTime(Models.A_Property? property)
|
||||
{
|
||||
DateTime result;
|
||||
List<DateTime> dateTimes;
|
||||
if (property is null)
|
||||
result = DateTime.MinValue;
|
||||
else
|
||||
{
|
||||
dateTimes = GetDateTimes(property);
|
||||
result = dateTimes.Min();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static string GetDiffRootDirectory(string diffPropertyDirectory)
|
||||
{
|
||||
string result = string.Empty;
|
||||
string results = " - Results";
|
||||
string? checkDirectory = diffPropertyDirectory;
|
||||
for (int i = 0; i < int.MaxValue; i++)
|
||||
{
|
||||
checkDirectory = Path.GetDirectoryName(checkDirectory);
|
||||
if (string.IsNullOrEmpty(checkDirectory))
|
||||
break;
|
||||
if (checkDirectory.EndsWith(results))
|
||||
{
|
||||
result = checkDirectory[..^results.Length];
|
||||
break;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static double GetStandardDeviation(IEnumerable<long> values, double average)
|
||||
{
|
||||
double result = 0;
|
||||
if (!values.Any())
|
||||
throw new Exception("Collection must have at least one value!");
|
||||
double sum = values.Sum(l => (l - average) * (l - average));
|
||||
result = Math.Sqrt(sum / values.Count());
|
||||
return result;
|
||||
}
|
||||
|
||||
public static TimeSpan GetThreeStandardDeviationHigh(int minimum, Models.Container container)
|
||||
{
|
||||
TimeSpan result;
|
||||
DateTime? minimumDateTime;
|
||||
List<long> ticksCollection = new();
|
||||
foreach (Item item in container.Items)
|
||||
{
|
||||
if (item.Property is null)
|
||||
continue;
|
||||
minimumDateTime = GetMinimumDateTime(item.Property);
|
||||
if (minimumDateTime is null)
|
||||
continue;
|
||||
ticksCollection.Add(minimumDateTime.Value.Ticks);
|
||||
}
|
||||
long threeStandardDeviationHigh;
|
||||
long min;
|
||||
if (!ticksCollection.Any())
|
||||
min = 0;
|
||||
else
|
||||
min = ticksCollection.Min();
|
||||
if (ticksCollection.Count < minimum)
|
||||
threeStandardDeviationHigh = long.MaxValue;
|
||||
else
|
||||
{
|
||||
ticksCollection = (from l in ticksCollection select l - min).ToList();
|
||||
double sum = ticksCollection.Sum();
|
||||
double average = sum / ticksCollection.Count;
|
||||
double standardDeviation = GetStandardDeviation(ticksCollection, average);
|
||||
threeStandardDeviationHigh = (long)Math.Ceiling(average + min + (standardDeviation * 3));
|
||||
}
|
||||
result = new TimeSpan(threeStandardDeviationHigh - min);
|
||||
return result;
|
||||
}
|
||||
|
||||
public static (int, List<DateTime>, List<Item>) Get(Models.Container container, TimeSpan threeStandardDeviationHigh, int i)
|
||||
{
|
||||
List<Item> results = new();
|
||||
int j = i;
|
||||
Item item;
|
||||
long? ticks;
|
||||
Item nextItem;
|
||||
TimeSpan timeSpan;
|
||||
DateTime? minimumDateTime;
|
||||
DateTime? nextMinimumDateTime;
|
||||
List<DateTime> dateTimes = new();
|
||||
for (; j < container.Items.Count; j++)
|
||||
{
|
||||
ticks = null;
|
||||
item = container.Items[j];
|
||||
if (item.Property is null)
|
||||
continue;
|
||||
minimumDateTime = GetMinimumDateTime(item.Property);
|
||||
if (minimumDateTime is null)
|
||||
continue;
|
||||
for (int k = j + 1; k < container.Items.Count; k++)
|
||||
{
|
||||
nextItem = container.Items[k];
|
||||
if (nextItem.Property is null)
|
||||
continue;
|
||||
nextMinimumDateTime = GetMinimumDateTime(nextItem.Property);
|
||||
if (nextMinimumDateTime is null)
|
||||
continue;
|
||||
ticks = nextMinimumDateTime.Value.Ticks;
|
||||
break;
|
||||
}
|
||||
results.Add(item);
|
||||
dateTimes.Add(minimumDateTime.Value);
|
||||
if (ticks.HasValue)
|
||||
{
|
||||
timeSpan = new(ticks.Value - minimumDateTime.Value.Ticks);
|
||||
if (timeSpan > threeStandardDeviationHigh)
|
||||
break;
|
||||
}
|
||||
}
|
||||
return new(j, dateTimes, results);
|
||||
}
|
||||
|
||||
public static bool Any(List<Models.Container> propertyHolderCollections)
|
||||
{
|
||||
bool result = false;
|
||||
foreach (Models.Container container in propertyHolderCollections)
|
||||
{
|
||||
if (!container.Items.Any())
|
||||
continue;
|
||||
if ((from l in container.Items where l.Any() select true).Any())
|
||||
{
|
||||
result = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
@ -1,42 +0,0 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Phares.Shared;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace View_by_Distance.Property.Models.Stateless;
|
||||
|
||||
public abstract class Configuration
|
||||
{
|
||||
|
||||
public static Models.Configuration Get(IsEnvironment isEnvironment, IConfigurationRoot configurationRoot, string workingDirectory)
|
||||
{
|
||||
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();
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
@ -1,4 +1,5 @@
|
||||
using System.Text.Json;
|
||||
using View_by_Distance.Shared.Models;
|
||||
|
||||
namespace View_by_Distance.Property.Models.Stateless;
|
||||
|
||||
@ -98,67 +99,61 @@ public class Container
|
||||
return results;
|
||||
}
|
||||
|
||||
private static List<(int g, string sourceDirectory, string[] sourceDirectoryFiles, int r)> GetJsonGroupCollection(Models.Configuration configuration, PropertyLogic propertyLogic, string rootDirectory)
|
||||
private static List<(int g, string sourceDirectory, string[] sourceDirectoryFiles, int r)> GetJsonGroupCollection(Configuration configuration, A_Property propertyLogic, string rootDirectory)
|
||||
{
|
||||
List<(int g, string sourceDirectory, string[] sourceDirectoryFiles, int r)> results;
|
||||
if (configuration.MaxImagesInDirectoryForTopLevelFirstPass is null)
|
||||
throw new NullReferenceException(nameof(configuration.MaxImagesInDirectoryForTopLevelFirstPass));
|
||||
string searchPattern = "*.json";
|
||||
List<string> topDirectories = new();
|
||||
results = GetGroupCollection(rootDirectory, configuration.MaxImagesInDirectoryForTopLevelFirstPass.Value, propertyLogic.Reverse, searchPattern, topDirectories);
|
||||
results = GetGroupCollection(rootDirectory, configuration.MaxImagesInDirectoryForTopLevelFirstPass, propertyLogic.Reverse, searchPattern, topDirectories);
|
||||
return results;
|
||||
}
|
||||
|
||||
private static List<(int g, string sourceDirectory, FileHolder[] sourceDirectoryFiles, int r)> GetFileHolderGroupCollection(Models.Configuration configuration, PropertyLogic propertyLogic, string searchPattern, List<string> topDirectories)
|
||||
private static List<(int g, string sourceDirectory, FileHolder[] sourceDirectoryFiles, int r)> GetFileHolderGroupCollection(Configuration configuration, A_Property propertyLogic, string searchPattern, List<string> topDirectories)
|
||||
{
|
||||
List<(int g, string sourceDirectory, FileHolder[] sourceDirectoryFiles, int r)> results = new();
|
||||
if (configuration.MaxImagesInDirectoryForTopLevelFirstPass is null)
|
||||
throw new NullReferenceException(nameof(configuration.MaxImagesInDirectoryForTopLevelFirstPass));
|
||||
List<(int g, string sourceDirectory, string[] sourceDirectoryFiles, int r)>? collection = GetGroupCollection(configuration.RootDirectory, configuration.MaxImagesInDirectoryForTopLevelFirstPass.Value, propertyLogic.Reverse, searchPattern, topDirectories);
|
||||
List<(int g, string sourceDirectory, string[] sourceDirectoryFiles, int r)>? collection = GetGroupCollection(configuration.RootDirectory, configuration.MaxImagesInDirectoryForTopLevelFirstPass, propertyLogic.Reverse, searchPattern, topDirectories);
|
||||
foreach ((int g, string sourceDirectory, string[] sourceDirectoryFiles, int r) in collection)
|
||||
results.Add(new(g, sourceDirectory, (from l in sourceDirectoryFiles select new FileHolder(l)).ToArray(), r));
|
||||
return results;
|
||||
}
|
||||
|
||||
private static void ParallelFor(List<(int, string, string[], int)> jsonCollection, int i, int length, List<(int, string, List<(string, Models.A_Property?)>, int)> results)
|
||||
private static void ParallelFor(List<(int, string, string[], int)> jsonCollection, int i, int length, List<(int, string, List<(string, Shared.Models.Property?)>, int)> results)
|
||||
{
|
||||
string key;
|
||||
string json;
|
||||
Models.A_Property? property;
|
||||
Shared.Models.Property? property;
|
||||
(int g, string sourceDirectory, string[] sourceDirectoryFiles, int r) = jsonCollection[i];
|
||||
List<(string, Models.A_Property?)> collection = new();
|
||||
List<(string, Shared.Models.Property?)> collection = new();
|
||||
foreach (string sourceDirectoryFile in sourceDirectoryFiles)
|
||||
{
|
||||
json = File.ReadAllText(sourceDirectoryFile);
|
||||
key = XPath.GetRelativePath(sourceDirectoryFile, length);
|
||||
property = JsonSerializer.Deserialize<Models.A_Property>(json);
|
||||
key = Shared.Models.Stateless.Methods.IPath.GetRelativePath(sourceDirectoryFile, length);
|
||||
property = JsonSerializer.Deserialize<Shared.Models.Property>(json);
|
||||
collection.Add(new(sourceDirectoryFile, property));
|
||||
}
|
||||
lock (results)
|
||||
results.Add(new(g, sourceDirectory, collection, r));
|
||||
}
|
||||
|
||||
private static List<(int g, string sourceDirectory, List<(string sourceDirectoryFile, Models.A_Property? property)> collection, int r)> GetCollection(string rootDirectory, List<(int g, string sourceDirectory, string[] SourceDirectoryFiles, int r)> jsonCollection)
|
||||
private static List<(int g, string sourceDirectory, List<(string sourceDirectoryFile, Shared.Models.Property? property)> collection, int r)> GetCollection(string rootDirectory, List<(int g, string sourceDirectory, string[] SourceDirectoryFiles, int r)> jsonCollection)
|
||||
{
|
||||
List<(int, string, List<(string, Models.A_Property?)>, int)> results = new();
|
||||
List<(int, string, List<(string, Shared.Models.Property?)>, int)> results = new();
|
||||
int length = rootDirectory.Length;
|
||||
ParallelOptions parallelOptions = new() { MaxDegreeOfParallelism = Environment.ProcessorCount };
|
||||
_ = Parallel.For(0, jsonCollection.Count, parallelOptions, i => ParallelFor(jsonCollection, i, length, results));
|
||||
return results;
|
||||
}
|
||||
|
||||
private static List<Models.Container> GetContainers(Models.Configuration configuration, string aPropertySingletonDirectory, List<(int, string, FileHolder[], int)> fileHolderGroupCollection, List<(int, string, List<(string, Models.A_Property?)>, int)> collectionFromJson)
|
||||
private static List<Shared.Models.Container> GetContainers(Configuration configuration, string aPropertySingletonDirectory, List<(int, string, FileHolder[], int)> fileHolderGroupCollection, List<(int, string, List<(string, Shared.Models.Property?)>, int)> collectionFromJson)
|
||||
{
|
||||
List<Models.Container> results = new();
|
||||
if (configuration.PropertiesChangedForProperty is null)
|
||||
throw new Exception($"{configuration.PropertiesChangedForProperty} is null");
|
||||
List<Shared.Models.Container> results = new();
|
||||
int length;
|
||||
string key;
|
||||
string inferred;
|
||||
List<Item> items;
|
||||
string relativePath;
|
||||
FileHolder keyFileHolder;
|
||||
Models.Container container;
|
||||
Shared.Models.Container container;
|
||||
bool isValidImageFormatExtension;
|
||||
List<string> keySourceDirectories;
|
||||
Dictionary<string, (string SourceDirectory, FileHolder FileHolder)> fileHolderKeyValuePairs = new();
|
||||
@ -167,21 +162,21 @@ public class Container
|
||||
{
|
||||
foreach (FileHolder sourceDirectoryFileHolder in sourceDirectoryFileHolderCollection)
|
||||
{
|
||||
relativePath = XPath.GetRelativePath(sourceDirectoryFileHolder.FullName, length);
|
||||
relativePath = Shared.Models.Stateless.Methods.IPath.GetRelativePath(sourceDirectoryFileHolder.FullName, length);
|
||||
key = string.Concat(relativePath, ".json");
|
||||
fileHolderKeyValuePairs.Add(key, new(sourceDirectory, sourceDirectoryFileHolder));
|
||||
}
|
||||
}
|
||||
length = aPropertySingletonDirectory.Length;
|
||||
foreach ((int g, string _, List<(string, Models.A_Property?)> collection, int r) in collectionFromJson)
|
||||
foreach ((int g, string _, List<(string, Shared.Models.Property?)> collection, int r) in collectionFromJson)
|
||||
{
|
||||
if (!collection.Any())
|
||||
continue;
|
||||
items = new();
|
||||
keySourceDirectories = new();
|
||||
foreach ((string sourceDirectoryFile, Models.A_Property? property) in collection)
|
||||
foreach ((string sourceDirectoryFile, Shared.Models.Property? property) in collection)
|
||||
{
|
||||
key = XPath.GetRelativePath(sourceDirectoryFile, length);
|
||||
key = Shared.Models.Stateless.Methods.IPath.GetRelativePath(sourceDirectoryFile, length);
|
||||
relativePath = key[..^5];
|
||||
if (!fileHolderKeyValuePairs.ContainsKey(key))
|
||||
{
|
||||
@ -204,7 +199,7 @@ public class Container
|
||||
isValidImageFormatExtension = configuration.ValidImageFormatExtensions.Contains(keyFileHolder.ExtensionLowered);
|
||||
if (property?.Id is null || property?.Width is null || property?.Height is null)
|
||||
items.Add(new(sourceDirectoryFile, relativePath, keyFileHolder, isValidImageFormatExtension, property, false, null));
|
||||
else if (configuration.PropertiesChangedForProperty.Value || property.LastWriteTime != keyFileHolder.LastWriteTime || property.FileSize != keyFileHolder.Length)
|
||||
else if (configuration.PropertiesChangedForProperty || property.LastWriteTime != keyFileHolder.LastWriteTime || property.FileSize != keyFileHolder.Length)
|
||||
items.Add(new(sourceDirectoryFile, relativePath, keyFileHolder, isValidImageFormatExtension, property, false, true));
|
||||
else
|
||||
items.Add(new(sourceDirectoryFile, relativePath, keyFileHolder, isValidImageFormatExtension, property, false, false));
|
||||
@ -224,7 +219,7 @@ public class Container
|
||||
items = new();
|
||||
foreach (FileHolder sourceDirectoryFileHolder in sourceDirectoryFileHolderCollection)
|
||||
{
|
||||
relativePath = XPath.GetRelativePath(sourceDirectoryFileHolder.FullName, length);
|
||||
relativePath = Shared.Models.Stateless.Methods.IPath.GetRelativePath(sourceDirectoryFileHolder.FullName, length);
|
||||
key = string.Concat(relativePath, ".json");
|
||||
if (!fileHolderKeyValuePairs.ContainsKey(key))
|
||||
continue;
|
||||
@ -247,16 +242,15 @@ public class Container
|
||||
return results;
|
||||
}
|
||||
|
||||
public static List<Models.Container> GetContainers(Models.Configuration configuration, PropertyLogic propertyLogic)
|
||||
public static List<Shared.Models.Container> GetContainers(Configuration configuration, A_Property propertyLogic)
|
||||
{
|
||||
List<Models.Container> results;
|
||||
List<Shared.Models.Container> results;
|
||||
string searchPattern = "*";
|
||||
long ticks = DateTime.Now.Ticks;
|
||||
List<string> topDirectories = new();
|
||||
List<(int g, string sourceDirectory, string[] sourceDirectoryFiles, int r)> jsonCollection;
|
||||
List<(int g, string sourceDirectory, FileHolder[] sourceDirectoryFiles, int r)> fileHolderGroupCollection;
|
||||
string aPropertySingletonDirectory = IResult.GetResultsDateGroupDirectory(configuration, nameof(A_Property), "{}");
|
||||
List<(int g, string sourceDirectory, List<(string sourceDirectoryFile, Models.A_Property? property)> collection, int r)> collectionFromJson;
|
||||
List<(int g, string sourceDirectory, List<(string sourceDirectoryFile, Shared.Models.Property? property)> collection, int r)> collectionFromJson;
|
||||
jsonCollection = GetJsonGroupCollection(configuration, propertyLogic, aPropertySingletonDirectory);
|
||||
fileHolderGroupCollection = GetFileHolderGroupCollection(configuration, propertyLogic, searchPattern, topDirectories);
|
||||
collectionFromJson = GetCollection(aPropertySingletonDirectory, jsonCollection);
|
||||
|
@ -1,24 +0,0 @@
|
||||
namespace View_by_Distance.Property.Models.Stateless;
|
||||
|
||||
public interface IPath
|
||||
{
|
||||
|
||||
string TestStatic_GetRelativePath(string path, int length);
|
||||
static string GetRelativePath(string path, int length) => XPath.GetRelativePath(path, length);
|
||||
|
||||
bool TestStatic_DeleteEmptyDirectories(string rootDirectory);
|
||||
static bool DeleteEmptyDirectories(string rootDirectory) => XPath.DeleteEmptyDirectories(rootDirectory);
|
||||
|
||||
List<string> TestStatic_GetDirectoryNames(string directory);
|
||||
static List<string> GetDirectoryNames(string directory) => XPath.GetDirectoryNames(directory);
|
||||
|
||||
bool TestStatic_WriteAllText(string path, string contents, bool updateDateWhenMatches, bool compareBeforeWrite);
|
||||
static bool WriteAllText(string path, string contents, bool updateDateWhenMatches, bool compareBeforeWrite, DateTime? updateToWhenMatches = null) => XPath.WriteAllText(path, contents, updateDateWhenMatches, compareBeforeWrite, updateToWhenMatches);
|
||||
|
||||
(int level, List<string> directories) TestStatic_Get(string rootDirectory, string sourceDirectory);
|
||||
static (int level, List<string> directories) Get(string rootDirectory, string sourceDirectory) => XPath.Get(rootDirectory, sourceDirectory);
|
||||
|
||||
string TestStatic_GetDirectory(string sourceDirectory, int level, string directoryName);
|
||||
static string GetDirectory(string sourceDirectory, int level, string directoryName) => XPath.GetDirectory(sourceDirectory, level, directoryName);
|
||||
|
||||
}
|
@ -10,32 +10,32 @@ public interface IResult
|
||||
public const string Collection = "[]";
|
||||
public const string AllInOne = "_ _ _";
|
||||
|
||||
string TestStatic_GetRelativePath(Models.Configuration configuration, string path);
|
||||
static string GetRelativePath(Models.Configuration configuration, string path)
|
||||
string TestStatic_GetRelativePath(Configuration configuration, string path);
|
||||
static string GetRelativePath(Configuration configuration, string path)
|
||||
=> Result.GetRelativePath(configuration, path);
|
||||
|
||||
string TestStatic_GetResultsGroupDirectory(Models.Configuration configuration, string description);
|
||||
static string GetResultsGroupDirectory(Models.Configuration configuration, string description)
|
||||
string TestStatic_GetResultsGroupDirectory(Configuration configuration, string description);
|
||||
static string GetResultsGroupDirectory(Configuration configuration, string description)
|
||||
=> Result.GetResultsGroupDirectory(configuration, description);
|
||||
|
||||
string TestStatic_GetResultsDateGroupDirectory(Models.Configuration configuration, string description);
|
||||
static string GetResultsDateGroupDirectory(Models.Configuration configuration, string description)
|
||||
string TestStatic_GetResultsDateGroupDirectory(Configuration configuration, string description);
|
||||
static string GetResultsDateGroupDirectory(Configuration configuration, string description)
|
||||
=> Result.GetResultsDateGroupDirectory(configuration, description);
|
||||
|
||||
string TestStatic_GetResultsDateGroupDirectory(Models.Configuration configuration, string description, string jsonGroup);
|
||||
static string GetResultsDateGroupDirectory(Models.Configuration configuration, string description, string jsonGroup)
|
||||
string TestStatic_GetResultsDateGroupDirectory(Configuration configuration, string description, string jsonGroup);
|
||||
static string GetResultsDateGroupDirectory(Configuration configuration, string description, string jsonGroup)
|
||||
=> Result.GetResultsDateGroupDirectory(configuration, description, jsonGroup);
|
||||
|
||||
List<string> TestStatic_GetDirectoryInfoCollection(Models.Configuration configuration, string sourceDirectory, string dateGroupDirectory, string contentDescription, string singletonDescription, string collectionDescription);
|
||||
static List<string> GetDirectoryInfoCollection(Models.Configuration configuration, string sourceDirectory, string dateGroupDirectory, string contentDescription, string singletonDescription, string collectionDescription, bool converted)
|
||||
List<string> TestStatic_GetDirectoryInfoCollection(Configuration configuration, string sourceDirectory, string dateGroupDirectory, string contentDescription, string singletonDescription, string collectionDescription);
|
||||
static List<string> GetDirectoryInfoCollection(Configuration configuration, string sourceDirectory, string dateGroupDirectory, string contentDescription, string singletonDescription, string collectionDescription, bool converted)
|
||||
=> Result.GetDirectoryInfoCollection(configuration, sourceDirectory, dateGroupDirectory, contentDescription, singletonDescription, collectionDescription, converted);
|
||||
|
||||
string TestStatic_GetResultsFullGroupDirectory(Models.Configuration configuration, Model? model, PredictorModel? predictorModel, string description, string outputResolution, bool includeResizeGroup, bool includeModel, bool includePredictorModel);
|
||||
static string GetResultsFullGroupDirectory(Models.Configuration configuration, Model? model, PredictorModel? predictorModel, string description, string outputResolution, bool includeResizeGroup, bool includeModel, bool includePredictorModel)
|
||||
string TestStatic_GetResultsFullGroupDirectory(Configuration configuration, Model? model, PredictorModel? predictorModel, string description, string outputResolution, bool includeResizeGroup, bool includeModel, bool includePredictorModel);
|
||||
static string GetResultsFullGroupDirectory(Configuration configuration, Model? model, PredictorModel? predictorModel, string description, string outputResolution, bool includeResizeGroup, bool includeModel, bool includePredictorModel)
|
||||
=> Result.GetResultsFullGroupDirectory(configuration, model, predictorModel, description, outputResolution, includeResizeGroup, includeModel, includePredictorModel);
|
||||
|
||||
List<string> TestStatic_GetDirectoryInfoCollection(Models.Configuration configuration, Model? model, PredictorModel? predictorModel, string sourceDirectory, string description, string outputResolution, bool includeResizeGroup, bool includeModel, bool includePredictorModel, string contentDescription, string singletonDescription, string collectionDescription);
|
||||
static List<string> GetDirectoryInfoCollection(Models.Configuration configuration, Model? model, PredictorModel? predictorModel, string sourceDirectory, string description, string outputResolution, bool includeResizeGroup, bool includeModel, bool includePredictorModel, string contentDescription, string singletonDescription, string collectionDescription)
|
||||
List<string> TestStatic_GetDirectoryInfoCollection(Configuration configuration, Model? model, PredictorModel? predictorModel, string sourceDirectory, string description, string outputResolution, bool includeResizeGroup, bool includeModel, bool includePredictorModel, string contentDescription, string singletonDescription, string collectionDescription);
|
||||
static List<string> GetDirectoryInfoCollection(Configuration configuration, Model? model, PredictorModel? predictorModel, string sourceDirectory, string description, string outputResolution, bool includeResizeGroup, bool includeModel, bool includePredictorModel, string contentDescription, string singletonDescription, string collectionDescription)
|
||||
=> Result.GetDirectoryInfoCollection(configuration, model, predictorModel, sourceDirectory, description, outputResolution, includeResizeGroup, includeModel, includePredictorModel, contentDescription, singletonDescription, collectionDescription);
|
||||
|
||||
}
|
@ -1,150 +0,0 @@
|
||||
namespace View_by_Distance.Property.Models.Stateless;
|
||||
|
||||
internal class XPath
|
||||
{
|
||||
|
||||
internal static string GetRelativePath(string path, int length)
|
||||
{
|
||||
string result = path[length..].Replace(@"\", "/");
|
||||
return result;
|
||||
}
|
||||
|
||||
internal static bool DeleteEmptyDirectories(string rootDirectory)
|
||||
{
|
||||
bool result;
|
||||
if (!Directory.Exists(rootDirectory))
|
||||
result = false;
|
||||
else
|
||||
{
|
||||
string[] files;
|
||||
string[] directories = Directory.GetDirectories(rootDirectory, "*", SearchOption.TopDirectoryOnly);
|
||||
if (directories.Length > 0)
|
||||
files = Array.Empty<string>();
|
||||
else
|
||||
files = Directory.GetFiles(rootDirectory, "*", SearchOption.AllDirectories);
|
||||
if (directories.Length == 0 && files.Length == 0)
|
||||
{
|
||||
result = true;
|
||||
Directory.Delete(rootDirectory);
|
||||
}
|
||||
else
|
||||
{
|
||||
result = false;
|
||||
foreach (string directory in directories)
|
||||
{
|
||||
result = DeleteEmptyDirectories(directory);
|
||||
if (result)
|
||||
result = DeleteEmptyDirectories(directory);
|
||||
}
|
||||
if (files is null)
|
||||
{
|
||||
directories = Directory.GetDirectories(rootDirectory, "*", SearchOption.TopDirectoryOnly);
|
||||
result = directories.Length == 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
internal static bool WriteAllText(string path, string contents, bool updateDateWhenMatches, bool compareBeforeWrite, DateTime? updateToWhenMatches)
|
||||
{
|
||||
bool result;
|
||||
string text;
|
||||
if (!compareBeforeWrite)
|
||||
result = true;
|
||||
else
|
||||
{
|
||||
if (!File.Exists(path))
|
||||
text = string.Empty;
|
||||
else
|
||||
text = File.ReadAllText(path);
|
||||
result = text != contents;
|
||||
if (!result && updateDateWhenMatches)
|
||||
{
|
||||
if (updateToWhenMatches is null)
|
||||
File.SetLastWriteTime(path, DateTime.Now);
|
||||
else
|
||||
File.SetLastWriteTime(path, updateToWhenMatches.Value);
|
||||
}
|
||||
}
|
||||
if (result)
|
||||
{
|
||||
if (path.Contains("()"))
|
||||
File.WriteAllText(path, contents);
|
||||
else if (path.Contains("{}") && !path.EndsWith(".json"))
|
||||
File.WriteAllText(path, contents);
|
||||
else if (path.Contains("[]") && !path.EndsWith(".json"))
|
||||
File.WriteAllText(path, contents);
|
||||
else if (path.Contains("{}") && path.EndsWith(".json") && contents[0] == '{')
|
||||
File.WriteAllText(path, contents);
|
||||
else if (path.Contains("[]") && path.EndsWith(".json") && contents[0] == '[')
|
||||
File.WriteAllText(path, contents);
|
||||
else
|
||||
File.WriteAllText(path, contents);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
internal static List<string> GetDirectoryNames(string directory)
|
||||
{
|
||||
List<string> results = new();
|
||||
string? checkDirectory = directory;
|
||||
string? pathRoot = Path.GetPathRoot(directory);
|
||||
string extension = Path.GetExtension(directory);
|
||||
if (string.IsNullOrEmpty(pathRoot))
|
||||
throw new NullReferenceException(nameof(pathRoot));
|
||||
if (Directory.Exists(directory))
|
||||
results.Add(Path.GetFileName(directory));
|
||||
else if ((string.IsNullOrEmpty(extension) || extension.Length > 3) && !File.Exists(directory))
|
||||
results.Add(Path.GetFileName(directory));
|
||||
for (int i = 0; i < int.MaxValue; i++)
|
||||
{
|
||||
checkDirectory = Path.GetDirectoryName(checkDirectory);
|
||||
if (string.IsNullOrEmpty(checkDirectory) || checkDirectory == pathRoot)
|
||||
break;
|
||||
results.Add(Path.GetFileName(checkDirectory));
|
||||
}
|
||||
results.Add(pathRoot);
|
||||
results.Reverse();
|
||||
return results;
|
||||
}
|
||||
|
||||
internal static (int level, List<string> directories) Get(string rootDirectory, string sourceDirectory)
|
||||
{
|
||||
int result = 0;
|
||||
string? directory;
|
||||
string? checkDirectory;
|
||||
List<string> results = new();
|
||||
checkDirectory = sourceDirectory;
|
||||
for (int i = 0; i < int.MaxValue; i++)
|
||||
{
|
||||
result += 1;
|
||||
directory = Path.GetFileName(checkDirectory);
|
||||
if (string.IsNullOrEmpty(directory))
|
||||
break;
|
||||
results.Add(directory);
|
||||
checkDirectory = Path.GetDirectoryName(checkDirectory);
|
||||
if (checkDirectory == rootDirectory)
|
||||
break;
|
||||
}
|
||||
results.Reverse();
|
||||
return new(result, results);
|
||||
}
|
||||
|
||||
internal static string GetDirectory(string sourceDirectory, int level, string directoryName)
|
||||
{
|
||||
string result;
|
||||
string? checkDirectory;
|
||||
checkDirectory = Path.GetDirectoryName(sourceDirectory);
|
||||
for (int i = 0; i < level; i++)
|
||||
checkDirectory = Path.GetDirectoryName(checkDirectory);
|
||||
if (string.IsNullOrEmpty(checkDirectory))
|
||||
throw new Exception();
|
||||
checkDirectory = Path.Combine(checkDirectory, directoryName);
|
||||
if (!Directory.Exists(checkDirectory))
|
||||
_ = Directory.CreateDirectory(checkDirectory);
|
||||
result = checkDirectory;
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
@ -5,13 +5,13 @@ namespace View_by_Distance.Property.Models.Stateless;
|
||||
internal class Result
|
||||
{
|
||||
|
||||
internal static string GetRelativePath(Models.Configuration configuration, string path)
|
||||
internal static string GetRelativePath(Configuration configuration, string path)
|
||||
{
|
||||
string result = XPath.GetRelativePath(path, configuration.RootDirectory.Length);
|
||||
string result = Shared.Models.Stateless.Methods.IPath.GetRelativePath(path, configuration.RootDirectory.Length);
|
||||
return result;
|
||||
}
|
||||
|
||||
internal static string GetResultsGroupDirectory(Models.Configuration configuration, string description)
|
||||
internal static string GetResultsGroupDirectory(Configuration configuration, string description)
|
||||
{
|
||||
string result = Path.Combine($"{configuration.RootDirectory} - Results", description.Replace("_", ") "));
|
||||
if (!Directory.Exists(result))
|
||||
@ -19,7 +19,7 @@ internal class Result
|
||||
return result;
|
||||
}
|
||||
|
||||
internal static string GetResultsDateGroupDirectory(Models.Configuration configuration, string description)
|
||||
internal static string GetResultsDateGroupDirectory(Configuration configuration, string description)
|
||||
{
|
||||
string result = Path.Combine(GetResultsGroupDirectory(configuration, description), configuration.DateGroup);
|
||||
if (!Directory.Exists(result))
|
||||
@ -27,7 +27,7 @@ internal class Result
|
||||
return result;
|
||||
}
|
||||
|
||||
internal static string GetResultsDateGroupDirectory(Models.Configuration configuration, string description, string jsonGroup)
|
||||
internal static string GetResultsDateGroupDirectory(Configuration configuration, string description, string jsonGroup)
|
||||
{
|
||||
string result = Path.Combine(GetResultsDateGroupDirectory(configuration, description), jsonGroup);
|
||||
if (!Directory.Exists(result))
|
||||
@ -35,7 +35,7 @@ internal class Result
|
||||
return result;
|
||||
}
|
||||
|
||||
internal static string GetResultsFullGroupDirectory(Models.Configuration configuration, Model? model, PredictorModel? predictorModel, string description, string outputResolution, bool includeResizeGroup, bool includeModel, bool includePredictorModel)
|
||||
internal static string GetResultsFullGroupDirectory(Configuration configuration, Model? model, PredictorModel? predictorModel, string description, string outputResolution, bool includeResizeGroup, bool includeModel, bool includePredictorModel)
|
||||
{
|
||||
string result = GetResultsDateGroupDirectory(configuration, description);
|
||||
if (includeResizeGroup)
|
||||
@ -64,59 +64,69 @@ internal class Result
|
||||
return result;
|
||||
}
|
||||
|
||||
internal static List<string> GetDirectoryInfoCollection(Models.Configuration configuration, string sourceDirectory, string dateGroupDirectory, string contentDescription, string singletonDescription, string collectionDescription, bool converted)
|
||||
private static void CheckContent(string dateGroupDirectory, string contentDescription, string result)
|
||||
{
|
||||
string checkDirectory;
|
||||
checkDirectory = Path.Combine(dateGroupDirectory, IResult.Content, IResult.AllInOne);
|
||||
if (!Directory.Exists(checkDirectory))
|
||||
_ = Directory.CreateDirectory(checkDirectory);
|
||||
string contentDirectory = new(result.Replace("<>", IResult.Content));
|
||||
if (!Directory.Exists(contentDirectory))
|
||||
_ = Directory.CreateDirectory(contentDirectory);
|
||||
checkDirectory = Path.Combine(dateGroupDirectory, string.Concat("() - ", contentDescription));
|
||||
if (!Directory.Exists(checkDirectory))
|
||||
_ = Directory.CreateDirectory(checkDirectory);
|
||||
}
|
||||
|
||||
private static void CheckSingleton(string dateGroupDirectory, string singletonDescription, bool converted, string result)
|
||||
{
|
||||
string checkDirectory;
|
||||
checkDirectory = Path.Combine(dateGroupDirectory, IResult.Singleton, IResult.AllInOne);
|
||||
if (!Directory.Exists(checkDirectory))
|
||||
_ = Directory.CreateDirectory(checkDirectory);
|
||||
if (!converted)
|
||||
{
|
||||
string singletonDirectory = new(result.Replace("<>", IResult.Singleton));
|
||||
if (!Directory.Exists(singletonDirectory))
|
||||
_ = Directory.CreateDirectory(singletonDirectory);
|
||||
}
|
||||
checkDirectory = Path.Combine(dateGroupDirectory, string.Concat("{} - ", singletonDescription));
|
||||
if (!Directory.Exists(checkDirectory))
|
||||
_ = Directory.CreateDirectory(checkDirectory);
|
||||
}
|
||||
|
||||
private static void CheckCollection(string dateGroupDirectory, string collectionDescription, bool converted, string result)
|
||||
{
|
||||
string checkDirectory = Path.Combine(dateGroupDirectory, IResult.Collection, IResult.AllInOne);
|
||||
if (!Directory.Exists(checkDirectory))
|
||||
_ = Directory.CreateDirectory(checkDirectory);
|
||||
if (!converted)
|
||||
{
|
||||
string collectionDirectory = new(result.Replace("<>", IResult.Collection));
|
||||
if (!Directory.Exists(collectionDirectory))
|
||||
_ = Directory.CreateDirectory(collectionDirectory);
|
||||
}
|
||||
checkDirectory = Path.Combine(dateGroupDirectory, string.Concat("[] - ", collectionDescription));
|
||||
if (!Directory.Exists(checkDirectory))
|
||||
_ = Directory.CreateDirectory(checkDirectory);
|
||||
}
|
||||
|
||||
internal static List<string> GetDirectoryInfoCollection(Configuration configuration, string sourceDirectory, string dateGroupDirectory, string contentDescription, string singletonDescription, string collectionDescription, bool converted)
|
||||
{
|
||||
List<string> results = new();
|
||||
string checkDirectory;
|
||||
string sourceDirectorySegment = GetRelativePath(configuration, sourceDirectory);
|
||||
string result = string.Concat(Path.Combine(dateGroupDirectory, "<>"), sourceDirectorySegment);
|
||||
if (!string.IsNullOrEmpty(contentDescription))
|
||||
{
|
||||
checkDirectory = Path.Combine(dateGroupDirectory, IResult.Content, IResult.AllInOne);
|
||||
if (!Directory.Exists(checkDirectory))
|
||||
_ = Directory.CreateDirectory(checkDirectory);
|
||||
string contentDirectory = new(result.Replace("<>", IResult.Content));
|
||||
if (!Directory.Exists(contentDirectory))
|
||||
_ = Directory.CreateDirectory(contentDirectory);
|
||||
checkDirectory = Path.Combine(dateGroupDirectory, string.Concat("() - ", contentDescription));
|
||||
if (!Directory.Exists(checkDirectory))
|
||||
_ = Directory.CreateDirectory(checkDirectory);
|
||||
}
|
||||
CheckContent(dateGroupDirectory, contentDescription, result);
|
||||
if (!string.IsNullOrEmpty(singletonDescription))
|
||||
{
|
||||
checkDirectory = Path.Combine(dateGroupDirectory, IResult.Singleton, IResult.AllInOne);
|
||||
if (!Directory.Exists(checkDirectory))
|
||||
_ = Directory.CreateDirectory(checkDirectory);
|
||||
if (!converted)
|
||||
{
|
||||
string singletonDirectory = new(result.Replace("<>", IResult.Singleton));
|
||||
if (!Directory.Exists(singletonDirectory))
|
||||
_ = Directory.CreateDirectory(singletonDirectory);
|
||||
}
|
||||
checkDirectory = Path.Combine(dateGroupDirectory, string.Concat("{} - ", singletonDescription));
|
||||
if (!Directory.Exists(checkDirectory))
|
||||
_ = Directory.CreateDirectory(checkDirectory);
|
||||
}
|
||||
CheckSingleton(dateGroupDirectory, singletonDescription, converted, result);
|
||||
if (!string.IsNullOrEmpty(collectionDescription))
|
||||
{
|
||||
checkDirectory = Path.Combine(dateGroupDirectory, IResult.Collection, IResult.AllInOne);
|
||||
if (!Directory.Exists(checkDirectory))
|
||||
_ = Directory.CreateDirectory(checkDirectory);
|
||||
if (!converted)
|
||||
{
|
||||
string collectionDirectory = new(result.Replace("<>", IResult.Collection));
|
||||
if (!Directory.Exists(collectionDirectory))
|
||||
_ = Directory.CreateDirectory(collectionDirectory);
|
||||
}
|
||||
checkDirectory = Path.Combine(dateGroupDirectory, string.Concat("[] - ", collectionDescription));
|
||||
if (!Directory.Exists(checkDirectory))
|
||||
_ = Directory.CreateDirectory(checkDirectory);
|
||||
}
|
||||
CheckCollection(dateGroupDirectory, collectionDescription, converted, result);
|
||||
results.Add(result);
|
||||
return results;
|
||||
}
|
||||
|
||||
internal static List<string> GetDirectoryInfoCollection(Models.Configuration configuration, Model? model, PredictorModel? predictorModel, string sourceDirectory, string description, string outputResolution, bool includeResizeGroup, bool includeModel, bool includePredictorModel, string contentDescription, string singletonDescription, string collectionDescription)
|
||||
internal static List<string> GetDirectoryInfoCollection(Configuration configuration, Model? model, PredictorModel? predictorModel, string sourceDirectory, string description, string outputResolution, bool includeResizeGroup, bool includeModel, bool includePredictorModel, string contentDescription, string singletonDescription, string collectionDescription)
|
||||
{
|
||||
List<string> results;
|
||||
bool converted = false;
|
||||
|
Reference in New Issue
Block a user