re-organized configurations - II
This commit is contained in:
@ -1,3 +1,5 @@
|
||||
using System.Collections.ObjectModel;
|
||||
|
||||
namespace View_by_Distance.Shared.Models.Stateless;
|
||||
|
||||
internal abstract class XPath
|
||||
@ -263,11 +265,12 @@ internal abstract class XPath
|
||||
}
|
||||
}
|
||||
|
||||
internal static (string, int) GetDirectoryNameAndIndex(int resultAllInOneSubdirectoryLength, string fileName)
|
||||
private static (string, int) GetDirectoryNameAndIndex(int resultAllInOneSubdirectoryLength, string fileNameWithoutExtension)
|
||||
{
|
||||
int converted;
|
||||
string result;
|
||||
string check = fileName.Length < resultAllInOneSubdirectoryLength ? new('-', resultAllInOneSubdirectoryLength) : fileName.Split('.')[0][^resultAllInOneSubdirectoryLength..];
|
||||
string fileNameBeforeFirst = fileNameWithoutExtension.Split('.')[0];
|
||||
string check = fileNameBeforeFirst.Length < resultAllInOneSubdirectoryLength ? new('-', resultAllInOneSubdirectoryLength) : fileNameBeforeFirst[^resultAllInOneSubdirectoryLength..];
|
||||
if (check.Any(l => !char.IsNumber(l)))
|
||||
{
|
||||
result = new('-', resultAllInOneSubdirectoryLength);
|
||||
@ -281,49 +284,97 @@ internal abstract class XPath
|
||||
return (result, converted);
|
||||
}
|
||||
|
||||
internal static Dictionary<string, string[]> GetKeyValuePairs(ResultConfiguration resultConfiguration, string? resultsFullGroupDirectory, string[]? directories)
|
||||
internal static (string, int) GetDirectoryNameAndIndex(ResultConfiguration resultConfiguration, int id)
|
||||
{
|
||||
Dictionary<string, string[]> results = [];
|
||||
(string result, int converted) = GetDirectoryNameAndIndex(resultConfiguration.ResultAllInOneSubdirectoryLength, id.ToString());
|
||||
return (result, converted);
|
||||
}
|
||||
|
||||
internal static (string, int) GetDirectoryNameAndIndex(ResultConfiguration resultConfiguration, FileHolder fileHolder)
|
||||
{
|
||||
(string result, int converted) = GetDirectoryNameAndIndex(resultConfiguration.ResultAllInOneSubdirectoryLength, fileHolder.NameWithoutExtension);
|
||||
return (result, converted);
|
||||
}
|
||||
|
||||
internal static (string, int) GetDirectoryNameAndIndex(ResultConfiguration resultConfiguration, FilePath filePath)
|
||||
{
|
||||
string result;
|
||||
int converted;
|
||||
if (filePath.Id is not null)
|
||||
(result, converted) = GetDirectoryNameAndIndex(resultConfiguration.ResultAllInOneSubdirectoryLength, filePath.Id.Value.ToString());
|
||||
else
|
||||
(result, converted) = GetDirectoryNameAndIndex(resultConfiguration.ResultAllInOneSubdirectoryLength, filePath.NameWithoutExtension);
|
||||
return (result, converted);
|
||||
}
|
||||
|
||||
private static ReadOnlyCollection<int> GetYears(ResultConfiguration resultConfiguration)
|
||||
{
|
||||
List<int> results = [];
|
||||
int currentYear = DateTime.Now.Year;
|
||||
for (int i = resultConfiguration.EpicYear; i < currentYear + 1; i++)
|
||||
results.Add(i);
|
||||
return new(results);
|
||||
}
|
||||
|
||||
private static ReadOnlyDictionary<int, ReadOnlyDictionary<string, string[]>> Convert(Dictionary<int, Dictionary<string, string[]>> collection)
|
||||
{
|
||||
Dictionary<int, ReadOnlyDictionary<string, string[]>> results = [];
|
||||
foreach (KeyValuePair<int, Dictionary<string, string[]>> keyValuePair in collection)
|
||||
results.Add(keyValuePair.Key, new(keyValuePair.Value));
|
||||
return new(results);
|
||||
}
|
||||
|
||||
internal static ReadOnlyDictionary<int, ReadOnlyDictionary<string, string[]>> GetKeyValuePairs(ResultConfiguration resultConfiguration, string? resultsFullGroupDirectory, string[]? directories)
|
||||
{
|
||||
Dictionary<int, Dictionary<string, string[]>> results = [];
|
||||
string directory;
|
||||
string checkDirectory;
|
||||
Dictionary<string, string[]>? keyValuePairs;
|
||||
ReadOnlyCollection<int> years = GetYears(resultConfiguration);
|
||||
int converted = int.Parse($"1{new string('0', resultConfiguration.ResultAllInOneSubdirectoryLength)}");
|
||||
int plusOne = converted + 1;
|
||||
List<string> collection = [];
|
||||
if (directories is not null)
|
||||
foreach (int year in years)
|
||||
{
|
||||
foreach (string key in directories)
|
||||
results.Add(year, []);
|
||||
if (!results.TryGetValue(year, out keyValuePairs))
|
||||
throw new NullReferenceException(nameof(keyValuePairs));
|
||||
if (directories is not null)
|
||||
{
|
||||
if (resultsFullGroupDirectory is null)
|
||||
continue;
|
||||
collection.Clear();
|
||||
for (int i = 0; i < plusOne; i++)
|
||||
foreach (string key in directories)
|
||||
{
|
||||
if (string.IsNullOrEmpty(key))
|
||||
if (resultsFullGroupDirectory is null)
|
||||
continue;
|
||||
collection.Clear();
|
||||
for (int i = 0; i < plusOne; i++)
|
||||
{
|
||||
if (i == converted)
|
||||
checkDirectory = Path.GetFullPath(Path.Combine(resultsFullGroupDirectory, new('-', resultConfiguration.ResultAllInOneSubdirectoryLength)));
|
||||
if (string.IsNullOrEmpty(key))
|
||||
{
|
||||
if (i == converted)
|
||||
checkDirectory = Path.GetFullPath(Path.Combine(resultsFullGroupDirectory, new('-', resultConfiguration.ResultAllInOneSubdirectoryLength)));
|
||||
else
|
||||
checkDirectory = Path.GetFullPath(Path.Combine(resultsFullGroupDirectory, i.ToString().PadLeft(resultConfiguration.ResultAllInOneSubdirectoryLength, '0')));
|
||||
}
|
||||
else
|
||||
checkDirectory = Path.GetFullPath(Path.Combine(resultsFullGroupDirectory, i.ToString().PadLeft(resultConfiguration.ResultAllInOneSubdirectoryLength, '0')));
|
||||
{
|
||||
directory = Path.Combine(resultsFullGroupDirectory, key, year.ToString());
|
||||
if (i == converted)
|
||||
checkDirectory = Path.GetFullPath(Path.Combine(directory, new('-', resultConfiguration.ResultAllInOneSubdirectoryLength)));
|
||||
else
|
||||
checkDirectory = Path.GetFullPath(Path.Combine(directory, i.ToString().PadLeft(resultConfiguration.ResultAllInOneSubdirectoryLength, '0')));
|
||||
}
|
||||
if (!Directory.Exists(checkDirectory))
|
||||
_ = Directory.CreateDirectory(checkDirectory);
|
||||
collection.Add(checkDirectory);
|
||||
}
|
||||
if (!string.IsNullOrEmpty(key))
|
||||
keyValuePairs.Add(key, collection.ToArray());
|
||||
else
|
||||
{
|
||||
directory = Path.Combine(resultsFullGroupDirectory, key, resultConfiguration.ResultAllInOne);
|
||||
if (i == converted)
|
||||
checkDirectory = Path.GetFullPath(Path.Combine(directory, new('-', resultConfiguration.ResultAllInOneSubdirectoryLength)));
|
||||
else
|
||||
checkDirectory = Path.GetFullPath(Path.Combine(directory, i.ToString().PadLeft(resultConfiguration.ResultAllInOneSubdirectoryLength, '0')));
|
||||
}
|
||||
if (!Directory.Exists(checkDirectory))
|
||||
_ = Directory.CreateDirectory(checkDirectory);
|
||||
collection.Add(checkDirectory);
|
||||
keyValuePairs.Add(year.ToString(), collection.ToArray());
|
||||
}
|
||||
if (!string.IsNullOrEmpty(key))
|
||||
results.Add(key, collection.ToArray());
|
||||
else
|
||||
results.Add(resultConfiguration.ResultAllInOne, collection.ToArray());
|
||||
}
|
||||
}
|
||||
return results;
|
||||
return Convert(results);
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user