net7.0
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
using System.Diagnostics;
|
||||
using System.Text.Json;
|
||||
using View_by_Distance.Metadata.Models.Stateless;
|
||||
using View_by_Distance.Property.Models.Stateless;
|
||||
using View_by_Distance.Shared.Models.Stateless;
|
||||
|
||||
namespace View_by_Distance.Metadata.Models;
|
||||
@ -35,6 +36,18 @@ public class B_Metadata
|
||||
return result;
|
||||
}
|
||||
|
||||
public void SetAngleBracketCollection(Property.Models.Configuration configuration, string bResultsFullGroupDirectory, string sourceDirectory)
|
||||
{
|
||||
AngleBracketCollection.Clear();
|
||||
AngleBracketCollection.AddRange(IResult.GetDirectoryInfoCollection(configuration,
|
||||
sourceDirectory,
|
||||
bResultsFullGroupDirectory,
|
||||
contentDescription: string.Empty,
|
||||
singletonDescription: "Metadata as key value pairs",
|
||||
collectionDescription: string.Empty,
|
||||
converted: true));
|
||||
}
|
||||
|
||||
private Dictionary<string, List<KeyValuePair<string, string>>> GetMetadataCollection(string subFile)
|
||||
{
|
||||
Dictionary<string, List<KeyValuePair<string, string>>> results = new();
|
||||
@ -78,38 +91,25 @@ public class B_Metadata
|
||||
return results;
|
||||
}
|
||||
|
||||
public (int, List<KeyValuePair<string, string>>) GetMetadataCollection(Property.Models.Configuration propertyConfiguration, string bResultsFullGroupDirectory, List<Tuple<string, DateTime>> subFileTuples, List<string> parseExceptions, Shared.Models.Item item)
|
||||
public (int, List<KeyValuePair<string, string>>) GetMetadataCollection(Property.Models.Configuration configuration, string bResultsFullGroupDirectory, List<Tuple<string, DateTime>> subFileTuples, List<string> parseExceptions, Shared.Models.MappingFromItem mappingFromItem)
|
||||
{
|
||||
List<KeyValuePair<string, string>> results = new();
|
||||
if (item.Property?.Id is null)
|
||||
throw new NullReferenceException(nameof(item.Property.Id));
|
||||
if (item.ImageFileHolder is null)
|
||||
throw new NullReferenceException(nameof(item.ImageFileHolder));
|
||||
string json = string.Empty;
|
||||
string[] changesFrom = Array.Empty<string>();
|
||||
Dictionary<string, List<KeyValuePair<string, string>>>? dictionary;
|
||||
List<DateTime> dateTimes = (from l in subFileTuples where changesFrom.Contains(l.Item1) select l.Item2).ToList();
|
||||
string usingRelativePath = Path.Combine(AngleBracketCollection[0].Replace("<>", "{}"), string.Concat(item.ImageFileHolder.NameWithoutExtension, ".json"));
|
||||
string bMetadataSingletonFile = Path.Combine(bResultsFullGroupDirectory, "{}", propertyConfiguration.ResultAllInOne, $"{item.Property.Id.Value}{item.ImageFileHolder.ExtensionLowered}.json");
|
||||
string bMetadataSingletonFile = Path.Combine(bResultsFullGroupDirectory, "{}", configuration.ResultAllInOne, $"{mappingFromItem.Id}{mappingFromItem.ImageFileHolder.ExtensionLowered}.json");
|
||||
FileInfo fileInfo = new(bMetadataSingletonFile);
|
||||
if (!fileInfo.Exists)
|
||||
if (!fileInfo.FullName.Contains(configuration.ResultAllInOne) && !fileInfo.Exists)
|
||||
{
|
||||
if (File.Exists(usingRelativePath))
|
||||
if (fileInfo.Directory?.Parent is null)
|
||||
throw new Exception();
|
||||
string parentCheck = Path.Combine(fileInfo.Directory.Parent.FullName, fileInfo.Name);
|
||||
if (File.Exists(parentCheck))
|
||||
{
|
||||
File.Move(usingRelativePath, fileInfo.FullName);
|
||||
File.Move(parentCheck, fileInfo.FullName);
|
||||
fileInfo.Refresh();
|
||||
}
|
||||
if (!fileInfo.Exists)
|
||||
{
|
||||
if (fileInfo.Directory?.Parent is null)
|
||||
throw new Exception();
|
||||
string parentCheck = Path.Combine(fileInfo.Directory.Parent.FullName, fileInfo.Name);
|
||||
if (File.Exists(parentCheck))
|
||||
{
|
||||
File.Move(parentCheck, fileInfo.FullName);
|
||||
fileInfo.Refresh();
|
||||
}
|
||||
}
|
||||
}
|
||||
if (_ForceMetadataLastWriteTimeToCreationTime && !fileInfo.Exists && File.Exists(Path.ChangeExtension(fileInfo.FullName, ".delete")))
|
||||
{
|
||||
@ -147,7 +147,7 @@ public class B_Metadata
|
||||
}
|
||||
if (dictionary is null || !dictionary.Any())
|
||||
{
|
||||
dictionary = GetMetadataCollection(item.ImageFileHolder.FullName);
|
||||
dictionary = GetMetadataCollection(mappingFromItem.ImageFileHolder.FullName);
|
||||
json = JsonSerializer.Serialize(dictionary, _WriteIndentedJsonSerializerOptions);
|
||||
bool updateDateWhenMatches = dateTimes.Any() && fileInfo.Exists && dateTimes.Max() > fileInfo.LastWriteTime;
|
||||
DateTime? dateTime = !updateDateWhenMatches ? null : dateTimes.Max();
|
||||
|
Reference in New Issue
Block a user