Offset-Date-Time-Original
Rename updates again Mirror-Length in place Delete-By-Distinct long to string Copy-Distinct handle move and move back
This commit is contained in:
@ -60,11 +60,9 @@ public class MirrorLength
|
||||
{
|
||||
List<(string, string, DateTime, long)[]> results = new();
|
||||
FileInfo fileInfo;
|
||||
List<string> lines = new();
|
||||
List<(string, string, DateTime, long)> collection;
|
||||
foreach (string[] files in filesCollection)
|
||||
{
|
||||
lines.Clear();
|
||||
progressBar.Tick();
|
||||
collection = new();
|
||||
foreach (string file in files)
|
||||
@ -83,7 +81,36 @@ public class MirrorLength
|
||||
return results;
|
||||
}
|
||||
|
||||
private void Save(ProgressBar progressBar, List<(string directory, string file, DateTime lastWriteTime, long length)[]> results)
|
||||
private List<(string, string, int)> GetToDoCollectionForMarkDown(string message, string today)
|
||||
{
|
||||
string[] files;
|
||||
ProgressBar progressBar;
|
||||
string directoryName;
|
||||
string[] subDirectories;
|
||||
string subDirectoryName;
|
||||
List<(string, string, int)> results = new();
|
||||
ProgressBarOptions options = new() { ProgressCharacter = '─', ProgressBarOnBottom = true, DisableBottomPercentage = true };
|
||||
string[] directories = Directory.GetDirectories(_PropertyConfiguration.RootDirectory, "*", SearchOption.TopDirectoryOnly);
|
||||
progressBar = new(directories.Length, message, options);
|
||||
foreach (string directory in directories)
|
||||
{
|
||||
progressBar.Tick();
|
||||
if (!directory.Contains(today))
|
||||
continue;
|
||||
directoryName = Path.GetFileName(directory);
|
||||
subDirectories = Directory.GetDirectories(directory, "*", SearchOption.TopDirectoryOnly);
|
||||
foreach (string subDirectory in subDirectories)
|
||||
{
|
||||
subDirectoryName = Path.GetFileName(subDirectory);
|
||||
files = Directory.GetFiles(subDirectory, "*len", SearchOption.AllDirectories);
|
||||
results.Add(new(directoryName, subDirectoryName, files.Length));
|
||||
}
|
||||
}
|
||||
progressBar.Dispose();
|
||||
return results;
|
||||
}
|
||||
|
||||
private void Write(bool inPlaceSave, ProgressBar progressBar, List<(string directory, string file, DateTime lastWriteTime, long length)[]> results)
|
||||
{
|
||||
string checkFile;
|
||||
string checkDirectory;
|
||||
@ -96,13 +123,17 @@ public class MirrorLength
|
||||
firstDirectory = collection.First().Directory;
|
||||
if (string.IsNullOrEmpty(firstDirectory))
|
||||
continue;
|
||||
checkDirectory = $"{_AppSettings.Destination}{firstDirectory[1..]}";
|
||||
if (Directory.Exists(checkDirectory))
|
||||
continue;
|
||||
_ = Directory.CreateDirectory(checkDirectory);
|
||||
checkDirectory = inPlaceSave ? firstDirectory : $"{_AppSettings.Destination}{firstDirectory[1..]}";
|
||||
if (!Directory.Exists(checkDirectory))
|
||||
_ = Directory.CreateDirectory(checkDirectory);
|
||||
else
|
||||
{
|
||||
if (!inPlaceSave)
|
||||
continue;
|
||||
}
|
||||
foreach ((string directory, string _, DateTime _, long _) in collection)
|
||||
{
|
||||
checkDirectory = $"{_AppSettings.Destination}{directory[1..]}";
|
||||
checkDirectory = inPlaceSave ? directory : $"{_AppSettings.Destination}{directory[1..]}";
|
||||
if (directories.Contains(checkDirectory))
|
||||
continue;
|
||||
directories.Add(checkDirectory);
|
||||
@ -111,7 +142,7 @@ public class MirrorLength
|
||||
}
|
||||
foreach ((string _, string file, DateTime lastWriteTime, long length) in collection)
|
||||
{
|
||||
checkFile = $"{_AppSettings.Destination}{file[1..]}len";
|
||||
checkFile = inPlaceSave ? $"{file}len" : $"{_AppSettings.Destination}{file[1..]}len";
|
||||
if (!Shared.Models.Stateless.Methods.IPath.WriteAllText(checkFile, length.ToString(), updateToWhenMatches: null, compareBeforeWrite: true, updateDateWhenMatches: false))
|
||||
continue;
|
||||
File.SetLastWriteTime(checkFile, lastWriteTime);
|
||||
@ -119,22 +150,77 @@ public class MirrorLength
|
||||
}
|
||||
}
|
||||
|
||||
private void Write(string today, List<(string directoryName, string subDirectoryName, int count)> collection)
|
||||
{
|
||||
string key;
|
||||
string text;
|
||||
string subKey;
|
||||
string checkFile;
|
||||
Dictionary<string, List<string>> directoryNameToCount = new();
|
||||
Dictionary<string, List<string>> subDirectoryNameToCount = new();
|
||||
foreach ((string directoryName, string subDirectoryName, int count) in collection)
|
||||
{
|
||||
key = directoryName.Replace(today, string.Empty).Replace(")", "-");
|
||||
subKey = subDirectoryName.Replace(today, string.Empty).Replace(") ", "-").Replace(" ", "-");
|
||||
if (!directoryNameToCount.ContainsKey(key))
|
||||
directoryNameToCount.Add(key, new() { "---", $"title: {key}", $"desc: '{directoryName}'", "---", string.Empty });
|
||||
if (count == 0)
|
||||
directoryNameToCount[key].Add($"- <00000000> '{subDirectoryName}'");
|
||||
else
|
||||
directoryNameToCount[key].Add($"- <{count:00000000}> [[{subKey}]]");
|
||||
if (!subDirectoryNameToCount.ContainsKey(subKey))
|
||||
subDirectoryNameToCount.Add(subKey, new() { "---", $"title: {subKey}", $"desc: '{subDirectoryName}'", "---", string.Empty });
|
||||
if (count == 0)
|
||||
subDirectoryNameToCount[subKey].Add($"- <00000000> '{directoryName}'");
|
||||
else
|
||||
subDirectoryNameToCount[subKey].Add($"- <{count:00000000}> [[{key}]]");
|
||||
}
|
||||
foreach (KeyValuePair<string, List<string>> keyValuePair in directoryNameToCount)
|
||||
{
|
||||
text = string.Join(Environment.NewLine, keyValuePair.Value);
|
||||
checkFile = Path.Combine(_PropertyConfiguration.RootDirectory, $"{keyValuePair.Key}.md");
|
||||
if (!Shared.Models.Stateless.Methods.IPath.WriteAllText(checkFile, text, updateToWhenMatches: null, compareBeforeWrite: true, updateDateWhenMatches: false))
|
||||
continue;
|
||||
}
|
||||
foreach (KeyValuePair<string, List<string>> keyValuePair in subDirectoryNameToCount)
|
||||
{
|
||||
text = string.Join(Environment.NewLine, keyValuePair.Value);
|
||||
checkFile = Path.Combine(_PropertyConfiguration.RootDirectory, $"{keyValuePair.Key}.md");
|
||||
if (!Shared.Models.Stateless.Methods.IPath.WriteAllText(checkFile, text, updateToWhenMatches: null, compareBeforeWrite: true, updateDateWhenMatches: false))
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
private List<string> MirrorLengthFilesInDirectories(ILogger log)
|
||||
{
|
||||
List<string> results = new();
|
||||
ProgressBar progressBar;
|
||||
const string fileSearchFilter = "*";
|
||||
string message = nameof(MirrorLength);
|
||||
const string directorySearchFilter = "*";
|
||||
List<string> distinctDirectories = new();
|
||||
List<string[]> filesCollection = Shared.Models.Stateless.Methods.IDirectory.GetFilesCollection(_PropertyConfiguration.RootDirectory, directorySearchFilter, fileSearchFilter);
|
||||
ProgressBarOptions options = new() { ProgressCharacter = '─', ProgressBarOnBottom = true, DisableBottomPercentage = true };
|
||||
progressBar = new(filesCollection.Count, message, options);
|
||||
List<(string, string, DateTime, long)[]> collection = GetToDoCollection(progressBar, filesCollection);
|
||||
progressBar.Dispose();
|
||||
progressBar = new(filesCollection.Count, message, options);
|
||||
Save(progressBar, collection);
|
||||
progressBar.Dispose();
|
||||
List<(string, string, int)> collectionForMarkDown;
|
||||
bool inPlaceSave = _PropertyConfiguration.RootDirectory.First() == _AppSettings.Destination;
|
||||
if (!inPlaceSave)
|
||||
collectionForMarkDown = new();
|
||||
else
|
||||
{
|
||||
string today = DateTime.Now.ToString("yyyy-MM-dd-");
|
||||
collectionForMarkDown = GetToDoCollectionForMarkDown(message, today);
|
||||
if (collectionForMarkDown.Any())
|
||||
Write(today, collectionForMarkDown);
|
||||
}
|
||||
if (!collectionForMarkDown.Any())
|
||||
{
|
||||
ProgressBar progressBar;
|
||||
const string fileSearchFilter = "*";
|
||||
const string directorySearchFilter = "*";
|
||||
List<string[]> filesCollection = Shared.Models.Stateless.Methods.IDirectory.GetFilesCollection(_PropertyConfiguration.RootDirectory, directorySearchFilter, fileSearchFilter);
|
||||
ProgressBarOptions options = new() { ProgressCharacter = '─', ProgressBarOnBottom = true, DisableBottomPercentage = true };
|
||||
progressBar = new(filesCollection.Count, message, options);
|
||||
List<(string, string, DateTime, long)[]> collection = GetToDoCollection(progressBar, filesCollection);
|
||||
progressBar.Dispose();
|
||||
progressBar = new(filesCollection.Count, message, options);
|
||||
if (collection.Any())
|
||||
Write(inPlaceSave, progressBar, collection);
|
||||
progressBar.Dispose();
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
|
@ -2,10 +2,10 @@ using System.Text.Json;
|
||||
|
||||
namespace View_by_Distance.Mirror.Length.Models;
|
||||
|
||||
public record AppSettings(string Company,
|
||||
char Destination,
|
||||
int MaxDegreeOfParallelism,
|
||||
string WorkingDirectoryName)
|
||||
public record AppSettings(string Company,
|
||||
char Destination,
|
||||
int MaxDegreeOfParallelism,
|
||||
string WorkingDirectoryName)
|
||||
{
|
||||
|
||||
public override string ToString()
|
||||
|
Reference in New Issue
Block a user