Keyword to work with Amazon
This commit is contained in:
@ -11,17 +11,9 @@ internal abstract class Container
|
||||
internal static DateTime[] GetContainerDateTimes(IEnumerable<Models.Item> items)
|
||||
{
|
||||
DateTime[] results;
|
||||
DateTime? containerMinimumDateTime;
|
||||
DateTime? containerMaximumDateTime;
|
||||
containerMinimumDateTime = (from l in items select l.ImageFileHolder.LastWriteTime).Min();
|
||||
if (containerMinimumDateTime is null)
|
||||
containerMaximumDateTime = null;
|
||||
else
|
||||
containerMaximumDateTime = (from l in items select l.ImageFileHolder.LastWriteTime).Max();
|
||||
if (containerMinimumDateTime is null || containerMaximumDateTime is null)
|
||||
results = [];
|
||||
else
|
||||
results = [containerMinimumDateTime.Value, containerMaximumDateTime.Value];
|
||||
long containerMinimumTicks = (from l in items select l.FilePath.LastWriteTicks).Min();
|
||||
long containerMaximumTicks = (from l in items select l.FilePath.LastWriteTicks).Max();
|
||||
results = [new(containerMinimumTicks), new(containerMaximumTicks)];
|
||||
return results;
|
||||
}
|
||||
|
||||
@ -30,9 +22,8 @@ internal abstract class Container
|
||||
List<Models.Item> results = [];
|
||||
foreach (Models.Item item in container.Items)
|
||||
{
|
||||
if (item.ImageFileHolder is not null
|
||||
&& item.IsValidImageFormatExtension
|
||||
&& !propertyConfiguration.IgnoreExtensions.Contains(item.ImageFileHolder.ExtensionLowered))
|
||||
if (item.IsValidImageFormatExtension
|
||||
&& !propertyConfiguration.IgnoreExtensions.Contains(item.FilePath.ExtensionLowered))
|
||||
results.Add(item);
|
||||
}
|
||||
return results.ToArray();
|
||||
@ -87,12 +78,23 @@ internal abstract class Container
|
||||
FilePath filePath = FilePath.Get(propertyConfiguration, imageFileInfo, index: null);
|
||||
bool? fileSizeChanged = property is not null ? property.FileSize != filePath.Length : null;
|
||||
bool isValidImageFormatExtension = propertyConfiguration.ValidImageFormatExtensions.Contains(filePath.ExtensionLowered);
|
||||
if (property is not null && property.Keywords is not null && !IId.IsIgnore(filePath) && propertyConfiguration.IgnoreRulesKeyWords.Any(l => property.Keywords.Contains(l)))
|
||||
if (property is not null && property.Keywords is not null)
|
||||
{
|
||||
if (filePath.DirectoryName.Contains("Results") && filePath.DirectoryName.Contains("Resize"))
|
||||
File.Delete(filePath.FullName);
|
||||
else
|
||||
throw new NotSupportedException($"Rename File! <{filePath.FileNameFirstSegment}>");
|
||||
if (filePath.IsIgnore is null)
|
||||
throw new NullReferenceException();
|
||||
bool shouldIgnore = propertyConfiguration.IgnoreRulesKeyWords.Any(l => property.Keywords.Contains(l));
|
||||
if (shouldIgnore)
|
||||
{
|
||||
if (shouldIgnore)
|
||||
{ }
|
||||
}
|
||||
if (filePath.IsIgnore.Value != shouldIgnore)
|
||||
{
|
||||
if (filePath.DirectoryName.Contains("Results") && filePath.DirectoryName.Contains("Resize"))
|
||||
File.Delete(filePath.FullName);
|
||||
else
|
||||
throw new NotSupportedException($"Rename File! <{filePath.FileNameFirstSegment}>");
|
||||
}
|
||||
}
|
||||
string relativePath = IPath.GetRelativePath(filePair.Path, rootDirectoryLength, forceExtensionToLower: true);
|
||||
bool? lastWriteTimeChanged = property is not null ? propertyConfiguration.PropertiesChangedForProperty || property.LastWriteTime.Ticks != filePath.LastWriteTicks : null;
|
||||
@ -111,17 +113,19 @@ internal abstract class Container
|
||||
File.SetCreationTime(sourceDirectoryFileHolder.FullName, new(filePath.LastWriteTicks));
|
||||
File.SetLastWriteTime(sourceDirectoryFileHolder.FullName, sourceDirectoryFileHolder.LastWriteTime.Value);
|
||||
}
|
||||
Models.Item item = new(filePath, sourceDirectoryFileHolder, relativePath, imageFileInfo, filePair.IsNotUniqueAndNeedsReview, filePair.IsUnique, isValidImageFormatExtension, property, abandoned, fileSizeChanged, lastWriteTimeChanged);
|
||||
Models.Item item = new(filePath, sourceDirectoryFileHolder, relativePath, filePair.IsNotUniqueAndNeedsReview, filePair.IsUnique, isValidImageFormatExtension, property, abandoned, fileSizeChanged, lastWriteTimeChanged);
|
||||
lock (results)
|
||||
results.Add(new(filePair.IsUnique, filePair.Collection, filePath, item));
|
||||
}
|
||||
|
||||
private static List<FilePair> GetFilePairs(Properties.IPropertyConfiguration propertyConfiguration, string aPropertySingletonDirectory, string filesCollectionDirectory, string extension, List<Models.FilePair> filePairs)
|
||||
private static List<FilePair> GetFilePairs(Properties.IPropertyConfiguration propertyConfiguration, string aPropertySingletonDirectory, string filesCollectionDirectory, ReadOnlyCollection<string[]> filesCollection, string directorySearchFilter)
|
||||
{
|
||||
List<FilePair> results = [];
|
||||
const string extension = ".json";
|
||||
int maxDegreeOfParallelism = Environment.ProcessorCount;
|
||||
int filesCollectionDirectoryLength = filesCollectionDirectory.Length;
|
||||
ParallelOptions parallelOptions = new() { MaxDegreeOfParallelism = maxDegreeOfParallelism };
|
||||
List<Models.FilePair> filePairs = GetFilePairs(propertyConfiguration, directorySearchFilter, extension, aPropertySingletonDirectory, filesCollection);
|
||||
_ = Parallel.For(0, filePairs.Count, parallelOptions, (i, state) => ParallelFor(propertyConfiguration, aPropertySingletonDirectory, extension, filesCollectionDirectoryLength, filePairs[i], results));
|
||||
return results;
|
||||
}
|
||||
@ -133,7 +137,6 @@ internal abstract class Container
|
||||
List<Models.Item>? items;
|
||||
Models.Container container;
|
||||
List<string> directories = [];
|
||||
const string extension = ".json";
|
||||
Dictionary<string, List<Models.Item>> directoryToItems = [];
|
||||
foreach (string[] files in filesCollection)
|
||||
{
|
||||
@ -151,9 +154,8 @@ internal abstract class Container
|
||||
throw new Exception();
|
||||
}
|
||||
}
|
||||
List<Models.FilePair> filePairs = GetFilePairs(propertyConfiguration, directorySearchFilter, extension, aPropertySingletonDirectory, filesCollection);
|
||||
List<FilePair> collection = GetFilePairs(propertyConfiguration, aPropertySingletonDirectory, filesCollectionDirectory, extension, filePairs);
|
||||
foreach (FilePair filePair in collection)
|
||||
List<FilePair> filePairs = GetFilePairs(propertyConfiguration, aPropertySingletonDirectory, filesCollectionDirectory, filesCollection, directorySearchFilter);
|
||||
foreach (FilePair filePair in filePairs)
|
||||
{
|
||||
if (!directoryToItems.TryGetValue(filePair.FilePath.DirectoryName, out items))
|
||||
{
|
||||
@ -170,7 +172,7 @@ internal abstract class Container
|
||||
container = new(keyValuePair.Key, keyValuePair.Value);
|
||||
results.Add(container);
|
||||
}
|
||||
return (collection.Count, results.ToArray());
|
||||
return (filePairs.Count, results.ToArray());
|
||||
}
|
||||
|
||||
internal static (int, Models.Container[]) GetContainers(Properties.IPropertyConfiguration propertyConfiguration, string aPropertySingletonDirectory, string filesCollectionDirectory, ReadOnlyCollection<string[]> filesCollection)
|
||||
|
@ -3,9 +3,9 @@ namespace View_by_Distance.Shared.Models.Stateless.Methods;
|
||||
public interface IId
|
||||
{ // ...
|
||||
|
||||
string TestStatic_GetIntelligentId(Properties.IPropertyConfiguration propertyConfiguration, long id, bool ignore) =>
|
||||
string TestStatic_GetIntelligentId(Properties.IPropertyConfiguration propertyConfiguration, long id, bool? ignore) =>
|
||||
GetIntelligentId(propertyConfiguration, id, ignore);
|
||||
static string GetIntelligentId(Properties.IPropertyConfiguration propertyConfiguration, long id, bool ignore) =>
|
||||
static string GetIntelligentId(Properties.IPropertyConfiguration propertyConfiguration, long id, bool? ignore) =>
|
||||
Id.GetIntelligentId(propertyConfiguration, id, ignore);
|
||||
|
||||
int TestStatic_GetId(Properties.IPropertyConfiguration propertyConfiguration, string intelligentId) =>
|
||||
@ -13,15 +13,10 @@ public interface IId
|
||||
static int GetId(Properties.IPropertyConfiguration propertyConfiguration, string intelligentId) =>
|
||||
Id.GetId(propertyConfiguration, intelligentId);
|
||||
|
||||
string TestStatic_GetPaddedId(Properties.IPropertyConfiguration propertyConfiguration, int id, int? index) =>
|
||||
GetPaddedId(propertyConfiguration, id, index);
|
||||
static string GetPaddedId(Properties.IPropertyConfiguration propertyConfiguration, int id, int? index) =>
|
||||
Id.GetPaddedId(propertyConfiguration, id, index);
|
||||
|
||||
bool TestStatic_IsIgnore(FilePath filePath) =>
|
||||
IsIgnore(filePath);
|
||||
static bool IsIgnore(FilePath filePath) =>
|
||||
filePath.FileNameFirstSegment[^1] is '2' or '8';
|
||||
string TestStatic_GetPaddedId(Properties.IPropertyConfiguration propertyConfiguration, int id, bool? ignore, int? index) =>
|
||||
GetPaddedId(propertyConfiguration, id, ignore, index);
|
||||
static string GetPaddedId(Properties.IPropertyConfiguration propertyConfiguration, int id, bool? ignore, int? index) =>
|
||||
Id.GetPaddedId(propertyConfiguration, id, ignore, index);
|
||||
|
||||
string TestStatic_GetIgnoreFullPath(FilePath filePath, Models.FileHolder fileHolder) =>
|
||||
GetIgnoreFullPath(filePath, fileHolder);
|
||||
|
@ -33,10 +33,10 @@ public interface IProperty
|
||||
static (bool?, string[]) IsWrongYear(string[] segments, string year) =>
|
||||
Property.IsWrongYear(segments, year);
|
||||
|
||||
(bool?, string[]) TestStatic_IsWrongYear(Models.FileHolder fileHolder, DateTime? dateTimeOriginal, List<DateTime> dateTimes) =>
|
||||
IsWrongYear(fileHolder, dateTimeOriginal, dateTimes);
|
||||
static (bool?, string[]) IsWrongYear(Models.FileHolder fileHolder, DateTime? dateTimeOriginal, List<DateTime> dateTimes) =>
|
||||
Property.IsWrongYear(fileHolder, dateTimeOriginal, dateTimes);
|
||||
(bool?, string[]) TestStatic_IsWrongYear(FilePath filePath, DateTime? dateTimeOriginal, List<DateTime> dateTimes) =>
|
||||
IsWrongYear(filePath, dateTimeOriginal, dateTimes);
|
||||
static (bool?, string[]) IsWrongYear(FilePath filePath, DateTime? dateTimeOriginal, List<DateTime> dateTimes) =>
|
||||
Property.IsWrongYear(filePath, dateTimeOriginal, dateTimes);
|
||||
|
||||
List<DateTime> TestStatic_GetDateTimes(Models.Property property) =>
|
||||
GetDateTimes(property);
|
||||
|
@ -35,7 +35,7 @@ internal abstract class Id
|
||||
return result;
|
||||
}
|
||||
|
||||
internal static string GetIntelligentId(Properties.IPropertyConfiguration propertyConfiguration, long id, bool ignore)
|
||||
internal static string GetIntelligentId(Properties.IPropertyConfiguration propertyConfiguration, long id, bool? ignore)
|
||||
{
|
||||
string result;
|
||||
StringBuilder stringBuilder = new();
|
||||
@ -46,12 +46,12 @@ internal abstract class Id
|
||||
List<char> resultAllInOneSubdirectoryChars = [];
|
||||
if (id > -1)
|
||||
{
|
||||
key = ignore ? 8 : 9;
|
||||
key = ignore is not null && ignore.Value ? 8 : 9;
|
||||
value = id.ToString().PadLeft(propertyConfiguration.IntMinValueLength, '0');
|
||||
}
|
||||
else
|
||||
{
|
||||
key = ignore ? 2 : 1;
|
||||
key = ignore is not null && ignore.Value ? 2 : 1;
|
||||
value = id.ToString()[1..].PadLeft(propertyConfiguration.IntMinValueLength, '0');
|
||||
}
|
||||
for (int i = value.Length - propertyConfiguration.ResultAllInOneSubdirectoryLength - 1; i > -1; i--)
|
||||
@ -62,14 +62,14 @@ internal abstract class Id
|
||||
return result;
|
||||
}
|
||||
|
||||
internal static string GetPaddedId(Properties.IPropertyConfiguration propertyConfiguration, int id, int? index)
|
||||
internal static string GetPaddedId(Properties.IPropertyConfiguration propertyConfiguration, int id, bool? ignore, int? index)
|
||||
{
|
||||
string result;
|
||||
if (propertyConfiguration.Offset < 0)
|
||||
result = Guid.NewGuid().ToString();
|
||||
else
|
||||
{
|
||||
string intelligentId = GetIntelligentId(propertyConfiguration, id, ignore: false);
|
||||
string intelligentId = GetIntelligentId(propertyConfiguration, id, ignore);
|
||||
int check = GetId(propertyConfiguration, intelligentId);
|
||||
if (check != id)
|
||||
throw new NotSupportedException();
|
||||
|
@ -10,11 +10,11 @@ internal abstract class Item
|
||||
foreach (Models.Item item in itemsA)
|
||||
{
|
||||
results.Add(item);
|
||||
collection.Add(item.ImageFileHolder.FullName);
|
||||
collection.Add(item.FilePath.FullName);
|
||||
}
|
||||
foreach (Models.Item item in itemsB)
|
||||
{
|
||||
if (collection.Contains(item.ImageFileHolder.FullName))
|
||||
if (collection.Contains(item.FilePath.FullName))
|
||||
continue;
|
||||
results.Add(item);
|
||||
}
|
||||
|
@ -47,7 +47,7 @@ internal abstract class Property
|
||||
return new(result, results);
|
||||
}
|
||||
|
||||
internal static (bool?, string[]) IsWrongYear(Models.FileHolder fileHolder, DateTime? dateTimeOriginal, List<DateTime> dateTimes)
|
||||
internal static (bool?, string[]) IsWrongYear(FilePath filePath, DateTime? dateTimeOriginal, List<DateTime> dateTimes)
|
||||
{
|
||||
string[] results = [];
|
||||
bool? result = null;
|
||||
@ -55,8 +55,8 @@ internal abstract class Property
|
||||
string directoryName;
|
||||
string[] directorySegments;
|
||||
List<DateTime> collection = [];
|
||||
string? check = Path.GetFullPath(fileHolder.FullName);
|
||||
string? pathRoot = Path.GetPathRoot(fileHolder.FullName);
|
||||
string? check = Path.GetFullPath(filePath.FullName);
|
||||
string? pathRoot = Path.GetPathRoot(filePath.FullName);
|
||||
if (string.IsNullOrEmpty(pathRoot))
|
||||
throw new Exception();
|
||||
if (dateTimeOriginal is not null)
|
||||
|
@ -291,7 +291,6 @@ internal abstract partial class XDirectory
|
||||
FileInfo fileInfo;
|
||||
FilePath filePath;
|
||||
int directoryIndex;
|
||||
bool ignore = false;
|
||||
string paddedIdFile;
|
||||
bool wrapped = false;
|
||||
string intelligentId;
|
||||
@ -324,7 +323,7 @@ internal abstract partial class XDirectory
|
||||
}
|
||||
if (ifCanUseId && filePath.IsIntelligentIdFormat && filePath.Id is not null && filePath.DirectoryName is not null)
|
||||
{
|
||||
paddedId = IId.GetPaddedId(propertyConfiguration, filePath.Id.Value, i);
|
||||
paddedId = IId.GetPaddedId(propertyConfiguration, filePath.Id.Value, filePath.IsIgnore, i);
|
||||
paddedIdFile = Path.Combine(filePath.DirectoryName, $"{paddedId}{filePath.ExtensionLowered}");
|
||||
if (!File.Exists(paddedIdFile))
|
||||
{
|
||||
@ -342,7 +341,7 @@ internal abstract partial class XDirectory
|
||||
{
|
||||
if (filePath.Id is null)
|
||||
throw new NullReferenceException(nameof(filePath.Id));
|
||||
intelligentId = IId.GetIntelligentId(propertyConfiguration, filePath.Id.Value, ignore);
|
||||
intelligentId = IId.GetIntelligentId(propertyConfiguration, filePath.Id.Value, filePath.IsIgnore);
|
||||
checkFile = Path.Combine(directory, $"{intelligentId}{filePath.ExtensionLowered}");
|
||||
}
|
||||
if ((filePath.Id is not null && distinctIds.Contains(filePath.Id.Value)) || distinct.Contains(checkFile))
|
||||
@ -396,10 +395,9 @@ internal abstract partial class XDirectory
|
||||
fileInfo = new(to);
|
||||
if (fileInfo.Exists)
|
||||
{
|
||||
if (filePath.Length != fileInfo.Length || filePath.LastWriteTicks != fileInfo.LastWriteTime.Ticks)
|
||||
fileInfo.Delete();
|
||||
else
|
||||
if (filePath.Length == fileInfo.Length && filePath.LastWriteTicks == fileInfo.LastWriteTime.Ticks)
|
||||
continue;
|
||||
fileInfo.Delete();
|
||||
}
|
||||
results.Add(filePath.NameWithoutExtension);
|
||||
try
|
||||
|
Reference in New Issue
Block a user