net7.0
This commit is contained in:
@ -8,7 +8,6 @@ using System.Text;
|
||||
using System.Text.Json;
|
||||
using View_by_Distance.Property.Models.Stateless;
|
||||
using View_by_Distance.Shared.Models;
|
||||
using View_by_Distance.Shared.Models.Properties;
|
||||
using View_by_Distance.Shared.Models.Stateless;
|
||||
|
||||
namespace View_by_Distance.Property.Models;
|
||||
@ -63,41 +62,9 @@ public class A_Property
|
||||
return result;
|
||||
}
|
||||
|
||||
public static List<DateTime> GetMetadataDateTimesByPattern(string dateTimeFormat, string filteredSourceDirectoryFile)
|
||||
{
|
||||
List<DateTime> results = new();
|
||||
try
|
||||
{
|
||||
DateTime checkDateTime;
|
||||
DateTime kristy = new(1976, 3, 8);
|
||||
IReadOnlyList<MetadataExtractor.Directory> directories = MetadataExtractor.ImageMetadataReader.ReadMetadata(filteredSourceDirectoryFile);
|
||||
foreach (MetadataExtractor.Directory directory in directories)
|
||||
{
|
||||
foreach (MetadataExtractor.Tag tag in directory.Tags)
|
||||
{
|
||||
if (string.IsNullOrEmpty(tag.Description) || tag.Description.Length != dateTimeFormat.Length)
|
||||
continue;
|
||||
if (!DateTime.TryParseExact(tag.Description, dateTimeFormat, CultureInfo.InvariantCulture, DateTimeStyles.None, out checkDateTime))
|
||||
continue;
|
||||
if (checkDateTime < kristy)
|
||||
continue;
|
||||
results.Add(checkDateTime);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception) { }
|
||||
return results;
|
||||
}
|
||||
|
||||
public static List<DateTime> GetMetadataDateTimesByPattern(string dateTimeFormat, IFileHolder filteredSourceDirectoryFileHolder)
|
||||
{
|
||||
List<DateTime> results = GetMetadataDateTimesByPattern(dateTimeFormat, filteredSourceDirectoryFileHolder.FullName);
|
||||
return results;
|
||||
}
|
||||
|
||||
#pragma warning disable CA1416
|
||||
|
||||
private Shared.Models.Property GetImageProperty(IFileHolder fileHolder, Shared.Models.Property? property, bool populateId, bool isIgnoreExtension, bool isValidImageFormatExtension, bool isValidMetadataExtensions, int? id, List<int> indices)
|
||||
private Shared.Models.Property GetImageProperty(FileHolder fileHolder, Shared.Models.Property? property, bool populateId, bool isIgnoreExtension, bool isValidImageFormatExtension, bool isValidMetadataExtensions, int? id, List<int> indices)
|
||||
{
|
||||
Shared.Models.Property result;
|
||||
if (_Log is null)
|
||||
@ -119,10 +86,11 @@ public class A_Property
|
||||
DateTime? dateTimeOriginal = null;
|
||||
string orientation = string.Empty;
|
||||
DateTime? dateTimeDigitized = null;
|
||||
DateTime? dateTimeFromName = Shared.Models.Stateless.Methods.IProperty.GetDateTimeFromName(fileHolder);
|
||||
if (!isValidImageFormatExtension && isValidMetadataExtensions && fileHolder.Exists)
|
||||
{
|
||||
dateTimeFormat = "ddd MMM dd HH:mm:ss yyyy";
|
||||
List<DateTime> dateTimes = GetMetadataDateTimesByPattern(dateTimeFormat, fileHolder);
|
||||
List<DateTime> dateTimes = Shared.Models.Stateless.Methods.IProperty.GetMetadataDateTimesByPattern(dateTimeFormat, fileHolder);
|
||||
if (dateTimes.Any())
|
||||
dateTimeOriginal = dateTimes.Min();
|
||||
}
|
||||
@ -257,9 +225,9 @@ public class A_Property
|
||||
if (fileHolder.LastWriteTime is null && property?.LastWriteTime is null)
|
||||
throw new NullReferenceException(nameof(fileHolder.LastWriteTime));
|
||||
if (fileHolder.CreationTime is not null && fileHolder.LastWriteTime is not null)
|
||||
result = new(fileHolder.CreationTime.Value, dateTime, dateTimeDigitized, dateTimeOriginal, fileLength, gpsDateStamp, height, id, indices.ToArray(), fileHolder.LastWriteTime.Value, make, model, orientation, width);
|
||||
result = new(fileHolder.CreationTime.Value, dateTime, dateTimeDigitized, dateTimeFromName, dateTimeOriginal, fileLength, gpsDateStamp, height, id, indices.ToArray(), fileHolder.LastWriteTime.Value, make, model, orientation, width);
|
||||
else if (property is not null)
|
||||
result = new(property.CreationTime, dateTime, dateTimeDigitized, dateTimeOriginal, fileLength, gpsDateStamp, height, id, indices.ToArray(), property.LastWriteTime, make, model, orientation, width);
|
||||
result = new(property.CreationTime, dateTime, dateTimeDigitized, dateTimeFromName, dateTimeOriginal, fileLength, gpsDateStamp, height, id, indices.ToArray(), property.LastWriteTime, make, model, orientation, width);
|
||||
else
|
||||
throw new NullReferenceException(nameof(property));
|
||||
return result;
|
||||
@ -270,8 +238,6 @@ public class A_Property
|
||||
private Shared.Models.Property GetPropertyOfPrivate(Item item, List<Tuple<string, DateTime>> sourceDirectoryFileTuples, List<string> parseExceptions, bool isIgnoreExtension, bool isValidMetadataExtensions)
|
||||
{
|
||||
Shared.Models.Property? result;
|
||||
if (item.ImageFileHolder is null)
|
||||
throw new NullReferenceException(nameof(item.ImageFileHolder));
|
||||
string json;
|
||||
int? id = null;
|
||||
List<int> indices = new();
|
||||
@ -288,7 +254,7 @@ public class A_Property
|
||||
fileInfo.Refresh();
|
||||
}
|
||||
List<DateTime> dateTimes = (from l in sourceDirectoryFileTuples where changesFrom.Contains(l.Item1) select l.Item2).ToList();
|
||||
if (!fileInfo.Exists)
|
||||
if (!fileInfo.FullName.Contains(_Configuration.ResultAllInOne) && !fileInfo.Exists)
|
||||
{
|
||||
if (fileInfo.Directory?.Parent is null)
|
||||
throw new Exception();
|
||||
@ -322,8 +288,6 @@ public class A_Property
|
||||
json = File.ReadAllText(fileInfo.FullName);
|
||||
try
|
||||
{
|
||||
if (item.ImageFileHolder is null)
|
||||
throw new NullReferenceException(nameof(item.ImageFileHolder));
|
||||
bool check = true;
|
||||
property = JsonSerializer.Deserialize<Shared.Models.Property>(json);
|
||||
if (!isIgnoreExtension && item.ValidImageFormatExtension && ((populateId && property?.Id is null) || property?.Width is null || property?.Height is null))
|
||||
@ -389,8 +353,6 @@ public class A_Property
|
||||
}
|
||||
if (result is null)
|
||||
{
|
||||
if (item.ImageFileHolder is null)
|
||||
throw new NullReferenceException(nameof(item.ImageFileHolder));
|
||||
result = GetImageProperty(item.ImageFileHolder, property, populateId, isIgnoreExtension, item.ValidImageFormatExtension, isValidMetadataExtensions, id, indices);
|
||||
json = JsonSerializer.Serialize(result, _WriteIndentedJsonSerializerOptions);
|
||||
if (populateId && Shared.Models.Stateless.Methods.IPath.WriteAllText(fileInfo.FullName, json, updateDateWhenMatches: true, compareBeforeWrite: true))
|
||||
@ -436,7 +398,7 @@ public class A_Property
|
||||
DateTime directoryMaximumOfMinimumDateTime = DateTime.MinValue;
|
||||
foreach (Item item in items)
|
||||
{
|
||||
if (!item.ValidImageFormatExtension || item.Property is null || item.ImageFileHolder is null || !item.ImageFileHolder.Exists)
|
||||
if (!item.ValidImageFormatExtension || item.Property is null || !item.ImageFileHolder.Exists)
|
||||
continue;
|
||||
minimumDateTime = Shared.Models.Stateless.Methods.IProperty.GetMinimumDateTime(item.Property);
|
||||
if (minimumDateTime > directoryMaximumOfMinimumDateTime)
|
||||
@ -520,8 +482,6 @@ public class A_Property
|
||||
|
||||
private void SavePropertyParallelForWork(string sourceDirectory, List<Tuple<string, DateTime>> sourceDirectoryFileTuples, List<Tuple<string, DateTime>> sourceDirectoryChanges, Item item)
|
||||
{
|
||||
if (item.ImageFileHolder is null)
|
||||
throw new NullReferenceException(nameof(item.ImageFileHolder));
|
||||
Shared.Models.Property property;
|
||||
List<string> parseExceptions = new();
|
||||
bool isValidMetadataExtensions = _Configuration.ValidMetadataExtensions.Contains(item.ImageFileHolder.ExtensionLowered);
|
||||
@ -529,7 +489,7 @@ public class A_Property
|
||||
string filteredSourceDirectoryFileExtensionLowered = Path.Combine(sourceDirectory, $"{item.ImageFileHolder.NameWithoutExtension}{item.ImageFileHolder.ExtensionLowered}");
|
||||
if (item.ValidImageFormatExtension && item.ImageFileHolder.FullName.Length == filteredSourceDirectoryFileExtensionLowered.Length && item.ImageFileHolder.FullName != filteredSourceDirectoryFileExtensionLowered)
|
||||
File.Move(item.ImageFileHolder.FullName, filteredSourceDirectoryFileExtensionLowered);
|
||||
if (item.Changed is null || item.Changed.Value || item.Property is null)
|
||||
if (item.FileSizeChanged is null || item.FileSizeChanged.Value || item.LastWriteTimeChanged is null || item.LastWriteTimeChanged.Value || item.Property is null)
|
||||
{
|
||||
property = GetPropertyOfPrivate(item, sourceDirectoryFileTuples, parseExceptions, isIgnoreExtension, isValidMetadataExtensions);
|
||||
lock (sourceDirectoryChanges)
|
||||
@ -568,19 +528,28 @@ public class A_Property
|
||||
});
|
||||
}
|
||||
|
||||
private void SetAngleBracketCollection(string sourceDirectory)
|
||||
public void SetAngleBracketCollection(string aResultsFullGroupDirectory, string sourceDirectory)
|
||||
{
|
||||
AngleBracketCollection.Clear();
|
||||
AngleBracketCollection.AddRange(IResult.GetDirectoryInfoCollection(_Configuration,
|
||||
sourceDirectory,
|
||||
nameof(A_Property),
|
||||
string.Empty,
|
||||
includeResizeGroup: false,
|
||||
includeModel: false,
|
||||
includePredictorModel: false,
|
||||
aResultsFullGroupDirectory,
|
||||
contentDescription: string.Empty,
|
||||
singletonDescription: "Properties for each image",
|
||||
collectionDescription: string.Empty));
|
||||
collectionDescription: string.Empty,
|
||||
converted: false));
|
||||
}
|
||||
|
||||
public void SetAngleBracketCollection(string sourceDirectory)
|
||||
{
|
||||
AngleBracketCollection.Clear();
|
||||
string aResultsFullGroupDirectory = IResult.GetResultsFullGroupDirectory(_Configuration,
|
||||
nameof(A_Property),
|
||||
string.Empty,
|
||||
includeResizeGroup: false,
|
||||
includeModel: false,
|
||||
includePredictorModel: false);
|
||||
SetAngleBracketCollection(aResultsFullGroupDirectory, sourceDirectory);
|
||||
}
|
||||
|
||||
public void SavePropertyParallelWork(long ticks, Shared.Models.Container[] containers)
|
||||
@ -633,8 +602,6 @@ public class A_Property
|
||||
public Shared.Models.Property GetProperty(Item item, List<Tuple<string, DateTime>> sourceDirectoryFileTuples, List<string> parseExceptions)
|
||||
{
|
||||
Shared.Models.Property result;
|
||||
if (item.ImageFileHolder is null)
|
||||
throw new NullReferenceException(nameof(item.ImageFileHolder));
|
||||
bool angleBracketCollectionAny = AngleBracketCollection.Any();
|
||||
if (!angleBracketCollectionAny)
|
||||
{
|
||||
|
@ -37,9 +37,11 @@ public class Configuration
|
||||
return result;
|
||||
}
|
||||
|
||||
private static Models.Configuration Get(Configuration configuration)
|
||||
private static Models.Configuration Get(Configuration? configuration)
|
||||
{
|
||||
Models.Configuration result;
|
||||
if (configuration is null)
|
||||
throw new NullReferenceException(nameof(configuration));
|
||||
if (configuration.ForcePropertyLastWriteTimeToCreationTime is null)
|
||||
throw new NullReferenceException(nameof(configuration.ForcePropertyLastWriteTimeToCreationTime));
|
||||
if (configuration.MaxImagesInDirectoryForTopLevelFirstPass is null)
|
||||
@ -58,16 +60,11 @@ public class Configuration
|
||||
throw new NullReferenceException(nameof(configuration.ResultSingleton));
|
||||
if (configuration.WriteBitmapDataBytes is null)
|
||||
throw new NullReferenceException(nameof(configuration.WriteBitmapDataBytes));
|
||||
if (configuration.IgnoreExtensions is null)
|
||||
configuration.IgnoreExtensions = Array.Empty<string>();
|
||||
if (configuration.PropertyContentCollectionFiles is null)
|
||||
configuration.PropertyContentCollectionFiles = Array.Empty<string>();
|
||||
if (configuration.ValidImageFormatExtensions is null)
|
||||
configuration.ValidImageFormatExtensions = Array.Empty<string>();
|
||||
if (configuration.ValidMetadataExtensions is null)
|
||||
configuration.ValidMetadataExtensions = Array.Empty<string>();
|
||||
if (configuration.VerifyToSeason is null)
|
||||
configuration.VerifyToSeason = Array.Empty<string>();
|
||||
configuration.IgnoreExtensions ??= Array.Empty<string>();
|
||||
configuration.PropertyContentCollectionFiles ??= Array.Empty<string>();
|
||||
configuration.ValidImageFormatExtensions ??= Array.Empty<string>();
|
||||
configuration.ValidMetadataExtensions ??= Array.Empty<string>();
|
||||
configuration.VerifyToSeason ??= Array.Empty<string>();
|
||||
result = new(configuration.DateGroup,
|
||||
configuration.FileNameDirectorySeparator,
|
||||
configuration.ForcePropertyLastWriteTimeToCreationTime.Value,
|
||||
@ -92,7 +89,7 @@ public class Configuration
|
||||
public static Models.Configuration Get(IsEnvironment isEnvironment, IConfigurationRoot configurationRoot)
|
||||
{
|
||||
Models.Configuration result;
|
||||
Configuration configuration;
|
||||
Configuration? configuration;
|
||||
if (isEnvironment is null)
|
||||
configuration = configurationRoot.Get<Configuration>();
|
||||
else
|
||||
|
@ -150,13 +150,18 @@ public class Container
|
||||
private static Item GetNewItem(Configuration configuration, A_Property propertyLogic, string relativePath, FileHolder sourceDirectoryFileHolder)
|
||||
{
|
||||
Item result;
|
||||
List<string> parseExceptions = new();
|
||||
Shared.Models.Property? property = null;
|
||||
List<Tuple<string, DateTime>> subFileTuples = new();
|
||||
bool isValidImageFormatExtension = configuration.ValidImageFormatExtensions.Contains(sourceDirectoryFileHolder.ExtensionLowered);
|
||||
Item item = new(sourceDirectoryFileHolder.FullName, relativePath, sourceDirectoryFileHolder, isValidImageFormatExtension, property, null, null);
|
||||
property = propertyLogic.GetProperty(item, subFileTuples, parseExceptions);
|
||||
result = new(sourceDirectoryFileHolder.FullName, relativePath, sourceDirectoryFileHolder, isValidImageFormatExtension, property, null, null);
|
||||
if (configuration.PopulatePropertyId)
|
||||
result = new(sourceDirectoryFileHolder.FullName, relativePath, sourceDirectoryFileHolder, isValidImageFormatExtension, property, null, null, null);
|
||||
else
|
||||
{
|
||||
List<string> parseExceptions = new();
|
||||
List<Tuple<string, DateTime>> subFileTuples = new();
|
||||
Item item = new(sourceDirectoryFileHolder.FullName, relativePath, sourceDirectoryFileHolder, isValidImageFormatExtension, property, null, null, null);
|
||||
property = propertyLogic.GetProperty(item, subFileTuples, parseExceptions);
|
||||
result = new(sourceDirectoryFileHolder.FullName, relativePath, sourceDirectoryFileHolder, isValidImageFormatExtension, property, null, null, null);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -171,10 +176,12 @@ public class Container
|
||||
List<Item> items;
|
||||
string keyWithJson;
|
||||
string relativePath;
|
||||
bool fileSizeChanged;
|
||||
FileHolder keyFileHolder;
|
||||
bool lastWriteTimeChanged;
|
||||
bool isValidImageFormatExtension;
|
||||
Shared.Models.Container container;
|
||||
List<string> keySourceDirectories;
|
||||
Shared.Models.Container container;
|
||||
Dictionary<string, Shared.Models.Container> keyValuePairs = new();
|
||||
Dictionary<string, (string SourceDirectory, FileHolder FileHolder)> fileHolderKeyValuePairs = new();
|
||||
length = configuration.RootDirectory.Length;
|
||||
@ -205,7 +212,7 @@ public class Container
|
||||
continue;
|
||||
keySourceDirectories.Add(string.Concat(keyFileHolder.DirectoryName));
|
||||
isValidImageFormatExtension = configuration.ValidImageFormatExtensions.Contains(keyFileHolder.ExtensionLowered);
|
||||
item = new(sourceDirectoryFile, relativePath, keyFileHolder, isValidImageFormatExtension, property, true, null);
|
||||
item = new(sourceDirectoryFile, relativePath, keyFileHolder, isValidImageFormatExtension, property, true, null, null);
|
||||
items.Add(item);
|
||||
}
|
||||
else
|
||||
@ -218,11 +225,13 @@ public class Container
|
||||
continue;
|
||||
isValidImageFormatExtension = configuration.ValidImageFormatExtensions.Contains(keyFileHolder.ExtensionLowered);
|
||||
if (property?.Id is null || property?.Width is null || property?.Height is null)
|
||||
item = new(sourceDirectoryFile, relativePath, keyFileHolder, isValidImageFormatExtension, property, false, null);
|
||||
else if (configuration.PropertiesChangedForProperty || property.LastWriteTime != keyFileHolder.LastWriteTime || property.FileSize != keyFileHolder.Length)
|
||||
item = new(sourceDirectoryFile, relativePath, keyFileHolder, isValidImageFormatExtension, property, false, true);
|
||||
item = new(sourceDirectoryFile, relativePath, keyFileHolder, isValidImageFormatExtension, property, false, null, null);
|
||||
else
|
||||
item = new(sourceDirectoryFile, relativePath, keyFileHolder, isValidImageFormatExtension, property, false, false);
|
||||
{
|
||||
fileSizeChanged = property.FileSize != keyFileHolder.Length;
|
||||
lastWriteTimeChanged = configuration.PropertiesChangedForProperty || property.LastWriteTime != keyFileHolder.LastWriteTime;
|
||||
item = new(sourceDirectoryFile, relativePath, keyFileHolder, isValidImageFormatExtension, property, false, fileSizeChanged, lastWriteTimeChanged);
|
||||
}
|
||||
items.Add(item);
|
||||
}
|
||||
}
|
||||
@ -239,6 +248,7 @@ public class Container
|
||||
foreach ((int g, string sourceDirectory, FileHolder[] sourceDirectoryFileHolderCollection) in fileHolderGroupCollection)
|
||||
{
|
||||
items = new();
|
||||
propertyLogic.SetAngleBracketCollection(sourceDirectory);
|
||||
foreach (FileHolder sourceDirectoryFileHolder in sourceDirectoryFileHolderCollection)
|
||||
{
|
||||
relativePath = Shared.Models.Stateless.Methods.IPath.GetRelativePath(sourceDirectoryFileHolder.FullName, length, forceExtensionToLower: true);
|
||||
|
@ -5,7 +5,7 @@
|
||||
<Nullable>enable</Nullable>
|
||||
<OutputType>library</OutputType>
|
||||
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<PackageId>Phares.View.by.Distance.Property</PackageId>
|
||||
@ -17,16 +17,13 @@
|
||||
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<IsWindows
|
||||
Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::Windows)))' == 'true'">
|
||||
<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'">
|
||||
<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'">
|
||||
<IsLinux Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::Linux)))' == 'true'">
|
||||
true
|
||||
</IsLinux>
|
||||
</PropertyGroup>
|
||||
@ -43,14 +40,12 @@
|
||||
<SupportedPlatform Include="browser" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="MetadataExtractor" Version="2.7.1" />
|
||||
<PackageReference Include="ShellProgressBar" Version="5.1.0" />
|
||||
<PackageReference Include="Serilog" Version="2.10.0" />
|
||||
<PackageReference Include="Serilog.Settings.Configuration" Version="3.3.0" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="System.Drawing.Common" Version="6.0.0" />
|
||||
<PackageReference Include="System.Text.Json" Version="6.0.0" />
|
||||
<PackageReference Include="MetadataExtractor" Version="2.7.2" />
|
||||
<PackageReference Include="ShellProgressBar" Version="5.2.0" />
|
||||
<PackageReference Include="Serilog" Version="2.12.0" />
|
||||
<PackageReference Include="Serilog.Settings.Configuration" Version="3.4.0" />
|
||||
<PackageReference Include="System.Drawing.Common" Version="7.0.0" />
|
||||
<PackageReference Include="System.Text.Json" Version="7.0.0" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Shared\View-by-Distance.Shared.csproj" />
|
||||
|
Reference in New Issue
Block a user