Removed Obsolete A_Property Methods
Changed GetDimensions to handle a stream at the end and one exit Switched to using Action? over IDlibDotNet for Tick method
This commit is contained in:
@ -1,4 +1,5 @@
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Text.Json;
|
||||
using View_by_Distance.Shared.Models;
|
||||
using View_by_Distance.Shared.Models.Properties;
|
||||
using View_by_Distance.Shared.Models.Stateless.Methods;
|
||||
@ -57,7 +58,7 @@ internal abstract class Container
|
||||
return results;
|
||||
}
|
||||
|
||||
internal static (int, Models.Container[]) GetContainers(IPropertyConfiguration propertyConfiguration, ReadOnlyDictionary<int, Identifier>? splatNineIdentifiers, string _)
|
||||
internal static (int, Models.Container[]) GetContainers(IPropertyConfiguration propertyConfiguration, ReadOnlyDictionary<int, Identifier>? splatNineIdentifiers)
|
||||
{
|
||||
int count;
|
||||
Models.Container[] results;
|
||||
@ -101,11 +102,11 @@ internal abstract class Container
|
||||
throw new Exception();
|
||||
}
|
||||
}
|
||||
(string aResultsFullGroupDirectory, _) = dlibDotNet.GetResultsFullGroupDirectories();
|
||||
string aPropertySingletonDirectory = Path.Combine(aResultsFullGroupDirectory, propertyConfiguration.ResultSingleton);
|
||||
if (!Directory.Exists(aPropertySingletonDirectory))
|
||||
_ = Directory.CreateDirectory(aPropertySingletonDirectory);
|
||||
List<FilePair> filePairs = GetFilePairs(dlibDotNet, propertyConfiguration, aPropertySingletonDirectory, filesCollectionDirectory, keyValuePairs, splatNineIdentifiers, filePathsCollection, exifDirectoriesById, directorySearchFilter);
|
||||
(_, string bResultsFullGroupDirectory) = dlibDotNet.GetResultsFullGroupDirectories();
|
||||
string bMetadataSingletonDirectory = Path.Combine(bResultsFullGroupDirectory, propertyConfiguration.ResultSingleton);
|
||||
if (!Directory.Exists(bMetadataSingletonDirectory))
|
||||
_ = Directory.CreateDirectory(bMetadataSingletonDirectory);
|
||||
List<FilePair> filePairs = GetFilePairs(propertyConfiguration, bMetadataSingletonDirectory, filesCollectionDirectory, keyValuePairs, splatNineIdentifiers, filePathsCollection, exifDirectoriesById, directorySearchFilter, dlibDotNet.Tick);
|
||||
foreach (FilePair filePair in filePairs)
|
||||
{
|
||||
if (!directoryToItems.TryGetValue(filePair.FilePath.DirectoryFullPath, out items))
|
||||
@ -126,24 +127,24 @@ internal abstract class Container
|
||||
return (filePairs.Count, results.ToArray());
|
||||
}
|
||||
|
||||
private static List<FilePair> GetFilePairs(IDlibDotNet dlibDotNet, IPropertyConfiguration propertyConfiguration, string aPropertySingletonDirectory, string filesCollectionDirectory, ReadOnlyDictionary<int, ReadOnlyCollection<FilePath>>? keyValuePairs, ReadOnlyDictionary<int, Identifier>? splatNineIdentifiers, ReadOnlyCollection<ReadOnlyCollection<FilePath>> filePathsCollection, ReadOnlyDictionary<int, ExifDirectory>? exifDirectoriesById, string directorySearchFilter)
|
||||
private static List<FilePair> GetFilePairs(IPropertyConfiguration propertyConfiguration, string bMetadataSingletonDirectory, string filesCollectionDirectory, ReadOnlyDictionary<int, ReadOnlyCollection<FilePath>>? keyValuePairs, ReadOnlyDictionary<int, Identifier>? splatNineIdentifiers, ReadOnlyCollection<ReadOnlyCollection<FilePath>> filePathsCollection, ReadOnlyDictionary<int, ExifDirectory>? exifDirectoriesById, string directorySearchFilter, Action? tick)
|
||||
{
|
||||
List<FilePair> results = [];
|
||||
const string extension = ".json";
|
||||
ReadOnlyCollection<Shared.Models.FilePair> filePairs;
|
||||
string jsonGroupDirectory = aPropertySingletonDirectory;
|
||||
string jsonGroupDirectory = bMetadataSingletonDirectory;
|
||||
int maxDegreeOfParallelism = Environment.ProcessorCount;
|
||||
int filesCollectionDirectoryLength = filesCollectionDirectory.Length;
|
||||
ParallelOptions parallelOptions = new() { MaxDegreeOfParallelism = maxDegreeOfParallelism };
|
||||
filePairs = IFilePair.GetFilePairs(propertyConfiguration, directorySearchFilter, extension, jsonGroupDirectory, filePathsCollection);
|
||||
_ = Parallel.For(0, filePairs.Count, parallelOptions, (i, state) =>
|
||||
ParallelFor(dlibDotNet, propertyConfiguration, jsonGroupDirectory, extension, keyValuePairs, splatNineIdentifiers, filesCollectionDirectoryLength, exifDirectoriesById, filePairs[i], results));
|
||||
ParallelFor(propertyConfiguration, jsonGroupDirectory, extension, keyValuePairs, splatNineIdentifiers, filesCollectionDirectoryLength, exifDirectoriesById, filePairs[i], results, tick));
|
||||
return results;
|
||||
}
|
||||
|
||||
private static void ParallelFor(IDlibDotNet dlibDotNet, IPropertyConfiguration propertyConfiguration, string jsonGroupDirectory, string extension, ReadOnlyDictionary<int, ReadOnlyCollection<FilePath>>? keyValuePairs, ReadOnlyDictionary<int, Identifier>? splatNineIdentifiers, int rootDirectoryLength, ReadOnlyDictionary<int, ExifDirectory>? exifDirectoriesById, Shared.Models.FilePair filePair, List<FilePair> results)
|
||||
private static void ParallelFor(IPropertyConfiguration propertyConfiguration, string jsonGroupDirectory, string extension, ReadOnlyDictionary<int, ReadOnlyCollection<FilePath>>? keyValuePairs, ReadOnlyDictionary<int, Identifier>? splatNineIdentifiers, int rootDirectoryLength, ReadOnlyDictionary<int, ExifDirectory>? exifDirectoriesById, Shared.Models.FilePair filePair, List<FilePair> results, Action? tick)
|
||||
{
|
||||
dlibDotNet?.Tick();
|
||||
tick?.Invoke();
|
||||
bool abandoned = false;
|
||||
FileHolder sourceDirectoryFileHolder;
|
||||
if (exifDirectoriesById is null || filePair.FilePath.Id is null || !exifDirectoriesById.TryGetValue(filePair.FilePath.Id.Value, out ExifDirectory? exifDirectory))
|
||||
@ -208,7 +209,14 @@ internal abstract class Container
|
||||
string jsonFileName = $"{fileName}{extension}";
|
||||
string fullFileName = Path.Combine(directory, jsonFileName);
|
||||
MoveIf(jsonFileName, cei, directory, fullFileName);
|
||||
sourceDirectoryFileHolder = IFileHolder.Get(fullFileName);
|
||||
FileInfo fileInfo = new(fullFileName);
|
||||
if (exifDirectory is not null && !fileInfo.Exists)
|
||||
{
|
||||
string json = JsonSerializer.Serialize(exifDirectory, ExifDirectorySourceGenerationContext.Default.ExifDirectory);
|
||||
_ = Shared.Models.Stateless.Methods.IPath.WriteAllText(fileInfo.FullName, json, updateDateWhenMatches: false, compareBeforeWrite: true, updateToWhenMatches: null);
|
||||
fileInfo.Refresh();
|
||||
}
|
||||
sourceDirectoryFileHolder = IFileHolder.Get(fileInfo);
|
||||
}
|
||||
if (sourceDirectoryFileHolder.CreationTime is not null && sourceDirectoryFileHolder.LastWriteTime is not null && filePair.FilePath.LastWriteTicks != sourceDirectoryFileHolder.CreationTime.Value.Ticks)
|
||||
{
|
||||
|
Reference in New Issue
Block a user