IDirectory first pass
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;
|
||||
using View_by_Distance.Property.Models.Stateless;
|
||||
using View_by_Distance.Shared.Models.Stateless;
|
||||
|
||||
@ -12,20 +13,32 @@ namespace View_by_Distance.Metadata.Models;
|
||||
public class B_Metadata
|
||||
{
|
||||
|
||||
public List<string> AngleBracketCollection { get; }
|
||||
|
||||
private readonly Serilog.ILogger? _Log;
|
||||
private readonly bool _PropertiesChangedForMetadata;
|
||||
private readonly bool _ForceMetadataLastWriteTimeToCreationTime;
|
||||
private readonly IReadOnlyDictionary<string, string[]> _JsonGroups;
|
||||
private readonly JsonSerializerOptions _WriteIndentedJsonSerializerOptions;
|
||||
|
||||
public B_Metadata(bool forceMetadataLastWriteTimeToCreationTime, bool propertiesChangedForMetadata)
|
||||
public B_Metadata(Configuration configuration, bool forceMetadataLastWriteTimeToCreationTime, bool propertiesChangedForMetadata, string aResultsFullGroupDirectory)
|
||||
{
|
||||
AngleBracketCollection = new List<string>();
|
||||
_Log = Serilog.Log.ForContext<B_Metadata>();
|
||||
_PropertiesChangedForMetadata = propertiesChangedForMetadata;
|
||||
_ForceMetadataLastWriteTimeToCreationTime = forceMetadataLastWriteTimeToCreationTime;
|
||||
_WriteIndentedJsonSerializerOptions = new JsonSerializerOptions { WriteIndented = true };
|
||||
string checkDirectory;
|
||||
List<string> collection = new();
|
||||
for (int i = 0; i < 11; i++)
|
||||
{
|
||||
if (i == 10)
|
||||
checkDirectory = Path.Combine(aResultsFullGroupDirectory, "{}", configuration.ResultAllInOne, "-");
|
||||
else
|
||||
checkDirectory = Path.Combine(aResultsFullGroupDirectory, "{}", configuration.ResultAllInOne, i.ToString());
|
||||
if (!Directory.Exists(checkDirectory))
|
||||
_ = Directory.CreateDirectory(checkDirectory);
|
||||
collection.Add(checkDirectory);
|
||||
}
|
||||
Dictionary<string, string[]> jsonGroups = new() { { "{}", collection.ToArray() } };
|
||||
_JsonGroups = jsonGroups;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
@ -34,18 +47,6 @@ 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();
|
||||
@ -89,15 +90,16 @@ public class B_Metadata
|
||||
return results;
|
||||
}
|
||||
|
||||
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)
|
||||
public (int, List<KeyValuePair<string, string>>) GetMetadataCollection(List<Tuple<string, DateTime>> subFileTuples, List<string> parseExceptions, Shared.Models.MappingFromItem mappingFromItem)
|
||||
{
|
||||
List<KeyValuePair<string, string>> results = new();
|
||||
string json = string.Empty;
|
||||
string[] changesFrom = new string[] { nameof(A_Property) };
|
||||
Dictionary<string, List<KeyValuePair<string, string>>>? dictionary;
|
||||
string[] changesFrom = new string[] { nameof(Property.Models.A_Property) };
|
||||
char directory = Shared.Models.Stateless.Methods.IDirectory.GetDirectory(mappingFromItem.ImageFileHolder.Name);
|
||||
int directoryIndex = Shared.Models.Stateless.Methods.IDirectory.GetDirectory(directory);
|
||||
List<DateTime> dateTimes = (from l in subFileTuples where changesFrom.Contains(l.Item1) select l.Item2).ToList();
|
||||
string bMetadataSingletonFile = Path.Combine(bResultsFullGroupDirectory, "{}", configuration.ResultAllInOne, $"{mappingFromItem.Id}{mappingFromItem.ImageFileHolder.ExtensionLowered}.json");
|
||||
FileInfo fileInfo = new(bMetadataSingletonFile);
|
||||
FileInfo fileInfo = new(Path.Combine(_JsonGroups["{}"][directoryIndex], $"{mappingFromItem.ImageFileHolder.NameWithoutExtension}{mappingFromItem.ImageFileHolder.ExtensionLowered}.json"));
|
||||
if (_ForceMetadataLastWriteTimeToCreationTime && !fileInfo.Exists && File.Exists(Path.ChangeExtension(fileInfo.FullName, ".delete")))
|
||||
{
|
||||
File.Move(Path.ChangeExtension(fileInfo.FullName, ".delete"), fileInfo.FullName);
|
||||
|
Reference in New Issue
Block a user