Metadata-Query

This commit is contained in:
2023-07-04 18:09:53 -07:00
parent 0bce2bf22b
commit fcd3f9030d
16 changed files with 709 additions and 85 deletions

View File

@ -25,6 +25,7 @@ public class MirrorLength
{ }
_AppSettings = appSettings;
_IsEnvironment = isEnvironment;
long ticks = DateTime.Now.Ticks;
_WorkingDirectory = workingDirectory;
_ConfigurationRoot = configurationRoot;
ILogger? log = Log.ForContext<MirrorLength>();
@ -35,25 +36,23 @@ public class MirrorLength
propertyConfiguration.Update();
log.Information(propertyConfiguration.RootDirectory);
Verify();
List<string> lines = MirrorLengthFilesInDirectories(log);
if (!lines.Any())
File.WriteAllLines($"D:/Tmp/Phares/{DateTime.Now.Ticks}.tsv", lines);
MirrorLengthFilesInDirectories(log, ticks);
}
private void Verify()
{
if (_AppSettings is null)
{ }
throw new NullReferenceException(nameof(_AppSettings));
if (_IsEnvironment is null)
{ }
throw new NullReferenceException(nameof(_IsEnvironment));
if (_Configuration is null)
{ }
throw new NullReferenceException(nameof(_Configuration));
if (_ConfigurationRoot is null)
{ }
throw new NullReferenceException(nameof(_ConfigurationRoot));
if (_WorkingDirectory is null)
{ }
throw new NullReferenceException(nameof(_WorkingDirectory));
if (_PropertyConfiguration is null)
{ }
throw new NullReferenceException(nameof(_PropertyConfiguration));
}
private static List<(string, string, DateTime, long)[]> GetToDoCollection(ProgressBar progressBar, List<string[]> filesCollection)
@ -84,10 +83,10 @@ public class MirrorLength
private List<(string, string, int)> GetToDoCollectionForMarkDown(string message, string today)
{
string[] files;
ProgressBar progressBar;
string directoryName;
string[] subDirectories;
ProgressBar progressBar;
string subDirectoryName;
string[] subDirectories;
List<(string, string, int)> results = new();
ProgressBarOptions options = new() { ProgressCharacter = '─', ProgressBarOnBottom = true, DisableBottomPercentage = true };
string[] directories = Directory.GetDirectories(_PropertyConfiguration.RootDirectory, "*", SearchOption.TopDirectoryOnly);
@ -110,7 +109,7 @@ public class MirrorLength
return results;
}
private void Write(bool inPlaceSave, ProgressBar progressBar, List<(string directory, string file, DateTime lastWriteTime, long length)[]> results)
private void Write(long ticks, bool inPlaceSave, ProgressBar progressBar, List<(string directory, string file, DateTime lastWriteTime, long length)[]> results)
{
string checkFile;
string checkDirectory;
@ -123,7 +122,7 @@ public class MirrorLength
firstDirectory = collection.First().Directory;
if (string.IsNullOrEmpty(firstDirectory))
continue;
checkDirectory = inPlaceSave ? firstDirectory : $"{_AppSettings.Destination}{firstDirectory[1..]}";
checkDirectory = inPlaceSave ? firstDirectory : $"{_AppSettings.Destination}:/{ticks}/{firstDirectory[3..]}";
if (!Directory.Exists(checkDirectory))
_ = Directory.CreateDirectory(checkDirectory);
else
@ -133,7 +132,7 @@ public class MirrorLength
}
foreach ((string directory, string _, DateTime _, long _) in collection)
{
checkDirectory = inPlaceSave ? directory : $"{_AppSettings.Destination}{directory[1..]}";
checkDirectory = inPlaceSave ? directory : $"{_AppSettings.Destination}:/{ticks}/{directory[3..]}";
if (directories.Contains(checkDirectory))
continue;
directories.Add(checkDirectory);
@ -142,7 +141,7 @@ public class MirrorLength
}
foreach ((string _, string file, DateTime lastWriteTime, long length) in collection)
{
checkFile = inPlaceSave ? $"{file}len" : $"{_AppSettings.Destination}{file[1..]}len";
checkFile = inPlaceSave ? $"{file}len" : $"{_AppSettings.Destination}:/{ticks}/{file[3..]}len";
if (!Shared.Models.Stateless.Methods.IPath.WriteAllText(checkFile, length.ToString(), updateToWhenMatches: null, compareBeforeWrite: true, updateDateWhenMatches: false))
continue;
File.SetLastWriteTime(checkFile, lastWriteTime);
@ -191,9 +190,8 @@ public class MirrorLength
}
}
private List<string> MirrorLengthFilesInDirectories(ILogger log)
private void MirrorLengthFilesInDirectories(ILogger log, long ticks)
{
List<string> results = new();
string message = nameof(MirrorLength);
List<(string, string, int)> collectionForMarkDown;
bool inPlaceSave = _PropertyConfiguration.RootDirectory.First() == _AppSettings.Destination;
@ -218,10 +216,9 @@ public class MirrorLength
progressBar.Dispose();
progressBar = new(filesCollection.Count, message, options);
if (collection.Any())
Write(inPlaceSave, progressBar, collection);
Write(ticks, inPlaceSave, progressBar, collection);
progressBar.Dispose();
}
return results;
}
}