Container bug fix
This commit is contained in:
@ -140,8 +140,8 @@ public class A_Property
|
||||
}
|
||||
else if (!isIgnoreExtension && isValidImageFormatExtension)
|
||||
{
|
||||
if (populateId && (id is null || !indices.Any()) && !_IndicesFromNew.Any() && !_KeyValuePairs.Any())
|
||||
throw new Exception("In order to keep six character indices at least one need to have an item!");
|
||||
// if (populateId && (id is null || !indices.Any()) && !_IndicesFromNew.Any() && !_KeyValuePairs.Any())
|
||||
// throw new Exception("In order to keep six character indices at least one need to have an item!");
|
||||
try
|
||||
{
|
||||
using Image image = Image.FromFile(filteredSourceDirectoryFileHolder.FullName);
|
||||
@ -611,7 +611,7 @@ public class A_Property
|
||||
collectionDescription: string.Empty));
|
||||
}
|
||||
|
||||
public void ParallelWork(long ticks, List<Shared.Models.Container> containers, bool firstPass)
|
||||
public void ParallelWork(long ticks, Shared.Models.Container[] containers, bool firstPass)
|
||||
{
|
||||
if (_Log is null)
|
||||
throw new NullReferenceException(nameof(_Log));
|
||||
@ -619,7 +619,7 @@ public class A_Property
|
||||
bool? anyFilesMoved;
|
||||
Item[] filteredItems;
|
||||
List<Exception> exceptions = new();
|
||||
int containersCount = containers.Count;
|
||||
int containersCount = containers.Length;
|
||||
List<Tuple<string, DateTime>> sourceDirectoryChanges = new();
|
||||
string propertyRoot = IResult.GetResultsGroupDirectory(_Configuration, nameof(A_Property));
|
||||
foreach (Shared.Models.Container container in containers)
|
||||
@ -706,12 +706,13 @@ public class A_Property
|
||||
return results.OrderBy(l => l.Ticks).ToArray();
|
||||
}
|
||||
|
||||
public static List<Shared.Models.Container> Get(Configuration configuration, A_Property propertyLogic)
|
||||
public static Shared.Models.Container[] Get(Configuration configuration, A_Property propertyLogic)
|
||||
{
|
||||
List<Shared.Models.Container> results;
|
||||
Shared.Models.Container[] results;
|
||||
bool firstRun = false;
|
||||
long ticks = DateTime.Now.Ticks;
|
||||
List<string> exceptionsDirectories = new();
|
||||
results = Stateless.Container.GetContainers(configuration, propertyLogic);
|
||||
results = Stateless.Container.GetContainers(configuration, firstRun, propertyLogic);
|
||||
propertyLogic.ParallelWork(ticks, results, firstPass: false);
|
||||
if (exceptionsDirectories.Any())
|
||||
throw new Exception();
|
||||
|
@ -144,18 +144,26 @@ public class Container
|
||||
return results;
|
||||
}
|
||||
|
||||
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)
|
||||
private static Shared.Models.Container[] GetContainers(Configuration configuration, bool firstRun, string aPropertySingletonDirectory, List<(int, string, FileHolder[], int)> fileHolderGroupCollection, List<(int, string, List<(string, Shared.Models.Property?)>, int)> collectionFromJson)
|
||||
{
|
||||
List<Shared.Models.Container> results = new();
|
||||
Shared.Models.Container[] results;
|
||||
int length;
|
||||
string key;
|
||||
int additional;
|
||||
string inferred;
|
||||
string fileName;
|
||||
string extension;
|
||||
List<Item> items;
|
||||
string[] existing;
|
||||
string keyWithJson;
|
||||
string relativePath;
|
||||
string? directoryName;
|
||||
string extensionLowered;
|
||||
FileHolder keyFileHolder;
|
||||
Shared.Models.Container container;
|
||||
string? fileNameWithoutExtension;
|
||||
bool isValidImageFormatExtension;
|
||||
Shared.Models.Container container;
|
||||
List<string> keySourceDirectories;
|
||||
Dictionary<string, Shared.Models.Container> keyValuePairs = new();
|
||||
Dictionary<string, (string SourceDirectory, FileHolder FileHolder)> fileHolderKeyValuePairs = new();
|
||||
length = configuration.RootDirectory.Length;
|
||||
foreach ((int g, string sourceDirectory, FileHolder[] sourceDirectoryFileHolderCollection, int r) in fileHolderGroupCollection)
|
||||
@ -163,8 +171,21 @@ public class Container
|
||||
foreach (FileHolder sourceDirectoryFileHolder in sourceDirectoryFileHolderCollection)
|
||||
{
|
||||
relativePath = Shared.Models.Stateless.Methods.IPath.GetRelativePath(sourceDirectoryFileHolder.FullName, length);
|
||||
key = string.Concat(relativePath, ".json");
|
||||
fileHolderKeyValuePairs.Add(key, new(sourceDirectory, sourceDirectoryFileHolder));
|
||||
fileHolderKeyValuePairs.Add(relativePath, new(sourceDirectory, sourceDirectoryFileHolder));
|
||||
extension = Path.GetExtension(sourceDirectoryFileHolder.FullName);
|
||||
extensionLowered = Path.GetExtension(sourceDirectoryFileHolder.FullName).ToLower();
|
||||
if (extension != extensionLowered)
|
||||
{
|
||||
directoryName = Path.GetDirectoryName(sourceDirectoryFileHolder.FullName);
|
||||
if (string.IsNullOrEmpty(directoryName))
|
||||
continue;
|
||||
fileNameWithoutExtension = Path.GetFileNameWithoutExtension(sourceDirectoryFileHolder.FullName);
|
||||
if (string.IsNullOrEmpty(fileNameWithoutExtension))
|
||||
continue;
|
||||
fileName = Path.Combine(directoryName, $"{fileNameWithoutExtension}{extensionLowered}");
|
||||
relativePath = Shared.Models.Stateless.Methods.IPath.GetRelativePath(fileName, length);
|
||||
fileHolderKeyValuePairs.Add(relativePath, new(sourceDirectory, sourceDirectoryFileHolder));
|
||||
}
|
||||
}
|
||||
}
|
||||
length = aPropertySingletonDirectory.Length;
|
||||
@ -176,9 +197,9 @@ public class Container
|
||||
keySourceDirectories = new();
|
||||
foreach ((string sourceDirectoryFile, Shared.Models.Property? property) in collection)
|
||||
{
|
||||
key = Shared.Models.Stateless.Methods.IPath.GetRelativePath(sourceDirectoryFile, length);
|
||||
relativePath = key[..^5];
|
||||
if (!fileHolderKeyValuePairs.ContainsKey(key))
|
||||
keyWithJson = Shared.Models.Stateless.Methods.IPath.GetRelativePath(sourceDirectoryFile, length);
|
||||
relativePath = keyWithJson[..^5];
|
||||
if (!fileHolderKeyValuePairs.ContainsKey(relativePath))
|
||||
{
|
||||
inferred = string.Concat(configuration.RootDirectory, relativePath);
|
||||
keyFileHolder = new(inferred);
|
||||
@ -190,9 +211,9 @@ public class Container
|
||||
}
|
||||
else
|
||||
{
|
||||
keyFileHolder = fileHolderKeyValuePairs[key].FileHolder;
|
||||
keySourceDirectories.Add(fileHolderKeyValuePairs[key].SourceDirectory);
|
||||
if (!fileHolderKeyValuePairs.Remove(key))
|
||||
keyFileHolder = fileHolderKeyValuePairs[relativePath].FileHolder;
|
||||
keySourceDirectories.Add(fileHolderKeyValuePairs[relativePath].SourceDirectory);
|
||||
if (!fileHolderKeyValuePairs.Remove(relativePath))
|
||||
throw new Exception();
|
||||
if (keyFileHolder.ExtensionLowered is ".json")
|
||||
continue;
|
||||
@ -210,7 +231,7 @@ public class Container
|
||||
if (keySourceDirectories.Distinct().Count() != 1)
|
||||
continue;
|
||||
container = new(g, r, items, keySourceDirectories[0]);
|
||||
results.Add(container);
|
||||
keyValuePairs.Add(keySourceDirectories[0], container);
|
||||
}
|
||||
}
|
||||
length = configuration.RootDirectory.Length;
|
||||
@ -220,10 +241,9 @@ public class Container
|
||||
foreach (FileHolder sourceDirectoryFileHolder in sourceDirectoryFileHolderCollection)
|
||||
{
|
||||
relativePath = Shared.Models.Stateless.Methods.IPath.GetRelativePath(sourceDirectoryFileHolder.FullName, length);
|
||||
key = string.Concat(relativePath, ".json");
|
||||
if (!fileHolderKeyValuePairs.ContainsKey(key))
|
||||
if (!fileHolderKeyValuePairs.ContainsKey(relativePath))
|
||||
continue;
|
||||
if (!fileHolderKeyValuePairs.Remove(key))
|
||||
if (!fileHolderKeyValuePairs.Remove(relativePath))
|
||||
throw new Exception();
|
||||
if (sourceDirectoryFileHolder.ExtensionLowered is ".json")
|
||||
continue;
|
||||
@ -232,19 +252,38 @@ public class Container
|
||||
}
|
||||
if (items.Any())
|
||||
{
|
||||
container = new(g, r, items, sourceDirectory);
|
||||
results.Add(container);
|
||||
if (!keyValuePairs.ContainsKey(sourceDirectory))
|
||||
{
|
||||
container = new(g, r, items, sourceDirectory);
|
||||
keyValuePairs.Add(sourceDirectory, container);
|
||||
}
|
||||
else
|
||||
{
|
||||
additional = 0;
|
||||
container = keyValuePairs[sourceDirectory];
|
||||
existing = (from l in container.Items select l.ImageFileHolder?.FullName).ToArray();
|
||||
foreach (Item item in items)
|
||||
{
|
||||
if (item.ImageFileHolder is null || existing.Contains(item.ImageFileHolder.FullName))
|
||||
continue;
|
||||
additional += 1;
|
||||
items.Add(item);
|
||||
}
|
||||
container = new(g, r + additional, items, sourceDirectory);
|
||||
keyValuePairs[sourceDirectory] = container;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (fileHolderKeyValuePairs.Any())
|
||||
if (!firstRun && fileHolderKeyValuePairs.Any())
|
||||
throw new Exception();
|
||||
results = (from l in results orderby l.G, l.R select l).ToList();
|
||||
KeyValuePair<string, Shared.Models.Container>[] sortedKeyValuePairs = (from l in keyValuePairs orderby l.Value.G, l.Value.R select l).ToArray();
|
||||
results = (from l in sortedKeyValuePairs select l.Value).ToArray();
|
||||
return results;
|
||||
}
|
||||
|
||||
public static List<Shared.Models.Container> GetContainers(Configuration configuration, A_Property propertyLogic)
|
||||
public static Shared.Models.Container[] GetContainers(Configuration configuration, bool firstRun, A_Property propertyLogic)
|
||||
{
|
||||
List<Shared.Models.Container> results;
|
||||
Shared.Models.Container[] results;
|
||||
string searchPattern = "*";
|
||||
List<string> topDirectories = new();
|
||||
List<(int g, string sourceDirectory, string[] sourceDirectoryFiles, int r)> jsonCollection;
|
||||
@ -254,7 +293,7 @@ public class Container
|
||||
jsonCollection = GetJsonGroupCollection(configuration, propertyLogic, aPropertySingletonDirectory);
|
||||
fileHolderGroupCollection = GetFileHolderGroupCollection(configuration, propertyLogic, searchPattern, topDirectories);
|
||||
collectionFromJson = GetCollection(aPropertySingletonDirectory, jsonCollection);
|
||||
results = GetContainers(configuration, aPropertySingletonDirectory, fileHolderGroupCollection, collectionFromJson);
|
||||
results = GetContainers(configuration, firstRun, aPropertySingletonDirectory, fileHolderGroupCollection, collectionFromJson);
|
||||
return results;
|
||||
}
|
||||
|
||||
|
@ -14,9 +14,13 @@ public interface IResult
|
||||
static string GetRelativePath(Configuration configuration, string path)
|
||||
=> Result.GetRelativePath(configuration, path);
|
||||
|
||||
string TestStatic_GetResultsGroupDirectory(Configuration configuration, string description, bool create);
|
||||
static string GetResultsGroupDirectory(Configuration configuration, string description, bool create)
|
||||
=> Result.GetResultsGroupDirectory(configuration, description, create);
|
||||
|
||||
string TestStatic_GetResultsGroupDirectory(Configuration configuration, string description);
|
||||
static string GetResultsGroupDirectory(Configuration configuration, string description)
|
||||
=> Result.GetResultsGroupDirectory(configuration, description);
|
||||
=> Result.GetResultsGroupDirectory(configuration, description, create: true);
|
||||
|
||||
string TestStatic_GetResultsDateGroupDirectory(Configuration configuration, string description);
|
||||
static string GetResultsDateGroupDirectory(Configuration configuration, string description)
|
||||
|
@ -11,17 +11,17 @@ internal class Result
|
||||
return result;
|
||||
}
|
||||
|
||||
internal static string GetResultsGroupDirectory(Configuration configuration, string description)
|
||||
internal static string GetResultsGroupDirectory(Configuration configuration, string description, bool create)
|
||||
{
|
||||
string result = Path.Combine($"{configuration.RootDirectory} - Results", description.Replace("_", ") "));
|
||||
if (!Directory.Exists(result))
|
||||
if (create && !Directory.Exists(result))
|
||||
_ = Directory.CreateDirectory(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
internal static string GetResultsDateGroupDirectory(Configuration configuration, string description)
|
||||
{
|
||||
string result = Path.Combine(GetResultsGroupDirectory(configuration, description), configuration.DateGroup);
|
||||
string result = Path.Combine(GetResultsGroupDirectory(configuration, description, create: true), configuration.DateGroup);
|
||||
if (!Directory.Exists(result))
|
||||
_ = Directory.CreateDirectory(result);
|
||||
return result;
|
||||
|
Reference in New Issue
Block a user